95b4b972e4f564ca4d17c503440a7372ebd3fdcb
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
25 from requests
.packages
.urllib3
.exceptions
import InsecureRequestWarning
27 requests
.packages
.urllib3
.disable_warnings(InsecureRequestWarning
)
29 logging
.basicConfig(level
=logging
.INFO
)
30 log
= logging
.getLogger('helper.py')
31 logging
.getLogger("urllib3").setLevel(logging
.INFO
)
36 self
._token
_endpoint
= 'admin/v1/tokens'
37 self
._user
_endpoint
= 'admin/v1/users'
38 self
._host
= os
.getenv('OSM_SERVER', "localhost")
40 self
._base
_path
= 'https://{0}:{1}/osm'.format(self
._host
, self
._so
_port
)
43 result
= {'error': True, 'data': ''}
44 token_url
= "{0}/{1}".format(self
._base
_path
, self
._token
_endpoint
)
45 headers
= {"Content-Type": "application/yaml", "accept": "application/json"}
47 r
= requests
.post(token_url
, json
=args
, verify
=False, headers
=headers
)
48 except Exception as e
:
50 result
['data'] = str(e
)
52 if r
.status_code
in (200, 201, 202, 204):
53 result
['error'] = False
55 result
['data'] = Util
.json_loads_byteified(r
.text
)
59 def switch_project(self
, args
):
60 result
= {'error': True, 'data': ''}
61 token_url
= "{0}/{1}".format(self
._base
_path
, self
._token
_endpoint
)
62 headers
= {"Content-Type": "application/yaml", "accept": "application/json"}
64 r
= requests
.post(token_url
, json
=args
, verify
=False, headers
=headers
)
65 except Exception as e
:
67 result
['data'] = str(e
)
69 if r
.status_code
in (200, 201, 202, 204):
70 result
['error'] = False
72 result
['data'] = Util
.json_loads_byteified(r
.text
)
76 def role_list(self
, token
):
77 result
= {'error': True, 'data': ''}
78 headers
= {"Content-Type": "application/json", "accept": "application/json",
79 'Authorization': 'Bearer {}'.format(token
['id'])}
81 _url
= "{0}/admin/v1/roles".format(self
._base
_path
)
83 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
84 except Exception as e
:
86 result
['data'] = str(e
)
88 if r
.status_code
in (200, 201, 202, 204):
89 result
['error'] = False
90 result
['data'] = Util
.json_loads_byteified(r
.text
)
94 def role_create(self
, token
, role_data
):
95 result
= {'error': True, 'data': ''}
96 headers
= {"Content-Type": "application/json", "accept": "application/json",
97 'Authorization': 'Bearer {}'.format(token
['id'])}
98 _url
= "{0}/admin/v1/roles".format(self
._base
_path
)
101 r
= requests
.post(_url
, json
=role_data
, verify
=False, headers
=headers
)
102 except Exception as e
:
104 result
['data'] = str(e
)
106 if r
.status_code
in (200, 201, 202, 204):
107 result
['error'] = False
108 result
['data'] = Util
.json_loads_byteified(r
.text
)
111 def role_update(self
, token
, role_id
, role_data
):
112 result
= {'error': True, 'data': ''}
113 headers
= {"Content-Type": "application/json", "accept": "application/json",
114 'Authorization': 'Bearer {}'.format(token
['id'])}
115 _url
= "{0}/admin/v1/roles/{1}".format(self
._base
_path
, role_id
)
118 r
= requests
.patch(_url
, json
=role_data
, verify
=False, headers
=headers
)
119 except Exception as e
:
121 result
['data'] = str(e
)
123 if r
.status_code
in (200, 201, 202, 204):
124 result
['error'] = False
126 result
['data'] = Util
.json_loads_byteified(r
.text
)
129 def role_delete(self
, token
, id, force
=None):
130 result
= {'error': True, 'data': ''}
131 headers
= {"Content-Type": "application/json", "accept": "application/json",
132 'Authorization': 'Bearer {}'.format(token
['id'])}
135 query_path
= '?FORCE=true'
136 _url
= "{0}/admin/v1/roles/{1}{2}".format(self
._base
_path
, id, query_path
)
138 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
139 except Exception as e
:
141 result
['data'] = str(e
)
143 if r
.status_code
in (200, 201, 202, 204):
144 result
['error'] = False
146 result
['data'] = Util
.json_loads_byteified(r
.text
)
149 def role_get(self
, token
, id):
150 result
= {'error': True, 'data': ''}
151 headers
= {"Content-Type": "application/json", "accept": "application/json",
152 'Authorization': 'Bearer {}'.format(token
['id'])}
154 _url
= "{0}/admin/v1/roles/{1}".format(self
._base
_path
, id)
156 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
157 except Exception as e
:
159 result
['data'] = str(e
)
161 if r
.status_code
in (200, 201, 202, 204):
162 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 project_list(self
, token
):
256 result
= {'error': True, 'data': ''}
257 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
258 'Authorization': 'Bearer {}'.format(token
['id'])}
260 _url
= "{0}/admin/v1/projects".format(self
._base
_path
)
262 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
263 except Exception as e
:
265 result
['data'] = str(e
)
267 if r
.status_code
in (200, 201, 202, 204):
268 result
['error'] = False
269 result
['data'] = Util
.json_loads_byteified(r
.text
)
273 def project_get(self
, token
, id):
274 result
= {'error': True, 'data': ''}
275 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
276 'Authorization': 'Bearer {}'.format(token
['id'])}
277 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
279 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
280 except Exception as e
:
282 result
['data'] = str(e
)
284 if r
.status_code
in (200, 201, 202, 204):
285 result
['error'] = False
286 result
['data'] = Util
.json_loads_byteified(r
.text
)
289 def project_create(self
, token
, project_data
):
291 result
= {'error': True, 'data': ''}
292 headers
= {"Content-Type": "application/json", "accept": "application/json",
293 'Authorization': 'Bearer {}'.format(token
['id'])}
295 _url
= "{0}/admin/v1/projects".format(self
._base
_path
)
298 r
= requests
.post(_url
, json
=project_data
, verify
=False, headers
=headers
)
299 except Exception as e
:
301 result
['data'] = str(e
)
303 if r
.status_code
in (200, 201, 202, 204):
304 result
['error'] = False
305 result
['data'] = Util
.json_loads_byteified(r
.text
)
308 def project_edit(self
, token
, id, project_data
):
310 result
= {'error': True, 'data': ''}
311 headers
= {"Content-Type": "application/json", "accept": "application/json",
312 'Authorization': 'Bearer {}'.format(token
['id'])}
314 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
317 r
= requests
.put(_url
, json
=project_data
, verify
=False, headers
=headers
)
318 except Exception as e
:
320 result
['data'] = str(e
)
322 if r
.status_code
in (200, 201, 202, 204):
323 result
['error'] = False
326 def project_delete(self
, token
, id):
327 result
= {'error': True, 'data': ''}
328 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
329 'Authorization': 'Bearer {}'.format(token
['id'])}
331 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
333 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
334 except Exception as e
:
336 result
['data'] = str(e
)
338 if r
.status_code
in (200, 201, 202, 204):
339 result
['error'] = False
341 result
['data'] = Util
.json_loads_byteified(r
.text
)
344 def nst_details(self
, token
, id):
345 result
= {'error': True, 'data': ''}
346 headers
= {"Content-Type": "application/json", "accept": "application/json",
347 'Authorization': 'Bearer {}'.format(token
['id'])}
348 _url
= "{0}/nst/v1/netslice_templates/{1}".format(self
._base
_path
,id)
350 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
351 except Exception as e
:
353 result
['data'] = str(e
)
355 if r
.status_code
in (200, 201, 202, 204):
356 result
['error'] = False
357 result
['data'] = Util
.json_loads_byteified(r
.text
)
361 def nst_content(self
, token
, id):
362 result
= {'error': True, 'data': ''}
363 headers
= {"Content-Type": "application/json", "accept": "text/plain",
364 'Authorization': 'Bearer {}'.format(token
['id'])}
365 _url
= "{0}/nst/v1/netslice_templates/{1}/nst".format(self
._base
_path
,id)
367 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
368 except Exception as e
:
370 result
['data'] = str(e
)
372 if r
.status_code
in (200, 201, 202, 204):
373 result
['error'] = False
374 result
['data'] = Util
.json2yaml(yaml
.load(str(r
.text
)))
378 def nst_list(self
, token
):
379 result
= {'error': True, 'data': ''}
380 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
381 'Authorization': 'Bearer {}'.format(token
['id'])}
383 _url
= "{0}/nst/v1/netslice_templates".format(self
._base
_path
)
385 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
386 except Exception as e
:
388 result
['data'] = str(e
)
390 if r
.status_code
in (200, 201, 202, 204):
391 result
['error'] = False
392 result
['data'] = Util
.json_loads_byteified(r
.text
)
396 def nsd_list(self
, token
, filter=None):
397 result
= {'error': True, 'data': ''}
398 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
399 'Authorization': 'Bearer {}'.format(token
['id'])}
402 query_path
= '?_admin.type='+filter
403 _url
= "{0}/nsd/v1/ns_descriptors_content{1}".format(self
._base
_path
, query_path
)
405 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
406 except Exception as e
:
408 result
['data'] = str(e
)
410 if r
.status_code
in (200, 201, 202, 204):
411 result
['error'] = False
412 result
['data'] = Util
.json_loads_byteified(r
.text
)
416 def vnfd_list(self
, token
, filter=None):
417 result
= {'error': True, 'data': ''}
418 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
419 'Authorization': 'Bearer {}'.format(token
['id'])}
422 query_path
= '?_admin.type='+filter
423 _url
= "{0}/vnfpkgm/v1/vnf_packages_content{1}".format(self
._base
_path
, query_path
)
425 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
426 except Exception as e
:
428 result
['data'] = str(e
)
430 if r
.status_code
in (200, 201, 202, 204):
431 result
['error'] = False
432 result
['data'] = Util
.json_loads_byteified(r
.text
)
436 def nsi_list(self
, token
):
437 result
= {'error': True, 'data': ''}
438 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
439 'Authorization': 'Bearer {}'.format(token
['id'])}
440 _url
= "{0}/nsilcm/v1/netslice_instances".format(self
._base
_path
)
442 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
443 except Exception as e
:
445 result
['data'] = str(e
)
447 if r
.status_code
in (200, 201, 202, 204):
448 result
['error'] = False
449 result
['data'] = Util
.json_loads_byteified(r
.text
)
453 def ns_list(self
, token
):
454 result
= {'error': True, 'data': ''}
455 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
456 'Authorization': 'Bearer {}'.format(token
['id'])}
457 _url
= "{0}/nslcm/v1/ns_instances_content".format(self
._base
_path
)
459 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
460 except Exception as e
:
462 result
['data'] = str(e
)
464 if r
.status_code
in (200, 201, 202, 204):
465 result
['error'] = False
466 result
['data'] = Util
.json_loads_byteified(r
.text
)
470 def vnf_list(self
, token
):
471 result
= {'error': True, 'data': ''}
472 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
473 'Authorization': 'Bearer {}'.format(token
['id'])}
474 _url
= "{0}/nslcm/v1/vnfrs".format(self
._base
_path
)
476 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
477 except Exception as e
:
479 result
['data'] = str(e
)
481 if r
.status_code
in (200, 201, 202, 204):
482 result
['error'] = False
483 result
['data'] = Util
.json_loads_byteified(r
.text
)
487 def pdu_list(self
, token
):
488 result
= {'error': True, 'data': ''}
489 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
490 'Authorization': 'Bearer {}'.format(token
['id'])}
491 _url
= "{0}/pdu/v1/pdu_descriptors".format(self
._base
_path
)
493 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
494 except Exception as e
:
496 result
['data'] = str(e
)
498 if r
.status_code
in (200, 201, 202, 204):
499 result
['error'] = False
500 result
['data'] = Util
.json_loads_byteified(r
.text
)
504 def nst_delete(self
, token
, id):
505 result
= {'error': True, 'data': ''}
506 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
507 'Authorization': 'Bearer {}'.format(token
['id'])}
509 _url
= "{0}/nst/v1/netslice_templates/{1}?FORCE=True".format(self
._base
_path
, id)
511 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
512 except Exception as e
:
514 result
['data'] = str(e
)
516 if r
.status_code
in (200, 201, 202, 204):
517 result
['error'] = False
521 def nsd_delete(self
, token
, id):
522 result
= {'error': True, 'data': ''}
523 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
524 'Authorization': 'Bearer {}'.format(token
['id'])}
526 _url
= "{0}/nsd/v1/ns_descriptors_content/{1}".format(self
._base
_path
, id)
528 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
529 except Exception as e
:
531 result
['data'] = str(e
)
534 result
['error'] = False
535 if r
.status_code
!= requests
.codes
.no_content
:
536 result
['data'] = Util
.json_loads_byteified(r
.text
)
539 def vnfd_delete(self
, token
, id):
540 result
= {'error': True, 'data': ''}
541 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
542 'Authorization': 'Bearer {}'.format(token
['id'])}
544 _url
= "{0}/vnfpkgm/v1/vnf_packages_content/{1}".format(self
._base
_path
, id)
546 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
547 except Exception as e
:
549 result
['data'] = str(e
)
552 result
['error'] = False
553 if r
.status_code
!= requests
.codes
.no_content
:
554 result
['data'] = Util
.json_loads_byteified(r
.text
)
557 def nst_onboard(self
, token
, template
):
558 result
= {'error': True, 'data': ''}
559 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
560 'Authorization': 'Bearer {}'.format(token
['id'])}
561 _url
= "{0}/nst/v1/netslice_templates_content".format(self
._base
_path
)
563 fileName
, fileExtension
= os
.path
.splitext(template
.name
)
564 if fileExtension
== '.gz':
565 headers
["Content-Type"] = "application/gzip"
567 headers
["Content-Type"] = "application/yaml"
568 r
= requests
.post(_url
, data
=template
, verify
=False, headers
=headers
)
569 except Exception as e
:
571 result
['data'] = str(e
)
573 if r
.status_code
in (200, 201, 202, 204):
574 result
['error'] = False
575 result
['data'] = Util
.json_loads_byteified(r
.text
)
578 def nsd_onboard(self
, token
, package
):
579 result
= {'error': True, 'data': ''}
580 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
581 'Authorization': 'Bearer {}'.format(token
['id'])}
582 with
open('/tmp/' + package
.name
, 'wb+') as destination
:
583 for chunk
in package
.chunks():
584 destination
.write(chunk
)
585 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + package
.name
, 'rb'))
586 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
588 r
= requests
.post(_url
, data
=open('/tmp/' + package
.name
, 'rb'), verify
=False, headers
=headers
)
589 except Exception as e
:
591 result
['data'] = str(e
)
593 if r
.status_code
in (200, 201, 202, 204):
594 result
['error'] = False
595 result
['data'] = Util
.json_loads_byteified(r
.text
)
598 def vnfd_onboard(self
, token
, package
):
599 result
= {'error': True, 'data': ''}
600 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
601 'Authorization': 'Bearer {}'.format(token
['id'])}
602 with
open('/tmp/' + package
.name
, 'wb+') as destination
:
603 for chunk
in package
.chunks():
604 destination
.write(chunk
)
605 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + package
.name
, 'rb'))
606 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
608 r
= requests
.post(_url
, data
=open('/tmp/' + package
.name
, 'rb'), verify
=False, headers
=headers
)
609 except Exception as e
:
611 result
['data'] = str(e
)
613 if r
.status_code
in (200, 201, 202, 204):
614 result
['error'] = False
615 result
['data'] = Util
.json_loads_byteified(r
.text
)
618 def nsd_create_pkg_base(self
, token
, pkg_name
):
619 result
= {'error': True, 'data': ''}
620 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
621 'Authorization': 'Bearer {}'.format(token
['id'])}
623 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
626 self
._create
_base
_pkg
('nsd', pkg_name
)
627 headers
['Content-Filename'] = pkg_name
+ '.tar.gz'
628 r
= requests
.post(_url
, data
=open('/tmp/' + pkg_name
+ '.tar.gz', 'rb'), verify
=False, headers
=headers
)
629 except Exception as e
:
631 result
['data'] = str(e
)
633 if r
.status_code
in (200, 201, 202, 204):
634 result
['data'] = r
.json()
635 result
['error'] = False
636 if r
.status_code
== requests
.codes
.conflict
:
637 result
['data'] = "Invalid ID."
640 def vnfd_create_pkg_base(self
, token
, pkg_name
):
641 result
= {'error': True, 'data': ''}
642 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
643 'Authorization': 'Bearer {}'.format(token
['id'])}
645 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
648 self
._create
_base
_pkg
('vnfd', pkg_name
)
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 nsd_clone(self
, token
, id):
662 result
= {'error': True, 'data': ''}
663 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
664 'Authorization': 'Bearer {}'.format(token
['id'])}
666 # get the package onboarded
667 tar_pkg
= self
.get_nsd_pkg(token
, id)
668 tarf
= tarfile
.open(fileobj
=tar_pkg
)
669 tarf
= self
._descriptor
_clone
(tarf
, 'nsd')
670 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'))
672 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
675 r
= requests
.post(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'), verify
=False,
677 except Exception as e
:
679 result
['data'] = str(e
)
681 if r
.status_code
in (200, 201, 202, 204):
682 result
['error'] = False
683 if r
.status_code
== requests
.codes
.conflict
:
684 result
['data'] = "Invalid ID."
688 def vnfd_clone(self
, token
, id):
689 result
= {'error': True, 'data': ''}
690 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
691 'Authorization': 'Bearer {}'.format(token
['id'])}
693 # get the package onboarded
694 tar_pkg
= self
.get_vnfd_pkg(token
, id)
695 tarf
= tarfile
.open(fileobj
=tar_pkg
)
697 tarf
= self
._descriptor
_clone
(tarf
, 'vnfd')
698 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'))
700 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
703 r
= requests
.post(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'), verify
=False,
705 except Exception as e
:
707 result
['data'] = str(e
)
709 if r
.status_code
in (200, 201, 202, 204):
710 result
['error'] = False
711 if r
.status_code
== requests
.codes
.conflict
:
712 result
['data'] = "Invalid ID."
716 def nst_content_update(self
, token
, id, template
):
717 result
= {'error': True, 'data': ''}
718 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
719 'Authorization': 'Bearer {}'.format(token
['id'])}
720 _url
= "{0}/nst/v1/netslice_templates/{1}/nst_content".format(self
._base
_path
,id)
722 r
= requests
.put(_url
, data
=template
, verify
=False, headers
=headers
)
723 except Exception as e
:
725 result
['data'] = str(e
)
727 if r
.status_code
in (200, 201, 202, 204):
728 result
['error'] = False
731 def nsd_update(self
, token
, id, data
):
732 result
= {'error': True, 'data': ''}
733 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
734 'Authorization': 'Bearer {}'.format(token
['id'])}
736 # get the package onboarded
737 tar_pkg
= self
.get_nsd_pkg(token
, id)
738 tarf
= tarfile
.open(fileobj
=tar_pkg
)
740 tarf
= self
._descriptor
_update
(tarf
, data
)
741 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
743 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self
._base
_path
, id)
746 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
748 except Exception as e
:
750 result
['data'] = str(e
)
752 if r
.status_code
in (200, 201, 202, 204):
753 result
['error'] = False
756 result
['data'] = r
.json()
757 except Exception as e
:
762 def vnfd_update(self
, token
, id, data
):
763 result
= {'error': True, 'data': ''}
764 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
765 'Authorization': 'Bearer {}'.format(token
['id'])}
767 # get the package onboarded
768 tar_pkg
= self
.get_vnfd_pkg(token
, id)
769 tarf
= tarfile
.open(fileobj
=tar_pkg
)
771 tarf
= self
._descriptor
_update
(tarf
, data
)
772 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
774 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self
._base
_path
, id)
777 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
779 except Exception as e
:
781 result
['data'] = str(e
)
783 if r
.status_code
in (200, 201, 202, 204):
784 result
['error'] = False
787 result
['data'] = r
.json()
788 except Exception as e
:
793 def get_nsd_pkg(self
, token
, id):
794 result
= {'error': True, 'data': ''}
795 headers
= {"accept": "application/zip",
796 'Authorization': 'Bearer {}'.format(token
['id'])}
798 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self
._base
_path
, id)
800 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
801 except Exception as e
:
803 result
['data'] = str(e
)
805 if r
.status_code
in (200, 201, 202, 204):
806 result
['error'] = False
807 tarf
= StringIO
.StringIO(r
.content
)
811 def get_vnfd_pkg(self
, token
, id):
812 result
= {'error': True, 'data': ''}
813 headers
= {"accept": "application/zip",
814 'Authorization': 'Bearer {}'.format(token
['id'])}
815 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self
._base
_path
, id)
817 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
818 except Exception as e
:
820 result
['data'] = str(e
)
822 if r
.status_code
in (200, 201, 202, 204):
823 result
['error'] = False
824 tarf
= StringIO
.StringIO(r
.content
)
828 def _descriptor_update(self
, tarf
, data
):
829 # extract the package on a tmp directory
830 tarf
.extractall('/tmp')
832 for name
in tarf
.getnames():
833 if name
.endswith(".yaml") or name
.endswith(".yml"):
834 with
open('/tmp/' + name
, 'w') as outfile
:
835 yaml
.safe_dump(data
, outfile
, default_flow_style
=False)
838 tarf_temp
= tarfile
.open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", "w:gz")
841 tarf_temp
.add('/tmp/' + tarinfo
.name
, tarinfo
.name
, recursive
=False)
845 def _create_base_pkg(self
, descriptor_type
, pkg_name
):
846 filename
= '/tmp/'+pkg_name
+'/' + pkg_name
+ '.yaml'
847 if descriptor_type
== 'nsd':
852 "short-name": str(pkg_name
),
853 "vendor": "OSM Composer",
854 "description": str(pkg_name
) + " descriptor",
856 "constituent-vnfd": [],
859 "name": str(pkg_name
)
865 elif descriptor_type
== 'vnfd':
867 "vnfd:vnfd-catalog": {
870 "short-name": str(pkg_name
),
879 "connection-point": [],
880 "name": str(pkg_name
)
886 if not os
.path
.exists(os
.path
.dirname(filename
)):
888 os
.makedirs(os
.path
.dirname(filename
))
889 except OSError as exc
: # Guard against race condition
890 if exc
.errno
!= errno
.EEXIST
:
893 with
open('/tmp/' + pkg_name
+ '/' + pkg_name
+ '.yaml', 'w') as yaml_file
:
894 yaml_file
.write(yaml
.dump(descriptor
, default_flow_style
=False))
896 tarf_temp
= tarfile
.open('/tmp/' + pkg_name
+ '.tar.gz', "w:gz")
897 tarf_temp
.add('/tmp/'+pkg_name
+'/' + pkg_name
+ '.yaml', pkg_name
+ '/' + pkg_name
+ '.yaml', recursive
=False)
900 def _descriptor_clone(self
, tarf
, descriptor_type
):
901 # extract the package on a tmp directory
902 tarf
.extractall('/tmp')
904 for name
in tarf
.getnames():
905 if name
.endswith(".yaml") or name
.endswith(".yml"):
906 with
open('/tmp/' + name
, 'r') as outfile
:
907 yaml_object
= yaml
.load(outfile
)
909 if descriptor_type
== 'nsd':
910 nsd_list
= yaml_object
['nsd:nsd-catalog']['nsd']
912 nsd
['id'] = 'clone_' + nsd
['id']
913 nsd
['name'] = 'clone_' + nsd
['name']
914 nsd
['short-name'] = 'clone_' + nsd
['short-name']
915 elif descriptor_type
== 'vnfd':
916 vnfd_list
= yaml_object
['vnfd:vnfd-catalog']['vnfd']
917 for vnfd
in vnfd_list
:
918 vnfd
['id'] = 'clone_' + vnfd
['id']
919 vnfd
['name'] = 'clone_' + vnfd
['name']
920 vnfd
['short-name'] = 'clone_' + vnfd
['short-name']
922 with
open('/tmp/' + name
, 'w') as yaml_file
:
923 yaml_file
.write(yaml
.dump(yaml_object
, default_flow_style
=False))
926 tarf_temp
= tarfile
.open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", "w:gz")
929 tarf_temp
.add('/tmp/' + tarinfo
.name
, tarinfo
.name
, recursive
=False)
933 def nsd_get(self
, token
, id):
934 result
= {'error': True, 'data': ''}
935 headers
= {'Content-Type': 'application/yaml',
936 'Authorization': 'Bearer {}'.format(token
['id'])}
937 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd".format(self
._base
_path
, id)
939 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
940 except Exception as e
:
942 result
['data'] = str(e
)
944 if r
.status_code
in (200, 201, 202, 204):
945 result
['error'] = False
946 return yaml
.load(r
.text
)
949 result
['data'] = r
.json()
950 except Exception as e
:
954 def vnfd_get(self
, token
, id):
955 result
= {'error': True, 'data': ''}
956 headers
= {'Content-Type': 'application/yaml',
957 'Authorization': 'Bearer {}'.format(token
['id'])}
958 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/vnfd".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 nsd_artifacts(self
, token
, id):
976 result
= {'error': True, 'data': ''}
977 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
978 'Authorization': 'Bearer {}'.format(token
['id'])}
979 _url
= "{0}/nsd/v1/ns_descriptors/{1}/artifacts".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 result
['data'] = r
.text
991 result
['data'] = r
.json()
992 except Exception as e
:
997 def vnf_packages_artifacts(self
, token
, id):
998 result
= {'error': True, 'data': ''}
999 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
1000 'Authorization': 'Bearer {}'.format(token
['id'])}
1001 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/artifacts".format(self
._base
_path
, id)
1003 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1004 except Exception as e
:
1006 result
['data'] = str(e
)
1008 if r
.status_code
in (200, 201, 202, 204):
1009 result
['error'] = False
1010 result
['data'] = r
.text
1013 result
['data'] = r
.json()
1014 except Exception as e
:
1019 def nsi_create(self
, token
, nsi_data
):
1020 result
= {'error': True, 'data': ''}
1021 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1022 'Authorization': 'Bearer {}'.format(token
['id'])}
1024 _url
= "{0}/nsilcm/v1/netslice_instances_content".format(self
._base
_path
)
1027 r
= requests
.post(_url
, json
=nsi_data
, verify
=False, headers
=headers
)
1028 except Exception as e
:
1030 result
['data'] = str(e
)
1032 if r
.status_code
in (200, 201, 202, 204):
1033 result
['error'] = False
1034 result
['data'] = Util
.json_loads_byteified(r
.text
)
1037 def ns_create(self
, token
, ns_data
):
1038 result
= {'error': True, 'data': ''}
1039 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1040 'Authorization': 'Bearer {}'.format(token
['id'])}
1042 _url
= "{0}/nslcm/v1/ns_instances_content".format(self
._base
_path
)
1045 r
= requests
.post(_url
, json
=ns_data
, verify
=False, headers
=headers
)
1046 except Exception as e
:
1048 result
['data'] = str(e
)
1050 if r
.status_code
in (200, 201, 202, 204):
1051 result
['error'] = False
1052 result
['data'] = Util
.json_loads_byteified(r
.text
)
1055 def pdu_create(self
, token
, pdu_data
):
1056 result
= {'error': True, 'data': ''}
1057 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1058 'Authorization': 'Bearer {}'.format(token
['id'])}
1060 _url
= "{0}/pdu/v1/pdu_descriptors".format(self
._base
_path
)
1063 r
= requests
.post(_url
, json
=pdu_data
, verify
=False, headers
=headers
)
1064 except Exception as e
:
1066 result
['data'] = str(e
)
1068 if r
.status_code
in (200, 201, 202, 204):
1069 result
['error'] = False
1070 result
['data'] = Util
.json_loads_byteified(r
.text
)
1073 def ns_op_list(self
, token
, id):
1074 result
= {'error': True, 'data': ''}
1075 headers
= {"Content-Type": "application/json", "accept": "application/json",
1076 'Authorization': 'Bearer {}'.format(token
['id'])}
1077 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/?nsInstanceId={1}".format(self
._base
_path
, id)
1080 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1081 except Exception as e
:
1083 result
['data'] = str(e
)
1085 if r
.status_code
in (200, 201, 202, 204):
1086 result
['error'] = False
1087 result
['data'] = Util
.json_loads_byteified(r
.text
)
1091 def nsi_op_list(self
, token
, id):
1092 result
= {'error': True, 'data': ''}
1093 headers
= {"Content-Type": "application/json", "accept": "application/json",
1094 'Authorization': 'Bearer {}'.format(token
['id'])}
1095 _url
= "{0}/nsilcm/v1/nsi_lcm_op_occs/?netsliceInstanceId={1}".format(self
._base
_path
, id)
1098 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1099 except Exception as e
:
1101 result
['data'] = str(e
)
1103 if r
.status_code
in (200, 201, 202, 204):
1104 result
['error'] = False
1105 result
['data'] = Util
.json_loads_byteified(r
.text
)
1109 def ns_op(self
, token
, id):
1110 result
= {'error': True, 'data': ''}
1111 headers
= {"Content-Type": "application/json", "accept": "application/json",
1112 'Authorization': 'Bearer {}'.format(token
['id'])}
1113 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/{1}".format(self
._base
_path
, id)
1116 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1117 except Exception as e
:
1119 result
['data'] = str(e
)
1121 if r
.status_code
in (200, 201, 202, 204):
1122 result
['error'] = False
1123 result
['data'] = Util
.json_loads_byteified(r
.text
)
1127 def ns_action(self
, token
, id, action_payload
):
1128 result
= {'error': True, 'data': ''}
1129 headers
= {"Content-Type": "application/json", "accept": "application/json",
1130 'Authorization': 'Bearer {}'.format(token
['id'])}
1132 _url
= "{0}/nslcm/v1/ns_instances/{1}/action".format(self
._base
_path
, id)
1135 r
= requests
.post(_url
, json
=action_payload
, verify
=False, headers
=headers
)
1136 except Exception as e
:
1138 result
['data'] = str(e
)
1140 if r
.status_code
in (200, 201, 202, 204):
1141 result
['error'] = False
1142 result
['data'] = Util
.json_loads_byteified(r
.text
)
1145 def nsi_delete(self
, token
, id, force
=None):
1146 result
= {'error': True, 'data': ''}
1147 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1148 'Authorization': 'Bearer {}'.format(token
['id'])}
1151 query_path
= '?FORCE=true'
1152 _url
= "{0}/nsilcm/v1/netslice_instances_content/{1}{2}".format(self
._base
_path
, id, query_path
)
1154 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1155 except Exception as e
:
1157 result
['data'] = str(e
)
1160 result
['error'] = False
1161 if r
.status_code
!= requests
.codes
.no_content
:
1162 result
['data'] = Util
.json_loads_byteified(r
.text
)
1165 def ns_delete(self
, token
, id, force
=None):
1166 result
= {'error': True, 'data': ''}
1167 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1168 'Authorization': 'Bearer {}'.format(token
['id'])}
1171 query_path
= '?FORCE=true'
1172 _url
= "{0}/nslcm/v1/ns_instances_content/{1}{2}".format(self
._base
_path
, id, query_path
)
1174 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1175 except Exception as e
:
1177 result
['data'] = str(e
)
1180 result
['error'] = False
1181 if r
.status_code
!= requests
.codes
.no_content
:
1182 result
['data'] = Util
.json_loads_byteified(r
.text
)
1185 def pdu_delete(self
, token
, id):
1186 result
= {'error': True, 'data': ''}
1187 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1188 'Authorization': 'Bearer {}'.format(token
['id'])}
1189 _url
= "{0}/pdu/v1/pdu_descriptors/{1}".format(self
._base
_path
, id)
1191 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1192 except Exception as e
:
1194 result
['data'] = str(e
)
1197 result
['error'] = False
1198 if r
.status_code
!= requests
.codes
.no_content
:
1199 result
['data'] = Util
.json_loads_byteified(r
.text
)
1202 def nsi_get(self
, token
, id):
1203 result
= {'error': True, 'data': ''}
1204 headers
= {"Content-Type": "application/json", "accept": "application/json",
1205 'Authorization': 'Bearer {}'.format(token
['id'])}
1206 _url
= "{0}/nsilcm/v1/netslice_instances/{1}".format(self
._base
_path
, id)
1209 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1210 except Exception as e
:
1212 result
['data'] = str(e
)
1214 if r
.status_code
in (200, 201, 202, 204):
1215 result
['error'] = False
1216 result
['data'] = Util
.json_loads_byteified(r
.text
)
1219 def ns_get(self
, token
, id):
1220 result
= {'error': True, 'data': ''}
1221 headers
= {"Content-Type": "application/json", "accept": "application/json",
1222 'Authorization': 'Bearer {}'.format(token
['id'])}
1223 _url
= "{0}/nslcm/v1/ns_instances_content/{1}".format(self
._base
_path
, id)
1226 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1227 except Exception as e
:
1229 result
['data'] = str(e
)
1231 if r
.status_code
in (200, 201, 202, 204):
1232 result
['error'] = False
1233 result
['data'] = Util
.json_loads_byteified(r
.text
)
1236 def vnf_get(self
, token
, id):
1237 result
= {'error': True, 'data': ''}
1238 headers
= {"Content-Type": "application/json", "accept": "application/json",
1239 'Authorization': 'Bearer {}'.format(token
['id'])}
1240 _url
= "{0}/nslcm/v1/vnfrs/{1}".format(self
._base
_path
, id)
1243 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1244 except Exception as e
:
1246 result
['data'] = str(e
)
1248 if r
.status_code
in (200, 201, 202, 204):
1249 result
['error'] = False
1250 result
['data'] = Util
.json_loads_byteified(r
.text
)
1253 def pdu_get(self
, token
, id):
1254 result
= {'error': True, 'data': ''}
1255 headers
= {"Content-Type": "application/json", "accept": "application/json",
1256 'Authorization': 'Bearer {}'.format(token
['id'])}
1257 _url
= "{0}/pdu/v1/pdu_descriptors/{1}".format(self
._base
_path
, id)
1260 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1261 except Exception as e
:
1263 result
['data'] = str(e
)
1265 if r
.status_code
in (200, 201, 202, 204):
1266 result
['error'] = False
1267 result
['data'] = Util
.json_loads_byteified(r
.text
)
1270 def ns_alarm_create(self
, token
, id, alarm_payload
):
1271 result
= {'error': True, 'data': ''}
1272 headers
= {"Content-Type": "application/json",
1273 'Authorization': 'Bearer {}'.format(token
['id'])}
1274 _url
= "{0}/test/message/alarm_request".format(self
._base
_path
)
1276 r
= requests
.post(_url
, json
=alarm_payload
, verify
=False, headers
=headers
)
1277 except Exception as e
:
1279 result
['data'] = str(e
)
1281 if r
.status_code
in (200, 201, 202, 204):
1282 result
['error'] = False
1283 # result['data'] = Util.json_loads_byteified(r.text)
1284 result
['data'] = r
.text
1287 def ns_metric_export(self
, token
, id, metric_payload
):
1288 result
= {'error': True, 'data': ''}
1289 headers
= {"Content-Type": "application/json",
1290 'Authorization': 'Bearer {}'.format(token
['id'])}
1291 _url
= "{0}/test/message/metric_request".format(self
._base
_path
)
1293 r
= requests
.post(_url
, json
=metric_payload
, verify
=False, headers
=headers
)
1294 except Exception as e
:
1296 result
['data'] = str(e
)
1298 if r
.status_code
in (200, 201, 202, 204):
1299 result
['error'] = False
1300 # result['data'] = Util.json_loads_byteified(r.text)
1301 result
['data'] = r
.text
1304 def wim_list(self
, token
):
1305 result
= {'error': True, 'data': ''}
1306 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1307 'Authorization': 'Bearer {}'.format(token
['id'])}
1308 _url
= "{0}/admin/v1/wim_accounts".format(self
._base
_path
)
1310 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1311 except Exception as e
:
1313 result
['data'] = str(e
)
1315 if r
.status_code
in (200, 201, 202, 204):
1316 result
['error'] = False
1317 result
['data'] = Util
.json_loads_byteified(r
.text
)
1321 def vim_list(self
, token
):
1322 result
= {'error': True, 'data': ''}
1323 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1324 'Authorization': 'Bearer {}'.format(token
['id'])}
1325 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
1327 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1328 except Exception as e
:
1330 result
['data'] = str(e
)
1332 if r
.status_code
in (200, 201, 202, 204):
1333 result
['error'] = False
1334 result
['data'] = Util
.json_loads_byteified(r
.text
)
1338 def wim_delete(self
, token
, id):
1339 result
= {'error': True, 'data': ''}
1340 headers
= {"accept": "application/json",
1341 'Authorization': 'Bearer {}'.format(token
['id'])}
1342 _url
= "{0}/admin/v1/wim_accounts/{1}".format(self
._base
_path
, id)
1344 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1345 except Exception as e
:
1347 result
['data'] = str(e
)
1349 if r
.status_code
in (200, 201, 202, 204):
1350 result
['error'] = False
1352 result
['data'] = r
.text
1355 def vim_delete(self
, token
, id):
1356 result
= {'error': True, 'data': ''}
1357 headers
= {"accept": "application/json",
1358 'Authorization': 'Bearer {}'.format(token
['id'])}
1359 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
1361 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1362 except Exception as e
:
1364 result
['data'] = str(e
)
1366 if r
.status_code
in (200, 201, 202, 204):
1367 result
['error'] = False
1369 result
['data'] = r
.text
1372 def wim_get(self
, token
, id):
1374 result
= {'error': True, 'data': ''}
1375 headers
= {"Content-Type": "application/json", "accept": "application/json",
1376 'Authorization': 'Bearer {}'.format(token
['id'])}
1377 _url
= "{0}/admin/v1/wim_accounts/{1}".format(self
._base
_path
, id)
1380 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1381 except Exception as e
:
1383 result
['data'] = str(e
)
1385 if r
.status_code
in (200, 201, 202, 204):
1386 result
['error'] = False
1387 result
['data'] = Util
.json_loads_byteified(r
.text
)
1390 def vim_get(self
, token
, id):
1392 result
= {'error': True, 'data': ''}
1393 headers
= {"Content-Type": "application/json", "accept": "application/json",
1394 'Authorization': 'Bearer {}'.format(token
['id'])}
1395 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
1398 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1399 except Exception as e
:
1401 result
['data'] = str(e
)
1403 if r
.status_code
in (200, 201, 202, 204):
1404 result
['error'] = False
1405 result
['data'] = Util
.json_loads_byteified(r
.text
)
1408 def wim_create(self
, token
, wim_data
):
1409 result
= {'error': True, 'data': ''}
1410 headers
= {"Content-Type": "application/json", "accept": "application/json",
1411 'Authorization': 'Bearer {}'.format(token
['id'])}
1413 _url
= "{0}/admin/v1/wim_accounts".format(self
._base
_path
)
1416 r
= requests
.post(_url
, json
=wim_data
, verify
=False, headers
=headers
)
1417 except Exception as e
:
1419 result
['data'] = str(e
)
1421 if r
.status_code
in (200, 201, 202, 204):
1422 result
['error'] = False
1423 result
['data'] = Util
.json_loads_byteified(r
.text
)
1426 def vim_create(self
, token
, vim_data
):
1428 result
= {'error': True, 'data': ''}
1429 headers
= {"Content-Type": "application/json", "accept": "application/json",
1430 'Authorization': 'Bearer {}'.format(token
['id'])}
1432 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
1435 r
= requests
.post(_url
, json
=vim_data
, verify
=False, headers
=headers
)
1436 except Exception as e
:
1438 result
['data'] = str(e
)
1440 if r
.status_code
in (200, 201, 202, 204):
1441 result
['error'] = False
1442 result
['data'] = Util
.json_loads_byteified(r
.text
)
1445 def sdn_list(self
, token
):
1446 result
= {'error': True, 'data': ''}
1447 headers
= {"accept": "application/json",
1448 'Authorization': 'Bearer {}'.format(token
['id'])}
1449 _url
= "{0}/admin/v1/sdns".format(self
._base
_path
)
1451 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1452 except Exception as e
:
1454 result
['data'] = str(e
)
1456 if r
.status_code
in (200, 201, 202, 204):
1457 result
['error'] = False
1458 result
['data'] = Util
.json_loads_byteified(r
.text
)
1461 def sdn_delete(self
, token
, id):
1462 result
= {'error': True, 'data': ''}
1463 headers
= {"accept": "application/json",
1464 'Authorization': 'Bearer {}'.format(token
['id'])}
1465 _url
= "{0}/admin/v1/sdns/{1}".format(self
._base
_path
, id)
1467 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1468 except Exception as e
:
1470 result
['data'] = str(e
)
1472 if r
.status_code
in (200, 201, 202, 204):
1473 result
['error'] = False
1475 result
['data'] = r
.text
1478 def sdn_get(self
, token
, id):
1479 result
= {'error': True, 'data': ''}
1480 headers
= {"accept": "application/json",
1481 'Authorization': 'Bearer {}'.format(token
['id'])}
1482 _url
= "{0}/admin/v1/sdns/{1}".format(self
._base
_path
, id)
1485 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1486 except Exception as e
:
1488 result
['data'] = str(e
)
1490 if r
.status_code
in (200, 201, 202, 204):
1491 result
['error'] = False
1492 result
['data'] = Util
.json_loads_byteified(r
.text
)
1495 def sdn_create(self
, token
, sdn_data
):
1496 result
= {'error': True, 'data': ''}
1497 headers
= {"Content-Type": "application/json", "accept": "application/json",
1498 'Authorization': 'Bearer {}'.format(token
['id'])}
1500 _url
= "{0}/admin/v1/sdns".format(self
._base
_path
)
1503 r
= requests
.post(_url
, json
=sdn_data
, verify
=False, headers
=headers
)
1504 except Exception as e
:
1506 result
['data'] = str(e
)
1508 if r
.status_code
in (200, 201, 202, 204):
1509 result
['error'] = False
1510 result
['data'] = Util
.json_loads_byteified(r
.text
)
1515 hash_md5
= hashlib
.md5()
1516 for chunk
in iter(lambda: f
.read(1024), b
""):
1517 hash_md5
.update(chunk
)
1518 return hash_md5
.hexdigest()