2 # Copyright 2018 EveryUP Srl
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
22 from lib
.util
import Util
26 from requests
.packages
.urllib3
.exceptions
import InsecureRequestWarning
28 requests
.packages
.urllib3
.disable_warnings(InsecureRequestWarning
)
30 logging
.basicConfig(level
=logging
.INFO
)
31 log
= logging
.getLogger('helper.py')
32 logging
.getLogger("urllib3").setLevel(logging
.INFO
)
37 self
._token
_endpoint
= 'admin/v1/tokens'
38 self
._user
_endpoint
= 'admin/v1/users'
39 self
._host
= os
.getenv('OSM_SERVER', "localhost")
41 self
._base
_path
= 'https://{0}:{1}/osm'.format(self
._host
, self
._so
_port
)
44 result
= {'error': True, 'data': ''}
45 token_url
= "{0}/{1}".format(self
._base
_path
, self
._token
_endpoint
)
46 headers
= {"Content-Type": "application/yaml", "accept": "application/json"}
48 r
= requests
.post(token_url
, json
=args
, verify
=False, headers
=headers
)
49 except Exception as e
:
51 result
['data'] = str(e
)
53 if r
.status_code
in (200, 201, 202, 204):
54 result
['error'] = False
56 result
['data'] = Util
.json_loads_byteified(r
.text
)
60 def switch_project(self
, args
):
61 result
= {'error': True, 'data': ''}
62 token_url
= "{0}/{1}".format(self
._base
_path
, self
._token
_endpoint
)
63 headers
= {"Content-Type": "application/yaml", "accept": "application/json"}
65 r
= requests
.post(token_url
, json
=args
, verify
=False, headers
=headers
)
66 except Exception as e
:
68 result
['data'] = str(e
)
70 if r
.status_code
in (200, 201, 202, 204):
71 result
['error'] = False
73 result
['data'] = Util
.json_loads_byteified(r
.text
)
77 def role_list(self
, token
):
78 result
= {'error': True, 'data': ''}
79 headers
= {"Content-Type": "application/json", "accept": "application/json",
80 'Authorization': 'Bearer {}'.format(token
['id'])}
82 _url
= "{0}/admin/v1/roles".format(self
._base
_path
)
84 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
85 except Exception as e
:
87 result
['data'] = str(e
)
89 if r
.status_code
in (200, 201, 202, 204):
90 result
['error'] = False
91 result
['data'] = Util
.json_loads_byteified(r
.text
)
95 def role_create(self
, token
, role_data
):
96 result
= {'error': True, 'data': ''}
97 headers
= {"Content-Type": "application/json", "accept": "application/json",
98 'Authorization': 'Bearer {}'.format(token
['id'])}
99 _url
= "{0}/admin/v1/roles".format(self
._base
_path
)
102 r
= requests
.post(_url
, json
=role_data
, verify
=False, headers
=headers
)
103 except Exception as e
:
105 result
['data'] = str(e
)
107 if r
.status_code
in (200, 201, 202, 204):
108 result
['error'] = False
109 result
['data'] = Util
.json_loads_byteified(r
.text
)
112 def role_update(self
, token
, role_id
, role_data
):
113 result
= {'error': True, 'data': ''}
114 headers
= {"Content-Type": "application/json", "accept": "application/json",
115 'Authorization': 'Bearer {}'.format(token
['id'])}
116 _url
= "{0}/admin/v1/roles/{1}".format(self
._base
_path
, role_id
)
119 r
= requests
.put(_url
, json
=role_data
, verify
=False, headers
=headers
)
120 except Exception as e
:
122 result
['data'] = str(e
)
124 if r
.status_code
in (200, 201, 202, 204):
125 result
['error'] = False
127 result
['data'] = Util
.json_loads_byteified(r
.text
)
130 def role_delete(self
, token
, id, force
=None):
131 result
= {'error': True, 'data': ''}
132 headers
= {"Content-Type": "application/json", "accept": "application/json",
133 'Authorization': 'Bearer {}'.format(token
['id'])}
136 query_path
= '?FORCE=true'
137 _url
= "{0}/admin/v1/roles/{1}{2}".format(self
._base
_path
, id, query_path
)
139 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
140 except Exception as e
:
142 result
['data'] = str(e
)
144 if r
.status_code
in (200, 201, 202, 204):
145 result
['error'] = False
147 result
['data'] = Util
.json_loads_byteified(r
.text
)
150 def role_get(self
, token
, id):
151 result
= {'error': True, 'data': ''}
152 headers
= {"Content-Type": "application/json", "accept": "application/json",
153 'Authorization': 'Bearer {}'.format(token
['id'])}
155 _url
= "{0}/admin/v1/roles/{1}".format(self
._base
_path
, id)
157 r
= requests
.get(_url
, params
=None, verify
=False, headers
=headers
)
158 except Exception as e
:
160 result
['data'] = str(e
)
162 if r
.status_code
in (200, 201, 202, 204):
163 result
['error'] = False
164 result
['data'] = Util
.json_loads_byteified(r
.text
)
167 def user_list(self
, token
):
168 result
= {'error': True, 'data': ''}
169 headers
= {"Content-Type": "application/json", "accept": "application/json",
170 'Authorization': 'Bearer {}'.format(token
['id'])}
172 _url
= "{0}/admin/v1/users".format(self
._base
_path
)
174 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
175 except Exception as e
:
177 result
['data'] = str(e
)
179 if r
.status_code
in (200, 201, 202, 204):
180 result
['error'] = False
181 result
['data'] = Util
.json_loads_byteified(r
.text
)
185 def user_create(self
, token
, user_data
):
186 result
= {'error': True, 'data': ''}
187 headers
= {"Content-Type": "application/json", "accept": "application/json",
188 'Authorization': 'Bearer {}'.format(token
['id'])}
190 _url
= "{0}/admin/v1/users".format(self
._base
_path
)
193 r
= requests
.post(_url
, json
=user_data
, verify
=False, headers
=headers
)
194 except Exception as e
:
196 result
['data'] = str(e
)
198 if r
.status_code
in (200, 201, 202, 204):
199 result
['error'] = False
200 result
['data'] = Util
.json_loads_byteified(r
.text
)
203 def user_update(self
, token
, id, user_data
):
204 result
= {'error': True, 'data': ''}
205 headers
= {"Content-Type": "application/json", "accept": "application/json",
206 'Authorization': 'Bearer {}'.format(token
['id'])}
208 _url
= "{0}/admin/v1/users/{1}".format(self
._base
_path
, id)
210 r
= requests
.patch(_url
, json
=user_data
, verify
=False, headers
=headers
)
211 except Exception as e
:
213 result
['data'] = str(e
)
215 if r
.status_code
in (200, 201, 202, 204):
216 result
['error'] = False
218 result
['data'] = Util
.json_loads_byteified(r
.text
)
221 def user_delete(self
, token
, id):
222 result
= {'error': True, 'data': ''}
223 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
224 'Authorization': 'Bearer {}'.format(token
['id'])}
226 _url
= "{0}/admin/v1/users/{1}".format(self
._base
_path
, id)
228 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
229 except Exception as e
:
231 result
['data'] = str(e
)
233 if r
.status_code
in (200, 201, 202, 204):
234 result
['error'] = False
236 result
['data'] = Util
.json_loads_byteified(r
.text
)
239 def get_user_info(self
, token
, id):
240 result
= {'error': True, 'data': ''}
241 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
242 'Authorization': 'Bearer {}'.format(token
['id'])}
243 _url
= "{0}/admin/v1/users/{1}".format(self
._base
_path
, id)
245 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
246 except Exception as e
:
248 result
['data'] = str(e
)
250 if r
.status_code
in (200, 201, 202, 204):
251 result
['error'] = False
252 result
['data'] = Util
.json_loads_byteified(r
.text
)
255 def get_projects(self
, token
, uuids
):
256 result
= {'error': False, 'data': ''}
257 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
258 'Authorization': 'Bearer {}'.format(token
['id'])}
263 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, uuid
)
264 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
265 if r
.status_code
not in (200, 201, 202, 204):
267 projects
.append(Util
.json_loads_byteified(r
.text
))
268 except Exception as e
:
270 result
['error'] = True
271 result
['data'] = str(e
)
273 result
['data'] = projects
276 def project_list(self
, token
):
277 result
= {'error': True, 'data': ''}
278 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
279 'Authorization': 'Bearer {}'.format(token
['id'])}
281 _url
= "{0}/admin/v1/projects".format(self
._base
_path
)
283 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
284 except Exception as e
:
286 result
['data'] = str(e
)
288 if r
.status_code
in (200, 201, 202, 204):
289 result
['error'] = False
290 result
['data'] = Util
.json_loads_byteified(r
.text
)
294 def project_get(self
, token
, id):
295 result
= {'error': True, 'data': ''}
296 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
297 'Authorization': 'Bearer {}'.format(token
['id'])}
298 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
300 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
301 except Exception as e
:
303 result
['data'] = str(e
)
305 if r
.status_code
in (200, 201, 202, 204):
306 result
['error'] = False
307 result
['data'] = Util
.json_loads_byteified(r
.text
)
310 def project_create(self
, token
, project_data
):
312 result
= {'error': True, 'data': ''}
313 headers
= {"Content-Type": "application/json", "accept": "application/json",
314 'Authorization': 'Bearer {}'.format(token
['id'])}
316 _url
= "{0}/admin/v1/projects".format(self
._base
_path
)
319 r
= requests
.post(_url
, json
=project_data
, verify
=False, headers
=headers
)
320 except Exception as e
:
322 result
['data'] = str(e
)
324 if r
.status_code
in (200, 201, 202, 204):
325 result
['error'] = False
326 result
['data'] = Util
.json_loads_byteified(r
.text
)
329 def project_edit(self
, token
, id, project_data
):
331 result
= {'error': True, 'data': ''}
332 headers
= {"Content-Type": "application/json", "accept": "application/json",
333 'Authorization': 'Bearer {}'.format(token
['id'])}
335 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
338 r
= requests
.put(_url
, json
=project_data
, verify
=False, headers
=headers
)
339 except Exception as e
:
341 result
['data'] = str(e
)
343 if r
.status_code
in (200, 201, 202, 204):
344 result
['error'] = False
347 def project_delete(self
, token
, id):
348 result
= {'error': True, 'data': ''}
349 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
350 'Authorization': 'Bearer {}'.format(token
['id'])}
352 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
354 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
355 except Exception as e
:
357 result
['data'] = str(e
)
359 if r
.status_code
in (200, 201, 202, 204):
360 result
['error'] = False
362 result
['data'] = Util
.json_loads_byteified(r
.text
)
365 def nst_details(self
, token
, id):
366 result
= {'error': True, 'data': ''}
367 headers
= {"Content-Type": "application/json", "accept": "application/json",
368 'Authorization': 'Bearer {}'.format(token
['id'])}
369 _url
= "{0}/nst/v1/netslice_templates/{1}".format(self
._base
_path
,id)
371 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
372 except Exception as e
:
374 result
['data'] = str(e
)
376 if r
.status_code
in (200, 201, 202, 204):
377 result
['error'] = False
378 result
['data'] = Util
.json_loads_byteified(r
.text
)
382 def nst_content(self
, token
, id):
383 result
= {'error': True, 'data': ''}
384 headers
= {"Content-Type": "application/json", "accept": "text/plain",
385 'Authorization': 'Bearer {}'.format(token
['id'])}
386 _url
= "{0}/nst/v1/netslice_templates/{1}/nst".format(self
._base
_path
,id)
388 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
389 except Exception as e
:
391 result
['data'] = str(e
)
393 if r
.status_code
in (200, 201, 202, 204):
394 result
['error'] = False
395 result
['data'] = Util
.json2yaml(yaml
.load(str(r
.text
)))
399 def nst_list(self
, token
):
400 result
= {'error': True, 'data': ''}
401 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
402 'Authorization': 'Bearer {}'.format(token
['id'])}
404 _url
= "{0}/nst/v1/netslice_templates".format(self
._base
_path
)
406 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
407 except Exception as e
:
409 result
['data'] = str(e
)
411 if r
.status_code
in (200, 201, 202, 204):
412 result
['error'] = False
413 result
['data'] = Util
.json_loads_byteified(r
.text
)
417 def nsd_list(self
, token
, filter=None):
418 result
= {'error': True, 'data': ''}
419 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
420 'Authorization': 'Bearer {}'.format(token
['id'])}
423 query_path
= '?_admin.type='+filter
424 _url
= "{0}/nsd/v1/ns_descriptors_content{1}".format(self
._base
_path
, query_path
)
426 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
427 except Exception as e
:
429 result
['data'] = str(e
)
431 if r
.status_code
in (200, 201, 202, 204):
432 result
['error'] = False
433 result
['data'] = Util
.json_loads_byteified(r
.text
)
437 def vnfd_list(self
, token
, filter=None):
438 result
= {'error': True, 'data': ''}
439 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
440 'Authorization': 'Bearer {}'.format(token
['id'])}
443 query_path
= '?_admin.type='+filter
444 _url
= "{0}/vnfpkgm/v1/vnf_packages_content{1}".format(self
._base
_path
, query_path
)
446 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
447 except Exception as e
:
449 result
['data'] = str(e
)
451 if r
.status_code
in (200, 201, 202, 204):
452 result
['error'] = False
453 result
['data'] = Util
.json_loads_byteified(r
.text
)
457 def nsi_list(self
, token
):
458 result
= {'error': True, 'data': ''}
459 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
460 'Authorization': 'Bearer {}'.format(token
['id'])}
461 _url
= "{0}/nsilcm/v1/netslice_instances".format(self
._base
_path
)
463 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
464 except Exception as e
:
466 result
['data'] = str(e
)
468 if r
.status_code
in (200, 201, 202, 204):
469 result
['error'] = False
470 result
['data'] = Util
.json_loads_byteified(r
.text
)
474 def ns_list(self
, token
):
475 result
= {'error': True, 'data': ''}
476 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
477 'Authorization': 'Bearer {}'.format(token
['id'])}
478 _url
= "{0}/nslcm/v1/ns_instances_content".format(self
._base
_path
)
480 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
481 except Exception as e
:
483 result
['data'] = str(e
)
485 if r
.status_code
in (200, 201, 202, 204):
486 result
['error'] = False
487 result
['data'] = Util
.json_loads_byteified(r
.text
)
491 def vnf_list(self
, token
):
492 result
= {'error': True, 'data': ''}
493 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
494 'Authorization': 'Bearer {}'.format(token
['id'])}
495 _url
= "{0}/nslcm/v1/vnfrs".format(self
._base
_path
)
497 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
498 except Exception as e
:
500 result
['data'] = str(e
)
502 if r
.status_code
in (200, 201, 202, 204):
503 result
['error'] = False
504 result
['data'] = Util
.json_loads_byteified(r
.text
)
508 def pdu_list(self
, token
):
509 result
= {'error': True, 'data': ''}
510 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
511 'Authorization': 'Bearer {}'.format(token
['id'])}
512 _url
= "{0}/pdu/v1/pdu_descriptors".format(self
._base
_path
)
514 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
515 except Exception as e
:
517 result
['data'] = str(e
)
519 if r
.status_code
in (200, 201, 202, 204):
520 result
['error'] = False
521 result
['data'] = Util
.json_loads_byteified(r
.text
)
525 def nst_delete(self
, token
, id):
526 result
= {'error': True, 'data': ''}
527 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
528 'Authorization': 'Bearer {}'.format(token
['id'])}
530 _url
= "{0}/nst/v1/netslice_templates/{1}?FORCE=True".format(self
._base
_path
, id)
532 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
533 except Exception as e
:
535 result
['data'] = str(e
)
537 if r
.status_code
in (200, 201, 202, 204):
538 result
['error'] = False
542 def nsd_delete(self
, token
, id):
543 result
= {'error': True, 'data': ''}
544 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
545 'Authorization': 'Bearer {}'.format(token
['id'])}
547 _url
= "{0}/nsd/v1/ns_descriptors_content/{1}".format(self
._base
_path
, id)
549 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
550 except Exception as e
:
552 result
['data'] = str(e
)
555 result
['error'] = False
556 if r
.status_code
!= requests
.codes
.no_content
:
557 result
['data'] = Util
.json_loads_byteified(r
.text
)
560 def vnfd_delete(self
, token
, id):
561 result
= {'error': True, 'data': ''}
562 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
563 'Authorization': 'Bearer {}'.format(token
['id'])}
565 _url
= "{0}/vnfpkgm/v1/vnf_packages_content/{1}".format(self
._base
_path
, id)
567 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
568 except Exception as e
:
570 result
['data'] = str(e
)
573 result
['error'] = False
574 if r
.status_code
!= requests
.codes
.no_content
:
575 result
['data'] = Util
.json_loads_byteified(r
.text
)
578 def nst_onboard(self
, token
, template
):
579 result
= {'error': True, 'data': ''}
580 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
581 'Authorization': 'Bearer {}'.format(token
['id'])}
582 _url
= "{0}/nst/v1/netslice_templates_content".format(self
._base
_path
)
584 fileName
, fileExtension
= os
.path
.splitext(template
.name
)
585 if fileExtension
== '.gz':
586 headers
["Content-Type"] = "application/gzip"
588 headers
["Content-Type"] = "application/yaml"
589 r
= requests
.post(_url
, data
=template
, verify
=False, headers
=headers
)
590 except Exception as e
:
592 result
['data'] = str(e
)
594 if r
.status_code
in (200, 201, 202, 204):
595 result
['error'] = False
596 result
['data'] = Util
.json_loads_byteified(r
.text
)
599 def nsd_onboard(self
, token
, package
):
600 result
= {'error': True, 'data': ''}
601 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
602 'Authorization': 'Bearer {}'.format(token
['id'])}
603 with
open('/tmp/' + package
.name
, 'wb+') as destination
:
604 for chunk
in package
.chunks():
605 destination
.write(chunk
)
606 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + package
.name
, 'rb'))
607 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
609 r
= requests
.post(_url
, data
=open('/tmp/' + package
.name
, 'rb'), verify
=False, headers
=headers
)
610 except Exception as e
:
612 result
['data'] = str(e
)
614 if r
.status_code
in (200, 201, 202, 204):
615 result
['error'] = False
616 result
['data'] = Util
.json_loads_byteified(r
.text
)
619 def vnfd_onboard(self
, token
, package
):
620 result
= {'error': True, 'data': ''}
621 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
622 'Authorization': 'Bearer {}'.format(token
['id'])}
623 with
open('/tmp/' + package
.name
, 'wb+') as destination
:
624 for chunk
in package
.chunks():
625 destination
.write(chunk
)
626 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + package
.name
, 'rb'))
627 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
629 r
= requests
.post(_url
, data
=open('/tmp/' + package
.name
, 'rb'), verify
=False, headers
=headers
)
630 except Exception as e
:
632 result
['data'] = str(e
)
634 if r
.status_code
in (200, 201, 202, 204):
635 result
['error'] = False
636 result
['data'] = Util
.json_loads_byteified(r
.text
)
639 def nsd_create_pkg_base(self
, token
, pkg_name
):
640 result
= {'error': True, 'data': ''}
641 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
642 'Authorization': 'Bearer {}'.format(token
['id'])}
644 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
647 self
._create
_base
_pkg
('nsd', pkg_name
)
648 headers
['Content-Filename'] = pkg_name
+ '.tar.gz'
649 r
= requests
.post(_url
, data
=open('/tmp/' + pkg_name
+ '.tar.gz', 'rb'), verify
=False, headers
=headers
)
650 except Exception as e
:
652 result
['data'] = str(e
)
654 if r
.status_code
in (200, 201, 202, 204):
655 result
['data'] = r
.json()
656 result
['error'] = False
657 if r
.status_code
== requests
.codes
.conflict
:
658 result
['data'] = "Invalid ID."
661 def vnfd_create_pkg_base(self
, token
, pkg_name
):
662 result
= {'error': True, 'data': ''}
663 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
664 'Authorization': 'Bearer {}'.format(token
['id'])}
666 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
669 self
._create
_base
_pkg
('vnfd', pkg_name
)
670 r
= requests
.post(_url
, data
=open('/tmp/' + pkg_name
+ '.tar.gz', 'rb'), verify
=False, headers
=headers
)
671 except Exception as e
:
673 result
['data'] = str(e
)
675 if r
.status_code
in (200, 201, 202, 204):
676 result
['data'] = r
.json()
677 result
['error'] = False
678 if r
.status_code
== requests
.codes
.conflict
:
679 result
['data'] = "Invalid ID."
682 def nsd_clone(self
, token
, id):
683 result
= {'error': True, 'data': ''}
684 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
685 'Authorization': 'Bearer {}'.format(token
['id'])}
687 # get the package onboarded
688 tar_pkg
= self
.get_nsd_pkg(token
, id)
689 tarf
= tarfile
.open(fileobj
=tar_pkg
)
690 tarf
= self
._descriptor
_clone
(tarf
, 'nsd')
691 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'))
693 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
696 r
= requests
.post(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'), verify
=False,
698 except Exception as e
:
700 result
['data'] = str(e
)
702 if r
.status_code
in (200, 201, 202, 204):
703 result
['error'] = False
704 if r
.status_code
== requests
.codes
.conflict
:
705 result
['data'] = "Invalid ID."
709 def vnfd_clone(self
, token
, id):
710 result
= {'error': True, 'data': ''}
711 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
712 'Authorization': 'Bearer {}'.format(token
['id'])}
714 # get the package onboarded
715 tar_pkg
= self
.get_vnfd_pkg(token
, id)
716 tarf
= tarfile
.open(fileobj
=tar_pkg
)
718 tarf
= self
._descriptor
_clone
(tarf
, 'vnfd')
719 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'))
721 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
724 r
= requests
.post(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'), verify
=False,
726 except Exception as e
:
728 result
['data'] = str(e
)
730 if r
.status_code
in (200, 201, 202, 204):
731 result
['error'] = False
732 if r
.status_code
== requests
.codes
.conflict
:
733 result
['data'] = "Invalid ID."
737 def nst_content_update(self
, token
, id, template
):
738 result
= {'error': True, 'data': ''}
739 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
740 'Authorization': 'Bearer {}'.format(token
['id'])}
741 _url
= "{0}/nst/v1/netslice_templates/{1}/nst_content".format(self
._base
_path
,id)
743 r
= requests
.put(_url
, data
=template
, verify
=False, headers
=headers
)
744 except Exception as e
:
746 result
['data'] = str(e
)
748 if r
.status_code
in (200, 201, 202, 204):
749 result
['error'] = False
752 def nsd_update(self
, token
, id, data
):
753 result
= {'error': True, 'data': ''}
754 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
755 'Authorization': 'Bearer {}'.format(token
['id'])}
757 # get the package onboarded
758 tar_pkg
= self
.get_nsd_pkg(token
, id)
759 tarf
= tarfile
.open(fileobj
=tar_pkg
)
761 tarf
= self
._descriptor
_update
(tarf
, data
)
762 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
764 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self
._base
_path
, id)
767 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
769 except Exception as e
:
771 result
['data'] = str(e
)
773 if r
.status_code
in (200, 201, 202, 204):
774 result
['error'] = False
777 result
['data'] = r
.json()
778 except Exception as e
:
783 def vnfd_update(self
, token
, id, data
):
784 result
= {'error': True, 'data': ''}
785 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
786 'Authorization': 'Bearer {}'.format(token
['id'])}
788 # get the package onboarded
789 tar_pkg
= self
.get_vnfd_pkg(token
, id)
790 tarf
= tarfile
.open(fileobj
=tar_pkg
)
792 tarf
= self
._descriptor
_update
(tarf
, data
)
793 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
795 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self
._base
_path
, id)
798 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
800 except Exception as e
:
802 result
['data'] = str(e
)
804 if r
.status_code
in (200, 201, 202, 204):
805 result
['error'] = False
808 result
['data'] = r
.json()
809 except Exception as e
:
814 def get_nsd_pkg(self
, token
, id):
815 result
= {'error': True, 'data': ''}
816 headers
= {"accept": "application/zip",
817 'Authorization': 'Bearer {}'.format(token
['id'])}
819 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self
._base
_path
, id)
821 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
822 except Exception as e
:
824 result
['data'] = str(e
)
826 if r
.status_code
in (200, 201, 202, 204):
827 result
['error'] = False
828 tarf
= StringIO
.StringIO(r
.content
)
832 def get_vnfd_pkg(self
, token
, id):
833 result
= {'error': True, 'data': ''}
834 headers
= {"accept": "application/zip",
835 'Authorization': 'Bearer {}'.format(token
['id'])}
836 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self
._base
_path
, id)
838 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
839 except Exception as e
:
841 result
['data'] = str(e
)
843 if r
.status_code
in (200, 201, 202, 204):
844 result
['error'] = False
845 tarf
= StringIO
.StringIO(r
.content
)
849 def _descriptor_update(self
, tarf
, data
):
850 # extract the package on a tmp directory
851 tarf
.extractall('/tmp')
852 regex
= re
.compile(r
"^[^/]+(/[^/]+\.(yaml|yml))$", re
.U
)
853 for name
in tarf
.getnames():
854 if regex
.match(name
):
855 with
open('/tmp/' + name
, 'w') as outfile
:
856 yaml
.safe_dump(data
, outfile
, default_flow_style
=False)
859 tarf_temp
= tarfile
.open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", "w:gz")
862 tarf_temp
.add('/tmp/' + tarinfo
.name
, tarinfo
.name
, recursive
=False)
866 def _create_base_pkg(self
, descriptor_type
, pkg_name
):
867 filename
= '/tmp/'+pkg_name
+'/' + pkg_name
+ '.yaml'
868 if descriptor_type
== 'nsd':
873 "short-name": str(pkg_name
),
874 "vendor": "OSM Composer",
875 "description": str(pkg_name
) + " descriptor",
877 "constituent-vnfd": [],
880 "name": str(pkg_name
)
886 elif descriptor_type
== 'vnfd':
888 "vnfd:vnfd-catalog": {
891 "short-name": str(pkg_name
),
900 "connection-point": [],
901 "name": str(pkg_name
)
907 if not os
.path
.exists(os
.path
.dirname(filename
)):
909 os
.makedirs(os
.path
.dirname(filename
))
910 except OSError as exc
: # Guard against race condition
911 if exc
.errno
!= errno
.EEXIST
:
914 with
open('/tmp/' + pkg_name
+ '/' + pkg_name
+ '.yaml', 'w') as yaml_file
:
915 yaml_file
.write(yaml
.dump(descriptor
, default_flow_style
=False))
917 tarf_temp
= tarfile
.open('/tmp/' + pkg_name
+ '.tar.gz', "w:gz")
918 tarf_temp
.add('/tmp/'+pkg_name
+'/' + pkg_name
+ '.yaml', pkg_name
+ '/' + pkg_name
+ '.yaml', recursive
=False)
921 def _descriptor_clone(self
, tarf
, descriptor_type
):
922 # extract the package on a tmp directory
923 tarf
.extractall('/tmp')
925 for name
in tarf
.getnames():
926 if name
.endswith(".yaml") or name
.endswith(".yml"):
927 with
open('/tmp/' + name
, 'r') as outfile
:
928 yaml_object
= yaml
.load(outfile
)
930 if descriptor_type
== 'nsd':
931 nsd_list
= yaml_object
['nsd:nsd-catalog']['nsd']
933 nsd
['id'] = 'clone_' + nsd
['id']
934 nsd
['name'] = 'clone_' + nsd
['name']
935 nsd
['short-name'] = 'clone_' + nsd
['short-name']
936 elif descriptor_type
== 'vnfd':
937 vnfd_list
= yaml_object
['vnfd:vnfd-catalog']['vnfd']
938 for vnfd
in vnfd_list
:
939 vnfd
['id'] = 'clone_' + vnfd
['id']
940 vnfd
['name'] = 'clone_' + vnfd
['name']
941 vnfd
['short-name'] = 'clone_' + vnfd
['short-name']
943 with
open('/tmp/' + name
, 'w') as yaml_file
:
944 yaml_file
.write(yaml
.dump(yaml_object
, default_flow_style
=False))
947 tarf_temp
= tarfile
.open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", "w:gz")
950 tarf_temp
.add('/tmp/' + tarinfo
.name
, tarinfo
.name
, recursive
=False)
954 def nsd_get(self
, token
, id):
955 result
= {'error': True, 'data': ''}
956 headers
= {'Content-Type': 'application/yaml',
957 'Authorization': 'Bearer {}'.format(token
['id'])}
958 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd".format(self
._base
_path
, id)
960 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
961 except Exception as e
:
963 result
['data'] = str(e
)
965 if r
.status_code
in (200, 201, 202, 204):
966 result
['error'] = False
967 return yaml
.load(r
.text
)
970 result
['data'] = r
.json()
971 except Exception as e
:
975 def vnfd_get(self
, token
, id):
976 result
= {'error': True, 'data': ''}
977 headers
= {'Content-Type': 'application/yaml',
978 'Authorization': 'Bearer {}'.format(token
['id'])}
979 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/vnfd".format(self
._base
_path
, id)
981 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
982 except Exception as e
:
984 result
['data'] = str(e
)
986 if r
.status_code
in (200, 201, 202, 204):
987 result
['error'] = False
988 return yaml
.load(r
.text
)
991 result
['data'] = r
.json()
992 except Exception as e
:
996 def nsd_artifacts(self
, token
, id):
997 result
= {'error': True, 'data': ''}
998 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
999 'Authorization': 'Bearer {}'.format(token
['id'])}
1000 _url
= "{0}/nsd/v1/ns_descriptors/{1}/artifacts".format(self
._base
_path
, id)
1002 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1003 except Exception as e
:
1005 result
['data'] = str(e
)
1007 if r
.status_code
in (200, 201, 202, 204):
1008 result
['error'] = False
1009 result
['data'] = r
.text
1012 result
['data'] = r
.json()
1013 except Exception as e
:
1018 def vnf_packages_artifacts(self
, token
, id):
1019 result
= {'error': True, 'data': ''}
1020 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
1021 'Authorization': 'Bearer {}'.format(token
['id'])}
1022 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/artifacts".format(self
._base
_path
, id)
1024 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1025 except Exception as e
:
1027 result
['data'] = str(e
)
1029 if r
.status_code
in (200, 201, 202, 204):
1030 result
['error'] = False
1031 result
['data'] = r
.text
1034 result
['data'] = r
.json()
1035 except Exception as e
:
1040 def nsi_create(self
, token
, nsi_data
):
1041 result
= {'error': True, 'data': ''}
1042 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1043 'Authorization': 'Bearer {}'.format(token
['id'])}
1045 _url
= "{0}/nsilcm/v1/netslice_instances_content".format(self
._base
_path
)
1048 r
= requests
.post(_url
, json
=nsi_data
, verify
=False, headers
=headers
)
1049 except Exception as e
:
1051 result
['data'] = str(e
)
1053 if r
.status_code
in (200, 201, 202, 204):
1054 result
['error'] = False
1055 result
['data'] = Util
.json_loads_byteified(r
.text
)
1058 def ns_create(self
, token
, ns_data
):
1059 result
= {'error': True, 'data': ''}
1060 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1061 'Authorization': 'Bearer {}'.format(token
['id'])}
1063 _url
= "{0}/nslcm/v1/ns_instances_content".format(self
._base
_path
)
1066 r
= requests
.post(_url
, json
=ns_data
, verify
=False, headers
=headers
)
1067 except Exception as e
:
1069 result
['data'] = str(e
)
1071 if r
.status_code
in (200, 201, 202, 204):
1072 result
['error'] = False
1073 result
['data'] = Util
.json_loads_byteified(r
.text
)
1076 def pdu_create(self
, token
, pdu_data
):
1077 result
= {'error': True, 'data': ''}
1078 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1079 'Authorization': 'Bearer {}'.format(token
['id'])}
1081 _url
= "{0}/pdu/v1/pdu_descriptors".format(self
._base
_path
)
1084 r
= requests
.post(_url
, json
=pdu_data
, verify
=False, headers
=headers
)
1085 except Exception as e
:
1087 result
['data'] = str(e
)
1089 if r
.status_code
in (200, 201, 202, 204):
1090 result
['error'] = False
1091 result
['data'] = Util
.json_loads_byteified(r
.text
)
1094 def ns_op_list(self
, token
, id):
1095 result
= {'error': True, 'data': ''}
1096 headers
= {"Content-Type": "application/json", "accept": "application/json",
1097 'Authorization': 'Bearer {}'.format(token
['id'])}
1098 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/?nsInstanceId={1}".format(self
._base
_path
, id)
1101 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1102 except Exception as e
:
1104 result
['data'] = str(e
)
1106 if r
.status_code
in (200, 201, 202, 204):
1107 result
['error'] = False
1108 result
['data'] = Util
.json_loads_byteified(r
.text
)
1112 def nsi_op_list(self
, token
, id):
1113 result
= {'error': True, 'data': ''}
1114 headers
= {"Content-Type": "application/json", "accept": "application/json",
1115 'Authorization': 'Bearer {}'.format(token
['id'])}
1116 _url
= "{0}/nsilcm/v1/nsi_lcm_op_occs/?netsliceInstanceId={1}".format(self
._base
_path
, id)
1119 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1120 except Exception as e
:
1122 result
['data'] = str(e
)
1124 if r
.status_code
in (200, 201, 202, 204):
1125 result
['error'] = False
1126 result
['data'] = Util
.json_loads_byteified(r
.text
)
1130 def ns_op(self
, token
, id):
1131 result
= {'error': True, 'data': ''}
1132 headers
= {"Content-Type": "application/json", "accept": "application/json",
1133 'Authorization': 'Bearer {}'.format(token
['id'])}
1134 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/{1}".format(self
._base
_path
, id)
1137 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1138 except Exception as e
:
1140 result
['data'] = str(e
)
1142 if r
.status_code
in (200, 201, 202, 204):
1143 result
['error'] = False
1144 result
['data'] = Util
.json_loads_byteified(r
.text
)
1148 def ns_action(self
, token
, id, action_payload
):
1149 result
= {'error': True, 'data': ''}
1150 headers
= {"Content-Type": "application/json", "accept": "application/json",
1151 'Authorization': 'Bearer {}'.format(token
['id'])}
1153 _url
= "{0}/nslcm/v1/ns_instances/{1}/action".format(self
._base
_path
, id)
1156 r
= requests
.post(_url
, json
=action_payload
, verify
=False, headers
=headers
)
1157 except Exception as e
:
1159 result
['data'] = str(e
)
1161 if r
.status_code
in (200, 201, 202, 204):
1162 result
['error'] = False
1163 result
['data'] = Util
.json_loads_byteified(r
.text
)
1166 def nsi_delete(self
, token
, id, force
=None):
1167 result
= {'error': True, 'data': ''}
1168 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1169 'Authorization': 'Bearer {}'.format(token
['id'])}
1172 query_path
= '?FORCE=true'
1173 _url
= "{0}/nsilcm/v1/netslice_instances_content/{1}{2}".format(self
._base
_path
, id, query_path
)
1175 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1176 except Exception as e
:
1178 result
['data'] = str(e
)
1181 result
['error'] = False
1182 if r
.status_code
!= requests
.codes
.no_content
:
1183 result
['data'] = Util
.json_loads_byteified(r
.text
)
1186 def ns_delete(self
, token
, id, force
=None):
1187 result
= {'error': True, 'data': ''}
1188 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1189 'Authorization': 'Bearer {}'.format(token
['id'])}
1192 query_path
= '?FORCE=true'
1193 _url
= "{0}/nslcm/v1/ns_instances_content/{1}{2}".format(self
._base
_path
, id, query_path
)
1195 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1196 except Exception as e
:
1198 result
['data'] = str(e
)
1201 result
['error'] = False
1202 if r
.status_code
!= requests
.codes
.no_content
:
1203 result
['data'] = Util
.json_loads_byteified(r
.text
)
1206 def pdu_delete(self
, token
, id):
1207 result
= {'error': True, 'data': ''}
1208 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1209 'Authorization': 'Bearer {}'.format(token
['id'])}
1210 _url
= "{0}/pdu/v1/pdu_descriptors/{1}".format(self
._base
_path
, id)
1212 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1213 except Exception as e
:
1215 result
['data'] = str(e
)
1218 result
['error'] = False
1219 if r
.status_code
!= requests
.codes
.no_content
:
1220 result
['data'] = Util
.json_loads_byteified(r
.text
)
1223 def nsi_get(self
, token
, id):
1224 result
= {'error': True, 'data': ''}
1225 headers
= {"Content-Type": "application/json", "accept": "application/json",
1226 'Authorization': 'Bearer {}'.format(token
['id'])}
1227 _url
= "{0}/nsilcm/v1/netslice_instances/{1}".format(self
._base
_path
, id)
1230 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1231 except Exception as e
:
1233 result
['data'] = str(e
)
1235 if r
.status_code
in (200, 201, 202, 204):
1236 result
['error'] = False
1237 result
['data'] = Util
.json_loads_byteified(r
.text
)
1240 def ns_get(self
, token
, id):
1241 result
= {'error': True, 'data': ''}
1242 headers
= {"Content-Type": "application/json", "accept": "application/json",
1243 'Authorization': 'Bearer {}'.format(token
['id'])}
1244 _url
= "{0}/nslcm/v1/ns_instances_content/{1}".format(self
._base
_path
, id)
1247 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1248 except Exception as e
:
1250 result
['data'] = str(e
)
1252 if r
.status_code
in (200, 201, 202, 204):
1253 result
['error'] = False
1254 result
['data'] = Util
.json_loads_byteified(r
.text
)
1257 def vnf_get(self
, token
, id):
1258 result
= {'error': True, 'data': ''}
1259 headers
= {"Content-Type": "application/json", "accept": "application/json",
1260 'Authorization': 'Bearer {}'.format(token
['id'])}
1261 _url
= "{0}/nslcm/v1/vnfrs/{1}".format(self
._base
_path
, id)
1264 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1265 except Exception as e
:
1267 result
['data'] = str(e
)
1269 if r
.status_code
in (200, 201, 202, 204):
1270 result
['error'] = False
1271 result
['data'] = Util
.json_loads_byteified(r
.text
)
1274 def pdu_get(self
, token
, id):
1275 result
= {'error': True, 'data': ''}
1276 headers
= {"Content-Type": "application/json", "accept": "application/json",
1277 'Authorization': 'Bearer {}'.format(token
['id'])}
1278 _url
= "{0}/pdu/v1/pdu_descriptors/{1}".format(self
._base
_path
, id)
1281 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1282 except Exception as e
:
1284 result
['data'] = str(e
)
1286 if r
.status_code
in (200, 201, 202, 204):
1287 result
['error'] = False
1288 result
['data'] = Util
.json_loads_byteified(r
.text
)
1291 def ns_alarm_create(self
, token
, id, alarm_payload
):
1292 result
= {'error': True, 'data': ''}
1293 headers
= {"Content-Type": "application/json",
1294 'Authorization': 'Bearer {}'.format(token
['id'])}
1295 _url
= "{0}/test/message/alarm_request".format(self
._base
_path
)
1297 r
= requests
.post(_url
, json
=alarm_payload
, verify
=False, headers
=headers
)
1298 except Exception as e
:
1300 result
['data'] = str(e
)
1302 if r
.status_code
in (200, 201, 202, 204):
1303 result
['error'] = False
1304 # result['data'] = Util.json_loads_byteified(r.text)
1305 result
['data'] = r
.text
1308 def ns_metric_export(self
, token
, id, metric_payload
):
1309 result
= {'error': True, 'data': ''}
1310 headers
= {"Content-Type": "application/json",
1311 'Authorization': 'Bearer {}'.format(token
['id'])}
1312 _url
= "{0}/test/message/metric_request".format(self
._base
_path
)
1314 r
= requests
.post(_url
, json
=metric_payload
, verify
=False, headers
=headers
)
1315 except Exception as e
:
1317 result
['data'] = str(e
)
1319 if r
.status_code
in (200, 201, 202, 204):
1320 result
['error'] = False
1321 # result['data'] = Util.json_loads_byteified(r.text)
1322 result
['data'] = r
.text
1325 def wim_list(self
, token
):
1326 result
= {'error': True, 'data': ''}
1327 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1328 'Authorization': 'Bearer {}'.format(token
['id'])}
1329 _url
= "{0}/admin/v1/wim_accounts".format(self
._base
_path
)
1331 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1332 except Exception as e
:
1334 result
['data'] = str(e
)
1336 if r
.status_code
in (200, 201, 202, 204):
1337 result
['error'] = False
1338 result
['data'] = Util
.json_loads_byteified(r
.text
)
1342 def vim_list(self
, token
):
1343 result
= {'error': True, 'data': ''}
1344 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1345 'Authorization': 'Bearer {}'.format(token
['id'])}
1346 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
1348 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1349 except Exception as e
:
1351 result
['data'] = str(e
)
1353 if r
.status_code
in (200, 201, 202, 204):
1354 result
['error'] = False
1355 result
['data'] = Util
.json_loads_byteified(r
.text
)
1359 def wim_delete(self
, token
, id):
1360 result
= {'error': True, 'data': ''}
1361 headers
= {"accept": "application/json",
1362 'Authorization': 'Bearer {}'.format(token
['id'])}
1363 _url
= "{0}/admin/v1/wim_accounts/{1}".format(self
._base
_path
, id)
1365 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1366 except Exception as e
:
1368 result
['data'] = str(e
)
1370 if r
.status_code
in (200, 201, 202, 204):
1371 result
['error'] = False
1373 result
['data'] = r
.text
1376 def vim_delete(self
, token
, id):
1377 result
= {'error': True, 'data': ''}
1378 headers
= {"accept": "application/json",
1379 'Authorization': 'Bearer {}'.format(token
['id'])}
1380 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
1382 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1383 except Exception as e
:
1385 result
['data'] = str(e
)
1387 if r
.status_code
in (200, 201, 202, 204):
1388 result
['error'] = False
1390 result
['data'] = r
.text
1393 def wim_get(self
, token
, id):
1395 result
= {'error': True, 'data': ''}
1396 headers
= {"Content-Type": "application/json", "accept": "application/json",
1397 'Authorization': 'Bearer {}'.format(token
['id'])}
1398 _url
= "{0}/admin/v1/wim_accounts/{1}".format(self
._base
_path
, id)
1401 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1402 except Exception as e
:
1404 result
['data'] = str(e
)
1406 if r
.status_code
in (200, 201, 202, 204):
1407 result
['error'] = False
1408 result
['data'] = Util
.json_loads_byteified(r
.text
)
1411 def vim_get(self
, token
, id):
1413 result
= {'error': True, 'data': ''}
1414 headers
= {"Content-Type": "application/json", "accept": "application/json",
1415 'Authorization': 'Bearer {}'.format(token
['id'])}
1416 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
1419 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1420 except Exception as e
:
1422 result
['data'] = str(e
)
1424 if r
.status_code
in (200, 201, 202, 204):
1425 result
['error'] = False
1426 result
['data'] = Util
.json_loads_byteified(r
.text
)
1429 def wim_create(self
, token
, wim_data
):
1430 result
= {'error': True, 'data': ''}
1431 headers
= {"Content-Type": "application/json", "accept": "application/json",
1432 'Authorization': 'Bearer {}'.format(token
['id'])}
1434 _url
= "{0}/admin/v1/wim_accounts".format(self
._base
_path
)
1437 r
= requests
.post(_url
, json
=wim_data
, verify
=False, headers
=headers
)
1438 except Exception as e
:
1440 result
['data'] = str(e
)
1442 if r
.status_code
in (200, 201, 202, 204):
1443 result
['error'] = False
1444 result
['data'] = Util
.json_loads_byteified(r
.text
)
1447 def vim_create(self
, token
, vim_data
):
1449 result
= {'error': True, 'data': ''}
1450 headers
= {"Content-Type": "application/json", "accept": "application/json",
1451 'Authorization': 'Bearer {}'.format(token
['id'])}
1453 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
1456 r
= requests
.post(_url
, json
=vim_data
, verify
=False, headers
=headers
)
1457 except Exception as e
:
1459 result
['data'] = str(e
)
1461 if r
.status_code
in (200, 201, 202, 204):
1462 result
['error'] = False
1463 result
['data'] = Util
.json_loads_byteified(r
.text
)
1466 def sdn_list(self
, token
):
1467 result
= {'error': True, 'data': ''}
1468 headers
= {"accept": "application/json",
1469 'Authorization': 'Bearer {}'.format(token
['id'])}
1470 _url
= "{0}/admin/v1/sdns".format(self
._base
_path
)
1472 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1473 except Exception as e
:
1475 result
['data'] = str(e
)
1477 if r
.status_code
in (200, 201, 202, 204):
1478 result
['error'] = False
1479 result
['data'] = Util
.json_loads_byteified(r
.text
)
1482 def sdn_delete(self
, token
, id):
1483 result
= {'error': True, 'data': ''}
1484 headers
= {"accept": "application/json",
1485 'Authorization': 'Bearer {}'.format(token
['id'])}
1486 _url
= "{0}/admin/v1/sdns/{1}".format(self
._base
_path
, id)
1488 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1489 except Exception as e
:
1491 result
['data'] = str(e
)
1493 if r
.status_code
in (200, 201, 202, 204):
1494 result
['error'] = False
1496 result
['data'] = r
.text
1499 def sdn_get(self
, token
, id):
1500 result
= {'error': True, 'data': ''}
1501 headers
= {"accept": "application/json",
1502 'Authorization': 'Bearer {}'.format(token
['id'])}
1503 _url
= "{0}/admin/v1/sdns/{1}".format(self
._base
_path
, id)
1506 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1507 except Exception as e
:
1509 result
['data'] = str(e
)
1511 if r
.status_code
in (200, 201, 202, 204):
1512 result
['error'] = False
1513 result
['data'] = Util
.json_loads_byteified(r
.text
)
1516 def sdn_create(self
, token
, sdn_data
):
1517 result
= {'error': True, 'data': ''}
1518 headers
= {"Content-Type": "application/json", "accept": "application/json",
1519 'Authorization': 'Bearer {}'.format(token
['id'])}
1521 _url
= "{0}/admin/v1/sdns".format(self
._base
_path
)
1524 r
= requests
.post(_url
, json
=sdn_data
, verify
=False, headers
=headers
)
1525 except Exception as e
:
1527 result
['data'] = str(e
)
1529 if r
.status_code
in (200, 201, 202, 204):
1530 result
['error'] = False
1531 result
['data'] = Util
.json_loads_byteified(r
.text
)
1536 hash_md5
= hashlib
.md5()
1537 for chunk
in iter(lambda: f
.read(1024), b
""):
1538 hash_md5
.update(chunk
)
1539 return hash_md5
.hexdigest()