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
:
33 result
['data'] = str(e
)
35 if r
.status_code
== requests
.codes
.ok
:
36 result
['error'] = False
38 result
['data'] = Util
.json_loads_byteified(r
.text
)
42 def project_list(self
, token
):
43 result
= {'error': True, 'data': ''}
44 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
45 'Authorization': 'Bearer {}'.format(token
['id'])}
47 _url
= "{0}/admin/v1/projects".format(self
._base
_path
)
49 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
50 except Exception as e
:
52 result
['data'] = str(e
)
54 if r
.status_code
== requests
.codes
.ok
:
55 result
['error'] = False
56 result
['data'] = Util
.json_loads_byteified(r
.text
)
60 def project_get(self
, token
, id):
61 result
= {'error': True, 'data': ''}
62 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
63 'Authorization': 'Bearer {}'.format(token
['id'])}
64 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
66 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
67 except Exception as e
:
69 result
['data'] = str(e
)
71 if r
.status_code
== requests
.codes
.ok
:
72 result
['error'] = False
73 result
['data'] = Util
.json_loads_byteified(r
.text
)
75 def project_create(self
, token
, project_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/projects".format(self
._base
_path
)
84 r
= requests
.post(_url
, json
=project_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 project_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/projects/{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 nsd_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}/nsd/v1/ns_descriptors_content".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 vnfd_list(self
, token
):
132 result
= {'error': True, 'data': ''}
133 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
134 'Authorization': 'Bearer {}'.format(token
['id'])}
136 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
138 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
139 except Exception as e
:
141 result
['data'] = str(e
)
143 if r
.status_code
== requests
.codes
.ok
:
144 result
['error'] = False
145 result
['data'] = Util
.json_loads_byteified(r
.text
)
149 def ns_list(self
, token
):
150 result
= {'error': True, 'data': ''}
151 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
152 'Authorization': 'Bearer {}'.format(token
['id'])}
153 _url
= "{0}/nslcm/v1/ns_instances_content".format(self
._base
_path
)
155 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
156 except Exception as e
:
158 result
['data'] = str(e
)
160 if r
.status_code
== requests
.codes
.ok
:
161 result
['error'] = False
162 result
['data'] = Util
.json_loads_byteified(r
.text
)
166 def vnf_list(self
, token
):
167 result
= {'error': True, 'data': ''}
168 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
169 'Authorization': 'Bearer {}'.format(token
['id'])}
170 _url
= "{0}/nslcm/v1/vnfrs".format(self
._base
_path
)
172 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
173 except Exception as e
:
175 result
['data'] = str(e
)
177 if r
.status_code
== requests
.codes
.ok
:
178 result
['error'] = False
179 result
['data'] = Util
.json_loads_byteified(r
.text
)
183 def nsd_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}/nsd/v1/ns_descriptors_content/{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
.ok
:
196 result
['error'] = False
197 result
['data'] = Util
.json_loads_byteified(r
.text
)
200 def vnfd_delete(self
, token
, id):
201 result
= {'error': True, 'data': ''}
202 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
203 'Authorization': 'Bearer {}'.format(token
['id'])}
205 _url
= "{0}/vnfpkgm/v1/vnf_packages_content/{1}".format(self
._base
_path
, id)
207 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
208 except Exception as e
:
210 result
['data'] = str(e
)
212 if r
.status_code
== requests
.codes
.ok
:
213 result
['error'] = False
214 result
['data'] = Util
.json_loads_byteified(r
.text
)
217 def nsd_onboard(self
, token
, package
):
218 result
= {'error': True, 'data': ''}
219 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
220 'Authorization': 'Bearer {}'.format(token
['id'])}
221 with
open('/tmp/'+package
.name
, 'wb+') as destination
:
222 for chunk
in package
.chunks():
223 destination
.write(chunk
)
224 headers
['Content-File-MD5'] = self
.md5(open('/tmp/'+package
.name
, 'rb'))
225 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
227 r
= requests
.post(_url
, data
=open('/tmp/'+package
.name
, 'rb'), verify
=False, headers
=headers
)
228 except Exception as e
:
230 result
['data'] = str(e
)
232 if r
.status_code
== requests
.codes
.created
:
233 result
['error'] = False
234 result
['data'] = Util
.json_loads_byteified(r
.text
)
237 def vnfd_onboard(self
, token
, package
):
238 result
= {'error': True, 'data': ''}
239 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
240 'Authorization': 'Bearer {}'.format(token
['id'])}
241 with
open('/tmp/'+package
.name
, 'wb+') as destination
:
242 for chunk
in package
.chunks():
243 destination
.write(chunk
)
244 headers
['Content-File-MD5'] = self
.md5(open('/tmp/'+package
.name
, 'rb'))
245 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
247 r
= requests
.post(_url
, data
=open('/tmp/'+package
.name
, 'rb'), verify
=False, headers
=headers
)
248 except Exception as e
:
250 result
['data'] = str(e
)
252 if r
.status_code
== requests
.codes
.created
:
253 result
['error'] = False
254 result
['data'] = Util
.json_loads_byteified(r
.text
)
257 def nsd_update(self
, token
, id, data
):
258 result
= {'error': True, 'data': ''}
259 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
260 'Authorization': 'Bearer {}'.format(token
['id'])}
262 # get the package onboarded
263 tar_pkg
= self
.get_nsd_pkg(token
, id)
264 tarf
= tarfile
.open(fileobj
=tar_pkg
)
266 tarf
= self
._descriptor
_update
(tarf
, data
)
267 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
269 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self
._base
_path
, id)
272 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
274 except Exception as e
:
276 result
['data'] = str(e
)
278 if r
.status_code
== requests
.codes
.no_content
:
279 result
['error'] = False
283 def vnfd_update(self
, token
, id, data
):
284 result
= {'error': True, 'data': ''}
285 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
286 'Authorization': 'Bearer {}'.format(token
['id'])}
288 # get the package onboarded
289 tar_pkg
= self
.get_vnfd_pkg(token
, id)
290 tarf
= tarfile
.open(fileobj
=tar_pkg
)
292 tarf
= self
._descriptor
_update
(tarf
, data
)
293 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
295 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self
._base
_path
, id)
298 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
300 except Exception as e
:
302 result
['data'] = str(e
)
304 if r
.status_code
== requests
.codes
.no_content
:
305 result
['error'] = False
309 def get_nsd_pkg(self
, token
, id):
310 result
= {'error': True, 'data': ''}
311 headers
= { "accept": "application/zip",
312 'Authorization': 'Bearer {}'.format(token
['id'])}
314 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self
._base
_path
, id)
316 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
317 except Exception as e
:
319 result
['data'] = str(e
)
321 if r
.status_code
== requests
.codes
.ok
:
322 result
['error'] = False
323 tarf
= StringIO
.StringIO(r
.content
)
327 def get_vnfd_pkg(self
, token
, id):
328 result
= {'error': True, 'data': ''}
329 headers
= {"accept": "application/zip",
330 'Authorization': 'Bearer {}'.format(token
['id'])}
331 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self
._base
_path
, id)
333 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
335 except Exception as e
:
337 result
['data'] = str(e
)
339 if r
.status_code
== requests
.codes
.ok
:
340 result
['error'] = False
341 tarf
= StringIO
.StringIO(r
.content
)
345 def _descriptor_update(self
, tarf
, data
):
346 print tarf
.getnames()
347 # extract the package on a tmp directory
348 tarf
.extractall('/tmp')
350 for name
in tarf
.getnames():
351 if name
.endswith(".yaml") or name
.endswith(".yml"):
352 with
open('/tmp/' + name
, 'w') as outfile
:
353 yaml
.safe_dump(data
, outfile
, default_flow_style
=False)
356 tarf_temp
= tarfile
.open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", "w:gz")
357 # tarf_temp = tarfile.open("pippo.tar.gz", "w:gz")
358 print tarf_temp
.getnames()
359 # tarf_temp.add('/tmp/'+tarf.getnames()[0])
361 # if tarinfo.name.startswith(tarf.getnames()[0]):
362 # new_name = tarinfo.name[len(tarf.getnames()[0]):]
363 tarf_temp
.add('/tmp/' + tarinfo
.name
, tarinfo
.name
, recursive
=False)
364 print tarf_temp
.getnames()
368 def nsd_get(self
, token
, id):
369 result
= {'error': True, 'data': ''}
370 headers
= {'Content-Type': 'application/yaml',
371 'Authorization': 'Bearer {}'.format(token
['id'])}
372 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd".format(self
._base
_path
, id)
374 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
375 except Exception as e
:
377 result
['data'] = str(e
)
379 if r
.status_code
== requests
.codes
.ok
:
380 result
['error'] = False
381 return yaml
.load(r
.text
)
384 result
['data'] = r
.json()
385 except Exception as e
:
389 def vnfd_get(self
, token
, id):
390 result
= {'error': True, 'data': ''}
391 headers
= {'Content-Type': 'application/yaml',
392 'Authorization': 'Bearer {}'.format(token
['id'])}
393 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/vnfd".format(self
._base
_path
, id)
395 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
396 except Exception as e
:
398 result
['data'] = str(e
)
400 if r
.status_code
== requests
.codes
.ok
:
401 result
['error'] = False
402 return yaml
.load(r
.text
)
405 result
['data'] = r
.json()
406 except Exception as e
:
410 def nsd_artifacts(self
, token
, id):
411 result
= {'error': True, 'data': ''}
412 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
413 'Authorization': 'Bearer {}'.format(token
['id'])}
414 _url
= "{0}/nsd/v1/ns_descriptors/{1}/artifacts".format(self
._base
_path
, id)
416 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
417 except Exception as e
:
419 result
['data'] = str(e
)
421 if r
.status_code
== requests
.codes
.ok
:
422 result
['error'] = False
423 result
['data'] = r
.text
426 result
['data'] = r
.json()
427 except Exception as e
:
432 def vnf_packages_artifacts(self
, token
, id):
433 result
= {'error': True, 'data': ''}
434 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
435 'Authorization': 'Bearer {}'.format(token
['id'])}
436 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/artifacts".format(self
._base
_path
, id)
438 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
439 except Exception as e
:
441 result
['data'] = str(e
)
443 if r
.status_code
== requests
.codes
.ok
:
444 result
['error'] = False
445 result
['data'] = r
.text
448 result
['data'] = r
.json()
449 except Exception as e
:
454 def ns_create(self
, token
, ns_data
):
455 result
= {'error': True, 'data': ''}
456 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
457 'Authorization': 'Bearer {}'.format(token
['id'])}
459 _url
= "{0}/nslcm/v1/ns_instances_content".format(self
._base
_path
)
462 r
= requests
.post(_url
, json
=ns_data
, verify
=False, 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 result
['data'] = Util
.json_loads_byteified(r
.text
)
472 def ns_op_list(self
, token
, id):
473 result
= {'error': True, 'data': ''}
474 headers
= {"Content-Type": "application/json", "accept": "application/json",
475 'Authorization': 'Bearer {}'.format(token
['id'])}
476 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/?nsInstanceId={1}".format(self
._base
_path
, id)
479 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
480 except Exception as e
:
482 result
['data'] = str(e
)
484 if r
.status_code
== requests
.codes
.ok
:
485 result
['error'] = False
486 result
['data'] = Util
.json_loads_byteified(r
.text
)
490 def ns_op(self
, token
, id):
491 result
= {'error': True, 'data': ''}
492 headers
= {"Content-Type": "application/json", "accept": "application/json",
493 'Authorization': 'Bearer {}'.format(token
['id'])}
494 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/{1}".format(self
._base
_path
, id)
497 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
498 except Exception as e
:
500 result
['data'] = str(e
)
502 if r
.status_code
== requests
.codes
.ok
:
503 result
['error'] = False
504 result
['data'] = Util
.json_loads_byteified(r
.text
)
508 def ns_action(self
, token
, id, action_payload
):
509 result
= {'error': True, 'data': ''}
510 headers
= {"Content-Type": "application/json", "accept": "application/json",
511 'Authorization': 'Bearer {}'.format(token
['id'])}
513 _url
= "{0}/nslcm/v1/ns_instances/{1}/action".format(self
._base
_path
, id)
516 r
= requests
.post(_url
, json
=action_payload
, verify
=False, headers
=headers
)
517 except Exception as e
:
519 result
['data'] = str(e
)
522 if r
.status_code
== requests
.codes
.created
:
523 result
['error'] = False
524 result
['data'] = Util
.json_loads_byteified(r
.text
)
527 def ns_delete(self
, token
, id, force
=None):
528 result
= {'error': True, 'data': ''}
529 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
530 'Authorization': 'Bearer {}'.format(token
['id'])}
533 query_path
= '?FORCE=true'
534 _url
= "{0}/nslcm/v1/ns_instances_content/{1}{2}".format(self
._base
_path
, id, query_path
)
536 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
537 except Exception as e
:
539 result
['data'] = str(e
)
541 if r
.status_code
== requests
.codes
.ok
:
542 result
['error'] = False
543 result
['data'] = Util
.json_loads_byteified(r
.text
)
546 def ns_get(self
, token
, id):
547 result
= {'error': True, 'data': ''}
548 headers
= {"Content-Type": "application/json", "accept": "application/json",
549 'Authorization': 'Bearer {}'.format(token
['id'])}
550 _url
= "{0}/nslcm/v1/ns_instances_content/{1}".format(self
._base
_path
, id)
553 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
554 except Exception as e
:
556 result
['data'] = str(e
)
558 if r
.status_code
== requests
.codes
.ok
:
559 result
['error'] = False
560 result
['data'] = Util
.json_loads_byteified(r
.text
)
563 def vnf_get(self
, token
, id):
564 result
= {'error': True, 'data': ''}
565 headers
= {"Content-Type": "application/json", "accept": "application/json",
566 'Authorization': 'Bearer {}'.format(token
['id'])}
567 _url
= "{0}/nslcm/v1/vnfrs/{1}".format(self
._base
_path
, id)
570 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
571 except Exception as e
:
573 result
['data'] = str(e
)
575 if r
.status_code
== requests
.codes
.ok
:
576 result
['error'] = False
577 result
['data'] = Util
.json_loads_byteified(r
.text
)
580 def ns_alarm_create(self
, token
, id, alarm_payload
):
581 result
= {'error': True, 'data': ''}
582 headers
= {"Content-Type": "application/json",
583 'Authorization': 'Bearer {}'.format(token
['id'])}
584 _url
= "{0}/test/message/alarm_request".format(self
._base
_path
)
586 r
= requests
.post(_url
, json
=alarm_payload
, verify
=False, headers
=headers
)
587 except Exception as e
:
589 result
['data'] = str(e
)
592 if r
.status_code
== requests
.codes
.ok
:
593 result
['error'] = False
594 #result['data'] = Util.json_loads_byteified(r.text)
595 result
['data'] = r
.text
598 def ns_metric_export(self
, token
, id, metric_payload
):
599 result
= {'error': True, 'data': ''}
600 headers
= {"Content-Type": "application/json",
601 'Authorization': 'Bearer {}'.format(token
['id'])}
602 _url
= "{0}/test/message/metric_request".format(self
._base
_path
)
604 r
= requests
.post(_url
, json
=metric_payload
, verify
=False, headers
=headers
)
605 except Exception as e
:
607 result
['data'] = str(e
)
610 if r
.status_code
== requests
.codes
.ok
:
611 result
['error'] = False
612 #result['data'] = Util.json_loads_byteified(r.text)
613 result
['data'] = r
.text
616 def vim_list(self
, token
):
617 result
= {'error': True, 'data': ''}
618 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
619 'Authorization': 'Bearer {}'.format(token
['id'])}
620 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
622 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
623 except Exception as e
:
625 result
['data'] = str(e
)
627 if r
.status_code
== requests
.codes
.ok
:
628 result
['error'] = False
629 result
['data'] = Util
.json_loads_byteified(r
.text
)
633 def vim_delete(self
, token
, id):
634 result
= {'error': True, 'data': ''}
635 headers
= { "accept": "application/json",
636 'Authorization': 'Bearer {}'.format(token
['id'])}
637 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
639 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
640 except Exception as e
:
642 result
['data'] = str(e
)
645 if r
.status_code
== requests
.codes
.accepted
:
646 result
['error'] = False
648 result
['data'] = r
.text
651 def vim_get(self
, token
, id):
653 result
= {'error': True, 'data': ''}
654 headers
= {"Content-Type": "application/json", "accept": "application/json",
655 'Authorization': 'Bearer {}'.format(token
['id'])}
656 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
659 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
660 except Exception as e
:
662 result
['data'] = str(e
)
664 if r
.status_code
== requests
.codes
.ok
:
665 result
['error'] = False
666 result
['data'] = Util
.json_loads_byteified(r
.text
)
669 def vim_create(self
, token
, vim_data
):
671 result
= {'error': True, 'data': ''}
672 headers
= {"Content-Type": "application/json", "accept": "application/json",
673 'Authorization': 'Bearer {}'.format(token
['id'])}
675 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
678 r
= requests
.post(_url
, json
=vim_data
, verify
=False, headers
=headers
)
679 except Exception as e
:
681 result
['data'] = str(e
)
684 if r
.status_code
== requests
.codes
.created
:
685 result
['error'] = False
686 result
['data'] = Util
.json_loads_byteified(r
.text
)
689 def sdn_list(self
, token
):
690 result
= {'error': True, 'data': ''}
691 headers
= {"accept": "application/json",
692 'Authorization': 'Bearer {}'.format(token
['id'])}
693 _url
= "{0}/admin/v1/sdns".format(self
._base
_path
)
695 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
696 except Exception as e
:
698 result
['data'] = str(e
)
700 if r
.status_code
== requests
.codes
.ok
:
701 result
['error'] = False
702 result
['data'] = Util
.json_loads_byteified(r
.text
)
705 def sdn_delete(self
, token
, id):
706 result
= {'error': True, 'data': ''}
707 headers
= {"accept": "application/json",
708 'Authorization': 'Bearer {}'.format(token
['id'])}
709 _url
= "{0}/admin/v1/sdns/{1}".format(self
._base
_path
, id)
711 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
712 except Exception as e
:
714 result
['data'] = str(e
)
717 if r
.status_code
== requests
.codes
.accepted
:
718 result
['error'] = False
720 result
['data'] = r
.text
723 def sdn_get(self
, token
, id):
724 result
= {'error': True, 'data': ''}
725 headers
= {"accept": "application/json",
726 'Authorization': 'Bearer {}'.format(token
['id'])}
727 _url
= "{0}/admin/v1/sdns/{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
)
741 def sdn_create(self
, token
, sdn_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/sdns".format(self
._base
_path
)
749 r
= requests
.post(_url
, json
=sdn_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
)
763 hash_md5
= hashlib
.md5()
764 for chunk
in iter(lambda: f
.read(1024), b
""):
765 hash_md5
.update(chunk
)
766 return hash_md5
.hexdigest()