working on clientv2: sdnctrlhandler
[osm/LW-UI.git] / lib / osm / osmclient / clientv2.py
1 import requests
2 import logging
3 import json
4 import tarfile
5 import yaml
6 import pyaml
7 import StringIO
8 from lib.util import Util
9 import hashlib
10 import os
11
12 logging.basicConfig(level=logging.DEBUG)
13 log = logging.getLogger('helper.py')
14
15
16 class Client(object):
17 def __init__(self):
18 self._token_endpoint = 'admin/v1/tokens'
19 self._user_endpoint = 'admin/v1/users'
20 self._host = os.getenv('OSM_SERVER', "localhost")
21 self._so_port = 9999
22 self._base_path = "https://{0}:{1}/osm".format(self._host, self._so_port)
23
24 def auth(self, args):
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"}
28 try:
29 r = requests.post(token_url, json=args, verify=False, headers=headers)
30 except Exception as e:
31 print "saltata"
32 log.exception(e)
33 result['data'] = str(e)
34 return result
35 if r.status_code == requests.codes.ok:
36 result['error'] = False
37
38 result['data'] = Util.json_loads_byteified(r.text)
39
40 return result
41
42 def nsd_list(self, token):
43 result = {'error': True, 'data': ''}
44 headers = {"Content-Type": "application/yaml", "accept": "application/json",
45 'Authorization': 'Bearer {}'.format(token['id'])}
46
47 _url = "{0}/nsd/v1/ns_descriptors_content".format(self._base_path)
48 try:
49 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
50 except Exception as e:
51 log.exception(e)
52 result['data'] = str(e)
53 return result
54 if r.status_code == requests.codes.ok:
55 result['error'] = False
56 result['data'] = Util.json_loads_byteified(r.text)
57
58 return result
59
60 def vnfd_list(self, token):
61 result = {'error': True, 'data': ''}
62 headers = {"Content-Type": "application/yaml", "accept": "application/json",
63 'Authorization': 'Bearer {}'.format(token['id'])}
64
65 _url = "{0}/vnfpkgm/v1/vnf_packages_content".format(self._base_path)
66 try:
67 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
68 except Exception as e:
69 log.exception(e)
70 result['data'] = str(e)
71 return result
72 if r.status_code == requests.codes.ok:
73 result['error'] = False
74 result['data'] = Util.json_loads_byteified(r.text)
75
76 return result
77
78 def ns_list(self, token):
79 result = {'error': True, 'data': ''}
80 headers = {"Content-Type": "application/yaml", "accept": "application/json",
81 'Authorization': 'Bearer {}'.format(token['id'])}
82 _url = "{0}/nslcm/v1/ns_instances_content".format(self._base_path)
83 try:
84 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
85 except Exception as e:
86 log.exception(e)
87 result['data'] = str(e)
88 return result
89 if r.status_code == requests.codes.ok:
90 result['error'] = False
91 result['data'] = Util.json_loads_byteified(r.text)
92
93 return result
94
95 def vnf_list(self, token):
96 result = {'error': True, 'data': ''}
97 headers = {"Content-Type": "application/yaml", "accept": "application/json",
98 'Authorization': 'Bearer {}'.format(token['id'])}
99 _url = "{0}/nslcm/v1/vnfrs".format(self._base_path)
100 try:
101 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
102 except Exception as e:
103 log.exception(e)
104 result['data'] = str(e)
105 return result
106 if r.status_code == requests.codes.ok:
107 result['error'] = False
108 result['data'] = Util.json_loads_byteified(r.text)
109
110 return result
111
112 def nsd_delete(self, token, id):
113 result = {'error': True, 'data': ''}
114 headers = {"Content-Type": "application/yaml", "accept": "application/json",
115 'Authorization': 'Bearer {}'.format(token['id'])}
116
117 _url = "{0}/nsd/v1/ns_descriptors_content/{1}".format(self._base_path, id)
118 try:
119 r = requests.delete(_url, params=None, verify=False,headers=headers)
120 except Exception as e:
121 log.exception(e)
122 result['data'] = str(e)
123 return result
124 if r.status_code == requests.codes.ok:
125 result['error'] = False
126 result['data'] = Util.json_loads_byteified(r.text)
127 return result
128
129 def vnfd_delete(self, token, id):
130 result = {'error': True, 'data': ''}
131 headers = {"Content-Type": "application/yaml", "accept": "application/json",
132 'Authorization': 'Bearer {}'.format(token['id'])}
133
134 _url = "{0}/vnfpkgm/v1/vnf_packages_content/{1}".format(self._base_path, id)
135 try:
136 r = requests.delete(_url, params=None, verify=False, headers=headers)
137 except Exception as e:
138 log.exception(e)
139 result['data'] = str(e)
140 return result
141 if r.status_code == requests.codes.ok:
142 result['error'] = False
143 result['data'] = Util.json_loads_byteified(r.text)
144 return result
145
146 def nsd_onboard(self, token, package):
147 result = {'error': True, 'data': ''}
148 headers = {"Content-Type": "application/gzip", "accept": "application/json",
149 'Authorization': 'Bearer {}'.format(token['id'])}
150 with open('/tmp/'+package.name, 'wb+') as destination:
151 for chunk in package.chunks():
152 destination.write(chunk)
153 headers['Content-File-MD5'] = self.md5(open('/tmp/'+package.name, 'rb'))
154 _url = "{0}/nsd/v1/ns_descriptors_content/".format(self._base_path)
155 try:
156 r = requests.post(_url, data=open('/tmp/'+package.name, 'rb'), verify=False, headers=headers)
157 except Exception as e:
158 log.exception(e)
159 result['data'] = str(e)
160 return result
161 if r.status_code == requests.codes.created:
162 result['error'] = False
163 result['data'] = Util.json_loads_byteified(r.text)
164 return result
165
166 def vnfd_onboard(self, token, package):
167 result = {'error': True, 'data': ''}
168 headers = {"Content-Type": "application/gzip", "accept": "application/json",
169 'Authorization': 'Bearer {}'.format(token['id'])}
170 with open('/tmp/'+package.name, 'wb+') as destination:
171 for chunk in package.chunks():
172 destination.write(chunk)
173 headers['Content-File-MD5'] = self.md5(open('/tmp/'+package.name, 'rb'))
174 _url = "{0}/vnfpkgm/v1/vnf_packages_content".format(self._base_path)
175 try:
176 r = requests.post(_url, data=open('/tmp/'+package.name, 'rb'), verify=False, headers=headers)
177 except Exception as e:
178 log.exception(e)
179 result['data'] = str(e)
180 return result
181 if r.status_code == requests.codes.created:
182 result['error'] = False
183 result['data'] = Util.json_loads_byteified(r.text)
184 return result
185
186 def nsd_update(self, token, id, data):
187 result = {'error': True, 'data': ''}
188 headers = {"Content-Type": "application/gzip", "accept": "application/json",
189 'Authorization': 'Bearer {}'.format(token['id'])}
190
191 # get the package onboarded
192 tar_pkg = self.get_nsd_pkg(token, id)
193 tarf = tarfile.open(fileobj=tar_pkg)
194
195 tarf = self._descriptor_update(tarf, data)
196 headers['Content-File-MD5'] = self.md5(open('/tmp/' + tarf.getnames()[0] + ".tar.gz", 'rb'))
197
198 _url = "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self._base_path, id)
199
200 try:
201 r = requests.put(_url, data=open('/tmp/' + tarf.getnames()[0] + ".tar.gz", 'rb'), verify=False,
202 headers=headers)
203 except Exception as e:
204 log.exception(e)
205 result['data'] = str(e)
206 return result
207 if r.status_code == requests.codes.no_content:
208 result['error'] = False
209
210 return result
211
212 def vnfd_update(self, token, id, data):
213 result = {'error': True, 'data': ''}
214 headers = {"Content-Type": "application/gzip", "accept": "application/json",
215 'Authorization': 'Bearer {}'.format(token['id'])}
216
217 # get the package onboarded
218 tar_pkg = self.get_vnfd_pkg(token, id)
219 tarf = tarfile.open(fileobj=tar_pkg)
220
221 tarf = self._descriptor_update(tarf, data)
222 headers['Content-File-MD5'] = self.md5(open('/tmp/' + tarf.getnames()[0] + ".tar.gz", 'rb'))
223
224 _url = "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self._base_path, id)
225
226 try:
227 r = requests.put(_url, data=open('/tmp/' + tarf.getnames()[0] + ".tar.gz", 'rb'), verify=False,
228 headers=headers)
229 except Exception as e:
230 log.exception(e)
231 result['data'] = str(e)
232 return result
233 if r.status_code == requests.codes.no_content:
234 result['error'] = False
235
236 return result
237
238 def get_nsd_pkg(self, token, id):
239 result = {'error': True, 'data': ''}
240 headers = { "accept": "application/zip",
241 'Authorization': 'Bearer {}'.format(token['id'])}
242
243 _url = "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self._base_path, id)
244 try:
245 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
246 except Exception as e:
247 log.exception(e)
248 result['data'] = str(e)
249 return result
250 if r.status_code == requests.codes.ok:
251 result['error'] = False
252 tarf = StringIO.StringIO(r.content)
253 return tarf
254 return result
255
256 def get_vnfd_pkg(self, token, id):
257 result = {'error': True, 'data': ''}
258 headers = {"accept": "application/zip",
259 'Authorization': 'Bearer {}'.format(token['id'])}
260 _url = "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self._base_path, id)
261 try:
262 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
263 print r.status_code
264 except Exception as e:
265 log.exception(e)
266 result['data'] = str(e)
267 return result
268 if r.status_code == requests.codes.ok:
269 result['error'] = False
270 tarf = StringIO.StringIO(r.content)
271 return tarf
272 return result
273
274 def _descriptor_update(self, tarf, data):
275 print tarf.getnames()
276 # extract the package on a tmp directory
277 tarf.extractall('/tmp')
278
279 for name in tarf.getnames():
280 if name.endswith(".yaml") or name.endswith(".yml"):
281 with open('/tmp/' + name, 'w') as outfile:
282 yaml.safe_dump(data, outfile, default_flow_style=False)
283 break
284
285 tarf_temp = tarfile.open('/tmp/' + tarf.getnames()[0] + ".tar.gz", "w:gz")
286 # tarf_temp = tarfile.open("pippo.tar.gz", "w:gz")
287 print tarf_temp.getnames()
288 # tarf_temp.add('/tmp/'+tarf.getnames()[0])
289 for tarinfo in tarf:
290 # if tarinfo.name.startswith(tarf.getnames()[0]):
291 # new_name = tarinfo.name[len(tarf.getnames()[0]):]
292 tarf_temp.add('/tmp/' + tarinfo.name, tarinfo.name, recursive=False)
293 print tarf_temp.getnames()
294 tarf_temp.close()
295 return tarf
296
297 def nsd_get(self, token, id):
298 result = {'error': True, 'data': ''}
299 headers = {'Content-Type': 'application/yaml',
300 'Authorization': 'Bearer {}'.format(token['id'])}
301 _url = "{0}/nsd/v1/ns_descriptors/{1}/nsd".format(self._base_path, id)
302 try:
303 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
304 except Exception as e:
305 log.exception(e)
306 result['data'] = str(e)
307 return result
308 if r.status_code == requests.codes.ok:
309 result['error'] = False
310 return yaml.load(r.text)
311 else:
312 try:
313 result['data'] = r.json()
314 except Exception as e:
315 result['data'] = {}
316 return result
317
318 def vnfd_get(self, token, id):
319 result = {'error': True, 'data': ''}
320 headers = {'Content-Type': 'application/yaml',
321 'Authorization': 'Bearer {}'.format(token['id'])}
322 _url = "{0}/vnfpkgm/v1/vnf_packages/{1}/vnfd".format(self._base_path, id)
323 try:
324 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
325 except Exception as e:
326 log.exception(e)
327 result['data'] = str(e)
328 return result
329 if r.status_code == requests.codes.ok:
330 result['error'] = False
331 return yaml.load(r.text)
332 else:
333 try:
334 result['data'] = r.json()
335 except Exception as e:
336 result['data'] = {}
337 return result
338
339 def nsd_artifacts(self, token, id):
340 result = {'error': True, 'data': ''}
341 headers = {'Content-Type': 'application/yaml', 'accept': 'text/plain',
342 'Authorization': 'Bearer {}'.format(token['id'])}
343 _url = "{0}/nsd/v1/ns_descriptors/{1}/artifacts".format(self._base_path, id)
344 try:
345 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
346 except Exception as e:
347 log.exception(e)
348 result['data'] = str(e)
349 return result
350 if r.status_code == requests.codes.ok:
351 result['error'] = False
352 result['data'] = r.text
353 else:
354 try:
355 result['data'] = r.json()
356 except Exception as e:
357 result['data'] = {}
358
359 return result
360
361 def vnf_packages_artifacts(self, token, id):
362 result = {'error': True, 'data': ''}
363 headers = {'Content-Type': 'application/yaml', 'accept': 'text/plain',
364 'Authorization': 'Bearer {}'.format(token['id'])}
365 _url = "{0}/vnfpkgm/v1/vnf_packages/{1}/artifacts".format(self._base_path, id)
366 try:
367 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
368 except Exception as e:
369 log.exception(e)
370 result['data'] = str(e)
371 return result
372 if r.status_code == requests.codes.ok:
373 result['error'] = False
374 result['data'] = r.text
375 else:
376 try:
377 result['data'] = r.json()
378 except Exception as e:
379 result['data'] = {}
380
381 return result
382
383 def ns_create(self, token, ns_data):
384 result = {'error': True, 'data': ''}
385 headers = {"Content-Type": "application/yaml", "accept": "application/json",
386 'Authorization': 'Bearer {}'.format(token['id'])}
387
388 _url = "{0}/nslcm/v1/ns_instances_content".format(self._base_path)
389
390 try:
391 r = requests.post(_url, json=ns_data, verify=False, headers=headers)
392 except Exception as e:
393 log.exception(e)
394 result['data'] = str(e)
395 return result
396 if r.status_code == requests.codes.ok:
397 result['error'] = False
398 result['data'] = Util.json_loads_byteified(r.text)
399 return result
400
401 def ns_op_list(self, token, id):
402 result = {'error': True, 'data': ''}
403 headers = {"Content-Type": "application/json", "accept": "application/json",
404 'Authorization': 'Bearer {}'.format(token['id'])}
405 _url = "{0}/nslcm/v1/ns_lcm_op_occs/?nsInstanceId={1}".format(self._base_path, id)
406
407 try:
408 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
409 except Exception as e:
410 log.exception(e)
411 result['data'] = str(e)
412 return result
413 if r.status_code == requests.codes.ok:
414 result['error'] = False
415 result['data'] = Util.json_loads_byteified(r.text)
416
417 return result
418
419 def ns_op(self, token, id):
420 result = {'error': True, 'data': ''}
421 headers = {"Content-Type": "application/json", "accept": "application/json",
422 'Authorization': 'Bearer {}'.format(token['id'])}
423 _url = "{0}/nslcm/v1/ns_lcm_op_occs/{1}".format(self._base_path, id)
424
425 try:
426 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
427 except Exception as e:
428 log.exception(e)
429 result['data'] = str(e)
430 return result
431 if r.status_code == requests.codes.ok:
432 result['error'] = False
433 result['data'] = Util.json_loads_byteified(r.text)
434
435 return result
436
437 def ns_action(self, token, id, action_payload):
438 result = {'error': True, 'data': ''}
439 headers = {"Content-Type": "application/json", "accept": "application/json",
440 'Authorization': 'Bearer {}'.format(token['id'])}
441
442 _url = "{0}/nslcm/v1/ns_instances/{1}/action".format(self._base_path, id)
443
444 try:
445 r = requests.post(_url, json=action_payload, verify=False, headers=headers)
446 except Exception as e:
447 log.exception(e)
448 result['data'] = str(e)
449 return result
450 print r.status_code
451 if r.status_code == requests.codes.created:
452 result['error'] = False
453 result['data'] = Util.json_loads_byteified(r.text)
454 return result
455
456 def ns_delete(self, token, id, force=None):
457 result = {'error': True, 'data': ''}
458 headers = {"Content-Type": "application/yaml", "accept": "application/json",
459 'Authorization': 'Bearer {}'.format(token['id'])}
460 query_path = ''
461 if force:
462 query_path = '?FORCE=true'
463 _url = "{0}/nslcm/v1/ns_instances_content/{1}{2}".format(self._base_path, id, query_path)
464 try:
465 r = requests.delete(_url, params=None, verify=False, headers=headers)
466 except Exception as e:
467 log.exception(e)
468 result['data'] = str(e)
469 return result
470 if r.status_code == requests.codes.ok:
471 result['error'] = False
472 result['data'] = Util.json_loads_byteified(r.text)
473 return result
474
475 def ns_get(self, token, id):
476 result = {'error': True, 'data': ''}
477 headers = {"Content-Type": "application/json", "accept": "application/json",
478 'Authorization': 'Bearer {}'.format(token['id'])}
479 _url = "{0}/nslcm/v1/ns_instances_content/{1}".format(self._base_path, id)
480
481 try:
482 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
483 except Exception as e:
484 log.exception(e)
485 result['data'] = str(e)
486 return result
487 if r.status_code == requests.codes.ok:
488 result['error'] = False
489 result['data'] = Util.json_loads_byteified(r.text)
490 return result
491
492 def vnf_get(self, token, id):
493 result = {'error': True, 'data': ''}
494 headers = {"Content-Type": "application/json", "accept": "application/json",
495 'Authorization': 'Bearer {}'.format(token['id'])}
496 _url = "{0}/nslcm/v1/vnfrs/{1}".format(self._base_path, id)
497
498 try:
499 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
500 except Exception as e:
501 log.exception(e)
502 result['data'] = str(e)
503 return result
504 if r.status_code == requests.codes.ok:
505 result['error'] = False
506 result['data'] = Util.json_loads_byteified(r.text)
507 return result
508
509 def ns_alarm_create(self, token, id, alarm_payload):
510 result = {'error': True, 'data': ''}
511 headers = {"Content-Type": "application/json",
512 'Authorization': 'Bearer {}'.format(token['id'])}
513 _url = "{0}/test/message/alarm_request".format(self._base_path)
514 try:
515 r = requests.post(_url, json=alarm_payload, verify=False, headers=headers)
516 except Exception as e:
517 log.exception(e)
518 result['data'] = str(e)
519 return result
520 print r.status_code
521 if r.status_code == requests.codes.ok:
522 result['error'] = False
523 #result['data'] = Util.json_loads_byteified(r.text)
524 result['data'] = r.text
525 return result
526
527 def ns_metric_export(self, token, id, metric_payload):
528 result = {'error': True, 'data': ''}
529 headers = {"Content-Type": "application/json",
530 'Authorization': 'Bearer {}'.format(token['id'])}
531 _url = "{0}/test/message/metric_request".format(self._base_path)
532 try:
533 r = requests.post(_url, json=metric_payload, verify=False, headers=headers)
534 except Exception as e:
535 log.exception(e)
536 result['data'] = str(e)
537 return result
538 print r.status_code
539 if r.status_code == requests.codes.ok:
540 result['error'] = False
541 #result['data'] = Util.json_loads_byteified(r.text)
542 result['data'] = r.text
543 return result
544
545 def vim_list(self, token):
546 result = {'error': True, 'data': ''}
547 headers = {"Content-Type": "application/yaml", "accept": "application/json",
548 'Authorization': 'Bearer {}'.format(token['id'])}
549 _url = "{0}/admin/v1/vims".format(self._base_path)
550 try:
551 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
552 except Exception as e:
553 log.exception(e)
554 result['data'] = str(e)
555 return result
556 if r.status_code == requests.codes.ok:
557 result['error'] = False
558 result['data'] = Util.json_loads_byteified(r.text)
559
560 return result
561
562 def vim_delete(self, token, id):
563 result = {'error': True, 'data': ''}
564 headers = { "accept": "application/json",
565 'Authorization': 'Bearer {}'.format(token['id'])}
566 _url = "{0}/admin/v1/vims/{1}".format(self._base_path, id)
567 try:
568 r = requests.delete(_url, params=None, verify=False, headers=headers)
569 except Exception as e:
570 log.exception(e)
571 result['data'] = str(e)
572 return result
573 print r.status_code
574 if r.status_code == requests.codes.accepted:
575 result['error'] = False
576 else:
577 result['data'] = r.text
578 return result
579
580 def vim_get(self, token, id):
581
582 result = {'error': True, 'data': ''}
583 headers = {"Content-Type": "application/json", "accept": "application/json",
584 'Authorization': 'Bearer {}'.format(token['id'])}
585 _url = "{0}/admin/v1/vims/{1}".format(self._base_path, id)
586
587 try:
588 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
589 except Exception as e:
590 log.exception(e)
591 result['data'] = str(e)
592 return result
593 if r.status_code == requests.codes.ok:
594 result['error'] = False
595 result['data'] = Util.json_loads_byteified(r.text)
596 return result
597
598 def vim_create(self, token, vim_data):
599
600 result = {'error': True, 'data': ''}
601 headers = {"Content-Type": "application/json", "accept": "application/json",
602 'Authorization': 'Bearer {}'.format(token['id'])}
603
604 _url = "{0}/admin/v1/vims".format(self._base_path)
605
606 try:
607 r = requests.post(_url, json=vim_data, verify=False, headers=headers)
608 except Exception as e:
609 log.exception(e)
610 result['data'] = str(e)
611 return result
612 print r.status_code
613 if r.status_code == requests.codes.created:
614 result['error'] = False
615 result['data'] = Util.json_loads_byteified(r.text)
616 return result
617
618 def sdn_list(self, token):
619 result = {'error': True, 'data': ''}
620 headers = {"accept": "application/json",
621 'Authorization': 'Bearer {}'.format(token['id'])}
622 _url = "{0}/admin/v1/sdns".format(self._base_path)
623 try:
624 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
625 except Exception as e:
626 log.exception(e)
627 result['data'] = str(e)
628 return result
629 if r.status_code == requests.codes.ok:
630 result['error'] = False
631 result['data'] = Util.json_loads_byteified(r.text)
632 return result
633
634 def sdn_delete(self, token, id):
635 result = {'error': True, 'data': ''}
636 headers = {"accept": "application/json",
637 'Authorization': 'Bearer {}'.format(token['id'])}
638 _url = "{0}/admin/v1/sdns/{1}".format(self._base_path, id)
639 try:
640 r = requests.delete(_url, params=None, verify=False, headers=headers)
641 except Exception as e:
642 log.exception(e)
643 result['data'] = str(e)
644 return result
645 print r.status_code
646 if r.status_code == requests.codes.accepted:
647 result['error'] = False
648 else:
649 result['data'] = r.text
650 return result
651
652 def sdn_get(self, token, id):
653 result = {'error': True, 'data': ''}
654 headers = {"accept": "application/json",
655 'Authorization': 'Bearer {}'.format(token['id'])}
656 _url = "{0}/admin/v1/sdns/{1}".format(self._base_path, id)
657
658 try:
659 r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
660 except Exception as e:
661 log.exception(e)
662 result['data'] = str(e)
663 return result
664 if r.status_code == requests.codes.ok:
665 result['error'] = False
666 result['data'] = Util.json_loads_byteified(r.text)
667 return result
668
669
670 def sdn_create(self, token, sdn_data):
671 result = {'error': True, 'data': ''}
672 headers = {"Content-Type": "application/json", "accept": "application/json",
673 'Authorization': 'Bearer {}'.format(token['id'])}
674
675 _url = "{0}/admin/v1/sdns".format(self._base_path)
676
677 try:
678 r = requests.post(_url, json=sdn_data, verify=False, headers=headers)
679 except Exception as e:
680 log.exception(e)
681 result['data'] = str(e)
682 return result
683 print r.status_code
684 if r.status_code == requests.codes.created:
685 result['error'] = False
686 result['data'] = Util.json_loads_byteified(r.text)
687 return result
688
689
690 @staticmethod
691 def md5(f):
692 hash_md5 = hashlib.md5()
693 for chunk in iter(lambda: f.read(1024), b""):
694 hash_md5.update(chunk)
695 return hash_md5.hexdigest()