2 # Copyright 2018 EveryUP Srl
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
22 from lib
.util
import Util
25 from requests
.packages
.urllib3
.exceptions
import InsecureRequestWarning
27 requests
.packages
.urllib3
.disable_warnings(InsecureRequestWarning
)
29 logging
.basicConfig(level
=logging
.INFO
)
30 log
= logging
.getLogger('helper.py')
31 logging
.getLogger("urllib3").setLevel(logging
.INFO
)
36 self
._token
_endpoint
= 'admin/v1/tokens'
37 self
._user
_endpoint
= 'admin/v1/users'
38 self
._host
= os
.getenv('OSM_SERVER', "localhost")
40 self
._base
_path
= 'https://{0}:{1}/osm'.format(self
._host
, self
._so
_port
)
43 result
= {'error': True, 'data': ''}
44 token_url
= "{0}/{1}".format(self
._base
_path
, self
._token
_endpoint
)
45 headers
= {"Content-Type": "application/yaml", "accept": "application/json"}
47 r
= requests
.post(token_url
, json
=args
, verify
=False, headers
=headers
)
48 except Exception as e
:
50 result
['data'] = str(e
)
52 if r
.status_code
== requests
.codes
.ok
:
53 result
['error'] = False
55 result
['data'] = Util
.json_loads_byteified(r
.text
)
59 def switch_project(self
, args
):
60 result
= {'error': True, 'data': ''}
61 token_url
= "{0}/{1}".format(self
._base
_path
, self
._token
_endpoint
)
62 headers
= {"Content-Type": "application/yaml", "accept": "application/json"}
64 r
= requests
.post(token_url
, json
=args
, verify
=False, headers
=headers
)
65 except Exception as e
:
67 result
['data'] = str(e
)
69 if r
.status_code
== requests
.codes
.ok
:
70 result
['error'] = False
72 result
['data'] = Util
.json_loads_byteified(r
.text
)
76 def user_list(self
, token
):
77 result
= {'error': True, 'data': ''}
78 headers
= {"Content-Type": "application/json", "accept": "application/json",
79 'Authorization': 'Bearer {}'.format(token
['id'])}
81 _url
= "{0}/admin/v1/users".format(self
._base
_path
)
83 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
84 except Exception as e
:
86 result
['data'] = str(e
)
88 if r
.status_code
== requests
.codes
.ok
:
89 result
['error'] = False
90 result
['data'] = Util
.json_loads_byteified(r
.text
)
94 def user_create(self
, token
, user_data
):
95 result
= {'error': True, 'data': ''}
96 headers
= {"Content-Type": "application/json", "accept": "application/json",
97 'Authorization': 'Bearer {}'.format(token
['id'])}
99 _url
= "{0}/admin/v1/users".format(self
._base
_path
)
102 r
= requests
.post(_url
, json
=user_data
, verify
=False, headers
=headers
)
103 except Exception as e
:
105 result
['data'] = str(e
)
107 if r
.status_code
== requests
.codes
.created
:
108 result
['error'] = False
109 result
['data'] = Util
.json_loads_byteified(r
.text
)
112 def user_update(self
, token
, id, user_data
):
113 result
= {'error': True, 'data': ''}
114 headers
= {"Content-Type": "application/json", "accept": "application/json",
115 'Authorization': 'Bearer {}'.format(token
['id'])}
117 _url
= "{0}/admin/v1/users/{1}".format(self
._base
_path
, id)
119 r
= requests
.patch(_url
, json
=user_data
, verify
=False, headers
=headers
)
120 except Exception as e
:
122 result
['data'] = str(e
)
124 if r
.status_code
== requests
.codes
.no_content
:
125 result
['error'] = False
127 result
['data'] = Util
.json_loads_byteified(r
.text
)
130 def user_delete(self
, token
, id):
131 result
= {'error': True, 'data': ''}
132 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
133 'Authorization': 'Bearer {}'.format(token
['id'])}
135 _url
= "{0}/admin/v1/users/{1}".format(self
._base
_path
, id)
137 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
138 except Exception as e
:
140 result
['data'] = str(e
)
142 if r
.status_code
== requests
.codes
.no_content
:
143 result
['error'] = False
145 result
['data'] = Util
.json_loads_byteified(r
.text
)
148 def get_user_info(self
, token
, id):
149 result
= {'error': True, 'data': ''}
150 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
151 'Authorization': 'Bearer {}'.format(token
['id'])}
152 _url
= "{0}/admin/v1/users/{1}".format(self
._base
_path
, id)
154 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
155 except Exception as e
:
157 result
['data'] = str(e
)
159 if r
.status_code
== requests
.codes
.ok
:
160 result
['error'] = False
161 result
['data'] = Util
.json_loads_byteified(r
.text
)
164 def project_list(self
, token
):
165 result
= {'error': True, 'data': ''}
166 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
167 'Authorization': 'Bearer {}'.format(token
['id'])}
169 _url
= "{0}/admin/v1/projects".format(self
._base
_path
)
171 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
172 except Exception as e
:
174 result
['data'] = str(e
)
176 if r
.status_code
== requests
.codes
.ok
:
177 result
['error'] = False
178 result
['data'] = Util
.json_loads_byteified(r
.text
)
182 def project_get(self
, token
, id):
183 result
= {'error': True, 'data': ''}
184 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
185 'Authorization': 'Bearer {}'.format(token
['id'])}
186 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
188 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
189 except Exception as e
:
191 result
['data'] = str(e
)
193 if r
.status_code
== requests
.codes
.ok
:
194 result
['error'] = False
195 result
['data'] = Util
.json_loads_byteified(r
.text
)
198 def project_create(self
, token
, project_data
):
200 result
= {'error': True, 'data': ''}
201 headers
= {"Content-Type": "application/json", "accept": "application/json",
202 'Authorization': 'Bearer {}'.format(token
['id'])}
204 _url
= "{0}/admin/v1/projects".format(self
._base
_path
)
207 r
= requests
.post(_url
, json
=project_data
, verify
=False, headers
=headers
)
208 except Exception as e
:
210 result
['data'] = str(e
)
212 if r
.status_code
== requests
.codes
.created
:
213 result
['error'] = False
214 result
['data'] = Util
.json_loads_byteified(r
.text
)
217 def project_edit(self
, token
, id, project_data
):
219 result
= {'error': True, 'data': ''}
220 headers
= {"Content-Type": "application/json", "accept": "application/json",
221 'Authorization': 'Bearer {}'.format(token
['id'])}
223 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
226 r
= requests
.put(_url
, json
=project_data
, verify
=False, headers
=headers
)
227 except Exception as e
:
229 result
['data'] = str(e
)
231 if r
.status_code
== requests
.codes
.no_content
:
232 result
['error'] = False
233 result
['data'] = Util
.json_loads_byteified(r
.text
)
236 def project_delete(self
, token
, id):
237 result
= {'error': True, 'data': ''}
238 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
239 'Authorization': 'Bearer {}'.format(token
['id'])}
241 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
243 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
244 except Exception as e
:
246 result
['data'] = str(e
)
248 if r
.status_code
== requests
.codes
.no_content
:
249 result
['error'] = False
251 result
['data'] = Util
.json_loads_byteified(r
.text
)
254 def nst_details(self
, token
, id):
255 result
= {'error': True, 'data': ''}
256 headers
= {"Content-Type": "application/json", "accept": "application/json",
257 'Authorization': 'Bearer {}'.format(token
['id'])}
258 _url
= "{0}/nst/v1/netslice_templates/{1}".format(self
._base
_path
,id)
260 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
261 except Exception as e
:
263 result
['data'] = str(e
)
265 if r
.status_code
== requests
.codes
.ok
:
266 result
['error'] = False
267 result
['data'] = Util
.json_loads_byteified(r
.text
)
271 def nst_content(self
, token
, id):
272 result
= {'error': True, 'data': ''}
273 headers
= {"Content-Type": "application/json", "accept": "text/plain",
274 'Authorization': 'Bearer {}'.format(token
['id'])}
275 _url
= "{0}/nst/v1/netslice_templates/{1}/nst".format(self
._base
_path
,id)
277 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
278 except Exception as e
:
280 result
['data'] = str(e
)
282 if r
.status_code
== requests
.codes
.ok
:
283 result
['error'] = False
284 result
['data'] = Util
.json2yaml(yaml
.load(str(r
.text
)))
288 def nst_list(self
, token
):
289 result
= {'error': True, 'data': ''}
290 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
291 'Authorization': 'Bearer {}'.format(token
['id'])}
293 _url
= "{0}/nst/v1/netslice_templates".format(self
._base
_path
)
295 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
296 except Exception as e
:
298 result
['data'] = str(e
)
300 if r
.status_code
== requests
.codes
.ok
:
301 result
['error'] = False
302 result
['data'] = Util
.json_loads_byteified(r
.text
)
306 def nsd_list(self
, token
, filter=None):
307 result
= {'error': True, 'data': ''}
308 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
309 'Authorization': 'Bearer {}'.format(token
['id'])}
312 query_path
= '?_admin.type='+filter
313 _url
= "{0}/nsd/v1/ns_descriptors_content{1}".format(self
._base
_path
, query_path
)
315 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
316 except Exception as e
:
318 result
['data'] = str(e
)
320 if r
.status_code
== requests
.codes
.ok
:
321 result
['error'] = False
322 result
['data'] = Util
.json_loads_byteified(r
.text
)
326 def vnfd_list(self
, token
, filter=None):
327 result
= {'error': True, 'data': ''}
328 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
329 'Authorization': 'Bearer {}'.format(token
['id'])}
332 query_path
= '?_admin.type='+filter
333 _url
= "{0}/vnfpkgm/v1/vnf_packages_content{1}".format(self
._base
_path
, query_path
)
335 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
336 except Exception as e
:
338 result
['data'] = str(e
)
340 if r
.status_code
== requests
.codes
.ok
:
341 result
['error'] = False
342 result
['data'] = Util
.json_loads_byteified(r
.text
)
346 def nsi_list(self
, token
):
347 result
= {'error': True, 'data': ''}
348 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
349 'Authorization': 'Bearer {}'.format(token
['id'])}
350 _url
= "{0}/nsilcm/v1/netslice_instances".format(self
._base
_path
)
352 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
353 except Exception as e
:
355 result
['data'] = str(e
)
357 if r
.status_code
== requests
.codes
.ok
:
358 result
['error'] = False
359 result
['data'] = Util
.json_loads_byteified(r
.text
)
363 def ns_list(self
, token
):
364 result
= {'error': True, 'data': ''}
365 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
366 'Authorization': 'Bearer {}'.format(token
['id'])}
367 _url
= "{0}/nslcm/v1/ns_instances_content".format(self
._base
_path
)
369 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
370 except Exception as e
:
372 result
['data'] = str(e
)
374 if r
.status_code
== requests
.codes
.ok
:
375 result
['error'] = False
376 result
['data'] = Util
.json_loads_byteified(r
.text
)
380 def vnf_list(self
, token
):
381 result
= {'error': True, 'data': ''}
382 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
383 'Authorization': 'Bearer {}'.format(token
['id'])}
384 _url
= "{0}/nslcm/v1/vnfrs".format(self
._base
_path
)
386 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
387 except Exception as e
:
389 result
['data'] = str(e
)
391 if r
.status_code
== requests
.codes
.ok
:
392 result
['error'] = False
393 result
['data'] = Util
.json_loads_byteified(r
.text
)
397 def pdu_list(self
, token
):
398 result
= {'error': True, 'data': ''}
399 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
400 'Authorization': 'Bearer {}'.format(token
['id'])}
401 _url
= "{0}/pdu/v1/pdu_descriptors".format(self
._base
_path
)
403 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
404 except Exception as e
:
406 result
['data'] = str(e
)
408 if r
.status_code
== requests
.codes
.ok
:
409 result
['error'] = False
410 result
['data'] = Util
.json_loads_byteified(r
.text
)
414 def nst_delete(self
, token
, id):
415 result
= {'error': True, 'data': ''}
416 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
417 'Authorization': 'Bearer {}'.format(token
['id'])}
419 _url
= "{0}/nst/v1/netslice_templates/{1}?FORCE=True".format(self
._base
_path
, id)
421 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
422 except Exception as e
:
424 result
['data'] = str(e
)
426 if r
.status_code
== requests
.codes
.no_content
:
427 result
['error'] = False
431 def nsd_delete(self
, token
, id):
432 result
= {'error': True, 'data': ''}
433 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
434 'Authorization': 'Bearer {}'.format(token
['id'])}
436 _url
= "{0}/nsd/v1/ns_descriptors_content/{1}".format(self
._base
_path
, id)
438 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
439 except Exception as e
:
441 result
['data'] = str(e
)
443 if r
.status_code
== requests
.codes
.ok
:
444 result
['error'] = False
445 result
['data'] = Util
.json_loads_byteified(r
.text
)
448 def vnfd_delete(self
, token
, id):
449 result
= {'error': True, 'data': ''}
450 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
451 'Authorization': 'Bearer {}'.format(token
['id'])}
453 _url
= "{0}/vnfpkgm/v1/vnf_packages_content/{1}".format(self
._base
_path
, id)
455 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
456 except Exception as e
:
458 result
['data'] = str(e
)
461 result
['error'] = False
462 if r
.status_code
!= requests
.codes
.no_content
:
463 result
['data'] = Util
.json_loads_byteified(r
.text
)
466 def nst_onboard(self
, token
, template
):
467 result
= {'error': True, 'data': ''}
468 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
469 'Authorization': 'Bearer {}'.format(token
['id'])}
470 _url
= "{0}/nst/v1/netslice_templates_content".format(self
._base
_path
)
472 fileName
, fileExtension
= os
.path
.splitext(template
.name
)
473 if fileExtension
== '.gz':
474 headers
["Content-Type"] = "application/gzip"
476 headers
["Content-Type"] = "application/yaml"
477 r
= requests
.post(_url
, data
=template
, verify
=False, headers
=headers
)
478 except Exception as e
:
480 result
['data'] = str(e
)
482 if r
.status_code
== requests
.codes
.created
:
483 result
['error'] = False
484 result
['data'] = Util
.json_loads_byteified(r
.text
)
487 def nsd_onboard(self
, token
, package
):
488 result
= {'error': True, 'data': ''}
489 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
490 'Authorization': 'Bearer {}'.format(token
['id'])}
491 with
open('/tmp/' + package
.name
, 'wb+') as destination
:
492 for chunk
in package
.chunks():
493 destination
.write(chunk
)
494 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + package
.name
, 'rb'))
495 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
497 r
= requests
.post(_url
, data
=open('/tmp/' + package
.name
, 'rb'), verify
=False, headers
=headers
)
498 except Exception as e
:
500 result
['data'] = str(e
)
502 if r
.status_code
== requests
.codes
.created
:
503 result
['error'] = False
504 result
['data'] = Util
.json_loads_byteified(r
.text
)
507 def vnfd_onboard(self
, token
, package
):
508 result
= {'error': True, 'data': ''}
509 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
510 'Authorization': 'Bearer {}'.format(token
['id'])}
511 with
open('/tmp/' + package
.name
, 'wb+') as destination
:
512 for chunk
in package
.chunks():
513 destination
.write(chunk
)
514 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + package
.name
, 'rb'))
515 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
517 r
= requests
.post(_url
, data
=open('/tmp/' + package
.name
, 'rb'), verify
=False, headers
=headers
)
518 except Exception as e
:
520 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 nsd_create_pkg_base(self
, token
, pkg_name
):
528 result
= {'error': True, 'data': ''}
529 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
530 'Authorization': 'Bearer {}'.format(token
['id'])}
532 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
535 self
._create
_base
_pkg
('nsd', pkg_name
)
536 headers
['Content-Filename'] = pkg_name
+ '.tar.gz'
537 r
= requests
.post(_url
, data
=open('/tmp/' + pkg_name
+ '.tar.gz', 'rb'), verify
=False, headers
=headers
)
538 except Exception as e
:
540 result
['data'] = str(e
)
542 if r
.status_code
== requests
.codes
.created
:
543 result
['data'] = r
.json()
544 result
['error'] = False
545 if r
.status_code
== requests
.codes
.conflict
:
546 result
['data'] = "Invalid ID."
549 def vnfd_create_pkg_base(self
, token
, pkg_name
):
550 result
= {'error': True, 'data': ''}
551 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
552 'Authorization': 'Bearer {}'.format(token
['id'])}
554 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
557 self
._create
_base
_pkg
('vnfd', pkg_name
)
558 r
= requests
.post(_url
, data
=open('/tmp/' + pkg_name
+ '.tar.gz', 'rb'), verify
=False, headers
=headers
)
559 except Exception as e
:
561 result
['data'] = str(e
)
563 if r
.status_code
== requests
.codes
.created
:
564 result
['data'] = r
.json()
565 result
['error'] = False
566 if r
.status_code
== requests
.codes
.conflict
:
567 result
['data'] = "Invalid ID."
570 def nsd_clone(self
, token
, id):
571 result
= {'error': True, 'data': ''}
572 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
573 'Authorization': 'Bearer {}'.format(token
['id'])}
575 # get the package onboarded
576 tar_pkg
= self
.get_nsd_pkg(token
, id)
577 tarf
= tarfile
.open(fileobj
=tar_pkg
)
578 tarf
= self
._descriptor
_clone
(tarf
, 'nsd')
579 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'))
581 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
584 r
= requests
.post(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'), verify
=False,
586 except Exception as e
:
588 result
['data'] = str(e
)
590 if r
.status_code
== requests
.codes
.created
:
591 result
['error'] = False
592 if r
.status_code
== requests
.codes
.conflict
:
593 result
['data'] = "Invalid ID."
597 def vnfd_clone(self
, token
, id):
598 result
= {'error': True, 'data': ''}
599 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
600 'Authorization': 'Bearer {}'.format(token
['id'])}
602 # get the package onboarded
603 tar_pkg
= self
.get_vnfd_pkg(token
, id)
604 tarf
= tarfile
.open(fileobj
=tar_pkg
)
606 tarf
= self
._descriptor
_clone
(tarf
, 'vnfd')
607 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'))
609 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
612 r
= requests
.post(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'), verify
=False,
614 except Exception as e
:
616 result
['data'] = str(e
)
618 if r
.status_code
== requests
.codes
.created
:
619 result
['error'] = False
620 if r
.status_code
== requests
.codes
.conflict
:
621 result
['data'] = "Invalid ID."
625 def nst_content_update(self
, token
, id, template
):
626 result
= {'error': True, 'data': ''}
627 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
628 'Authorization': 'Bearer {}'.format(token
['id'])}
629 _url
= "{0}/nst/v1/netslice_templates/{1}/nst_content".format(self
._base
_path
,id)
631 r
= requests
.put(_url
, data
=template
, verify
=False, headers
=headers
)
632 except Exception as e
:
634 result
['data'] = str(e
)
636 if r
.status_code
== requests
.codes
.no_content
:
637 result
['error'] = False
640 def nsd_update(self
, token
, id, data
):
641 result
= {'error': True, 'data': ''}
642 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
643 'Authorization': 'Bearer {}'.format(token
['id'])}
645 # get the package onboarded
646 tar_pkg
= self
.get_nsd_pkg(token
, id)
647 tarf
= tarfile
.open(fileobj
=tar_pkg
)
649 tarf
= self
._descriptor
_update
(tarf
, data
)
650 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
652 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self
._base
_path
, id)
655 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
657 except Exception as e
:
659 result
['data'] = str(e
)
661 if r
.status_code
== requests
.codes
.no_content
:
662 result
['error'] = False
665 result
['data'] = r
.json()
666 except Exception as e
:
671 def vnfd_update(self
, token
, id, data
):
672 result
= {'error': True, 'data': ''}
673 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
674 'Authorization': 'Bearer {}'.format(token
['id'])}
676 # get the package onboarded
677 tar_pkg
= self
.get_vnfd_pkg(token
, id)
678 tarf
= tarfile
.open(fileobj
=tar_pkg
)
680 tarf
= self
._descriptor
_update
(tarf
, data
)
681 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
683 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self
._base
_path
, id)
686 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
688 except Exception as e
:
690 result
['data'] = str(e
)
692 if r
.status_code
== requests
.codes
.no_content
:
693 result
['error'] = False
696 result
['data'] = r
.json()
697 except Exception as e
:
702 def get_nsd_pkg(self
, token
, id):
703 result
= {'error': True, 'data': ''}
704 headers
= {"accept": "application/zip",
705 'Authorization': 'Bearer {}'.format(token
['id'])}
707 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self
._base
_path
, id)
709 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
710 except Exception as e
:
712 result
['data'] = str(e
)
714 if r
.status_code
== requests
.codes
.ok
:
715 result
['error'] = False
716 tarf
= StringIO
.StringIO(r
.content
)
720 def get_vnfd_pkg(self
, token
, id):
721 result
= {'error': True, 'data': ''}
722 headers
= {"accept": "application/zip",
723 'Authorization': 'Bearer {}'.format(token
['id'])}
724 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self
._base
_path
, id)
726 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
727 except Exception as e
:
729 result
['data'] = str(e
)
731 if r
.status_code
== requests
.codes
.ok
:
732 result
['error'] = False
733 tarf
= StringIO
.StringIO(r
.content
)
737 def _descriptor_update(self
, tarf
, data
):
738 # extract the package on a tmp directory
739 tarf
.extractall('/tmp')
741 for name
in tarf
.getnames():
742 if name
.endswith(".yaml") or name
.endswith(".yml"):
743 with
open('/tmp/' + name
, 'w') as outfile
:
744 yaml
.safe_dump(data
, outfile
, default_flow_style
=False)
747 tarf_temp
= tarfile
.open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", "w:gz")
750 tarf_temp
.add('/tmp/' + tarinfo
.name
, tarinfo
.name
, recursive
=False)
754 def _create_base_pkg(self
, descriptor_type
, pkg_name
):
755 filename
= '/tmp/'+pkg_name
+'/' + pkg_name
+ '.yaml'
756 if descriptor_type
== 'nsd':
761 "short-name": str(pkg_name
),
762 "vendor": "OSM Composer",
763 "description": str(pkg_name
) + " descriptor",
765 "constituent-vnfd": [],
768 "name": str(pkg_name
)
774 elif descriptor_type
== 'vnfd':
776 "vnfd:vnfd-catalog": {
779 "short-name": str(pkg_name
),
788 "connection-point": [],
789 "name": str(pkg_name
)
795 if not os
.path
.exists(os
.path
.dirname(filename
)):
797 os
.makedirs(os
.path
.dirname(filename
))
798 except OSError as exc
: # Guard against race condition
799 if exc
.errno
!= errno
.EEXIST
:
802 with
open('/tmp/' + pkg_name
+ '/' + pkg_name
+ '.yaml', 'w') as yaml_file
:
803 yaml_file
.write(yaml
.dump(descriptor
, default_flow_style
=False))
805 tarf_temp
= tarfile
.open('/tmp/' + pkg_name
+ '.tar.gz', "w:gz")
806 tarf_temp
.add('/tmp/'+pkg_name
+'/' + pkg_name
+ '.yaml', pkg_name
+ '/' + pkg_name
+ '.yaml', recursive
=False)
809 def _descriptor_clone(self
, tarf
, descriptor_type
):
810 # extract the package on a tmp directory
811 tarf
.extractall('/tmp')
813 for name
in tarf
.getnames():
814 if name
.endswith(".yaml") or name
.endswith(".yml"):
815 with
open('/tmp/' + name
, 'r') as outfile
:
816 yaml_object
= yaml
.load(outfile
)
818 if descriptor_type
== 'nsd':
819 nsd_list
= yaml_object
['nsd:nsd-catalog']['nsd']
821 nsd
['id'] = 'clone_' + nsd
['id']
822 nsd
['name'] = 'clone_' + nsd
['name']
823 nsd
['short-name'] = 'clone_' + nsd
['short-name']
824 elif descriptor_type
== 'vnfd':
825 vnfd_list
= yaml_object
['vnfd:vnfd-catalog']['vnfd']
826 for vnfd
in vnfd_list
:
827 vnfd
['id'] = 'clone_' + vnfd
['id']
828 vnfd
['name'] = 'clone_' + vnfd
['name']
829 vnfd
['short-name'] = 'clone_' + vnfd
['short-name']
831 with
open('/tmp/' + name
, 'w') as yaml_file
:
832 yaml_file
.write(yaml
.dump(yaml_object
, default_flow_style
=False))
835 tarf_temp
= tarfile
.open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", "w:gz")
838 tarf_temp
.add('/tmp/' + tarinfo
.name
, tarinfo
.name
, recursive
=False)
842 def nsd_get(self
, token
, id):
843 result
= {'error': True, 'data': ''}
844 headers
= {'Content-Type': 'application/yaml',
845 'Authorization': 'Bearer {}'.format(token
['id'])}
846 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd".format(self
._base
_path
, id)
848 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
849 except Exception as e
:
851 result
['data'] = str(e
)
853 if r
.status_code
== requests
.codes
.ok
:
854 result
['error'] = False
855 return yaml
.load(r
.text
)
858 result
['data'] = r
.json()
859 except Exception as e
:
863 def vnfd_get(self
, token
, id):
864 result
= {'error': True, 'data': ''}
865 headers
= {'Content-Type': 'application/yaml',
866 'Authorization': 'Bearer {}'.format(token
['id'])}
867 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/vnfd".format(self
._base
_path
, id)
869 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
870 except Exception as e
:
872 result
['data'] = str(e
)
874 if r
.status_code
== requests
.codes
.ok
:
875 result
['error'] = False
876 return yaml
.load(r
.text
)
879 result
['data'] = r
.json()
880 except Exception as e
:
884 def nsd_artifacts(self
, token
, id):
885 result
= {'error': True, 'data': ''}
886 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
887 'Authorization': 'Bearer {}'.format(token
['id'])}
888 _url
= "{0}/nsd/v1/ns_descriptors/{1}/artifacts".format(self
._base
_path
, id)
890 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
891 except Exception as e
:
893 result
['data'] = str(e
)
895 if r
.status_code
== requests
.codes
.ok
:
896 result
['error'] = False
897 result
['data'] = r
.text
900 result
['data'] = r
.json()
901 except Exception as e
:
906 def vnf_packages_artifacts(self
, token
, id):
907 result
= {'error': True, 'data': ''}
908 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
909 'Authorization': 'Bearer {}'.format(token
['id'])}
910 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/artifacts".format(self
._base
_path
, id)
912 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
913 except Exception as e
:
915 result
['data'] = str(e
)
917 if r
.status_code
== requests
.codes
.ok
:
918 result
['error'] = False
919 result
['data'] = r
.text
922 result
['data'] = r
.json()
923 except Exception as e
:
928 def nsi_create(self
, token
, nsi_data
):
929 result
= {'error': True, 'data': ''}
930 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
931 'Authorization': 'Bearer {}'.format(token
['id'])}
933 _url
= "{0}/nsilcm/v1/netslice_instances_content".format(self
._base
_path
)
936 r
= requests
.post(_url
, json
=nsi_data
, verify
=False, headers
=headers
)
937 except Exception as e
:
939 result
['data'] = str(e
)
941 if r
.status_code
== requests
.codes
.ok
:
942 result
['error'] = False
943 result
['data'] = Util
.json_loads_byteified(r
.text
)
946 def ns_create(self
, token
, ns_data
):
947 result
= {'error': True, 'data': ''}
948 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
949 'Authorization': 'Bearer {}'.format(token
['id'])}
951 _url
= "{0}/nslcm/v1/ns_instances_content".format(self
._base
_path
)
954 r
= requests
.post(_url
, json
=ns_data
, verify
=False, headers
=headers
)
955 except Exception as e
:
957 result
['data'] = str(e
)
959 if r
.status_code
== requests
.codes
.ok
:
960 result
['error'] = False
961 result
['data'] = Util
.json_loads_byteified(r
.text
)
964 def pdu_create(self
, token
, pdu_data
):
965 result
= {'error': True, 'data': ''}
966 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
967 'Authorization': 'Bearer {}'.format(token
['id'])}
969 _url
= "{0}/pdu/v1/pdu_descriptors".format(self
._base
_path
)
972 r
= requests
.post(_url
, json
=pdu_data
, verify
=False, headers
=headers
)
973 except Exception as e
:
975 result
['data'] = str(e
)
977 if r
.status_code
== requests
.codes
.created
:
978 result
['error'] = False
979 result
['data'] = Util
.json_loads_byteified(r
.text
)
982 def ns_op_list(self
, token
, id):
983 result
= {'error': True, 'data': ''}
984 headers
= {"Content-Type": "application/json", "accept": "application/json",
985 'Authorization': 'Bearer {}'.format(token
['id'])}
986 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/?nsInstanceId={1}".format(self
._base
_path
, id)
989 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
990 except Exception as e
:
992 result
['data'] = str(e
)
994 if r
.status_code
== requests
.codes
.ok
:
995 result
['error'] = False
996 result
['data'] = Util
.json_loads_byteified(r
.text
)
1000 def nsi_op_list(self
, token
, id):
1001 result
= {'error': True, 'data': ''}
1002 headers
= {"Content-Type": "application/json", "accept": "application/json",
1003 'Authorization': 'Bearer {}'.format(token
['id'])}
1004 _url
= "{0}/nsilcm/v1/nsi_lcm_op_occs/?nsInstanceId={1}".format(self
._base
_path
, id)
1007 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1008 except Exception as e
:
1010 result
['data'] = str(e
)
1012 if r
.status_code
== requests
.codes
.ok
:
1013 result
['error'] = False
1014 result
['data'] = Util
.json_loads_byteified(r
.text
)
1018 def ns_op(self
, token
, id):
1019 result
= {'error': True, 'data': ''}
1020 headers
= {"Content-Type": "application/json", "accept": "application/json",
1021 'Authorization': 'Bearer {}'.format(token
['id'])}
1022 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/{1}".format(self
._base
_path
, id)
1025 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1026 except Exception as e
:
1028 result
['data'] = str(e
)
1030 if r
.status_code
== requests
.codes
.ok
:
1031 result
['error'] = False
1032 result
['data'] = Util
.json_loads_byteified(r
.text
)
1036 def ns_action(self
, token
, id, action_payload
):
1037 result
= {'error': True, 'data': ''}
1038 headers
= {"Content-Type": "application/json", "accept": "application/json",
1039 'Authorization': 'Bearer {}'.format(token
['id'])}
1041 _url
= "{0}/nslcm/v1/ns_instances/{1}/action".format(self
._base
_path
, id)
1044 r
= requests
.post(_url
, json
=action_payload
, verify
=False, headers
=headers
)
1045 except Exception as e
:
1047 result
['data'] = str(e
)
1049 if r
.status_code
== requests
.codes
.created
:
1050 result
['error'] = False
1051 result
['data'] = Util
.json_loads_byteified(r
.text
)
1054 def nsi_delete(self
, token
, id, force
=None):
1055 result
= {'error': True, 'data': ''}
1056 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1057 'Authorization': 'Bearer {}'.format(token
['id'])}
1060 query_path
= '?FORCE=true'
1061 _url
= "{0}/nsilcm/v1/netslice_instances_content/{1}{2}".format(self
._base
_path
, id, query_path
)
1063 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1064 except Exception as e
:
1066 result
['data'] = str(e
)
1069 result
['error'] = False
1070 if r
.status_code
!= requests
.codes
.no_content
:
1071 result
['data'] = Util
.json_loads_byteified(r
.text
)
1074 def ns_delete(self
, token
, id, force
=None):
1075 result
= {'error': True, 'data': ''}
1076 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1077 'Authorization': 'Bearer {}'.format(token
['id'])}
1080 query_path
= '?FORCE=true'
1081 _url
= "{0}/nslcm/v1/ns_instances_content/{1}{2}".format(self
._base
_path
, id, query_path
)
1083 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1084 except Exception as e
:
1086 result
['data'] = str(e
)
1089 result
['error'] = False
1090 if r
.status_code
!= requests
.codes
.no_content
:
1091 result
['data'] = Util
.json_loads_byteified(r
.text
)
1094 def pdu_delete(self
, token
, id):
1095 result
= {'error': True, 'data': ''}
1096 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1097 'Authorization': 'Bearer {}'.format(token
['id'])}
1098 _url
= "{0}/pdu/v1/pdu_descriptors/{1}".format(self
._base
_path
, id)
1100 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1101 except Exception as e
:
1103 result
['data'] = str(e
)
1106 result
['error'] = False
1107 if r
.status_code
!= requests
.codes
.no_content
:
1108 result
['data'] = Util
.json_loads_byteified(r
.text
)
1111 def nsi_get(self
, token
, id):
1112 result
= {'error': True, 'data': ''}
1113 headers
= {"Content-Type": "application/json", "accept": "application/json",
1114 'Authorization': 'Bearer {}'.format(token
['id'])}
1115 _url
= "{0}/nsilcm/v1/netslice_instances/{1}".format(self
._base
_path
, id)
1118 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1119 except Exception as e
:
1121 result
['data'] = str(e
)
1123 if r
.status_code
== requests
.codes
.ok
:
1124 result
['error'] = False
1125 result
['data'] = Util
.json_loads_byteified(r
.text
)
1128 def ns_get(self
, token
, id):
1129 result
= {'error': True, 'data': ''}
1130 headers
= {"Content-Type": "application/json", "accept": "application/json",
1131 'Authorization': 'Bearer {}'.format(token
['id'])}
1132 _url
= "{0}/nslcm/v1/ns_instances_content/{1}".format(self
._base
_path
, id)
1135 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1136 except Exception as e
:
1138 result
['data'] = str(e
)
1140 if r
.status_code
== requests
.codes
.ok
:
1141 result
['error'] = False
1142 result
['data'] = Util
.json_loads_byteified(r
.text
)
1145 def vnf_get(self
, token
, id):
1146 result
= {'error': True, 'data': ''}
1147 headers
= {"Content-Type": "application/json", "accept": "application/json",
1148 'Authorization': 'Bearer {}'.format(token
['id'])}
1149 _url
= "{0}/nslcm/v1/vnfrs/{1}".format(self
._base
_path
, id)
1152 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1153 except Exception as e
:
1155 result
['data'] = str(e
)
1157 if r
.status_code
== requests
.codes
.ok
:
1158 result
['error'] = False
1159 result
['data'] = Util
.json_loads_byteified(r
.text
)
1162 def pdu_get(self
, token
, id):
1163 result
= {'error': True, 'data': ''}
1164 headers
= {"Content-Type": "application/json", "accept": "application/json",
1165 'Authorization': 'Bearer {}'.format(token
['id'])}
1166 _url
= "{0}/pdu/v1/pdu_descriptors/{1}".format(self
._base
_path
, id)
1169 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1170 except Exception as e
:
1172 result
['data'] = str(e
)
1174 if r
.status_code
== requests
.codes
.ok
:
1175 result
['error'] = False
1176 result
['data'] = Util
.json_loads_byteified(r
.text
)
1179 def ns_alarm_create(self
, token
, id, alarm_payload
):
1180 result
= {'error': True, 'data': ''}
1181 headers
= {"Content-Type": "application/json",
1182 'Authorization': 'Bearer {}'.format(token
['id'])}
1183 _url
= "{0}/test/message/alarm_request".format(self
._base
_path
)
1185 r
= requests
.post(_url
, json
=alarm_payload
, verify
=False, headers
=headers
)
1186 except Exception as e
:
1188 result
['data'] = str(e
)
1190 if r
.status_code
== requests
.codes
.ok
:
1191 result
['error'] = False
1192 # result['data'] = Util.json_loads_byteified(r.text)
1193 result
['data'] = r
.text
1196 def ns_metric_export(self
, token
, id, metric_payload
):
1197 result
= {'error': True, 'data': ''}
1198 headers
= {"Content-Type": "application/json",
1199 'Authorization': 'Bearer {}'.format(token
['id'])}
1200 _url
= "{0}/test/message/metric_request".format(self
._base
_path
)
1202 r
= requests
.post(_url
, json
=metric_payload
, verify
=False, headers
=headers
)
1203 except Exception as e
:
1205 result
['data'] = str(e
)
1207 if r
.status_code
== requests
.codes
.ok
:
1208 result
['error'] = False
1209 # result['data'] = Util.json_loads_byteified(r.text)
1210 result
['data'] = r
.text
1213 def vim_list(self
, token
):
1214 result
= {'error': True, 'data': ''}
1215 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1216 'Authorization': 'Bearer {}'.format(token
['id'])}
1217 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
1219 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1220 except Exception as e
:
1222 result
['data'] = str(e
)
1224 if r
.status_code
== requests
.codes
.ok
:
1225 result
['error'] = False
1226 result
['data'] = Util
.json_loads_byteified(r
.text
)
1230 def vim_delete(self
, token
, id):
1231 result
= {'error': True, 'data': ''}
1232 headers
= {"accept": "application/json",
1233 'Authorization': 'Bearer {}'.format(token
['id'])}
1234 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
1236 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1237 except Exception as e
:
1239 result
['data'] = str(e
)
1241 if r
.status_code
== requests
.codes
.accepted
:
1242 result
['error'] = False
1244 result
['data'] = r
.text
1247 def vim_get(self
, token
, id):
1249 result
= {'error': True, 'data': ''}
1250 headers
= {"Content-Type": "application/json", "accept": "application/json",
1251 'Authorization': 'Bearer {}'.format(token
['id'])}
1252 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
1255 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1256 except Exception as e
:
1258 result
['data'] = str(e
)
1260 if r
.status_code
== requests
.codes
.ok
:
1261 result
['error'] = False
1262 result
['data'] = Util
.json_loads_byteified(r
.text
)
1265 def vim_create(self
, token
, vim_data
):
1267 result
= {'error': True, 'data': ''}
1268 headers
= {"Content-Type": "application/json", "accept": "application/json",
1269 'Authorization': 'Bearer {}'.format(token
['id'])}
1271 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
1274 r
= requests
.post(_url
, json
=vim_data
, verify
=False, headers
=headers
)
1275 except Exception as e
:
1277 result
['data'] = str(e
)
1279 if r
.status_code
== requests
.codes
.created
:
1280 result
['error'] = False
1281 result
['data'] = Util
.json_loads_byteified(r
.text
)
1284 def sdn_list(self
, token
):
1285 result
= {'error': True, 'data': ''}
1286 headers
= {"accept": "application/json",
1287 'Authorization': 'Bearer {}'.format(token
['id'])}
1288 _url
= "{0}/admin/v1/sdns".format(self
._base
_path
)
1290 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1291 except Exception as e
:
1293 result
['data'] = str(e
)
1295 if r
.status_code
== requests
.codes
.ok
:
1296 result
['error'] = False
1297 result
['data'] = Util
.json_loads_byteified(r
.text
)
1300 def sdn_delete(self
, token
, id):
1301 result
= {'error': True, 'data': ''}
1302 headers
= {"accept": "application/json",
1303 'Authorization': 'Bearer {}'.format(token
['id'])}
1304 _url
= "{0}/admin/v1/sdns/{1}".format(self
._base
_path
, id)
1306 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1307 except Exception as e
:
1309 result
['data'] = str(e
)
1311 if r
.status_code
== requests
.codes
.accepted
:
1312 result
['error'] = False
1314 result
['data'] = r
.text
1317 def sdn_get(self
, token
, id):
1318 result
= {'error': True, 'data': ''}
1319 headers
= {"accept": "application/json",
1320 'Authorization': 'Bearer {}'.format(token
['id'])}
1321 _url
= "{0}/admin/v1/sdns/{1}".format(self
._base
_path
, id)
1324 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1325 except Exception as e
:
1327 result
['data'] = str(e
)
1329 if r
.status_code
== requests
.codes
.ok
:
1330 result
['error'] = False
1331 result
['data'] = Util
.json_loads_byteified(r
.text
)
1334 def sdn_create(self
, token
, sdn_data
):
1335 result
= {'error': True, 'data': ''}
1336 headers
= {"Content-Type": "application/json", "accept": "application/json",
1337 'Authorization': 'Bearer {}'.format(token
['id'])}
1339 _url
= "{0}/admin/v1/sdns".format(self
._base
_path
)
1342 r
= requests
.post(_url
, json
=sdn_data
, verify
=False, headers
=headers
)
1343 except Exception as e
:
1345 result
['data'] = str(e
)
1347 if r
.status_code
== requests
.codes
.created
:
1348 result
['error'] = False
1349 result
['data'] = Util
.json_loads_byteified(r
.text
)
1354 hash_md5
= hashlib
.md5()
1355 for chunk
in iter(lambda: f
.read(1024), b
""):
1356 hash_md5
.update(chunk
)
1357 return hash_md5
.hexdigest()