536ef652b5649822eee75f643f9186381536b786
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 project_list(self
, token
):
114 result
= {'error': True, 'data': ''}
115 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
116 'Authorization': 'Bearer {}'.format(token
['id'])}
118 _url
= "{0}/admin/v1/projects".format(self
._base
_path
)
120 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
121 except Exception as e
:
123 result
['data'] = str(e
)
125 if r
.status_code
== requests
.codes
.ok
:
126 result
['error'] = False
127 result
['data'] = Util
.json_loads_byteified(r
.text
)
131 def project_get(self
, token
, id):
132 result
= {'error': True, 'data': ''}
133 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
134 'Authorization': 'Bearer {}'.format(token
['id'])}
135 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
137 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
138 except Exception as e
:
140 result
['data'] = str(e
)
142 if r
.status_code
== requests
.codes
.ok
:
143 result
['error'] = False
144 result
['data'] = Util
.json_loads_byteified(r
.text
)
146 def project_create(self
, token
, project_data
):
148 result
= {'error': True, 'data': ''}
149 headers
= {"Content-Type": "application/json", "accept": "application/json",
150 'Authorization': 'Bearer {}'.format(token
['id'])}
152 _url
= "{0}/admin/v1/projects".format(self
._base
_path
)
155 r
= requests
.post(_url
, json
=project_data
, verify
=False, headers
=headers
)
156 except Exception as e
:
158 result
['data'] = str(e
)
161 if r
.status_code
== requests
.codes
.created
:
162 result
['error'] = False
163 result
['data'] = Util
.json_loads_byteified(r
.text
)
166 def project_delete(self
, token
, id):
167 result
= {'error': True, 'data': ''}
168 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
169 'Authorization': 'Bearer {}'.format(token
['id'])}
171 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
173 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
174 except Exception as e
:
176 result
['data'] = str(e
)
178 if r
.status_code
== requests
.codes
.no_content
:
179 result
['error'] = False
181 result
['data'] = Util
.json_loads_byteified(r
.text
)
184 def nsd_list(self
, token
):
185 result
= {'error': True, 'data': ''}
186 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
187 'Authorization': 'Bearer {}'.format(token
['id'])}
189 _url
= "{0}/nsd/v1/ns_descriptors_content".format(self
._base
_path
)
191 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
192 except Exception as e
:
194 result
['data'] = str(e
)
196 if r
.status_code
== requests
.codes
.ok
:
197 result
['error'] = False
198 result
['data'] = Util
.json_loads_byteified(r
.text
)
202 def vnfd_list(self
, token
):
203 result
= {'error': True, 'data': ''}
204 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
205 'Authorization': 'Bearer {}'.format(token
['id'])}
207 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
209 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
210 except Exception as e
:
212 result
['data'] = str(e
)
214 if r
.status_code
== requests
.codes
.ok
:
215 result
['error'] = False
216 result
['data'] = Util
.json_loads_byteified(r
.text
)
220 def ns_list(self
, token
):
221 result
= {'error': True, 'data': ''}
222 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
223 'Authorization': 'Bearer {}'.format(token
['id'])}
224 _url
= "{0}/nslcm/v1/ns_instances_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 vnf_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/vnfrs".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 nsd_delete(self
, token
, id):
255 result
= {'error': True, 'data': ''}
256 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
257 'Authorization': 'Bearer {}'.format(token
['id'])}
259 _url
= "{0}/nsd/v1/ns_descriptors_content/{1}".format(self
._base
_path
, id)
261 r
= requests
.delete(_url
, params
=None, verify
=False,headers
=headers
)
262 except Exception as e
:
264 result
['data'] = str(e
)
266 if r
.status_code
== requests
.codes
.ok
:
267 result
['error'] = False
268 result
['data'] = Util
.json_loads_byteified(r
.text
)
271 def vnfd_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}/vnfpkgm/v1/vnf_packages_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 nsd_onboard(self
, token
, package
):
289 result
= {'error': True, 'data': ''}
290 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
291 'Authorization': 'Bearer {}'.format(token
['id'])}
292 with
open('/tmp/'+package
.name
, 'wb+') as destination
:
293 for chunk
in package
.chunks():
294 destination
.write(chunk
)
295 headers
['Content-File-MD5'] = self
.md5(open('/tmp/'+package
.name
, 'rb'))
296 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
298 r
= requests
.post(_url
, data
=open('/tmp/'+package
.name
, 'rb'), verify
=False, headers
=headers
)
299 except Exception as e
:
301 result
['data'] = str(e
)
303 if r
.status_code
== requests
.codes
.created
:
304 result
['error'] = False
305 result
['data'] = Util
.json_loads_byteified(r
.text
)
308 def vnfd_onboard(self
, token
, package
):
309 result
= {'error': True, 'data': ''}
310 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
311 'Authorization': 'Bearer {}'.format(token
['id'])}
312 with
open('/tmp/'+package
.name
, 'wb+') as destination
:
313 for chunk
in package
.chunks():
314 destination
.write(chunk
)
315 headers
['Content-File-MD5'] = self
.md5(open('/tmp/'+package
.name
, 'rb'))
316 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
318 r
= requests
.post(_url
, data
=open('/tmp/'+package
.name
, 'rb'), verify
=False, headers
=headers
)
319 except Exception as e
:
321 result
['data'] = str(e
)
323 if r
.status_code
== requests
.codes
.created
:
324 result
['error'] = False
325 result
['data'] = Util
.json_loads_byteified(r
.text
)
328 def nsd_update(self
, token
, id, data
):
329 result
= {'error': True, 'data': ''}
330 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
331 'Authorization': 'Bearer {}'.format(token
['id'])}
333 # get the package onboarded
334 tar_pkg
= self
.get_nsd_pkg(token
, id)
335 tarf
= tarfile
.open(fileobj
=tar_pkg
)
337 tarf
= self
._descriptor
_update
(tarf
, data
)
338 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
340 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self
._base
_path
, id)
343 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
345 except Exception as e
:
347 result
['data'] = str(e
)
349 if r
.status_code
== requests
.codes
.no_content
:
350 result
['error'] = False
354 def vnfd_update(self
, token
, id, data
):
355 result
= {'error': True, 'data': ''}
356 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
357 'Authorization': 'Bearer {}'.format(token
['id'])}
359 # get the package onboarded
360 tar_pkg
= self
.get_vnfd_pkg(token
, id)
361 tarf
= tarfile
.open(fileobj
=tar_pkg
)
363 tarf
= self
._descriptor
_update
(tarf
, data
)
364 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
366 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self
._base
_path
, id)
369 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
371 except Exception as e
:
373 result
['data'] = str(e
)
375 if r
.status_code
== requests
.codes
.no_content
:
376 result
['error'] = False
380 def get_nsd_pkg(self
, token
, id):
381 result
= {'error': True, 'data': ''}
382 headers
= { "accept": "application/zip",
383 'Authorization': 'Bearer {}'.format(token
['id'])}
385 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self
._base
_path
, id)
387 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
388 except Exception as e
:
390 result
['data'] = str(e
)
392 if r
.status_code
== requests
.codes
.ok
:
393 result
['error'] = False
394 tarf
= StringIO
.StringIO(r
.content
)
398 def get_vnfd_pkg(self
, token
, id):
399 result
= {'error': True, 'data': ''}
400 headers
= {"accept": "application/zip",
401 'Authorization': 'Bearer {}'.format(token
['id'])}
402 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self
._base
_path
, id)
404 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
== requests
.codes
.ok
:
411 result
['error'] = False
412 tarf
= StringIO
.StringIO(r
.content
)
416 def _descriptor_update(self
, tarf
, data
):
417 print tarf
.getnames()
418 # extract the package on a tmp directory
419 tarf
.extractall('/tmp')
421 for name
in tarf
.getnames():
422 if name
.endswith(".yaml") or name
.endswith(".yml"):
423 with
open('/tmp/' + name
, 'w') as outfile
:
424 yaml
.safe_dump(data
, outfile
, default_flow_style
=False)
427 tarf_temp
= tarfile
.open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", "w:gz")
428 # tarf_temp = tarfile.open("pippo.tar.gz", "w:gz")
429 print tarf_temp
.getnames()
430 # tarf_temp.add('/tmp/'+tarf.getnames()[0])
432 # if tarinfo.name.startswith(tarf.getnames()[0]):
433 # new_name = tarinfo.name[len(tarf.getnames()[0]):]
434 tarf_temp
.add('/tmp/' + tarinfo
.name
, tarinfo
.name
, recursive
=False)
435 print tarf_temp
.getnames()
439 def nsd_get(self
, token
, id):
440 result
= {'error': True, 'data': ''}
441 headers
= {'Content-Type': 'application/yaml',
442 'Authorization': 'Bearer {}'.format(token
['id'])}
443 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd".format(self
._base
_path
, id)
445 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
446 except Exception as e
:
448 result
['data'] = str(e
)
450 if r
.status_code
== requests
.codes
.ok
:
451 result
['error'] = False
452 return yaml
.load(r
.text
)
455 result
['data'] = r
.json()
456 except Exception as e
:
460 def vnfd_get(self
, token
, id):
461 result
= {'error': True, 'data': ''}
462 headers
= {'Content-Type': 'application/yaml',
463 'Authorization': 'Bearer {}'.format(token
['id'])}
464 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/vnfd".format(self
._base
_path
, id)
466 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
467 except Exception as e
:
469 result
['data'] = str(e
)
471 if r
.status_code
== requests
.codes
.ok
:
472 result
['error'] = False
473 return yaml
.load(r
.text
)
476 result
['data'] = r
.json()
477 except Exception as e
:
481 def nsd_artifacts(self
, token
, id):
482 result
= {'error': True, 'data': ''}
483 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
484 'Authorization': 'Bearer {}'.format(token
['id'])}
485 _url
= "{0}/nsd/v1/ns_descriptors/{1}/artifacts".format(self
._base
_path
, id)
487 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
488 except Exception as e
:
490 result
['data'] = str(e
)
492 if r
.status_code
== requests
.codes
.ok
:
493 result
['error'] = False
494 result
['data'] = r
.text
497 result
['data'] = r
.json()
498 except Exception as e
:
503 def vnf_packages_artifacts(self
, token
, id):
504 result
= {'error': True, 'data': ''}
505 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
506 'Authorization': 'Bearer {}'.format(token
['id'])}
507 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/artifacts".format(self
._base
_path
, id)
509 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
510 except Exception as e
:
512 result
['data'] = str(e
)
514 if r
.status_code
== requests
.codes
.ok
:
515 result
['error'] = False
516 result
['data'] = r
.text
519 result
['data'] = r
.json()
520 except Exception as e
:
525 def ns_create(self
, token
, ns_data
):
526 result
= {'error': True, 'data': ''}
527 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
528 'Authorization': 'Bearer {}'.format(token
['id'])}
530 _url
= "{0}/nslcm/v1/ns_instances_content".format(self
._base
_path
)
533 r
= requests
.post(_url
, json
=ns_data
, verify
=False, headers
=headers
)
534 except Exception as e
:
536 result
['data'] = str(e
)
538 if r
.status_code
== requests
.codes
.ok
:
539 result
['error'] = False
540 result
['data'] = Util
.json_loads_byteified(r
.text
)
543 def ns_op_list(self
, token
, id):
544 result
= {'error': True, 'data': ''}
545 headers
= {"Content-Type": "application/json", "accept": "application/json",
546 'Authorization': 'Bearer {}'.format(token
['id'])}
547 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/?nsInstanceId={1}".format(self
._base
_path
, id)
550 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, 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
)
561 def ns_op(self
, token
, id):
562 result
= {'error': True, 'data': ''}
563 headers
= {"Content-Type": "application/json", "accept": "application/json",
564 'Authorization': 'Bearer {}'.format(token
['id'])}
565 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/{1}".format(self
._base
_path
, id)
568 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
569 except Exception as e
:
571 result
['data'] = str(e
)
573 if r
.status_code
== requests
.codes
.ok
:
574 result
['error'] = False
575 result
['data'] = Util
.json_loads_byteified(r
.text
)
579 def ns_action(self
, token
, id, action_payload
):
580 result
= {'error': True, 'data': ''}
581 headers
= {"Content-Type": "application/json", "accept": "application/json",
582 'Authorization': 'Bearer {}'.format(token
['id'])}
584 _url
= "{0}/nslcm/v1/ns_instances/{1}/action".format(self
._base
_path
, id)
587 r
= requests
.post(_url
, json
=action_payload
, verify
=False, headers
=headers
)
588 except Exception as e
:
590 result
['data'] = str(e
)
593 if r
.status_code
== requests
.codes
.created
:
594 result
['error'] = False
595 result
['data'] = Util
.json_loads_byteified(r
.text
)
598 def ns_delete(self
, token
, id, force
=None):
599 result
= {'error': True, 'data': ''}
600 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
601 'Authorization': 'Bearer {}'.format(token
['id'])}
604 query_path
= '?FORCE=true'
605 _url
= "{0}/nslcm/v1/ns_instances_content/{1}{2}".format(self
._base
_path
, id, query_path
)
607 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
608 except Exception as e
:
610 result
['data'] = str(e
)
612 if r
.status_code
== requests
.codes
.ok
:
613 result
['error'] = False
614 result
['data'] = Util
.json_loads_byteified(r
.text
)
617 def ns_get(self
, token
, id):
618 result
= {'error': True, 'data': ''}
619 headers
= {"Content-Type": "application/json", "accept": "application/json",
620 'Authorization': 'Bearer {}'.format(token
['id'])}
621 _url
= "{0}/nslcm/v1/ns_instances_content/{1}".format(self
._base
_path
, id)
624 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, 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 vnf_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/vnfrs/{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 ns_alarm_create(self
, token
, id, alarm_payload
):
652 result
= {'error': True, 'data': ''}
653 headers
= {"Content-Type": "application/json",
654 'Authorization': 'Bearer {}'.format(token
['id'])}
655 _url
= "{0}/test/message/alarm_request".format(self
._base
_path
)
657 r
= requests
.post(_url
, json
=alarm_payload
, verify
=False, headers
=headers
)
658 except Exception as e
:
660 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)
666 result
['data'] = r
.text
669 def ns_metric_export(self
, token
, id, metric_payload
):
670 result
= {'error': True, 'data': ''}
671 headers
= {"Content-Type": "application/json",
672 'Authorization': 'Bearer {}'.format(token
['id'])}
673 _url
= "{0}/test/message/metric_request".format(self
._base
_path
)
675 r
= requests
.post(_url
, json
=metric_payload
, verify
=False, headers
=headers
)
676 except Exception as e
:
678 result
['data'] = str(e
)
681 if r
.status_code
== requests
.codes
.ok
:
682 result
['error'] = False
683 #result['data'] = Util.json_loads_byteified(r.text)
684 result
['data'] = r
.text
687 def vim_list(self
, token
):
688 result
= {'error': True, 'data': ''}
689 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
690 'Authorization': 'Bearer {}'.format(token
['id'])}
691 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
693 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
694 except Exception as e
:
696 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
)
704 def vim_delete(self
, token
, id):
705 result
= {'error': True, 'data': ''}
706 headers
= { "accept": "application/json",
707 'Authorization': 'Bearer {}'.format(token
['id'])}
708 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
710 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
711 except Exception as e
:
713 result
['data'] = str(e
)
716 if r
.status_code
== requests
.codes
.accepted
:
717 result
['error'] = False
719 result
['data'] = r
.text
722 def vim_get(self
, token
, id):
724 result
= {'error': True, 'data': ''}
725 headers
= {"Content-Type": "application/json", "accept": "application/json",
726 'Authorization': 'Bearer {}'.format(token
['id'])}
727 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
730 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
731 except Exception as e
:
733 result
['data'] = str(e
)
735 if r
.status_code
== requests
.codes
.ok
:
736 result
['error'] = False
737 result
['data'] = Util
.json_loads_byteified(r
.text
)
740 def vim_create(self
, token
, vim_data
):
742 result
= {'error': True, 'data': ''}
743 headers
= {"Content-Type": "application/json", "accept": "application/json",
744 'Authorization': 'Bearer {}'.format(token
['id'])}
746 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
749 r
= requests
.post(_url
, json
=vim_data
, verify
=False, headers
=headers
)
750 except Exception as e
:
752 result
['data'] = str(e
)
755 if r
.status_code
== requests
.codes
.created
:
756 result
['error'] = False
757 result
['data'] = Util
.json_loads_byteified(r
.text
)
760 def sdn_list(self
, token
):
761 result
= {'error': True, 'data': ''}
762 headers
= {"accept": "application/json",
763 'Authorization': 'Bearer {}'.format(token
['id'])}
764 _url
= "{0}/admin/v1/sdns".format(self
._base
_path
)
766 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
767 except Exception as e
:
769 result
['data'] = str(e
)
771 if r
.status_code
== requests
.codes
.ok
:
772 result
['error'] = False
773 result
['data'] = Util
.json_loads_byteified(r
.text
)
776 def sdn_delete(self
, token
, id):
777 result
= {'error': True, 'data': ''}
778 headers
= {"accept": "application/json",
779 'Authorization': 'Bearer {}'.format(token
['id'])}
780 _url
= "{0}/admin/v1/sdns/{1}".format(self
._base
_path
, id)
782 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
783 except Exception as e
:
785 result
['data'] = str(e
)
788 if r
.status_code
== requests
.codes
.accepted
:
789 result
['error'] = False
791 result
['data'] = r
.text
794 def sdn_get(self
, token
, id):
795 result
= {'error': True, 'data': ''}
796 headers
= {"accept": "application/json",
797 'Authorization': 'Bearer {}'.format(token
['id'])}
798 _url
= "{0}/admin/v1/sdns/{1}".format(self
._base
_path
, id)
801 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
802 except Exception as e
:
804 result
['data'] = str(e
)
806 if r
.status_code
== requests
.codes
.ok
:
807 result
['error'] = False
808 result
['data'] = Util
.json_loads_byteified(r
.text
)
812 def sdn_create(self
, token
, sdn_data
):
813 result
= {'error': True, 'data': ''}
814 headers
= {"Content-Type": "application/json", "accept": "application/json",
815 'Authorization': 'Bearer {}'.format(token
['id'])}
817 _url
= "{0}/admin/v1/sdns".format(self
._base
_path
)
820 r
= requests
.post(_url
, json
=sdn_data
, verify
=False, headers
=headers
)
821 except Exception as e
:
823 result
['data'] = str(e
)
826 if r
.status_code
== requests
.codes
.created
:
827 result
['error'] = False
828 result
['data'] = Util
.json_loads_byteified(r
.text
)
834 hash_md5
= hashlib
.md5()
835 for chunk
in iter(lambda: f
.read(1024), b
""):
836 hash_md5
.update(chunk
)
837 return hash_md5
.hexdigest()