5e4f390f9bb185dff98c9782175e102d667da5bc
8 from lib
.util
import Util
12 logging
.basicConfig(level
=logging
.DEBUG
)
13 log
= logging
.getLogger('helper.py')
18 self
._token
_endpoint
= 'admin/v1/tokens'
19 self
._user
_endpoint
= 'admin/v1/users'
20 self
._host
= os
.getenv('OSM_SERVER', "localhost")
22 self
._base
_path
= "https://{0}:{1}/osm".format(self
._host
, self
._so
_port
)
25 result
= {'error': True, 'data': ''}
26 token_url
= "{0}/{1}".format(self
._base
_path
, self
._token
_endpoint
)
27 headers
= {"Content-Type": "application/yaml", "accept": "application/json"}
29 r
= requests
.post(token_url
, json
=args
, verify
=False, headers
=headers
)
30 except Exception as e
:
32 result
['data'] = str(e
)
34 if r
.status_code
== requests
.codes
.ok
:
35 result
['error'] = False
37 result
['data'] = Util
.json_loads_byteified(r
.text
)
41 def switch_project(self
, args
):
42 result
= {'error': True, 'data': ''}
43 token_url
= "{0}/{1}".format(self
._base
_path
, self
._token
_endpoint
)
44 headers
= {"Content-Type": "application/yaml", "accept": "application/json"}
46 r
= requests
.post(token_url
, json
=args
, verify
=False, headers
=headers
)
47 except Exception as e
:
49 result
['data'] = str(e
)
51 if r
.status_code
== requests
.codes
.ok
:
52 result
['error'] = False
54 result
['data'] = Util
.json_loads_byteified(r
.text
)
58 def user_list(self
, token
):
59 result
= {'error': True, 'data': ''}
60 headers
= {"Content-Type": "application/json", "accept": "application/json",
61 'Authorization': 'Bearer {}'.format(token
['id'])}
63 _url
= "{0}/admin/v1/users".format(self
._base
_path
)
65 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
66 except Exception as e
:
68 result
['data'] = str(e
)
70 if r
.status_code
== requests
.codes
.ok
:
71 result
['error'] = False
72 result
['data'] = Util
.json_loads_byteified(r
.text
)
76 def user_create(self
, token
, user_data
):
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
)
84 r
= requests
.post(_url
, json
=user_data
, verify
=False, headers
=headers
)
85 except Exception as e
:
87 result
['data'] = str(e
)
90 if r
.status_code
== requests
.codes
.created
:
91 result
['error'] = False
92 result
['data'] = Util
.json_loads_byteified(r
.text
)
95 def user_delete(self
, token
, id):
96 result
= {'error': True, 'data': ''}
97 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
98 'Authorization': 'Bearer {}'.format(token
['id'])}
100 _url
= "{0}/admin/v1/users/{1}".format(self
._base
_path
, id)
102 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
103 except Exception as e
:
105 result
['data'] = str(e
)
107 if r
.status_code
== requests
.codes
.no_content
:
108 result
['error'] = False
110 result
['data'] = Util
.json_loads_byteified(r
.text
)
113 def get_user_info(self
, token
, id):
114 result
= {'error': True, 'data': ''}
115 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
116 'Authorization': 'Bearer {}'.format(token
['id'])}
117 _url
= "{0}/admin/v1/users/{1}".format(self
._base
_path
, id)
119 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
120 except Exception as e
:
122 result
['data'] = str(e
)
124 if r
.status_code
== requests
.codes
.ok
:
125 result
['error'] = False
126 result
['data'] = Util
.json_loads_byteified(r
.text
)
129 def project_list(self
, token
):
130 result
= {'error': True, 'data': ''}
131 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
132 'Authorization': 'Bearer {}'.format(token
['id'])}
134 _url
= "{0}/admin/v1/projects".format(self
._base
_path
)
136 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
137 except Exception as e
:
139 result
['data'] = str(e
)
141 if r
.status_code
== requests
.codes
.ok
:
142 result
['error'] = False
143 result
['data'] = Util
.json_loads_byteified(r
.text
)
147 def project_get(self
, token
, id):
148 result
= {'error': True, 'data': ''}
149 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
150 'Authorization': 'Bearer {}'.format(token
['id'])}
151 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
153 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
154 except Exception as e
:
156 result
['data'] = str(e
)
158 if r
.status_code
== requests
.codes
.ok
:
159 result
['error'] = False
160 result
['data'] = Util
.json_loads_byteified(r
.text
)
163 def project_create(self
, token
, project_data
):
165 result
= {'error': True, 'data': ''}
166 headers
= {"Content-Type": "application/json", "accept": "application/json",
167 'Authorization': 'Bearer {}'.format(token
['id'])}
169 _url
= "{0}/admin/v1/projects".format(self
._base
_path
)
172 r
= requests
.post(_url
, json
=project_data
, verify
=False, headers
=headers
)
173 except Exception as e
:
175 result
['data'] = str(e
)
178 if r
.status_code
== requests
.codes
.created
:
179 result
['error'] = False
180 result
['data'] = Util
.json_loads_byteified(r
.text
)
183 def project_delete(self
, token
, id):
184 result
= {'error': True, 'data': ''}
185 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
186 'Authorization': 'Bearer {}'.format(token
['id'])}
188 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
190 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
191 except Exception as e
:
193 result
['data'] = str(e
)
195 if r
.status_code
== requests
.codes
.no_content
:
196 result
['error'] = False
198 result
['data'] = Util
.json_loads_byteified(r
.text
)
201 def nsd_list(self
, token
):
202 result
= {'error': True, 'data': ''}
203 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
204 'Authorization': 'Bearer {}'.format(token
['id'])}
206 _url
= "{0}/nsd/v1/ns_descriptors_content".format(self
._base
_path
)
208 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
209 except Exception as e
:
211 result
['data'] = str(e
)
213 if r
.status_code
== requests
.codes
.ok
:
214 result
['error'] = False
215 result
['data'] = Util
.json_loads_byteified(r
.text
)
219 def vnfd_list(self
, token
):
220 result
= {'error': True, 'data': ''}
221 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
222 'Authorization': 'Bearer {}'.format(token
['id'])}
224 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
226 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
227 except Exception as e
:
229 result
['data'] = str(e
)
231 if r
.status_code
== requests
.codes
.ok
:
232 result
['error'] = False
233 result
['data'] = Util
.json_loads_byteified(r
.text
)
237 def ns_list(self
, token
):
238 result
= {'error': True, 'data': ''}
239 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
240 'Authorization': 'Bearer {}'.format(token
['id'])}
241 _url
= "{0}/nslcm/v1/ns_instances_content".format(self
._base
_path
)
243 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
244 except Exception as e
:
246 result
['data'] = str(e
)
248 if r
.status_code
== requests
.codes
.ok
:
249 result
['error'] = False
250 result
['data'] = Util
.json_loads_byteified(r
.text
)
254 def vnf_list(self
, token
):
255 result
= {'error': True, 'data': ''}
256 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
257 'Authorization': 'Bearer {}'.format(token
['id'])}
258 _url
= "{0}/nslcm/v1/vnfrs".format(self
._base
_path
)
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 nsd_delete(self
, token
, id):
272 result
= {'error': True, 'data': ''}
273 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
274 'Authorization': 'Bearer {}'.format(token
['id'])}
276 _url
= "{0}/nsd/v1/ns_descriptors_content/{1}".format(self
._base
_path
, id)
278 r
= requests
.delete(_url
, params
=None, verify
=False,headers
=headers
)
279 except Exception as e
:
281 result
['data'] = str(e
)
283 if r
.status_code
== requests
.codes
.ok
:
284 result
['error'] = False
285 result
['data'] = Util
.json_loads_byteified(r
.text
)
288 def vnfd_delete(self
, token
, id):
289 result
= {'error': True, 'data': ''}
290 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
291 'Authorization': 'Bearer {}'.format(token
['id'])}
293 _url
= "{0}/vnfpkgm/v1/vnf_packages_content/{1}".format(self
._base
_path
, id)
295 r
= requests
.delete(_url
, params
=None, verify
=False, 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
)
305 def nsd_onboard(self
, token
, package
):
306 result
= {'error': True, 'data': ''}
307 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
308 'Authorization': 'Bearer {}'.format(token
['id'])}
309 with
open('/tmp/'+package
.name
, 'wb+') as destination
:
310 for chunk
in package
.chunks():
311 destination
.write(chunk
)
312 headers
['Content-File-MD5'] = self
.md5(open('/tmp/'+package
.name
, 'rb'))
313 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
315 r
= requests
.post(_url
, data
=open('/tmp/'+package
.name
, 'rb'), verify
=False, headers
=headers
)
316 except Exception as e
:
318 result
['data'] = str(e
)
320 if r
.status_code
== requests
.codes
.created
:
321 result
['error'] = False
322 result
['data'] = Util
.json_loads_byteified(r
.text
)
325 def vnfd_onboard(self
, token
, package
):
326 result
= {'error': True, 'data': ''}
327 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
328 'Authorization': 'Bearer {}'.format(token
['id'])}
329 with
open('/tmp/'+package
.name
, 'wb+') as destination
:
330 for chunk
in package
.chunks():
331 destination
.write(chunk
)
332 headers
['Content-File-MD5'] = self
.md5(open('/tmp/'+package
.name
, 'rb'))
333 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
335 r
= requests
.post(_url
, data
=open('/tmp/'+package
.name
, 'rb'), verify
=False, headers
=headers
)
336 except Exception as e
:
338 result
['data'] = str(e
)
340 if r
.status_code
== requests
.codes
.created
:
341 result
['error'] = False
342 result
['data'] = Util
.json_loads_byteified(r
.text
)
345 def nsd_update(self
, token
, id, data
):
346 result
= {'error': True, 'data': ''}
347 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
348 'Authorization': 'Bearer {}'.format(token
['id'])}
350 # get the package onboarded
351 tar_pkg
= self
.get_nsd_pkg(token
, id)
352 tarf
= tarfile
.open(fileobj
=tar_pkg
)
354 tarf
= self
._descriptor
_update
(tarf
, data
)
355 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
357 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self
._base
_path
, id)
360 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
362 except Exception as e
:
364 result
['data'] = str(e
)
366 if r
.status_code
== requests
.codes
.no_content
:
367 result
['error'] = False
371 def vnfd_update(self
, token
, id, data
):
372 result
= {'error': True, 'data': ''}
373 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
374 'Authorization': 'Bearer {}'.format(token
['id'])}
376 # get the package onboarded
377 tar_pkg
= self
.get_vnfd_pkg(token
, id)
378 tarf
= tarfile
.open(fileobj
=tar_pkg
)
380 tarf
= self
._descriptor
_update
(tarf
, data
)
381 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
383 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self
._base
_path
, id)
386 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
388 except Exception as e
:
390 result
['data'] = str(e
)
392 if r
.status_code
== requests
.codes
.no_content
:
393 result
['error'] = False
397 def get_nsd_pkg(self
, token
, id):
398 result
= {'error': True, 'data': ''}
399 headers
= { "accept": "application/zip",
400 'Authorization': 'Bearer {}'.format(token
['id'])}
402 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self
._base
_path
, id)
404 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
405 except Exception as e
:
407 result
['data'] = str(e
)
409 if r
.status_code
== requests
.codes
.ok
:
410 result
['error'] = False
411 tarf
= StringIO
.StringIO(r
.content
)
415 def get_vnfd_pkg(self
, token
, id):
416 result
= {'error': True, 'data': ''}
417 headers
= {"accept": "application/zip",
418 'Authorization': 'Bearer {}'.format(token
['id'])}
419 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self
._base
_path
, id)
421 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
423 except Exception as e
:
425 result
['data'] = str(e
)
427 if r
.status_code
== requests
.codes
.ok
:
428 result
['error'] = False
429 tarf
= StringIO
.StringIO(r
.content
)
433 def _descriptor_update(self
, tarf
, data
):
434 print tarf
.getnames()
435 # extract the package on a tmp directory
436 tarf
.extractall('/tmp')
438 for name
in tarf
.getnames():
439 if name
.endswith(".yaml") or name
.endswith(".yml"):
440 with
open('/tmp/' + name
, 'w') as outfile
:
441 yaml
.safe_dump(data
, outfile
, default_flow_style
=False)
444 tarf_temp
= tarfile
.open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", "w:gz")
445 # tarf_temp = tarfile.open("pippo.tar.gz", "w:gz")
446 print tarf_temp
.getnames()
447 # tarf_temp.add('/tmp/'+tarf.getnames()[0])
449 # if tarinfo.name.startswith(tarf.getnames()[0]):
450 # new_name = tarinfo.name[len(tarf.getnames()[0]):]
451 tarf_temp
.add('/tmp/' + tarinfo
.name
, tarinfo
.name
, recursive
=False)
452 print tarf_temp
.getnames()
456 def nsd_get(self
, token
, id):
457 result
= {'error': True, 'data': ''}
458 headers
= {'Content-Type': 'application/yaml',
459 'Authorization': 'Bearer {}'.format(token
['id'])}
460 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd".format(self
._base
_path
, id)
462 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
463 except Exception as e
:
465 result
['data'] = str(e
)
467 if r
.status_code
== requests
.codes
.ok
:
468 result
['error'] = False
469 return yaml
.load(r
.text
)
472 result
['data'] = r
.json()
473 except Exception as e
:
477 def vnfd_get(self
, token
, id):
478 result
= {'error': True, 'data': ''}
479 headers
= {'Content-Type': 'application/yaml',
480 'Authorization': 'Bearer {}'.format(token
['id'])}
481 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/vnfd".format(self
._base
_path
, id)
483 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
484 except Exception as e
:
486 result
['data'] = str(e
)
488 if r
.status_code
== requests
.codes
.ok
:
489 result
['error'] = False
490 return yaml
.load(r
.text
)
493 result
['data'] = r
.json()
494 except Exception as e
:
498 def nsd_artifacts(self
, token
, id):
499 result
= {'error': True, 'data': ''}
500 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
501 'Authorization': 'Bearer {}'.format(token
['id'])}
502 _url
= "{0}/nsd/v1/ns_descriptors/{1}/artifacts".format(self
._base
_path
, id)
504 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
505 except Exception as e
:
507 result
['data'] = str(e
)
509 if r
.status_code
== requests
.codes
.ok
:
510 result
['error'] = False
511 result
['data'] = r
.text
514 result
['data'] = r
.json()
515 except Exception as e
:
520 def vnf_packages_artifacts(self
, token
, id):
521 result
= {'error': True, 'data': ''}
522 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
523 'Authorization': 'Bearer {}'.format(token
['id'])}
524 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/artifacts".format(self
._base
_path
, id)
526 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
527 except Exception as e
:
529 result
['data'] = str(e
)
531 if r
.status_code
== requests
.codes
.ok
:
532 result
['error'] = False
533 result
['data'] = r
.text
536 result
['data'] = r
.json()
537 except Exception as e
:
542 def ns_create(self
, token
, ns_data
):
543 result
= {'error': True, 'data': ''}
544 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
545 'Authorization': 'Bearer {}'.format(token
['id'])}
547 _url
= "{0}/nslcm/v1/ns_instances_content".format(self
._base
_path
)
550 r
= requests
.post(_url
, json
=ns_data
, verify
=False, headers
=headers
)
551 except Exception as e
:
553 result
['data'] = str(e
)
555 if r
.status_code
== requests
.codes
.ok
:
556 result
['error'] = False
557 result
['data'] = Util
.json_loads_byteified(r
.text
)
560 def ns_op_list(self
, token
, id):
561 result
= {'error': True, 'data': ''}
562 headers
= {"Content-Type": "application/json", "accept": "application/json",
563 'Authorization': 'Bearer {}'.format(token
['id'])}
564 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/?nsInstanceId={1}".format(self
._base
_path
, id)
567 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
568 except Exception as e
:
570 result
['data'] = str(e
)
572 if r
.status_code
== requests
.codes
.ok
:
573 result
['error'] = False
574 result
['data'] = Util
.json_loads_byteified(r
.text
)
578 def ns_op(self
, token
, id):
579 result
= {'error': True, 'data': ''}
580 headers
= {"Content-Type": "application/json", "accept": "application/json",
581 'Authorization': 'Bearer {}'.format(token
['id'])}
582 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/{1}".format(self
._base
_path
, id)
585 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
586 except Exception as e
:
588 result
['data'] = str(e
)
590 if r
.status_code
== requests
.codes
.ok
:
591 result
['error'] = False
592 result
['data'] = Util
.json_loads_byteified(r
.text
)
596 def ns_action(self
, token
, id, action_payload
):
597 result
= {'error': True, 'data': ''}
598 headers
= {"Content-Type": "application/json", "accept": "application/json",
599 'Authorization': 'Bearer {}'.format(token
['id'])}
601 _url
= "{0}/nslcm/v1/ns_instances/{1}/action".format(self
._base
_path
, id)
604 r
= requests
.post(_url
, json
=action_payload
, verify
=False, headers
=headers
)
605 except Exception as e
:
607 result
['data'] = str(e
)
610 if r
.status_code
== requests
.codes
.created
:
611 result
['error'] = False
612 result
['data'] = Util
.json_loads_byteified(r
.text
)
615 def ns_delete(self
, token
, id, force
=None):
616 result
= {'error': True, 'data': ''}
617 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
618 'Authorization': 'Bearer {}'.format(token
['id'])}
621 query_path
= '?FORCE=true'
622 _url
= "{0}/nslcm/v1/ns_instances_content/{1}{2}".format(self
._base
_path
, id, query_path
)
624 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
625 except Exception as e
:
627 result
['data'] = str(e
)
629 if r
.status_code
== requests
.codes
.ok
:
630 result
['error'] = False
631 result
['data'] = Util
.json_loads_byteified(r
.text
)
634 def ns_get(self
, token
, id):
635 result
= {'error': True, 'data': ''}
636 headers
= {"Content-Type": "application/json", "accept": "application/json",
637 'Authorization': 'Bearer {}'.format(token
['id'])}
638 _url
= "{0}/nslcm/v1/ns_instances_content/{1}".format(self
._base
_path
, id)
641 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
642 except Exception as e
:
644 result
['data'] = str(e
)
646 if r
.status_code
== requests
.codes
.ok
:
647 result
['error'] = False
648 result
['data'] = Util
.json_loads_byteified(r
.text
)
651 def vnf_get(self
, token
, id):
652 result
= {'error': True, 'data': ''}
653 headers
= {"Content-Type": "application/json", "accept": "application/json",
654 'Authorization': 'Bearer {}'.format(token
['id'])}
655 _url
= "{0}/nslcm/v1/vnfrs/{1}".format(self
._base
_path
, id)
658 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
659 except Exception as e
:
661 result
['data'] = str(e
)
663 if r
.status_code
== requests
.codes
.ok
:
664 result
['error'] = False
665 result
['data'] = Util
.json_loads_byteified(r
.text
)
668 def ns_alarm_create(self
, token
, id, alarm_payload
):
669 result
= {'error': True, 'data': ''}
670 headers
= {"Content-Type": "application/json",
671 'Authorization': 'Bearer {}'.format(token
['id'])}
672 _url
= "{0}/test/message/alarm_request".format(self
._base
_path
)
674 r
= requests
.post(_url
, json
=alarm_payload
, verify
=False, headers
=headers
)
675 except Exception as e
:
677 result
['data'] = str(e
)
680 if r
.status_code
== requests
.codes
.ok
:
681 result
['error'] = False
682 #result['data'] = Util.json_loads_byteified(r.text)
683 result
['data'] = r
.text
686 def ns_metric_export(self
, token
, id, metric_payload
):
687 result
= {'error': True, 'data': ''}
688 headers
= {"Content-Type": "application/json",
689 'Authorization': 'Bearer {}'.format(token
['id'])}
690 _url
= "{0}/test/message/metric_request".format(self
._base
_path
)
692 r
= requests
.post(_url
, json
=metric_payload
, verify
=False, headers
=headers
)
693 except Exception as e
:
695 result
['data'] = str(e
)
698 if r
.status_code
== requests
.codes
.ok
:
699 result
['error'] = False
700 #result['data'] = Util.json_loads_byteified(r.text)
701 result
['data'] = r
.text
704 def vim_list(self
, token
):
705 result
= {'error': True, 'data': ''}
706 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
707 'Authorization': 'Bearer {}'.format(token
['id'])}
708 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
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 result
['data'] = Util
.json_loads_byteified(r
.text
)
721 def vim_delete(self
, token
, id):
722 result
= {'error': True, 'data': ''}
723 headers
= { "accept": "application/json",
724 'Authorization': 'Bearer {}'.format(token
['id'])}
725 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
727 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
728 except Exception as e
:
730 result
['data'] = str(e
)
733 if r
.status_code
== requests
.codes
.accepted
:
734 result
['error'] = False
736 result
['data'] = r
.text
739 def vim_get(self
, token
, id):
741 result
= {'error': True, 'data': ''}
742 headers
= {"Content-Type": "application/json", "accept": "application/json",
743 'Authorization': 'Bearer {}'.format(token
['id'])}
744 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
747 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
748 except Exception as e
:
750 result
['data'] = str(e
)
752 if r
.status_code
== requests
.codes
.ok
:
753 result
['error'] = False
754 result
['data'] = Util
.json_loads_byteified(r
.text
)
757 def vim_create(self
, token
, vim_data
):
759 result
= {'error': True, 'data': ''}
760 headers
= {"Content-Type": "application/json", "accept": "application/json",
761 'Authorization': 'Bearer {}'.format(token
['id'])}
763 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
766 r
= requests
.post(_url
, json
=vim_data
, verify
=False, headers
=headers
)
767 except Exception as e
:
769 result
['data'] = str(e
)
772 if r
.status_code
== requests
.codes
.created
:
773 result
['error'] = False
774 result
['data'] = Util
.json_loads_byteified(r
.text
)
777 def sdn_list(self
, token
):
778 result
= {'error': True, 'data': ''}
779 headers
= {"accept": "application/json",
780 'Authorization': 'Bearer {}'.format(token
['id'])}
781 _url
= "{0}/admin/v1/sdns".format(self
._base
_path
)
783 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
784 except Exception as e
:
786 result
['data'] = str(e
)
788 if r
.status_code
== requests
.codes
.ok
:
789 result
['error'] = False
790 result
['data'] = Util
.json_loads_byteified(r
.text
)
793 def sdn_delete(self
, token
, id):
794 result
= {'error': True, 'data': ''}
795 headers
= {"accept": "application/json",
796 'Authorization': 'Bearer {}'.format(token
['id'])}
797 _url
= "{0}/admin/v1/sdns/{1}".format(self
._base
_path
, id)
799 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
800 except Exception as e
:
802 result
['data'] = str(e
)
805 if r
.status_code
== requests
.codes
.accepted
:
806 result
['error'] = False
808 result
['data'] = r
.text
811 def sdn_get(self
, token
, id):
812 result
= {'error': True, 'data': ''}
813 headers
= {"accept": "application/json",
814 'Authorization': 'Bearer {}'.format(token
['id'])}
815 _url
= "{0}/admin/v1/sdns/{1}".format(self
._base
_path
, id)
818 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
819 except Exception as e
:
821 result
['data'] = str(e
)
823 if r
.status_code
== requests
.codes
.ok
:
824 result
['error'] = False
825 result
['data'] = Util
.json_loads_byteified(r
.text
)
829 def sdn_create(self
, token
, sdn_data
):
830 result
= {'error': True, 'data': ''}
831 headers
= {"Content-Type": "application/json", "accept": "application/json",
832 'Authorization': 'Bearer {}'.format(token
['id'])}
834 _url
= "{0}/admin/v1/sdns".format(self
._base
_path
)
837 r
= requests
.post(_url
, json
=sdn_data
, verify
=False, headers
=headers
)
838 except Exception as e
:
840 result
['data'] = str(e
)
843 if r
.status_code
== requests
.codes
.created
:
844 result
['error'] = False
845 result
['data'] = Util
.json_loads_byteified(r
.text
)
851 hash_md5
= hashlib
.md5()
852 for chunk
in iter(lambda: f
.read(1024), b
""):
853 hash_md5
.update(chunk
)
854 return hash_md5
.hexdigest()