2025277a6447b098d777a499d0943227da7b4b01
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
== requests
.codes
.ok
:
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
== requests
.codes
.ok
:
70 result
['error'] = False
72 result
['data'] = Util
.json_loads_byteified(r
.text
)
76 def user_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/users".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
== requests
.codes
.ok
:
89 result
['error'] = False
90 result
['data'] = Util
.json_loads_byteified(r
.text
)
94 def user_create(self
, token
, user_data
):
95 result
= {'error': True, 'data': ''}
96 headers
= {"Content-Type": "application/json", "accept": "application/json",
97 'Authorization': 'Bearer {}'.format(token
['id'])}
99 _url
= "{0}/admin/v1/users".format(self
._base
_path
)
102 r
= requests
.post(_url
, json
=user_data
, verify
=False, headers
=headers
)
103 except Exception as e
:
105 result
['data'] = str(e
)
107 if r
.status_code
== requests
.codes
.created
:
108 result
['error'] = False
109 result
['data'] = Util
.json_loads_byteified(r
.text
)
112 def user_update(self
, token
, id, user_data
):
113 result
= {'error': True, 'data': ''}
114 headers
= {"Content-Type": "application/json", "accept": "application/json",
115 'Authorization': 'Bearer {}'.format(token
['id'])}
117 _url
= "{0}/admin/v1/users/{1}".format(self
._base
_path
, id)
119 r
= requests
.patch(_url
, json
=user_data
, verify
=False, headers
=headers
)
120 except Exception as e
:
122 result
['data'] = str(e
)
124 if r
.status_code
== requests
.codes
.no_content
:
125 result
['error'] = False
127 result
['data'] = Util
.json_loads_byteified(r
.text
)
130 def user_delete(self
, token
, id):
131 result
= {'error': True, 'data': ''}
132 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
133 'Authorization': 'Bearer {}'.format(token
['id'])}
135 _url
= "{0}/admin/v1/users/{1}".format(self
._base
_path
, id)
137 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
138 except Exception as e
:
140 result
['data'] = str(e
)
142 if r
.status_code
== requests
.codes
.no_content
:
143 result
['error'] = False
145 result
['data'] = Util
.json_loads_byteified(r
.text
)
148 def get_user_info(self
, token
, id):
149 result
= {'error': True, 'data': ''}
150 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
151 'Authorization': 'Bearer {}'.format(token
['id'])}
152 _url
= "{0}/admin/v1/users/{1}".format(self
._base
_path
, id)
154 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
155 except Exception as e
:
157 result
['data'] = str(e
)
159 if r
.status_code
== requests
.codes
.ok
:
160 result
['error'] = False
161 result
['data'] = Util
.json_loads_byteified(r
.text
)
164 def project_list(self
, token
):
165 result
= {'error': True, 'data': ''}
166 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
167 'Authorization': 'Bearer {}'.format(token
['id'])}
169 _url
= "{0}/admin/v1/projects".format(self
._base
_path
)
171 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
172 except Exception as e
:
174 result
['data'] = str(e
)
176 if r
.status_code
== requests
.codes
.ok
:
177 result
['error'] = False
178 result
['data'] = Util
.json_loads_byteified(r
.text
)
182 def project_get(self
, token
, id):
183 result
= {'error': True, 'data': ''}
184 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
185 'Authorization': 'Bearer {}'.format(token
['id'])}
186 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
188 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
189 except Exception as e
:
191 result
['data'] = str(e
)
193 if r
.status_code
== requests
.codes
.ok
:
194 result
['error'] = False
195 result
['data'] = Util
.json_loads_byteified(r
.text
)
198 def project_create(self
, token
, project_data
):
200 result
= {'error': True, 'data': ''}
201 headers
= {"Content-Type": "application/json", "accept": "application/json",
202 'Authorization': 'Bearer {}'.format(token
['id'])}
204 _url
= "{0}/admin/v1/projects".format(self
._base
_path
)
207 r
= requests
.post(_url
, json
=project_data
, verify
=False, headers
=headers
)
208 except Exception as e
:
210 result
['data'] = str(e
)
212 if r
.status_code
== requests
.codes
.created
:
213 result
['error'] = False
214 result
['data'] = Util
.json_loads_byteified(r
.text
)
217 def project_edit(self
, token
, id, project_data
):
219 result
= {'error': True, 'data': ''}
220 headers
= {"Content-Type": "application/json", "accept": "application/json",
221 'Authorization': 'Bearer {}'.format(token
['id'])}
223 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
226 r
= requests
.put(_url
, json
=project_data
, verify
=False, headers
=headers
)
227 except Exception as e
:
229 result
['data'] = str(e
)
231 if r
.status_code
== requests
.codes
.no_content
:
232 result
['error'] = False
233 result
['data'] = Util
.json_loads_byteified(r
.text
)
236 def project_delete(self
, token
, id):
237 result
= {'error': True, 'data': ''}
238 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
239 'Authorization': 'Bearer {}'.format(token
['id'])}
241 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
243 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
244 except Exception as e
:
246 result
['data'] = str(e
)
248 if r
.status_code
== requests
.codes
.no_content
:
249 result
['error'] = False
251 result
['data'] = Util
.json_loads_byteified(r
.text
)
254 def nst_details(self
, token
, id):
255 result
= {'error': True, 'data': ''}
256 headers
= {"Content-Type": "application/json", "accept": "application/json",
257 'Authorization': 'Bearer {}'.format(token
['id'])}
258 _url
= "{0}/nst/v1/netslice_templates/{1}".format(self
._base
_path
,id)
260 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
261 except Exception as e
:
263 result
['data'] = str(e
)
265 if r
.status_code
== requests
.codes
.ok
:
266 result
['error'] = False
267 result
['data'] = Util
.json_loads_byteified(r
.text
)
271 def nst_content(self
, token
, id):
272 result
= {'error': True, 'data': ''}
273 headers
= {"Content-Type": "application/json", "accept": "text/plain",
274 'Authorization': 'Bearer {}'.format(token
['id'])}
275 _url
= "{0}/nst/v1/netslice_templates/{1}/nst".format(self
._base
_path
,id)
277 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
278 except Exception as e
:
280 result
['data'] = str(e
)
282 if r
.status_code
== requests
.codes
.ok
:
283 result
['error'] = False
284 result
['data'] = Util
.json2yaml(yaml
.load(str(r
.text
)))
288 def nst_list(self
, token
):
289 result
= {'error': True, 'data': ''}
290 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
291 'Authorization': 'Bearer {}'.format(token
['id'])}
293 _url
= "{0}/nst/v1/netslice_templates".format(self
._base
_path
)
295 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
296 except Exception as e
:
298 result
['data'] = str(e
)
300 if r
.status_code
== requests
.codes
.ok
:
301 result
['error'] = False
302 result
['data'] = Util
.json_loads_byteified(r
.text
)
306 def nsd_list(self
, token
, filter=None):
307 result
= {'error': True, 'data': ''}
308 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
309 'Authorization': 'Bearer {}'.format(token
['id'])}
312 query_path
= '?_admin.type='+filter
313 _url
= "{0}/nsd/v1/ns_descriptors_content{1}".format(self
._base
_path
, query_path
)
315 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
316 except Exception as e
:
318 result
['data'] = str(e
)
320 if r
.status_code
== requests
.codes
.ok
:
321 result
['error'] = False
322 result
['data'] = Util
.json_loads_byteified(r
.text
)
326 def vnfd_list(self
, token
, filter=None):
327 result
= {'error': True, 'data': ''}
328 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
329 'Authorization': 'Bearer {}'.format(token
['id'])}
332 query_path
= '?_admin.type='+filter
333 _url
= "{0}/vnfpkgm/v1/vnf_packages_content{1}".format(self
._base
_path
, query_path
)
335 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
336 except Exception as e
:
338 result
['data'] = str(e
)
340 if r
.status_code
== requests
.codes
.ok
:
341 result
['error'] = False
342 result
['data'] = Util
.json_loads_byteified(r
.text
)
346 def nsi_list(self
, token
):
347 result
= {'error': True, 'data': ''}
348 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
349 'Authorization': 'Bearer {}'.format(token
['id'])}
350 _url
= "{0}/nsilcm/v1/netslice_instances".format(self
._base
_path
)
352 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
353 except Exception as e
:
355 result
['data'] = str(e
)
357 if r
.status_code
== requests
.codes
.ok
:
358 result
['error'] = False
359 result
['data'] = Util
.json_loads_byteified(r
.text
)
363 def ns_list(self
, token
):
364 result
= {'error': True, 'data': ''}
365 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
366 'Authorization': 'Bearer {}'.format(token
['id'])}
367 _url
= "{0}/nslcm/v1/ns_instances_content".format(self
._base
_path
)
369 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
370 except Exception as e
:
372 result
['data'] = str(e
)
374 if r
.status_code
== requests
.codes
.ok
:
375 result
['error'] = False
376 result
['data'] = Util
.json_loads_byteified(r
.text
)
380 def vnf_list(self
, token
):
381 result
= {'error': True, 'data': ''}
382 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
383 'Authorization': 'Bearer {}'.format(token
['id'])}
384 _url
= "{0}/nslcm/v1/vnfrs".format(self
._base
_path
)
386 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
387 except Exception as e
:
389 result
['data'] = str(e
)
391 if r
.status_code
== requests
.codes
.ok
:
392 result
['error'] = False
393 result
['data'] = Util
.json_loads_byteified(r
.text
)
397 def pdu_list(self
, token
):
398 result
= {'error': True, 'data': ''}
399 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
400 'Authorization': 'Bearer {}'.format(token
['id'])}
401 _url
= "{0}/pdu/v1/pdu_descriptors".format(self
._base
_path
)
403 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
404 except Exception as e
:
406 result
['data'] = str(e
)
408 if r
.status_code
== requests
.codes
.ok
:
409 result
['error'] = False
410 result
['data'] = Util
.json_loads_byteified(r
.text
)
414 def nst_delete(self
, token
, id):
415 result
= {'error': True, 'data': ''}
416 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
417 'Authorization': 'Bearer {}'.format(token
['id'])}
419 _url
= "{0}/nst/v1/netslice_templates/{1}?FORCE=True".format(self
._base
_path
, id)
421 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
422 except Exception as e
:
424 result
['data'] = str(e
)
426 if r
.status_code
== requests
.codes
.no_content
:
427 result
['error'] = False
431 def nsd_delete(self
, token
, id):
432 result
= {'error': True, 'data': ''}
433 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
434 'Authorization': 'Bearer {}'.format(token
['id'])}
436 _url
= "{0}/nsd/v1/ns_descriptors_content/{1}".format(self
._base
_path
, id)
438 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
439 except Exception as e
:
441 result
['data'] = str(e
)
444 result
['error'] = False
445 if r
.status_code
!= requests
.codes
.no_content
:
446 result
['data'] = Util
.json_loads_byteified(r
.text
)
449 def vnfd_delete(self
, token
, id):
450 result
= {'error': True, 'data': ''}
451 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
452 'Authorization': 'Bearer {}'.format(token
['id'])}
454 _url
= "{0}/vnfpkgm/v1/vnf_packages_content/{1}".format(self
._base
_path
, id)
456 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
457 except Exception as e
:
459 result
['data'] = str(e
)
462 result
['error'] = False
463 if r
.status_code
!= requests
.codes
.no_content
:
464 result
['data'] = Util
.json_loads_byteified(r
.text
)
467 def nst_onboard(self
, token
, template
):
468 result
= {'error': True, 'data': ''}
469 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
470 'Authorization': 'Bearer {}'.format(token
['id'])}
471 _url
= "{0}/nst/v1/netslice_templates_content".format(self
._base
_path
)
473 fileName
, fileExtension
= os
.path
.splitext(template
.name
)
474 if fileExtension
== '.gz':
475 headers
["Content-Type"] = "application/gzip"
477 headers
["Content-Type"] = "application/yaml"
478 r
= requests
.post(_url
, data
=template
, verify
=False, headers
=headers
)
479 except Exception as e
:
481 result
['data'] = str(e
)
483 if r
.status_code
== requests
.codes
.created
:
484 result
['error'] = False
485 result
['data'] = Util
.json_loads_byteified(r
.text
)
488 def nsd_onboard(self
, token
, package
):
489 result
= {'error': True, 'data': ''}
490 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
491 'Authorization': 'Bearer {}'.format(token
['id'])}
492 with
open('/tmp/' + package
.name
, 'wb+') as destination
:
493 for chunk
in package
.chunks():
494 destination
.write(chunk
)
495 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + package
.name
, 'rb'))
496 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
498 r
= requests
.post(_url
, data
=open('/tmp/' + package
.name
, 'rb'), verify
=False, headers
=headers
)
499 except Exception as e
:
501 result
['data'] = str(e
)
503 if r
.status_code
== requests
.codes
.created
:
504 result
['error'] = False
505 result
['data'] = Util
.json_loads_byteified(r
.text
)
508 def vnfd_onboard(self
, token
, package
):
509 result
= {'error': True, 'data': ''}
510 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
511 'Authorization': 'Bearer {}'.format(token
['id'])}
512 with
open('/tmp/' + package
.name
, 'wb+') as destination
:
513 for chunk
in package
.chunks():
514 destination
.write(chunk
)
515 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + package
.name
, 'rb'))
516 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
518 r
= requests
.post(_url
, data
=open('/tmp/' + package
.name
, 'rb'), verify
=False, headers
=headers
)
519 except Exception as e
:
521 result
['data'] = str(e
)
523 if r
.status_code
== requests
.codes
.created
:
524 result
['error'] = False
525 result
['data'] = Util
.json_loads_byteified(r
.text
)
528 def nsd_create_pkg_base(self
, token
, pkg_name
):
529 result
= {'error': True, 'data': ''}
530 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
531 'Authorization': 'Bearer {}'.format(token
['id'])}
533 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
536 self
._create
_base
_pkg
('nsd', pkg_name
)
537 headers
['Content-Filename'] = pkg_name
+ '.tar.gz'
538 r
= requests
.post(_url
, data
=open('/tmp/' + pkg_name
+ '.tar.gz', 'rb'), verify
=False, headers
=headers
)
539 except Exception as e
:
541 result
['data'] = str(e
)
543 if r
.status_code
== requests
.codes
.created
:
544 result
['data'] = r
.json()
545 result
['error'] = False
546 if r
.status_code
== requests
.codes
.conflict
:
547 result
['data'] = "Invalid ID."
550 def vnfd_create_pkg_base(self
, token
, pkg_name
):
551 result
= {'error': True, 'data': ''}
552 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
553 'Authorization': 'Bearer {}'.format(token
['id'])}
555 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
558 self
._create
_base
_pkg
('vnfd', pkg_name
)
559 r
= requests
.post(_url
, data
=open('/tmp/' + pkg_name
+ '.tar.gz', 'rb'), verify
=False, headers
=headers
)
560 except Exception as e
:
562 result
['data'] = str(e
)
564 if r
.status_code
== requests
.codes
.created
:
565 result
['data'] = r
.json()
566 result
['error'] = False
567 if r
.status_code
== requests
.codes
.conflict
:
568 result
['data'] = "Invalid ID."
571 def nsd_clone(self
, token
, id):
572 result
= {'error': True, 'data': ''}
573 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
574 'Authorization': 'Bearer {}'.format(token
['id'])}
576 # get the package onboarded
577 tar_pkg
= self
.get_nsd_pkg(token
, id)
578 tarf
= tarfile
.open(fileobj
=tar_pkg
)
579 tarf
= self
._descriptor
_clone
(tarf
, 'nsd')
580 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'))
582 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
585 r
= requests
.post(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'), verify
=False,
587 except Exception as e
:
589 result
['data'] = str(e
)
591 if r
.status_code
== requests
.codes
.created
:
592 result
['error'] = False
593 if r
.status_code
== requests
.codes
.conflict
:
594 result
['data'] = "Invalid ID."
598 def vnfd_clone(self
, token
, id):
599 result
= {'error': True, 'data': ''}
600 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
601 'Authorization': 'Bearer {}'.format(token
['id'])}
603 # get the package onboarded
604 tar_pkg
= self
.get_vnfd_pkg(token
, id)
605 tarf
= tarfile
.open(fileobj
=tar_pkg
)
607 tarf
= self
._descriptor
_clone
(tarf
, 'vnfd')
608 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'))
610 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
613 r
= requests
.post(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'), verify
=False,
615 except Exception as e
:
617 result
['data'] = str(e
)
619 if r
.status_code
== requests
.codes
.created
:
620 result
['error'] = False
621 if r
.status_code
== requests
.codes
.conflict
:
622 result
['data'] = "Invalid ID."
626 def nst_content_update(self
, token
, id, template
):
627 result
= {'error': True, 'data': ''}
628 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
629 'Authorization': 'Bearer {}'.format(token
['id'])}
630 _url
= "{0}/nst/v1/netslice_templates/{1}/nst_content".format(self
._base
_path
,id)
632 r
= requests
.put(_url
, data
=template
, verify
=False, headers
=headers
)
633 except Exception as e
:
635 result
['data'] = str(e
)
637 if r
.status_code
== requests
.codes
.no_content
:
638 result
['error'] = False
641 def nsd_update(self
, token
, id, data
):
642 result
= {'error': True, 'data': ''}
643 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
644 'Authorization': 'Bearer {}'.format(token
['id'])}
646 # get the package onboarded
647 tar_pkg
= self
.get_nsd_pkg(token
, id)
648 tarf
= tarfile
.open(fileobj
=tar_pkg
)
650 tarf
= self
._descriptor
_update
(tarf
, data
)
651 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
653 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self
._base
_path
, id)
656 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
658 except Exception as e
:
660 result
['data'] = str(e
)
662 if r
.status_code
== requests
.codes
.no_content
:
663 result
['error'] = False
666 result
['data'] = r
.json()
667 except Exception as e
:
672 def vnfd_update(self
, token
, id, data
):
673 result
= {'error': True, 'data': ''}
674 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
675 'Authorization': 'Bearer {}'.format(token
['id'])}
677 # get the package onboarded
678 tar_pkg
= self
.get_vnfd_pkg(token
, id)
679 tarf
= tarfile
.open(fileobj
=tar_pkg
)
681 tarf
= self
._descriptor
_update
(tarf
, data
)
682 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
684 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self
._base
_path
, id)
687 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
689 except Exception as e
:
691 result
['data'] = str(e
)
693 if r
.status_code
== requests
.codes
.no_content
:
694 result
['error'] = False
697 result
['data'] = r
.json()
698 except Exception as e
:
703 def get_nsd_pkg(self
, token
, id):
704 result
= {'error': True, 'data': ''}
705 headers
= {"accept": "application/zip",
706 'Authorization': 'Bearer {}'.format(token
['id'])}
708 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self
._base
_path
, id)
710 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
711 except Exception as e
:
713 result
['data'] = str(e
)
715 if r
.status_code
== requests
.codes
.ok
:
716 result
['error'] = False
717 tarf
= StringIO
.StringIO(r
.content
)
721 def get_vnfd_pkg(self
, token
, id):
722 result
= {'error': True, 'data': ''}
723 headers
= {"accept": "application/zip",
724 'Authorization': 'Bearer {}'.format(token
['id'])}
725 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self
._base
_path
, id)
727 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
728 except Exception as e
:
730 result
['data'] = str(e
)
732 if r
.status_code
== requests
.codes
.ok
:
733 result
['error'] = False
734 tarf
= StringIO
.StringIO(r
.content
)
738 def _descriptor_update(self
, tarf
, data
):
739 # extract the package on a tmp directory
740 tarf
.extractall('/tmp')
742 for name
in tarf
.getnames():
743 if name
.endswith(".yaml") or name
.endswith(".yml"):
744 with
open('/tmp/' + name
, 'w') as outfile
:
745 yaml
.safe_dump(data
, outfile
, default_flow_style
=False)
748 tarf_temp
= tarfile
.open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", "w:gz")
751 tarf_temp
.add('/tmp/' + tarinfo
.name
, tarinfo
.name
, recursive
=False)
755 def _create_base_pkg(self
, descriptor_type
, pkg_name
):
756 filename
= '/tmp/'+pkg_name
+'/' + pkg_name
+ '.yaml'
757 if descriptor_type
== 'nsd':
762 "short-name": str(pkg_name
),
763 "vendor": "OSM Composer",
764 "description": str(pkg_name
) + " descriptor",
766 "constituent-vnfd": [],
769 "name": str(pkg_name
)
775 elif descriptor_type
== 'vnfd':
777 "vnfd:vnfd-catalog": {
780 "short-name": str(pkg_name
),
789 "connection-point": [],
790 "name": str(pkg_name
)
796 if not os
.path
.exists(os
.path
.dirname(filename
)):
798 os
.makedirs(os
.path
.dirname(filename
))
799 except OSError as exc
: # Guard against race condition
800 if exc
.errno
!= errno
.EEXIST
:
803 with
open('/tmp/' + pkg_name
+ '/' + pkg_name
+ '.yaml', 'w') as yaml_file
:
804 yaml_file
.write(yaml
.dump(descriptor
, default_flow_style
=False))
806 tarf_temp
= tarfile
.open('/tmp/' + pkg_name
+ '.tar.gz', "w:gz")
807 tarf_temp
.add('/tmp/'+pkg_name
+'/' + pkg_name
+ '.yaml', pkg_name
+ '/' + pkg_name
+ '.yaml', recursive
=False)
810 def _descriptor_clone(self
, tarf
, descriptor_type
):
811 # extract the package on a tmp directory
812 tarf
.extractall('/tmp')
814 for name
in tarf
.getnames():
815 if name
.endswith(".yaml") or name
.endswith(".yml"):
816 with
open('/tmp/' + name
, 'r') as outfile
:
817 yaml_object
= yaml
.load(outfile
)
819 if descriptor_type
== 'nsd':
820 nsd_list
= yaml_object
['nsd:nsd-catalog']['nsd']
822 nsd
['id'] = 'clone_' + nsd
['id']
823 nsd
['name'] = 'clone_' + nsd
['name']
824 nsd
['short-name'] = 'clone_' + nsd
['short-name']
825 elif descriptor_type
== 'vnfd':
826 vnfd_list
= yaml_object
['vnfd:vnfd-catalog']['vnfd']
827 for vnfd
in vnfd_list
:
828 vnfd
['id'] = 'clone_' + vnfd
['id']
829 vnfd
['name'] = 'clone_' + vnfd
['name']
830 vnfd
['short-name'] = 'clone_' + vnfd
['short-name']
832 with
open('/tmp/' + name
, 'w') as yaml_file
:
833 yaml_file
.write(yaml
.dump(yaml_object
, default_flow_style
=False))
836 tarf_temp
= tarfile
.open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", "w:gz")
839 tarf_temp
.add('/tmp/' + tarinfo
.name
, tarinfo
.name
, recursive
=False)
843 def nsd_get(self
, token
, id):
844 result
= {'error': True, 'data': ''}
845 headers
= {'Content-Type': 'application/yaml',
846 'Authorization': 'Bearer {}'.format(token
['id'])}
847 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd".format(self
._base
_path
, id)
849 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
850 except Exception as e
:
852 result
['data'] = str(e
)
854 if r
.status_code
== requests
.codes
.ok
:
855 result
['error'] = False
856 return yaml
.load(r
.text
)
859 result
['data'] = r
.json()
860 except Exception as e
:
864 def vnfd_get(self
, token
, id):
865 result
= {'error': True, 'data': ''}
866 headers
= {'Content-Type': 'application/yaml',
867 'Authorization': 'Bearer {}'.format(token
['id'])}
868 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/vnfd".format(self
._base
_path
, id)
870 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
871 except Exception as e
:
873 result
['data'] = str(e
)
875 if r
.status_code
== requests
.codes
.ok
:
876 result
['error'] = False
877 return yaml
.load(r
.text
)
880 result
['data'] = r
.json()
881 except Exception as e
:
885 def nsd_artifacts(self
, token
, id):
886 result
= {'error': True, 'data': ''}
887 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
888 'Authorization': 'Bearer {}'.format(token
['id'])}
889 _url
= "{0}/nsd/v1/ns_descriptors/{1}/artifacts".format(self
._base
_path
, id)
891 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
892 except Exception as e
:
894 result
['data'] = str(e
)
896 if r
.status_code
== requests
.codes
.ok
:
897 result
['error'] = False
898 result
['data'] = r
.text
901 result
['data'] = r
.json()
902 except Exception as e
:
907 def vnf_packages_artifacts(self
, token
, id):
908 result
= {'error': True, 'data': ''}
909 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
910 'Authorization': 'Bearer {}'.format(token
['id'])}
911 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/artifacts".format(self
._base
_path
, id)
913 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
914 except Exception as e
:
916 result
['data'] = str(e
)
918 if r
.status_code
== requests
.codes
.ok
:
919 result
['error'] = False
920 result
['data'] = r
.text
923 result
['data'] = r
.json()
924 except Exception as e
:
929 def nsi_create(self
, token
, nsi_data
):
930 result
= {'error': True, 'data': ''}
931 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
932 'Authorization': 'Bearer {}'.format(token
['id'])}
934 _url
= "{0}/nsilcm/v1/netslice_instances_content".format(self
._base
_path
)
937 r
= requests
.post(_url
, json
=nsi_data
, verify
=False, headers
=headers
)
938 except Exception as e
:
940 result
['data'] = str(e
)
942 if r
.status_code
== requests
.codes
.ok
:
943 result
['error'] = False
944 result
['data'] = Util
.json_loads_byteified(r
.text
)
947 def ns_create(self
, token
, ns_data
):
948 result
= {'error': True, 'data': ''}
949 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
950 'Authorization': 'Bearer {}'.format(token
['id'])}
952 _url
= "{0}/nslcm/v1/ns_instances_content".format(self
._base
_path
)
955 r
= requests
.post(_url
, json
=ns_data
, verify
=False, headers
=headers
)
956 except Exception as e
:
958 result
['data'] = str(e
)
960 if r
.status_code
== requests
.codes
.ok
:
961 result
['error'] = False
962 result
['data'] = Util
.json_loads_byteified(r
.text
)
965 def pdu_create(self
, token
, pdu_data
):
966 result
= {'error': True, 'data': ''}
967 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
968 'Authorization': 'Bearer {}'.format(token
['id'])}
970 _url
= "{0}/pdu/v1/pdu_descriptors".format(self
._base
_path
)
973 r
= requests
.post(_url
, json
=pdu_data
, verify
=False, headers
=headers
)
974 except Exception as e
:
976 result
['data'] = str(e
)
978 if r
.status_code
== requests
.codes
.created
:
979 result
['error'] = False
980 result
['data'] = Util
.json_loads_byteified(r
.text
)
983 def ns_op_list(self
, token
, id):
984 result
= {'error': True, 'data': ''}
985 headers
= {"Content-Type": "application/json", "accept": "application/json",
986 'Authorization': 'Bearer {}'.format(token
['id'])}
987 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/?nsInstanceId={1}".format(self
._base
_path
, id)
990 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
991 except Exception as e
:
993 result
['data'] = str(e
)
995 if r
.status_code
== requests
.codes
.ok
:
996 result
['error'] = False
997 result
['data'] = Util
.json_loads_byteified(r
.text
)
1001 def nsi_op_list(self
, token
, id):
1002 result
= {'error': True, 'data': ''}
1003 headers
= {"Content-Type": "application/json", "accept": "application/json",
1004 'Authorization': 'Bearer {}'.format(token
['id'])}
1005 _url
= "{0}/nsilcm/v1/nsi_lcm_op_occs/?nsInstanceId={1}".format(self
._base
_path
, id)
1008 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1009 except Exception as e
:
1011 result
['data'] = str(e
)
1013 if r
.status_code
== requests
.codes
.ok
:
1014 result
['error'] = False
1015 result
['data'] = Util
.json_loads_byteified(r
.text
)
1019 def ns_op(self
, token
, id):
1020 result
= {'error': True, 'data': ''}
1021 headers
= {"Content-Type": "application/json", "accept": "application/json",
1022 'Authorization': 'Bearer {}'.format(token
['id'])}
1023 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/{1}".format(self
._base
_path
, id)
1026 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1027 except Exception as e
:
1029 result
['data'] = str(e
)
1031 if r
.status_code
== requests
.codes
.ok
:
1032 result
['error'] = False
1033 result
['data'] = Util
.json_loads_byteified(r
.text
)
1037 def ns_action(self
, token
, id, action_payload
):
1038 result
= {'error': True, 'data': ''}
1039 headers
= {"Content-Type": "application/json", "accept": "application/json",
1040 'Authorization': 'Bearer {}'.format(token
['id'])}
1042 _url
= "{0}/nslcm/v1/ns_instances/{1}/action".format(self
._base
_path
, id)
1045 r
= requests
.post(_url
, json
=action_payload
, verify
=False, headers
=headers
)
1046 except Exception as e
:
1048 result
['data'] = str(e
)
1050 if r
.status_code
== requests
.codes
.created
:
1051 result
['error'] = False
1052 result
['data'] = Util
.json_loads_byteified(r
.text
)
1055 def nsi_delete(self
, token
, id, force
=None):
1056 result
= {'error': True, 'data': ''}
1057 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1058 'Authorization': 'Bearer {}'.format(token
['id'])}
1061 query_path
= '?FORCE=true'
1062 _url
= "{0}/nsilcm/v1/netslice_instances_content/{1}{2}".format(self
._base
_path
, id, query_path
)
1064 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1065 except Exception as e
:
1067 result
['data'] = str(e
)
1070 result
['error'] = False
1071 if r
.status_code
!= requests
.codes
.no_content
:
1072 result
['data'] = Util
.json_loads_byteified(r
.text
)
1075 def ns_delete(self
, token
, id, force
=None):
1076 result
= {'error': True, 'data': ''}
1077 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1078 'Authorization': 'Bearer {}'.format(token
['id'])}
1081 query_path
= '?FORCE=true'
1082 _url
= "{0}/nslcm/v1/ns_instances_content/{1}{2}".format(self
._base
_path
, id, query_path
)
1084 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1085 except Exception as e
:
1087 result
['data'] = str(e
)
1090 result
['error'] = False
1091 if r
.status_code
!= requests
.codes
.no_content
:
1092 result
['data'] = Util
.json_loads_byteified(r
.text
)
1095 def pdu_delete(self
, token
, id):
1096 result
= {'error': True, 'data': ''}
1097 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1098 'Authorization': 'Bearer {}'.format(token
['id'])}
1099 _url
= "{0}/pdu/v1/pdu_descriptors/{1}".format(self
._base
_path
, id)
1101 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1102 except Exception as e
:
1104 result
['data'] = str(e
)
1107 result
['error'] = False
1108 if r
.status_code
!= requests
.codes
.no_content
:
1109 result
['data'] = Util
.json_loads_byteified(r
.text
)
1112 def nsi_get(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/netslice_instances/{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
== requests
.codes
.ok
:
1125 result
['error'] = False
1126 result
['data'] = Util
.json_loads_byteified(r
.text
)
1129 def ns_get(self
, token
, id):
1130 result
= {'error': True, 'data': ''}
1131 headers
= {"Content-Type": "application/json", "accept": "application/json",
1132 'Authorization': 'Bearer {}'.format(token
['id'])}
1133 _url
= "{0}/nslcm/v1/ns_instances_content/{1}".format(self
._base
_path
, id)
1136 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1137 except Exception as e
:
1139 result
['data'] = str(e
)
1141 if r
.status_code
== requests
.codes
.ok
:
1142 result
['error'] = False
1143 result
['data'] = Util
.json_loads_byteified(r
.text
)
1146 def vnf_get(self
, token
, id):
1147 result
= {'error': True, 'data': ''}
1148 headers
= {"Content-Type": "application/json", "accept": "application/json",
1149 'Authorization': 'Bearer {}'.format(token
['id'])}
1150 _url
= "{0}/nslcm/v1/vnfrs/{1}".format(self
._base
_path
, id)
1153 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1154 except Exception as e
:
1156 result
['data'] = str(e
)
1158 if r
.status_code
== requests
.codes
.ok
:
1159 result
['error'] = False
1160 result
['data'] = Util
.json_loads_byteified(r
.text
)
1163 def pdu_get(self
, token
, id):
1164 result
= {'error': True, 'data': ''}
1165 headers
= {"Content-Type": "application/json", "accept": "application/json",
1166 'Authorization': 'Bearer {}'.format(token
['id'])}
1167 _url
= "{0}/pdu/v1/pdu_descriptors/{1}".format(self
._base
_path
, id)
1170 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1171 except Exception as e
:
1173 result
['data'] = str(e
)
1175 if r
.status_code
== requests
.codes
.ok
:
1176 result
['error'] = False
1177 result
['data'] = Util
.json_loads_byteified(r
.text
)
1180 def ns_alarm_create(self
, token
, id, alarm_payload
):
1181 result
= {'error': True, 'data': ''}
1182 headers
= {"Content-Type": "application/json",
1183 'Authorization': 'Bearer {}'.format(token
['id'])}
1184 _url
= "{0}/test/message/alarm_request".format(self
._base
_path
)
1186 r
= requests
.post(_url
, json
=alarm_payload
, verify
=False, headers
=headers
)
1187 except Exception as e
:
1189 result
['data'] = str(e
)
1191 if r
.status_code
== requests
.codes
.ok
:
1192 result
['error'] = False
1193 # result['data'] = Util.json_loads_byteified(r.text)
1194 result
['data'] = r
.text
1197 def ns_metric_export(self
, token
, id, metric_payload
):
1198 result
= {'error': True, 'data': ''}
1199 headers
= {"Content-Type": "application/json",
1200 'Authorization': 'Bearer {}'.format(token
['id'])}
1201 _url
= "{0}/test/message/metric_request".format(self
._base
_path
)
1203 r
= requests
.post(_url
, json
=metric_payload
, verify
=False, headers
=headers
)
1204 except Exception as e
:
1206 result
['data'] = str(e
)
1208 if r
.status_code
== requests
.codes
.ok
:
1209 result
['error'] = False
1210 # result['data'] = Util.json_loads_byteified(r.text)
1211 result
['data'] = r
.text
1214 def wim_list(self
, token
):
1215 result
= {'error': True, 'data': ''}
1216 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1217 'Authorization': 'Bearer {}'.format(token
['id'])}
1218 _url
= "{0}/admin/v1/wim_accounts".format(self
._base
_path
)
1220 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1221 except Exception as e
:
1223 result
['data'] = str(e
)
1225 if r
.status_code
== requests
.codes
.ok
:
1226 result
['error'] = False
1227 result
['data'] = Util
.json_loads_byteified(r
.text
)
1231 def vim_list(self
, token
):
1232 result
= {'error': True, 'data': ''}
1233 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1234 'Authorization': 'Bearer {}'.format(token
['id'])}
1235 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
1237 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1238 except Exception as e
:
1240 result
['data'] = str(e
)
1242 if r
.status_code
== requests
.codes
.ok
:
1243 result
['error'] = False
1244 result
['data'] = Util
.json_loads_byteified(r
.text
)
1248 def wim_delete(self
, token
, id):
1249 result
= {'error': True, 'data': ''}
1250 headers
= {"accept": "application/json",
1251 'Authorization': 'Bearer {}'.format(token
['id'])}
1252 _url
= "{0}/admin/v1/wim_accounts/{1}".format(self
._base
_path
, id)
1254 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1255 except Exception as e
:
1257 result
['data'] = str(e
)
1259 if r
.status_code
== requests
.codes
.accepted
:
1260 result
['error'] = False
1262 result
['data'] = r
.text
1265 def vim_delete(self
, token
, id):
1266 result
= {'error': True, 'data': ''}
1267 headers
= {"accept": "application/json",
1268 'Authorization': 'Bearer {}'.format(token
['id'])}
1269 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
1271 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1272 except Exception as e
:
1274 result
['data'] = str(e
)
1276 if r
.status_code
== requests
.codes
.accepted
:
1277 result
['error'] = False
1279 result
['data'] = r
.text
1282 def wim_get(self
, token
, id):
1284 result
= {'error': True, 'data': ''}
1285 headers
= {"Content-Type": "application/json", "accept": "application/json",
1286 'Authorization': 'Bearer {}'.format(token
['id'])}
1287 _url
= "{0}/admin/v1/wim_accounts/{1}".format(self
._base
_path
, id)
1290 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1291 except Exception as e
:
1293 result
['data'] = str(e
)
1295 if r
.status_code
== requests
.codes
.ok
:
1296 result
['error'] = False
1297 result
['data'] = Util
.json_loads_byteified(r
.text
)
1300 def vim_get(self
, token
, id):
1302 result
= {'error': True, 'data': ''}
1303 headers
= {"Content-Type": "application/json", "accept": "application/json",
1304 'Authorization': 'Bearer {}'.format(token
['id'])}
1305 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
1308 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1309 except Exception as e
:
1311 result
['data'] = str(e
)
1313 if r
.status_code
== requests
.codes
.ok
:
1314 result
['error'] = False
1315 result
['data'] = Util
.json_loads_byteified(r
.text
)
1318 def wim_create(self
, token
, wim_data
):
1319 result
= {'error': True, 'data': ''}
1320 headers
= {"Content-Type": "application/json", "accept": "application/json",
1321 'Authorization': 'Bearer {}'.format(token
['id'])}
1323 _url
= "{0}/admin/v1/wim_accounts".format(self
._base
_path
)
1326 r
= requests
.post(_url
, json
=wim_data
, verify
=False, headers
=headers
)
1327 except Exception as e
:
1329 result
['data'] = str(e
)
1331 if r
.status_code
== requests
.codes
.created
:
1332 result
['error'] = False
1333 result
['data'] = Util
.json_loads_byteified(r
.text
)
1336 def vim_create(self
, token
, vim_data
):
1338 result
= {'error': True, 'data': ''}
1339 headers
= {"Content-Type": "application/json", "accept": "application/json",
1340 'Authorization': 'Bearer {}'.format(token
['id'])}
1342 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
1345 r
= requests
.post(_url
, json
=vim_data
, verify
=False, headers
=headers
)
1346 except Exception as e
:
1348 result
['data'] = str(e
)
1350 if r
.status_code
== requests
.codes
.created
:
1351 result
['error'] = False
1352 result
['data'] = Util
.json_loads_byteified(r
.text
)
1355 def sdn_list(self
, token
):
1356 result
= {'error': True, 'data': ''}
1357 headers
= {"accept": "application/json",
1358 'Authorization': 'Bearer {}'.format(token
['id'])}
1359 _url
= "{0}/admin/v1/sdns".format(self
._base
_path
)
1361 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1362 except Exception as e
:
1364 result
['data'] = str(e
)
1366 if r
.status_code
== requests
.codes
.ok
:
1367 result
['error'] = False
1368 result
['data'] = Util
.json_loads_byteified(r
.text
)
1371 def sdn_delete(self
, token
, id):
1372 result
= {'error': True, 'data': ''}
1373 headers
= {"accept": "application/json",
1374 'Authorization': 'Bearer {}'.format(token
['id'])}
1375 _url
= "{0}/admin/v1/sdns/{1}".format(self
._base
_path
, id)
1377 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1378 except Exception as e
:
1380 result
['data'] = str(e
)
1382 if r
.status_code
== requests
.codes
.accepted
:
1383 result
['error'] = False
1385 result
['data'] = r
.text
1388 def sdn_get(self
, token
, id):
1389 result
= {'error': True, 'data': ''}
1390 headers
= {"accept": "application/json",
1391 'Authorization': 'Bearer {}'.format(token
['id'])}
1392 _url
= "{0}/admin/v1/sdns/{1}".format(self
._base
_path
, id)
1395 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1396 except Exception as e
:
1398 result
['data'] = str(e
)
1400 if r
.status_code
== requests
.codes
.ok
:
1401 result
['error'] = False
1402 result
['data'] = Util
.json_loads_byteified(r
.text
)
1405 def sdn_create(self
, token
, sdn_data
):
1406 result
= {'error': True, 'data': ''}
1407 headers
= {"Content-Type": "application/json", "accept": "application/json",
1408 'Authorization': 'Bearer {}'.format(token
['id'])}
1410 _url
= "{0}/admin/v1/sdns".format(self
._base
_path
)
1413 r
= requests
.post(_url
, json
=sdn_data
, verify
=False, headers
=headers
)
1414 except Exception as e
:
1416 result
['data'] = str(e
)
1418 if r
.status_code
== requests
.codes
.created
:
1419 result
['error'] = False
1420 result
['data'] = Util
.json_loads_byteified(r
.text
)
1425 hash_md5
= hashlib
.md5()
1426 for chunk
in iter(lambda: f
.read(1024), b
""):
1427 hash_md5
.update(chunk
)
1428 return hash_md5
.hexdigest()