1820d2fc8547db24ac79e407d2e38a7f6b0f2444
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
26 from requests
.packages
.urllib3
.exceptions
import InsecureRequestWarning
28 requests
.packages
.urllib3
.disable_warnings(InsecureRequestWarning
)
30 logging
.basicConfig(level
=logging
.INFO
)
31 log
= logging
.getLogger('helper.py')
32 logging
.getLogger("urllib3").setLevel(logging
.INFO
)
37 self
._token
_endpoint
= 'admin/v1/tokens'
38 self
._user
_endpoint
= 'admin/v1/users'
39 self
._host
= os
.getenv('OSM_SERVER', "localhost")
41 self
._base
_path
= 'https://{0}:{1}/osm'.format(self
._host
, self
._so
_port
)
44 result
= {'error': True, 'data': ''}
45 token_url
= "{0}/{1}".format(self
._base
_path
, self
._token
_endpoint
)
46 headers
= {"Content-Type": "application/yaml", "accept": "application/json"}
48 r
= requests
.post(token_url
, json
=args
, verify
=False, headers
=headers
)
49 except Exception as e
:
51 result
['data'] = str(e
)
53 if r
.status_code
in (200, 201, 202, 204):
54 result
['error'] = False
56 result
['data'] = Util
.json_loads_byteified(r
.text
)
60 def switch_project(self
, args
):
61 result
= {'error': True, 'data': ''}
62 token_url
= "{0}/{1}".format(self
._base
_path
, self
._token
_endpoint
)
63 headers
= {"Content-Type": "application/yaml", "accept": "application/json"}
65 r
= requests
.post(token_url
, json
=args
, verify
=False, headers
=headers
)
66 except Exception as e
:
68 result
['data'] = str(e
)
70 if r
.status_code
in (200, 201, 202, 204):
71 result
['error'] = False
73 result
['data'] = Util
.json_loads_byteified(r
.text
)
77 def role_list(self
, token
):
78 result
= {'error': True, 'data': ''}
79 headers
= {"Content-Type": "application/json", "accept": "application/json",
80 'Authorization': 'Bearer {}'.format(token
['id'])}
82 _url
= "{0}/admin/v1/roles".format(self
._base
_path
)
84 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
85 except Exception as e
:
87 result
['data'] = str(e
)
89 if r
.status_code
in (200, 201, 202, 204):
90 result
['error'] = False
91 result
['data'] = Util
.json_loads_byteified(r
.text
)
95 def role_create(self
, token
, role_data
):
96 result
= {'error': True, 'data': ''}
97 headers
= {"Content-Type": "application/json", "accept": "application/json",
98 'Authorization': 'Bearer {}'.format(token
['id'])}
99 _url
= "{0}/admin/v1/roles".format(self
._base
_path
)
102 r
= requests
.post(_url
, json
=role_data
, verify
=False, headers
=headers
)
103 except Exception as e
:
105 result
['data'] = str(e
)
107 if r
.status_code
in (200, 201, 202, 204):
108 result
['error'] = False
109 result
['data'] = Util
.json_loads_byteified(r
.text
)
112 def role_update(self
, token
, role_id
, role_data
):
113 result
= {'error': True, 'data': ''}
114 headers
= {"Content-Type": "application/json", "accept": "application/json",
115 'Authorization': 'Bearer {}'.format(token
['id'])}
116 _url
= "{0}/admin/v1/roles/{1}".format(self
._base
_path
, role_id
)
118 r
= requests
.patch(_url
, json
=role_data
, verify
=False, headers
=headers
)
119 except Exception as e
:
121 result
['data'] = str(e
)
123 if r
.status_code
in (200, 201, 202, 204):
124 result
['error'] = False
126 result
['data'] = Util
.json_loads_byteified(r
.text
)
129 def role_delete(self
, token
, id, force
=None):
130 result
= {'error': True, 'data': ''}
131 headers
= {"Content-Type": "application/json", "accept": "application/json",
132 'Authorization': 'Bearer {}'.format(token
['id'])}
135 query_path
= '?FORCE=true'
136 _url
= "{0}/admin/v1/roles/{1}{2}".format(self
._base
_path
, id, query_path
)
138 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
139 except Exception as e
:
141 result
['data'] = str(e
)
143 if r
.status_code
in (200, 201, 202, 204):
144 result
['error'] = False
146 result
['data'] = Util
.json_loads_byteified(r
.text
)
149 def role_get(self
, token
, id):
150 result
= {'error': True, 'data': ''}
151 headers
= {"Content-Type": "application/json", "accept": "application/json",
152 'Authorization': 'Bearer {}'.format(token
['id'])}
154 _url
= "{0}/admin/v1/roles/{1}".format(self
._base
_path
, id)
156 r
= requests
.get(_url
, params
=None, verify
=False, headers
=headers
)
157 except Exception as e
:
159 result
['data'] = str(e
)
161 if r
.status_code
in (200, 201, 202, 204):
162 result
['error'] = False
163 result
['data'] = Util
.json_loads_byteified(r
.text
)
166 def user_list(self
, token
):
167 result
= {'error': True, 'data': ''}
168 headers
= {"Content-Type": "application/json", "accept": "application/json",
169 'Authorization': 'Bearer {}'.format(token
['id'])}
171 _url
= "{0}/admin/v1/users".format(self
._base
_path
)
173 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
174 except Exception as e
:
176 result
['data'] = str(e
)
178 if r
.status_code
in (200, 201, 202, 204):
179 result
['error'] = False
180 result
['data'] = Util
.json_loads_byteified(r
.text
)
184 def user_create(self
, token
, user_data
):
185 result
= {'error': True, 'data': ''}
186 headers
= {"Content-Type": "application/json", "accept": "application/json",
187 'Authorization': 'Bearer {}'.format(token
['id'])}
189 _url
= "{0}/admin/v1/users".format(self
._base
_path
)
192 r
= requests
.post(_url
, json
=user_data
, verify
=False, headers
=headers
)
193 except Exception as e
:
195 result
['data'] = str(e
)
197 if r
.status_code
in (200, 201, 202, 204):
198 result
['error'] = False
199 result
['data'] = Util
.json_loads_byteified(r
.text
)
202 def user_update(self
, token
, id, user_data
):
203 result
= {'error': True, 'data': ''}
204 headers
= {"Content-Type": "application/json", "accept": "application/json",
205 'Authorization': 'Bearer {}'.format(token
['id'])}
207 _url
= "{0}/admin/v1/users/{1}".format(self
._base
_path
, id)
209 r
= requests
.patch(_url
, json
=user_data
, verify
=False, headers
=headers
)
210 except Exception as e
:
212 result
['data'] = str(e
)
214 if r
.status_code
in (200, 201, 202, 204):
215 result
['error'] = False
217 result
['data'] = Util
.json_loads_byteified(r
.text
)
220 def user_delete(self
, token
, id):
221 result
= {'error': True, 'data': ''}
222 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
223 'Authorization': 'Bearer {}'.format(token
['id'])}
225 _url
= "{0}/admin/v1/users/{1}".format(self
._base
_path
, id)
227 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
228 except Exception as e
:
230 result
['data'] = str(e
)
232 if r
.status_code
in (200, 201, 202, 204):
233 result
['error'] = False
235 result
['data'] = Util
.json_loads_byteified(r
.text
)
238 def get_user_info(self
, token
, id):
239 result
= {'error': True, 'data': ''}
240 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
241 'Authorization': 'Bearer {}'.format(token
['id'])}
242 _url
= "{0}/admin/v1/users/{1}".format(self
._base
_path
, id)
244 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
245 except Exception as e
:
247 result
['data'] = str(e
)
249 if r
.status_code
in (200, 201, 202, 204):
250 result
['error'] = False
251 result
['data'] = Util
.json_loads_byteified(r
.text
)
254 def get_projects(self
, token
, uuids
):
255 result
= {'error': False, 'data': ''}
256 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
257 'Authorization': 'Bearer {}'.format(token
['id'])}
262 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, uuid
)
263 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
264 if r
.status_code
not in (200, 201, 202, 204):
266 projects
.append(Util
.json_loads_byteified(r
.text
))
267 except Exception as e
:
269 result
['error'] = True
270 result
['data'] = str(e
)
272 result
['data'] = projects
275 def project_list(self
, token
):
276 result
= {'error': True, 'data': ''}
277 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
278 'Authorization': 'Bearer {}'.format(token
['id'])}
280 _url
= "{0}/admin/v1/projects".format(self
._base
_path
)
282 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
283 except Exception as e
:
285 result
['data'] = str(e
)
287 if r
.status_code
in (200, 201, 202, 204):
288 result
['error'] = False
289 result
['data'] = Util
.json_loads_byteified(r
.text
)
293 def project_get(self
, token
, id):
294 result
= {'error': True, 'data': ''}
295 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
296 'Authorization': 'Bearer {}'.format(token
['id'])}
297 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
299 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
300 except Exception as e
:
302 result
['data'] = str(e
)
304 if r
.status_code
in (200, 201, 202, 204):
305 result
['error'] = False
306 result
['data'] = Util
.json_loads_byteified(r
.text
)
309 def project_create(self
, token
, project_data
):
311 result
= {'error': True, 'data': ''}
312 headers
= {"Content-Type": "application/json", "accept": "application/json",
313 'Authorization': 'Bearer {}'.format(token
['id'])}
315 _url
= "{0}/admin/v1/projects".format(self
._base
_path
)
318 r
= requests
.post(_url
, json
=project_data
, verify
=False, headers
=headers
)
319 except Exception as e
:
321 result
['data'] = str(e
)
323 if r
.status_code
in (200, 201, 202, 204):
324 result
['error'] = False
325 result
['data'] = Util
.json_loads_byteified(r
.text
)
328 def project_edit(self
, token
, id, project_data
):
330 result
= {'error': True, 'data': ''}
331 headers
= {"Content-Type": "application/json", "accept": "application/json",
332 'Authorization': 'Bearer {}'.format(token
['id'])}
334 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
337 r
= requests
.patch(_url
, json
=project_data
, verify
=False, headers
=headers
)
338 except Exception as e
:
340 result
['data'] = str(e
)
342 if r
.status_code
in (200, 201, 202, 204):
343 result
['error'] = False
346 def project_delete(self
, token
, id):
347 result
= {'error': True, 'data': ''}
348 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
349 'Authorization': 'Bearer {}'.format(token
['id'])}
351 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
353 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
354 except Exception as e
:
356 result
['data'] = str(e
)
358 if r
.status_code
in (200, 201, 202, 204):
359 result
['error'] = False
361 result
['data'] = Util
.json_loads_byteified(r
.text
)
364 def nst_details(self
, token
, id):
365 result
= {'error': True, 'data': ''}
366 headers
= {"Content-Type": "application/json", "accept": "application/json",
367 'Authorization': 'Bearer {}'.format(token
['id'])}
368 _url
= "{0}/nst/v1/netslice_templates/{1}".format(self
._base
_path
,id)
370 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
371 except Exception as e
:
373 result
['data'] = str(e
)
375 if r
.status_code
in (200, 201, 202, 204):
376 result
['error'] = False
377 result
['data'] = Util
.json_loads_byteified(r
.text
)
381 def nst_content(self
, token
, id):
382 result
= {'error': True, 'data': ''}
383 headers
= {"Content-Type": "application/json", "accept": "text/plain",
384 'Authorization': 'Bearer {}'.format(token
['id'])}
385 _url
= "{0}/nst/v1/netslice_templates/{1}/nst".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
in (200, 201, 202, 204):
393 result
['error'] = False
394 result
['data'] = Util
.json2yaml(yaml
.load(str(r
.text
)))
398 def nst_list(self
, token
):
399 result
= {'error': True, 'data': ''}
400 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
401 'Authorization': 'Bearer {}'.format(token
['id'])}
403 _url
= "{0}/nst/v1/netslice_templates".format(self
._base
_path
)
405 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
in (200, 201, 202, 204):
411 result
['error'] = False
412 result
['data'] = Util
.json_loads_byteified(r
.text
)
416 def nsd_list(self
, token
, filter=None):
417 result
= {'error': True, 'data': ''}
418 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
419 'Authorization': 'Bearer {}'.format(token
['id'])}
422 query_path
= '?_admin.type='+filter
423 _url
= "{0}/nsd/v1/ns_descriptors_content{1}".format(self
._base
_path
, query_path
)
425 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
426 except Exception as e
:
428 result
['data'] = str(e
)
430 if r
.status_code
in (200, 201, 202, 204):
431 result
['error'] = False
432 result
['data'] = Util
.json_loads_byteified(r
.text
)
436 def vnfd_list(self
, token
, filter=None):
437 result
= {'error': True, 'data': ''}
438 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
439 'Authorization': 'Bearer {}'.format(token
['id'])}
442 query_path
= '?_admin.type='+filter
443 _url
= "{0}/vnfpkgm/v1/vnf_packages_content{1}".format(self
._base
_path
, query_path
)
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
in (200, 201, 202, 204):
451 result
['error'] = False
452 result
['data'] = Util
.json_loads_byteified(r
.text
)
456 def nsi_list(self
, token
):
457 result
= {'error': True, 'data': ''}
458 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
459 'Authorization': 'Bearer {}'.format(token
['id'])}
460 _url
= "{0}/nsilcm/v1/netslice_instances".format(self
._base
_path
)
462 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
463 except Exception as e
:
465 result
['data'] = str(e
)
467 if r
.status_code
in (200, 201, 202, 204):
468 result
['error'] = False
469 result
['data'] = Util
.json_loads_byteified(r
.text
)
473 def ns_list(self
, token
):
474 result
= {'error': True, 'data': ''}
475 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
476 'Authorization': 'Bearer {}'.format(token
['id'])}
477 _url
= "{0}/nslcm/v1/ns_instances_content".format(self
._base
_path
)
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
in (200, 201, 202, 204):
485 result
['error'] = False
486 result
['data'] = Util
.json_loads_byteified(r
.text
)
490 def vnf_list(self
, token
):
491 result
= {'error': True, 'data': ''}
492 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
493 'Authorization': 'Bearer {}'.format(token
['id'])}
494 _url
= "{0}/nslcm/v1/vnfrs".format(self
._base
_path
)
496 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
497 except Exception as e
:
499 result
['data'] = str(e
)
501 if r
.status_code
in (200, 201, 202, 204):
502 result
['error'] = False
503 result
['data'] = Util
.json_loads_byteified(r
.text
)
507 def pdu_list(self
, token
):
508 result
= {'error': True, 'data': ''}
509 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
510 'Authorization': 'Bearer {}'.format(token
['id'])}
511 _url
= "{0}/pdu/v1/pdu_descriptors".format(self
._base
_path
)
513 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
514 except Exception as e
:
516 result
['data'] = str(e
)
518 if r
.status_code
in (200, 201, 202, 204):
519 result
['error'] = False
520 result
['data'] = Util
.json_loads_byteified(r
.text
)
524 def nst_delete(self
, token
, id):
525 result
= {'error': True, 'data': ''}
526 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
527 'Authorization': 'Bearer {}'.format(token
['id'])}
529 _url
= "{0}/nst/v1/netslice_templates/{1}?FORCE=True".format(self
._base
_path
, id)
531 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
532 except Exception as e
:
534 result
['data'] = str(e
)
536 if r
.status_code
in (200, 201, 202, 204):
537 result
['error'] = False
541 def nsd_delete(self
, token
, id):
542 result
= {'error': True, 'data': ''}
543 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
544 'Authorization': 'Bearer {}'.format(token
['id'])}
546 _url
= "{0}/nsd/v1/ns_descriptors_content/{1}".format(self
._base
_path
, id)
548 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
549 except Exception as e
:
551 result
['data'] = str(e
)
554 result
['error'] = False
555 if r
.status_code
!= requests
.codes
.no_content
:
556 result
['data'] = Util
.json_loads_byteified(r
.text
)
559 def vnfd_delete(self
, token
, id):
560 result
= {'error': True, 'data': ''}
561 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
562 'Authorization': 'Bearer {}'.format(token
['id'])}
564 _url
= "{0}/vnfpkgm/v1/vnf_packages_content/{1}".format(self
._base
_path
, id)
566 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
567 except Exception as e
:
569 result
['data'] = str(e
)
572 result
['error'] = False
573 if r
.status_code
!= requests
.codes
.no_content
:
574 result
['data'] = Util
.json_loads_byteified(r
.text
)
577 def nst_onboard(self
, token
, template
):
578 result
= {'error': True, 'data': ''}
579 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
580 'Authorization': 'Bearer {}'.format(token
['id'])}
581 _url
= "{0}/nst/v1/netslice_templates_content".format(self
._base
_path
)
583 fileName
, fileExtension
= os
.path
.splitext(template
.name
)
584 if fileExtension
== '.gz':
585 headers
["Content-Type"] = "application/gzip"
587 headers
["Content-Type"] = "application/yaml"
588 r
= requests
.post(_url
, data
=template
, verify
=False, headers
=headers
)
589 except Exception as e
:
591 result
['data'] = str(e
)
593 if r
.status_code
in (200, 201, 202, 204):
594 result
['error'] = False
595 result
['data'] = Util
.json_loads_byteified(r
.text
)
598 def nsd_onboard(self
, token
, package
):
599 result
= {'error': True, 'data': ''}
600 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
601 'Authorization': 'Bearer {}'.format(token
['id'])}
602 with
open('/tmp/' + package
.name
, 'wb+') as destination
:
603 for chunk
in package
.chunks():
604 destination
.write(chunk
)
605 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + package
.name
, 'rb'))
606 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
608 r
= requests
.post(_url
, data
=open('/tmp/' + package
.name
, 'rb'), verify
=False, headers
=headers
)
609 except Exception as e
:
611 result
['data'] = str(e
)
613 if r
.status_code
in (200, 201, 202, 204):
614 result
['error'] = False
615 result
['data'] = Util
.json_loads_byteified(r
.text
)
618 def vnfd_onboard(self
, token
, package
):
619 result
= {'error': True, 'data': ''}
620 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
621 'Authorization': 'Bearer {}'.format(token
['id'])}
622 with
open('/tmp/' + package
.name
, 'wb+') as destination
:
623 for chunk
in package
.chunks():
624 destination
.write(chunk
)
625 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + package
.name
, 'rb'))
626 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
628 r
= requests
.post(_url
, data
=open('/tmp/' + package
.name
, 'rb'), verify
=False, headers
=headers
)
629 except Exception as e
:
631 result
['data'] = str(e
)
633 if r
.status_code
in (200, 201, 202, 204):
634 result
['error'] = False
635 result
['data'] = Util
.json_loads_byteified(r
.text
)
638 def nsd_create_pkg_base(self
, token
, pkg_name
):
639 result
= {'error': True, 'data': ''}
640 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
641 'Authorization': 'Bearer {}'.format(token
['id'])}
643 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
646 self
._create
_base
_pkg
('nsd', pkg_name
)
647 headers
['Content-Filename'] = pkg_name
+ '.tar.gz'
648 r
= requests
.post(_url
, data
=open('/tmp/' + pkg_name
+ '.tar.gz', 'rb'), verify
=False, headers
=headers
)
649 except Exception as e
:
651 result
['data'] = str(e
)
653 if r
.status_code
in (200, 201, 202, 204):
654 result
['data'] = r
.json()
655 result
['error'] = False
656 if r
.status_code
== requests
.codes
.conflict
:
657 result
['data'] = "Invalid ID."
660 def vnfd_create_pkg_base(self
, token
, pkg_name
):
661 result
= {'error': True, 'data': ''}
662 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
663 'Authorization': 'Bearer {}'.format(token
['id'])}
665 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
668 self
._create
_base
_pkg
('vnfd', pkg_name
)
669 r
= requests
.post(_url
, data
=open('/tmp/' + pkg_name
+ '.tar.gz', 'rb'), verify
=False, headers
=headers
)
670 except Exception as e
:
672 result
['data'] = str(e
)
674 if r
.status_code
in (200, 201, 202, 204):
675 result
['data'] = r
.json()
676 result
['error'] = False
677 if r
.status_code
== requests
.codes
.conflict
:
678 result
['data'] = "Invalid ID."
681 def nsd_clone(self
, token
, id):
682 result
= {'error': True, 'data': ''}
683 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
684 'Authorization': 'Bearer {}'.format(token
['id'])}
686 # get the package onboarded
687 tar_pkg
= self
.get_nsd_pkg(token
, id)
688 tarf
= tarfile
.open(fileobj
=tar_pkg
)
689 tarf
= self
._descriptor
_clone
(tarf
, 'nsd')
690 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'))
692 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
695 r
= requests
.post(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'), verify
=False,
697 except Exception as e
:
699 result
['data'] = str(e
)
701 if r
.status_code
in (200, 201, 202, 204):
702 result
['error'] = False
703 if r
.status_code
== requests
.codes
.conflict
:
704 result
['data'] = "Invalid ID."
708 def vnfd_clone(self
, token
, id):
709 result
= {'error': True, 'data': ''}
710 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
711 'Authorization': 'Bearer {}'.format(token
['id'])}
713 # get the package onboarded
714 tar_pkg
= self
.get_vnfd_pkg(token
, id)
715 tarf
= tarfile
.open(fileobj
=tar_pkg
)
717 tarf
= self
._descriptor
_clone
(tarf
, 'vnfd')
718 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'))
720 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
723 r
= requests
.post(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'), verify
=False,
725 except Exception as e
:
727 result
['data'] = str(e
)
729 if r
.status_code
in (200, 201, 202, 204):
730 result
['error'] = False
731 if r
.status_code
== requests
.codes
.conflict
:
732 result
['data'] = "Invalid ID."
736 def nst_content_update(self
, token
, id, template
):
737 result
= {'error': True, 'data': ''}
738 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
739 'Authorization': 'Bearer {}'.format(token
['id'])}
740 _url
= "{0}/nst/v1/netslice_templates/{1}/nst_content".format(self
._base
_path
,id)
742 r
= requests
.put(_url
, data
=template
, verify
=False, headers
=headers
)
743 except Exception as e
:
745 result
['data'] = str(e
)
747 if r
.status_code
in (200, 201, 202, 204):
748 result
['error'] = False
751 def nsd_update(self
, token
, id, data
):
752 result
= {'error': True, 'data': ''}
753 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
754 'Authorization': 'Bearer {}'.format(token
['id'])}
756 # get the package onboarded
757 tar_pkg
= self
.get_nsd_pkg(token
, id)
758 tarf
= tarfile
.open(fileobj
=tar_pkg
)
760 tarf
= self
._descriptor
_update
(tarf
, data
)
761 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
763 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self
._base
_path
, id)
766 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
768 except Exception as e
:
770 result
['data'] = str(e
)
772 if r
.status_code
in (200, 201, 202, 204):
773 result
['error'] = False
776 result
['data'] = r
.json()
777 except Exception as e
:
782 def vnfd_update(self
, token
, id, data
):
783 result
= {'error': True, 'data': ''}
784 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
785 'Authorization': 'Bearer {}'.format(token
['id'])}
787 # get the package onboarded
788 tar_pkg
= self
.get_vnfd_pkg(token
, id)
789 tarf
= tarfile
.open(fileobj
=tar_pkg
)
791 tarf
= self
._descriptor
_update
(tarf
, data
)
792 headers
['Content-File-MD5'] = self
.md5(open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
794 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self
._base
_path
, id)
797 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
799 except Exception as e
:
801 result
['data'] = str(e
)
803 if r
.status_code
in (200, 201, 202, 204):
804 result
['error'] = False
807 result
['data'] = r
.json()
808 except Exception as e
:
813 def get_nsd_pkg(self
, token
, id):
814 result
= {'error': True, 'data': ''}
815 headers
= {"accept": "application/zip",
816 'Authorization': 'Bearer {}'.format(token
['id'])}
818 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(self
._base
_path
, id)
820 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
821 except Exception as e
:
823 result
['data'] = str(e
)
825 if r
.status_code
in (200, 201, 202, 204):
826 result
['error'] = False
827 tarf
= StringIO
.StringIO(r
.content
)
831 def get_vnfd_pkg(self
, token
, id):
832 result
= {'error': True, 'data': ''}
833 headers
= {"accept": "application/zip",
834 'Authorization': 'Bearer {}'.format(token
['id'])}
835 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(self
._base
_path
, id)
837 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
838 except Exception as e
:
840 result
['data'] = str(e
)
842 if r
.status_code
in (200, 201, 202, 204):
843 result
['error'] = False
844 tarf
= StringIO
.StringIO(r
.content
)
848 def _descriptor_update(self
, tarf
, data
):
849 # extract the package on a tmp directory
850 tarf
.extractall('/tmp')
851 regex
= re
.compile(r
"^[^/]+(/[^/]+\.(yaml|yml))$", re
.U
)
852 for name
in tarf
.getnames():
853 if regex
.match(name
):
854 with
open('/tmp/' + name
, 'w') as outfile
:
855 yaml
.safe_dump(data
, outfile
, default_flow_style
=False)
858 tarf_temp
= tarfile
.open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", "w:gz")
861 tarf_temp
.add('/tmp/' + tarinfo
.name
, tarinfo
.name
, recursive
=False)
865 def _create_base_pkg(self
, descriptor_type
, pkg_name
):
866 filename
= '/tmp/'+pkg_name
+'/' + pkg_name
+ '.yaml'
867 if descriptor_type
== 'nsd':
872 "short-name": str(pkg_name
),
873 "vendor": "OSM Composer",
874 "description": str(pkg_name
) + " descriptor",
876 "constituent-vnfd": [],
879 "name": str(pkg_name
)
885 elif descriptor_type
== 'vnfd':
887 "vnfd:vnfd-catalog": {
890 "short-name": str(pkg_name
),
899 "connection-point": [],
900 "name": str(pkg_name
)
906 if not os
.path
.exists(os
.path
.dirname(filename
)):
908 os
.makedirs(os
.path
.dirname(filename
))
909 except OSError as exc
: # Guard against race condition
910 if exc
.errno
!= errno
.EEXIST
:
913 with
open('/tmp/' + pkg_name
+ '/' + pkg_name
+ '.yaml', 'w') as yaml_file
:
914 yaml_file
.write(yaml
.dump(descriptor
, default_flow_style
=False))
916 tarf_temp
= tarfile
.open('/tmp/' + pkg_name
+ '.tar.gz', "w:gz")
917 tarf_temp
.add('/tmp/'+pkg_name
+'/' + pkg_name
+ '.yaml', pkg_name
+ '/' + pkg_name
+ '.yaml', recursive
=False)
920 def _descriptor_clone(self
, tarf
, descriptor_type
):
921 # extract the package on a tmp directory
922 tarf
.extractall('/tmp')
924 for name
in tarf
.getnames():
925 if name
.endswith(".yaml") or name
.endswith(".yml"):
926 with
open('/tmp/' + name
, 'r') as outfile
:
927 yaml_object
= yaml
.load(outfile
)
929 if descriptor_type
== 'nsd':
930 nsd_list
= yaml_object
['nsd:nsd-catalog']['nsd']
932 nsd
['id'] = 'clone_' + nsd
['id']
933 nsd
['name'] = 'clone_' + nsd
['name']
934 nsd
['short-name'] = 'clone_' + nsd
['short-name']
935 elif descriptor_type
== 'vnfd':
936 vnfd_list
= yaml_object
['vnfd:vnfd-catalog']['vnfd']
937 for vnfd
in vnfd_list
:
938 vnfd
['id'] = 'clone_' + vnfd
['id']
939 vnfd
['name'] = 'clone_' + vnfd
['name']
940 vnfd
['short-name'] = 'clone_' + vnfd
['short-name']
942 with
open('/tmp/' + name
, 'w') as yaml_file
:
943 yaml_file
.write(yaml
.dump(yaml_object
, default_flow_style
=False))
946 tarf_temp
= tarfile
.open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", "w:gz")
949 tarf_temp
.add('/tmp/' + tarinfo
.name
, tarinfo
.name
, recursive
=False)
953 def nsd_get(self
, token
, id):
954 result
= {'error': True, 'data': ''}
955 headers
= {'Content-Type': 'application/yaml',
956 'Authorization': 'Bearer {}'.format(token
['id'])}
957 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd".format(self
._base
_path
, id)
959 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
960 except Exception as e
:
962 result
['data'] = str(e
)
964 if r
.status_code
in (200, 201, 202, 204):
965 result
['error'] = False
966 return yaml
.load(r
.text
)
969 result
['data'] = r
.json()
970 except Exception as e
:
974 def vnfd_get(self
, token
, id):
975 result
= {'error': True, 'data': ''}
976 headers
= {'Content-Type': 'application/yaml',
977 'Authorization': 'Bearer {}'.format(token
['id'])}
978 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/vnfd".format(self
._base
_path
, id)
980 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
981 except Exception as e
:
983 result
['data'] = str(e
)
985 if r
.status_code
in (200, 201, 202, 204):
986 result
['error'] = False
987 return yaml
.load(r
.text
)
990 result
['data'] = r
.json()
991 except Exception as e
:
995 def nsd_artifacts(self
, token
, id):
996 result
= {'error': True, 'data': ''}
997 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
998 'Authorization': 'Bearer {}'.format(token
['id'])}
999 _url
= "{0}/nsd/v1/ns_descriptors/{1}/artifacts".format(self
._base
_path
, id)
1001 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1002 except Exception as e
:
1004 result
['data'] = str(e
)
1006 if r
.status_code
in (200, 201, 202, 204):
1007 result
['error'] = False
1008 result
['data'] = r
.text
1011 result
['data'] = r
.json()
1012 except Exception as e
:
1017 def vnf_packages_artifacts(self
, token
, id):
1018 result
= {'error': True, 'data': ''}
1019 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
1020 'Authorization': 'Bearer {}'.format(token
['id'])}
1021 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/artifacts".format(self
._base
_path
, id)
1023 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1024 except Exception as e
:
1026 result
['data'] = str(e
)
1028 if r
.status_code
in (200, 201, 202, 204):
1029 result
['error'] = False
1030 result
['data'] = r
.text
1033 result
['data'] = r
.json()
1034 except Exception as e
:
1039 def nsi_create(self
, token
, nsi_data
):
1040 result
= {'error': True, 'data': ''}
1041 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1042 'Authorization': 'Bearer {}'.format(token
['id'])}
1044 _url
= "{0}/nsilcm/v1/netslice_instances_content".format(self
._base
_path
)
1047 r
= requests
.post(_url
, json
=nsi_data
, verify
=False, headers
=headers
)
1048 except Exception as e
:
1050 result
['data'] = str(e
)
1052 if r
.status_code
in (200, 201, 202, 204):
1053 result
['error'] = False
1054 result
['data'] = Util
.json_loads_byteified(r
.text
)
1057 def ns_create(self
, token
, ns_data
):
1058 result
= {'error': True, 'data': ''}
1059 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1060 'Authorization': 'Bearer {}'.format(token
['id'])}
1062 _url
= "{0}/nslcm/v1/ns_instances_content".format(self
._base
_path
)
1065 r
= requests
.post(_url
, json
=ns_data
, verify
=False, headers
=headers
)
1066 except Exception as e
:
1068 result
['data'] = str(e
)
1070 if r
.status_code
in (200, 201, 202, 204):
1071 result
['error'] = False
1072 result
['data'] = Util
.json_loads_byteified(r
.text
)
1075 def pdu_create(self
, token
, pdu_data
):
1076 result
= {'error': True, 'data': ''}
1077 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1078 'Authorization': 'Bearer {}'.format(token
['id'])}
1080 _url
= "{0}/pdu/v1/pdu_descriptors".format(self
._base
_path
)
1083 r
= requests
.post(_url
, json
=pdu_data
, verify
=False, headers
=headers
)
1084 except Exception as e
:
1086 result
['data'] = str(e
)
1088 if r
.status_code
in (200, 201, 202, 204):
1089 result
['error'] = False
1090 result
['data'] = Util
.json_loads_byteified(r
.text
)
1093 def ns_op_list(self
, token
, id):
1094 result
= {'error': True, 'data': ''}
1095 headers
= {"Content-Type": "application/json", "accept": "application/json",
1096 'Authorization': 'Bearer {}'.format(token
['id'])}
1097 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/?nsInstanceId={1}".format(self
._base
_path
, id)
1100 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1101 except Exception as e
:
1103 result
['data'] = str(e
)
1105 if r
.status_code
in (200, 201, 202, 204):
1106 result
['error'] = False
1107 result
['data'] = Util
.json_loads_byteified(r
.text
)
1111 def nsi_op_list(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/nsi_lcm_op_occs/?netsliceInstanceId={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
in (200, 201, 202, 204):
1124 result
['error'] = False
1125 result
['data'] = Util
.json_loads_byteified(r
.text
)
1129 def ns_op(self
, token
, id):
1130 result
= {'error': True, 'data': ''}
1131 headers
= {"Content-Type": "application/json", "accept": "application/json",
1132 'Authorization': 'Bearer {}'.format(token
['id'])}
1133 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/{1}".format(self
._base
_path
, id)
1136 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1137 except Exception as e
:
1139 result
['data'] = str(e
)
1141 if r
.status_code
in (200, 201, 202, 204):
1142 result
['error'] = False
1143 result
['data'] = Util
.json_loads_byteified(r
.text
)
1147 def ns_action(self
, token
, id, action_payload
):
1148 result
= {'error': True, 'data': ''}
1149 headers
= {"Content-Type": "application/json", "accept": "application/json",
1150 'Authorization': 'Bearer {}'.format(token
['id'])}
1152 _url
= "{0}/nslcm/v1/ns_instances/{1}/action".format(self
._base
_path
, id)
1155 r
= requests
.post(_url
, json
=action_payload
, verify
=False, headers
=headers
)
1156 except Exception as e
:
1158 result
['data'] = str(e
)
1160 if r
.status_code
in (200, 201, 202, 204):
1161 result
['error'] = False
1162 result
['data'] = Util
.json_loads_byteified(r
.text
)
1165 def nsi_delete(self
, token
, id, force
=None):
1166 result
= {'error': True, 'data': ''}
1167 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1168 'Authorization': 'Bearer {}'.format(token
['id'])}
1171 query_path
= '?FORCE=true'
1172 _url
= "{0}/nsilcm/v1/netslice_instances_content/{1}{2}".format(self
._base
_path
, id, query_path
)
1174 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1175 except Exception as e
:
1177 result
['data'] = str(e
)
1180 result
['error'] = False
1181 if r
.status_code
!= requests
.codes
.no_content
:
1182 result
['data'] = Util
.json_loads_byteified(r
.text
)
1185 def ns_delete(self
, token
, id, force
=None):
1186 result
= {'error': True, 'data': ''}
1187 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1188 'Authorization': 'Bearer {}'.format(token
['id'])}
1191 query_path
= '?FORCE=true'
1192 _url
= "{0}/nslcm/v1/ns_instances_content/{1}{2}".format(self
._base
_path
, id, query_path
)
1194 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1195 except Exception as e
:
1197 result
['data'] = str(e
)
1200 result
['error'] = False
1201 if r
.status_code
!= requests
.codes
.no_content
:
1202 result
['data'] = Util
.json_loads_byteified(r
.text
)
1205 def pdu_delete(self
, token
, id):
1206 result
= {'error': True, 'data': ''}
1207 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1208 'Authorization': 'Bearer {}'.format(token
['id'])}
1209 _url
= "{0}/pdu/v1/pdu_descriptors/{1}".format(self
._base
_path
, id)
1211 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1212 except Exception as e
:
1214 result
['data'] = str(e
)
1217 result
['error'] = False
1218 if r
.status_code
!= requests
.codes
.no_content
:
1219 result
['data'] = Util
.json_loads_byteified(r
.text
)
1222 def nsi_get(self
, token
, id):
1223 result
= {'error': True, 'data': ''}
1224 headers
= {"Content-Type": "application/json", "accept": "application/json",
1225 'Authorization': 'Bearer {}'.format(token
['id'])}
1226 _url
= "{0}/nsilcm/v1/netslice_instances/{1}".format(self
._base
_path
, id)
1229 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1230 except Exception as e
:
1232 result
['data'] = str(e
)
1234 if r
.status_code
in (200, 201, 202, 204):
1235 result
['error'] = False
1236 result
['data'] = Util
.json_loads_byteified(r
.text
)
1239 def ns_get(self
, token
, id):
1240 result
= {'error': True, 'data': ''}
1241 headers
= {"Content-Type": "application/json", "accept": "application/json",
1242 'Authorization': 'Bearer {}'.format(token
['id'])}
1243 _url
= "{0}/nslcm/v1/ns_instances_content/{1}".format(self
._base
_path
, id)
1246 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1247 except Exception as e
:
1249 result
['data'] = str(e
)
1251 if r
.status_code
in (200, 201, 202, 204):
1252 result
['error'] = False
1253 result
['data'] = Util
.json_loads_byteified(r
.text
)
1256 def vnf_get(self
, token
, id):
1257 result
= {'error': True, 'data': ''}
1258 headers
= {"Content-Type": "application/json", "accept": "application/json",
1259 'Authorization': 'Bearer {}'.format(token
['id'])}
1260 _url
= "{0}/nslcm/v1/vnfrs/{1}".format(self
._base
_path
, id)
1263 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1264 except Exception as e
:
1266 result
['data'] = str(e
)
1268 if r
.status_code
in (200, 201, 202, 204):
1269 result
['error'] = False
1270 result
['data'] = Util
.json_loads_byteified(r
.text
)
1273 def pdu_get(self
, token
, id):
1274 result
= {'error': True, 'data': ''}
1275 headers
= {"Content-Type": "application/json", "accept": "application/json",
1276 'Authorization': 'Bearer {}'.format(token
['id'])}
1277 _url
= "{0}/pdu/v1/pdu_descriptors/{1}".format(self
._base
_path
, id)
1280 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1281 except Exception as e
:
1283 result
['data'] = str(e
)
1285 if r
.status_code
in (200, 201, 202, 204):
1286 result
['error'] = False
1287 result
['data'] = Util
.json_loads_byteified(r
.text
)
1290 def ns_alarm_create(self
, token
, id, alarm_payload
):
1291 result
= {'error': True, 'data': ''}
1292 headers
= {"Content-Type": "application/json",
1293 'Authorization': 'Bearer {}'.format(token
['id'])}
1294 _url
= "{0}/test/message/alarm_request".format(self
._base
_path
)
1296 r
= requests
.post(_url
, json
=alarm_payload
, verify
=False, headers
=headers
)
1297 except Exception as e
:
1299 result
['data'] = str(e
)
1301 if r
.status_code
in (200, 201, 202, 204):
1302 result
['error'] = False
1303 # result['data'] = Util.json_loads_byteified(r.text)
1304 result
['data'] = r
.text
1307 def ns_metric_export(self
, token
, id, metric_payload
):
1308 result
= {'error': True, 'data': ''}
1309 headers
= {"Content-Type": "application/json",
1310 'Authorization': 'Bearer {}'.format(token
['id'])}
1311 _url
= "{0}/test/message/metric_request".format(self
._base
_path
)
1313 r
= requests
.post(_url
, json
=metric_payload
, verify
=False, headers
=headers
)
1314 except Exception as e
:
1316 result
['data'] = str(e
)
1318 if r
.status_code
in (200, 201, 202, 204):
1319 result
['error'] = False
1320 # result['data'] = Util.json_loads_byteified(r.text)
1321 result
['data'] = r
.text
1324 def wim_list(self
, token
):
1325 result
= {'error': True, 'data': ''}
1326 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1327 'Authorization': 'Bearer {}'.format(token
['id'])}
1328 _url
= "{0}/admin/v1/wim_accounts".format(self
._base
_path
)
1330 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1331 except Exception as e
:
1333 result
['data'] = str(e
)
1335 if r
.status_code
in (200, 201, 202, 204):
1336 result
['error'] = False
1337 result
['data'] = Util
.json_loads_byteified(r
.text
)
1341 def vim_list(self
, token
):
1342 result
= {'error': True, 'data': ''}
1343 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1344 'Authorization': 'Bearer {}'.format(token
['id'])}
1345 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
1347 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1348 except Exception as e
:
1350 result
['data'] = str(e
)
1352 if r
.status_code
in (200, 201, 202, 204):
1353 result
['error'] = False
1354 result
['data'] = Util
.json_loads_byteified(r
.text
)
1358 def wim_delete(self
, token
, id):
1359 result
= {'error': True, 'data': ''}
1360 headers
= {"accept": "application/json",
1361 'Authorization': 'Bearer {}'.format(token
['id'])}
1362 _url
= "{0}/admin/v1/wim_accounts/{1}".format(self
._base
_path
, id)
1364 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1365 except Exception as e
:
1367 result
['data'] = str(e
)
1369 if r
.status_code
in (200, 201, 202, 204):
1370 result
['error'] = False
1372 result
['data'] = r
.text
1375 def vim_delete(self
, token
, id):
1376 result
= {'error': True, 'data': ''}
1377 headers
= {"accept": "application/json",
1378 'Authorization': 'Bearer {}'.format(token
['id'])}
1379 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
1381 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1382 except Exception as e
:
1384 result
['data'] = str(e
)
1386 if r
.status_code
in (200, 201, 202, 204):
1387 result
['error'] = False
1389 result
['data'] = r
.text
1392 def wim_get(self
, token
, id):
1394 result
= {'error': True, 'data': ''}
1395 headers
= {"Content-Type": "application/json", "accept": "application/json",
1396 'Authorization': 'Bearer {}'.format(token
['id'])}
1397 _url
= "{0}/admin/v1/wim_accounts/{1}".format(self
._base
_path
, id)
1400 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1401 except Exception as e
:
1403 result
['data'] = str(e
)
1405 if r
.status_code
in (200, 201, 202, 204):
1406 result
['error'] = False
1407 result
['data'] = Util
.json_loads_byteified(r
.text
)
1410 def vim_get(self
, token
, id):
1412 result
= {'error': True, 'data': ''}
1413 headers
= {"Content-Type": "application/json", "accept": "application/json",
1414 'Authorization': 'Bearer {}'.format(token
['id'])}
1415 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
1418 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1419 except Exception as e
:
1421 result
['data'] = str(e
)
1423 if r
.status_code
in (200, 201, 202, 204):
1424 result
['error'] = False
1425 result
['data'] = Util
.json_loads_byteified(r
.text
)
1428 def wim_create(self
, token
, wim_data
):
1429 result
= {'error': True, 'data': ''}
1430 headers
= {"Content-Type": "application/json", "accept": "application/json",
1431 'Authorization': 'Bearer {}'.format(token
['id'])}
1433 _url
= "{0}/admin/v1/wim_accounts".format(self
._base
_path
)
1436 r
= requests
.post(_url
, json
=wim_data
, verify
=False, headers
=headers
)
1437 except Exception as e
:
1439 result
['data'] = str(e
)
1441 if r
.status_code
in (200, 201, 202, 204):
1442 result
['error'] = False
1443 result
['data'] = Util
.json_loads_byteified(r
.text
)
1446 def vim_create(self
, token
, vim_data
):
1448 result
= {'error': True, 'data': ''}
1449 headers
= {"Content-Type": "application/json", "accept": "application/json",
1450 'Authorization': 'Bearer {}'.format(token
['id'])}
1452 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
1455 r
= requests
.post(_url
, json
=vim_data
, verify
=False, headers
=headers
)
1456 except Exception as e
:
1458 result
['data'] = str(e
)
1460 if r
.status_code
in (200, 201, 202, 204):
1461 result
['error'] = False
1462 result
['data'] = Util
.json_loads_byteified(r
.text
)
1465 def sdn_list(self
, token
):
1466 result
= {'error': True, 'data': ''}
1467 headers
= {"accept": "application/json",
1468 'Authorization': 'Bearer {}'.format(token
['id'])}
1469 _url
= "{0}/admin/v1/sdns".format(self
._base
_path
)
1471 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1472 except Exception as e
:
1474 result
['data'] = str(e
)
1476 if r
.status_code
in (200, 201, 202, 204):
1477 result
['error'] = False
1478 result
['data'] = Util
.json_loads_byteified(r
.text
)
1481 def sdn_delete(self
, token
, id):
1482 result
= {'error': True, 'data': ''}
1483 headers
= {"accept": "application/json",
1484 'Authorization': 'Bearer {}'.format(token
['id'])}
1485 _url
= "{0}/admin/v1/sdns/{1}".format(self
._base
_path
, id)
1487 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1488 except Exception as e
:
1490 result
['data'] = str(e
)
1492 if r
.status_code
in (200, 201, 202, 204):
1493 result
['error'] = False
1495 result
['data'] = r
.text
1498 def sdn_get(self
, token
, id):
1499 result
= {'error': True, 'data': ''}
1500 headers
= {"accept": "application/json",
1501 'Authorization': 'Bearer {}'.format(token
['id'])}
1502 _url
= "{0}/admin/v1/sdns/{1}".format(self
._base
_path
, id)
1505 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1506 except Exception as e
:
1508 result
['data'] = str(e
)
1510 if r
.status_code
in (200, 201, 202, 204):
1511 result
['error'] = False
1512 result
['data'] = Util
.json_loads_byteified(r
.text
)
1515 def sdn_create(self
, token
, sdn_data
):
1516 result
= {'error': True, 'data': ''}
1517 headers
= {"Content-Type": "application/json", "accept": "application/json",
1518 'Authorization': 'Bearer {}'.format(token
['id'])}
1520 _url
= "{0}/admin/v1/sdns".format(self
._base
_path
)
1523 r
= requests
.post(_url
, json
=sdn_data
, verify
=False, headers
=headers
)
1524 except Exception as e
:
1526 result
['data'] = str(e
)
1528 if r
.status_code
in (200, 201, 202, 204):
1529 result
['error'] = False
1530 result
['data'] = Util
.json_loads_byteified(r
.text
)
1533 def k8sc_get(self
, token
, id):
1534 result
= {'error': True, 'data': ''}
1535 headers
= {"accept": "application/json",
1536 'Authorization': 'Bearer {}'.format(token
['id'])}
1537 _url
= "{0}/admin/v1/k8sclusters/{1}".format(self
._base
_path
, id)
1539 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1540 except Exception as e
:
1542 result
['data'] = str(e
)
1544 if r
.status_code
in (200, 201, 202, 204):
1545 result
['error'] = False
1546 result
['data'] = Util
.json_loads_byteified(r
.text
)
1549 def k8sc_list(self
, token
):
1550 result
= {'error': True, 'data': ''}
1551 headers
= {"accept": "application/json",
1552 'Authorization': 'Bearer {}'.format(token
['id'])}
1553 _url
= "{0}/admin/v1/k8sclusters".format(self
._base
_path
)
1555 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1556 except Exception as e
:
1558 result
['data'] = str(e
)
1560 if r
.status_code
in (200, 201, 202, 204):
1561 result
['error'] = False
1562 result
['data'] = Util
.json_loads_byteified(r
.text
)
1565 def k8sc_create(self
, token
, cluster_data
):
1566 result
= {'error': True, 'data': ''}
1567 headers
= {"Content-Type": "application/json", "accept": "application/json",
1568 'Authorization': 'Bearer {}'.format(token
['id'])}
1570 _url
= "{0}/admin/v1/k8sclusters".format(self
._base
_path
)
1573 r
= requests
.post(_url
, json
=cluster_data
, verify
=False, headers
=headers
)
1574 except Exception as e
:
1576 result
['data'] = str(e
)
1578 if r
.status_code
in (200, 201, 202, 204):
1579 result
['error'] = False
1580 result
['data'] = Util
.json_loads_byteified(r
.text
)
1583 def k8sc_update(self
, token
, id, cluster_data
):
1584 result
= {'error': True, 'data': ''}
1585 headers
= {"Content-Type": "application/json", "accept": "application/json",
1586 'Authorization': 'Bearer {}'.format(token
['id'])}
1588 _url
= "{0}/admin/v1/k8sclusters/{1}".format(self
._base
_path
, id)
1590 r
= requests
.patch(_url
, json
=cluster_data
, verify
=False, headers
=headers
)
1591 except Exception as e
:
1593 result
['data'] = str(e
)
1595 if r
.status_code
in (200, 201, 202, 204):
1596 result
['error'] = False
1598 result
['data'] = Util
.json_loads_byteified(r
.text
)
1601 def k8sc_delete(self
, token
, id):
1602 result
= {'error': True, 'data': ''}
1603 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1604 'Authorization': 'Bearer {}'.format(token
['id'])}
1606 _url
= "{0}/admin/v1/k8sclusters/{1}".format(self
._base
_path
, id)
1608 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1609 except Exception as e
:
1611 result
['data'] = str(e
)
1613 if r
.status_code
in (200, 201, 202, 204):
1614 result
['error'] = False
1616 result
['data'] = Util
.json_loads_byteified(r
.text
)
1619 def k8sr_get(self
, token
, id):
1620 result
= {'error': True, 'data': ''}
1621 headers
= {"accept": "application/json",
1622 'Authorization': 'Bearer {}'.format(token
['id'])}
1623 _url
= "{0}/admin/v1/k8srepos/{1}".format(self
._base
_path
, id)
1625 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1626 except Exception as e
:
1628 result
['data'] = str(e
)
1630 if r
.status_code
in (200, 201, 202, 204):
1631 result
['error'] = False
1632 result
['data'] = Util
.json_loads_byteified(r
.text
)
1635 def k8sr_list(self
, token
):
1636 result
= {'error': True, 'data': ''}
1637 headers
= {"accept": "application/json",
1638 'Authorization': 'Bearer {}'.format(token
['id'])}
1639 _url
= "{0}/admin/v1/k8srepos".format(self
._base
_path
)
1641 r
= requests
.get(_url
, params
=None, verify
=False, stream
=True, headers
=headers
)
1642 except Exception as e
:
1644 result
['data'] = str(e
)
1646 if r
.status_code
in (200, 201, 202, 204):
1647 result
['error'] = False
1648 result
['data'] = Util
.json_loads_byteified(r
.text
)
1651 def k8sr_create(self
, token
, cluster_data
):
1652 result
= {'error': True, 'data': ''}
1653 headers
= {"Content-Type": "application/json", "accept": "application/json",
1654 'Authorization': 'Bearer {}'.format(token
['id'])}
1656 _url
= "{0}/admin/v1/k8srepos".format(self
._base
_path
)
1659 r
= requests
.post(_url
, json
=cluster_data
, verify
=False, headers
=headers
)
1660 except Exception as e
:
1662 result
['data'] = str(e
)
1664 if r
.status_code
in (200, 201, 202, 204):
1665 result
['error'] = False
1666 result
['data'] = Util
.json_loads_byteified(r
.text
)
1669 def k8sr_update(self
, token
, id, cluster_data
):
1670 result
= {'error': True, 'data': ''}
1671 headers
= {"Content-Type": "application/json", "accept": "application/json",
1672 'Authorization': 'Bearer {}'.format(token
['id'])}
1674 _url
= "{0}/admin/v1/k8srepos/{1}".format(self
._base
_path
, id)
1676 r
= requests
.patch(_url
, json
=cluster_data
, verify
=False, headers
=headers
)
1677 except Exception as e
:
1679 result
['data'] = str(e
)
1681 if r
.status_code
in (200, 201, 202, 204):
1682 result
['error'] = False
1684 result
['data'] = Util
.json_loads_byteified(r
.text
)
1687 def k8sr_delete(self
, token
, id):
1688 result
= {'error': True, 'data': ''}
1689 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1690 'Authorization': 'Bearer {}'.format(token
['id'])}
1692 _url
= "{0}/admin/v1/k8srepos/{1}".format(self
._base
_path
, id)
1694 r
= requests
.delete(_url
, params
=None, verify
=False, headers
=headers
)
1695 except Exception as e
:
1697 result
['data'] = str(e
)
1699 if r
.status_code
in (200, 201, 202, 204):
1700 result
['error'] = False
1702 result
['data'] = Util
.json_loads_byteified(r
.text
)
1707 hash_md5
= hashlib
.md5()
1708 for chunk
in iter(lambda: f
.read(1024), b
""):
1709 hash_md5
.update(chunk
)
1710 return hash_md5
.hexdigest()