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(
42 self
._host
, self
._so
_port
)
45 result
= {'error': True, 'data': ''}
46 token_url
= "{0}/{1}".format(self
._base
_path
, self
._token
_endpoint
)
47 headers
= {"Content-Type": "application/yaml",
48 "accept": "application/json"}
50 r
= requests
.post(token_url
, json
=args
,
51 verify
=False, headers
=headers
)
52 except Exception as e
:
54 result
['data'] = str(e
)
56 if r
.status_code
in (200, 201, 202, 204):
57 result
['error'] = False
59 result
['data'] = Util
.json_loads_byteified(r
.text
)
63 def switch_project(self
, args
):
64 result
= {'error': True, 'data': ''}
65 token_url
= "{0}/{1}".format(self
._base
_path
, self
._token
_endpoint
)
66 headers
= {"Content-Type": "application/yaml",
67 "accept": "application/json"}
69 r
= requests
.post(token_url
, json
=args
,
70 verify
=False, headers
=headers
)
71 except Exception as e
:
73 result
['data'] = str(e
)
75 if r
.status_code
in (200, 201, 202, 204):
76 result
['error'] = False
78 result
['data'] = Util
.json_loads_byteified(r
.text
)
82 def role_list(self
, token
):
83 result
= {'error': True, 'data': ''}
84 headers
= {"Content-Type": "application/json", "accept": "application/json",
85 'Authorization': 'Bearer {}'.format(token
['id'])}
87 _url
= "{0}/admin/v1/roles".format(self
._base
_path
)
89 r
= requests
.get(_url
, params
=None, verify
=False,
90 stream
=True, headers
=headers
)
91 except Exception as e
:
93 result
['data'] = str(e
)
95 if r
.status_code
in (200, 201, 202, 204):
96 result
['error'] = False
97 result
['data'] = Util
.json_loads_byteified(r
.text
)
101 def role_create(self
, token
, role_data
):
102 result
= {'error': True, 'data': ''}
103 headers
= {"Content-Type": "application/json", "accept": "application/json",
104 'Authorization': 'Bearer {}'.format(token
['id'])}
105 _url
= "{0}/admin/v1/roles".format(self
._base
_path
)
108 r
= requests
.post(_url
, json
=role_data
,
109 verify
=False, headers
=headers
)
110 except Exception as e
:
112 result
['data'] = str(e
)
114 if r
.status_code
in (200, 201, 202, 204):
115 result
['error'] = False
116 result
['data'] = Util
.json_loads_byteified(r
.text
)
119 def role_update(self
, token
, role_id
, role_data
):
120 result
= {'error': True, 'data': ''}
121 headers
= {"Content-Type": "application/json", "accept": "application/json",
122 'Authorization': 'Bearer {}'.format(token
['id'])}
123 _url
= "{0}/admin/v1/roles/{1}".format(self
._base
_path
, role_id
)
125 r
= requests
.patch(_url
, json
=role_data
,
126 verify
=False, headers
=headers
)
127 except Exception as e
:
129 result
['data'] = str(e
)
131 if r
.status_code
in (200, 201, 202, 204):
132 result
['error'] = False
134 result
['data'] = Util
.json_loads_byteified(r
.text
)
137 def role_delete(self
, token
, id, force
=None):
138 result
= {'error': True, 'data': ''}
139 headers
= {"Content-Type": "application/json", "accept": "application/json",
140 'Authorization': 'Bearer {}'.format(token
['id'])}
143 query_path
= '?FORCE=true'
144 _url
= "{0}/admin/v1/roles/{1}{2}".format(
145 self
._base
_path
, id, query_path
)
147 r
= requests
.delete(_url
, params
=None,
148 verify
=False, headers
=headers
)
149 except Exception as e
:
151 result
['data'] = str(e
)
153 if r
.status_code
in (200, 201, 202, 204):
154 result
['error'] = False
156 result
['data'] = Util
.json_loads_byteified(r
.text
)
159 def role_get(self
, token
, id):
160 result
= {'error': True, 'data': ''}
161 headers
= {"Content-Type": "application/json", "accept": "application/json",
162 'Authorization': 'Bearer {}'.format(token
['id'])}
164 _url
= "{0}/admin/v1/roles/{1}".format(self
._base
_path
, id)
166 r
= requests
.get(_url
, params
=None, verify
=False, headers
=headers
)
167 except Exception as e
:
169 result
['data'] = str(e
)
171 if r
.status_code
in (200, 201, 202, 204):
172 result
['error'] = False
173 result
['data'] = Util
.json_loads_byteified(r
.text
)
176 def user_list(self
, token
):
177 result
= {'error': True, 'data': ''}
178 headers
= {"Content-Type": "application/json", "accept": "application/json",
179 'Authorization': 'Bearer {}'.format(token
['id'])}
181 _url
= "{0}/admin/v1/users".format(self
._base
_path
)
183 r
= requests
.get(_url
, params
=None, verify
=False,
184 stream
=True, headers
=headers
)
185 except Exception as e
:
187 result
['data'] = str(e
)
189 if r
.status_code
in (200, 201, 202, 204):
190 result
['error'] = False
191 result
['data'] = Util
.json_loads_byteified(r
.text
)
195 def user_create(self
, token
, user_data
):
196 result
= {'error': True, 'data': ''}
197 headers
= {"Content-Type": "application/json", "accept": "application/json",
198 'Authorization': 'Bearer {}'.format(token
['id'])}
200 _url
= "{0}/admin/v1/users".format(self
._base
_path
)
203 r
= requests
.post(_url
, json
=user_data
,
204 verify
=False, headers
=headers
)
205 except Exception as e
:
207 result
['data'] = str(e
)
209 if r
.status_code
in (200, 201, 202, 204):
210 result
['error'] = False
211 result
['data'] = Util
.json_loads_byteified(r
.text
)
214 def user_update(self
, token
, id, user_data
):
215 result
= {'error': True, 'data': ''}
216 headers
= {"Content-Type": "application/json", "accept": "application/json",
217 'Authorization': 'Bearer {}'.format(token
['id'])}
219 _url
= "{0}/admin/v1/users/{1}".format(self
._base
_path
, id)
221 r
= requests
.patch(_url
, json
=user_data
,
222 verify
=False, headers
=headers
)
223 except Exception as e
:
225 result
['data'] = str(e
)
227 if r
.status_code
in (200, 201, 202, 204):
228 result
['error'] = False
230 result
['data'] = Util
.json_loads_byteified(r
.text
)
233 def user_delete(self
, token
, id):
234 result
= {'error': True, 'data': ''}
235 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
236 'Authorization': 'Bearer {}'.format(token
['id'])}
238 _url
= "{0}/admin/v1/users/{1}".format(self
._base
_path
, id)
240 r
= requests
.delete(_url
, params
=None,
241 verify
=False, headers
=headers
)
242 except Exception as e
:
244 result
['data'] = str(e
)
246 if r
.status_code
in (200, 201, 202, 204):
247 result
['error'] = False
249 result
['data'] = Util
.json_loads_byteified(r
.text
)
252 def get_user_info(self
, token
, id):
253 result
= {'error': True, 'data': ''}
254 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
255 'Authorization': 'Bearer {}'.format(token
['id'])}
256 _url
= "{0}/admin/v1/users/{1}".format(self
._base
_path
, id)
258 r
= requests
.get(_url
, params
=None, verify
=False,
259 stream
=True, headers
=headers
)
260 except Exception as e
:
262 result
['data'] = str(e
)
264 if r
.status_code
in (200, 201, 202, 204):
265 result
['error'] = False
266 result
['data'] = Util
.json_loads_byteified(r
.text
)
269 def get_domains(self
, token
):
270 result
= {'error': False, 'data': ''}
271 headers
= {"accept": "application/json", 'Authorization': 'Bearer {}'.format(token
['id'])}
273 _url
= "{0}/admin/v1/domains".format(self
._base
_path
)
275 r
= requests
.get(_url
, params
=None, verify
=False,
276 stream
=True, headers
=headers
)
277 except Exception as e
:
279 result
['data'] = str(e
)
281 if r
.status_code
in (200, 201, 202, 204):
282 result
['error'] = False
284 result
['data'] = Util
.json_loads_byteified(r
.text
)
287 def get_projects(self
, token
, uuids
):
288 result
= {'error': False, 'data': ''}
289 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
290 'Authorization': 'Bearer {}'.format(token
['id'])}
295 _url
= "{0}/admin/v1/projects/{1}".format(
296 self
._base
_path
, uuid
)
297 r
= requests
.get(_url
, params
=None, verify
=False,
298 stream
=True, headers
=headers
)
299 if r
.status_code
not in (200, 201, 202, 204):
301 projects
.append(Util
.json_loads_byteified(r
.text
))
302 except Exception as e
:
304 result
['error'] = True
305 result
['data'] = str(e
)
307 result
['data'] = projects
310 def project_list(self
, token
):
311 result
= {'error': True, 'data': ''}
312 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
313 'Authorization': 'Bearer {}'.format(token
['id'])}
315 _url
= "{0}/admin/v1/projects".format(self
._base
_path
)
317 r
= requests
.get(_url
, params
=None, verify
=False,
318 stream
=True, 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
)
329 def project_get(self
, token
, id):
330 result
= {'error': True, 'data': ''}
331 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
332 'Authorization': 'Bearer {}'.format(token
['id'])}
333 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
335 r
= requests
.get(_url
, params
=None, verify
=False,
336 stream
=True, headers
=headers
)
337 except Exception as e
:
339 result
['data'] = str(e
)
341 if r
.status_code
in (200, 201, 202, 204):
342 result
['error'] = False
343 result
['data'] = Util
.json_loads_byteified(r
.text
)
346 def project_create(self
, token
, project_data
):
348 result
= {'error': True, 'data': ''}
349 headers
= {"Content-Type": "application/json", "accept": "application/json",
350 'Authorization': 'Bearer {}'.format(token
['id'])}
352 _url
= "{0}/admin/v1/projects".format(self
._base
_path
)
355 r
= requests
.post(_url
, json
=project_data
,
356 verify
=False, headers
=headers
)
357 except Exception as e
:
359 result
['data'] = str(e
)
361 if r
.status_code
in (200, 201, 202, 204):
362 result
['error'] = False
363 result
['data'] = Util
.json_loads_byteified(r
.text
)
366 def project_edit(self
, token
, id, project_data
):
368 result
= {'error': True, 'data': ''}
369 headers
= {"Content-Type": "application/json", "accept": "application/json",
370 'Authorization': 'Bearer {}'.format(token
['id'])}
372 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
375 r
= requests
.patch(_url
, json
=project_data
,
376 verify
=False, headers
=headers
)
377 except Exception as e
:
379 result
['data'] = str(e
)
381 if r
.status_code
in (200, 201, 202, 204):
382 result
['error'] = False
385 def project_delete(self
, token
, id):
386 result
= {'error': True, 'data': ''}
387 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
388 'Authorization': 'Bearer {}'.format(token
['id'])}
390 _url
= "{0}/admin/v1/projects/{1}".format(self
._base
_path
, id)
392 r
= requests
.delete(_url
, params
=None,
393 verify
=False, headers
=headers
)
394 except Exception as e
:
396 result
['data'] = str(e
)
398 if r
.status_code
in (200, 201, 202, 204):
399 result
['error'] = False
401 result
['data'] = Util
.json_loads_byteified(r
.text
)
404 def nst_details(self
, token
, id):
405 result
= {'error': True, 'data': ''}
406 headers
= {"Content-Type": "application/json", "accept": "application/json",
407 'Authorization': 'Bearer {}'.format(token
['id'])}
408 _url
= "{0}/nst/v1/netslice_templates/{1}".format(self
._base
_path
, id)
410 r
= requests
.get(_url
, params
=None, verify
=False,
411 stream
=True, headers
=headers
)
412 except Exception as e
:
414 result
['data'] = str(e
)
416 if r
.status_code
in (200, 201, 202, 204):
417 result
['error'] = False
418 result
['data'] = Util
.json_loads_byteified(r
.text
)
422 def nst_content(self
, token
, id):
423 result
= {'error': True, 'data': ''}
424 headers
= {"Content-Type": "application/json", "accept": "text/plain",
425 'Authorization': 'Bearer {}'.format(token
['id'])}
426 _url
= "{0}/nst/v1/netslice_templates/{1}/nst".format(
429 r
= requests
.get(_url
, params
=None, verify
=False,
430 stream
=True, headers
=headers
)
431 except Exception as e
:
433 result
['data'] = str(e
)
435 if r
.status_code
in (200, 201, 202, 204):
436 result
['error'] = False
437 result
['data'] = Util
.json2yaml(yaml
.load(str(r
.text
)))
441 def nst_list(self
, token
):
442 result
= {'error': True, 'data': ''}
443 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
444 'Authorization': 'Bearer {}'.format(token
['id'])}
446 _url
= "{0}/nst/v1/netslice_templates".format(self
._base
_path
)
448 r
= requests
.get(_url
, params
=None, verify
=False,
449 stream
=True, headers
=headers
)
450 except Exception as e
:
452 result
['data'] = str(e
)
454 if r
.status_code
in (200, 201, 202, 204):
455 result
['error'] = False
456 result
['data'] = Util
.json_loads_byteified(r
.text
)
460 def nsd_list(self
, token
, filter=None):
461 result
= {'error': True, 'data': ''}
462 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
463 'Authorization': 'Bearer {}'.format(token
['id'])}
466 query_path
= '?_admin.type='+filter
467 _url
= "{0}/nsd/v1/ns_descriptors_content{1}".format(
468 self
._base
_path
, query_path
)
470 r
= requests
.get(_url
, params
=None, verify
=False,
471 stream
=True, headers
=headers
)
472 except Exception as e
:
474 result
['data'] = str(e
)
476 if r
.status_code
in (200, 201, 202, 204):
477 result
['error'] = False
478 result
['data'] = Util
.json_loads_byteified(r
.text
)
482 def vnfd_list(self
, token
, filter=None):
483 result
= {'error': True, 'data': ''}
484 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
485 'Authorization': 'Bearer {}'.format(token
['id'])}
488 query_path
= '?_admin.type='+filter
489 _url
= "{0}/vnfpkgm/v1/vnf_packages_content{1}".format(
490 self
._base
_path
, query_path
)
492 r
= requests
.get(_url
, params
=None, verify
=False,
493 stream
=True, headers
=headers
)
494 except Exception as e
:
496 result
['data'] = str(e
)
498 if r
.status_code
in (200, 201, 202, 204):
499 result
['error'] = False
500 result
['data'] = Util
.json_loads_byteified(r
.text
)
504 def nsi_list(self
, token
):
505 result
= {'error': True, 'data': ''}
506 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
507 'Authorization': 'Bearer {}'.format(token
['id'])}
508 _url
= "{0}/nsilcm/v1/netslice_instances".format(self
._base
_path
)
510 r
= requests
.get(_url
, params
=None, verify
=False,
511 stream
=True, headers
=headers
)
512 except Exception as e
:
514 result
['data'] = str(e
)
516 if r
.status_code
in (200, 201, 202, 204):
517 result
['error'] = False
518 result
['data'] = Util
.json_loads_byteified(r
.text
)
522 def ns_list(self
, token
):
523 result
= {'error': True, 'data': ''}
524 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
525 'Authorization': 'Bearer {}'.format(token
['id'])}
526 _url
= "{0}/nslcm/v1/ns_instances_content".format(self
._base
_path
)
528 r
= requests
.get(_url
, params
=None, verify
=False,
529 stream
=True, headers
=headers
)
530 except Exception as e
:
532 result
['data'] = str(e
)
534 if r
.status_code
in (200, 201, 202, 204):
535 result
['error'] = False
536 result
['data'] = Util
.json_loads_byteified(r
.text
)
540 def vnf_list(self
, token
):
541 result
= {'error': True, 'data': ''}
542 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
543 'Authorization': 'Bearer {}'.format(token
['id'])}
544 _url
= "{0}/nslcm/v1/vnfrs".format(self
._base
_path
)
546 r
= requests
.get(_url
, params
=None, verify
=False,
547 stream
=True, headers
=headers
)
548 except Exception as e
:
550 result
['data'] = str(e
)
552 if r
.status_code
in (200, 201, 202, 204):
553 result
['error'] = False
554 result
['data'] = Util
.json_loads_byteified(r
.text
)
558 def pdu_list(self
, token
):
559 result
= {'error': True, 'data': ''}
560 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
561 'Authorization': 'Bearer {}'.format(token
['id'])}
562 _url
= "{0}/pdu/v1/pdu_descriptors".format(self
._base
_path
)
564 r
= requests
.get(_url
, params
=None, verify
=False,
565 stream
=True, headers
=headers
)
566 except Exception as e
:
568 result
['data'] = str(e
)
570 if r
.status_code
in (200, 201, 202, 204):
571 result
['error'] = False
572 result
['data'] = Util
.json_loads_byteified(r
.text
)
576 def nst_delete(self
, token
, id):
577 result
= {'error': True, 'data': ''}
578 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
579 'Authorization': 'Bearer {}'.format(token
['id'])}
581 _url
= "{0}/nst/v1/netslice_templates/{1}?FORCE=True".format(
584 r
= requests
.delete(_url
, params
=None,
585 verify
=False, headers
=headers
)
586 except Exception as e
:
588 result
['data'] = str(e
)
590 if r
.status_code
in (200, 201, 202, 204):
591 result
['error'] = False
595 def nsd_delete(self
, token
, id):
596 result
= {'error': True, 'data': ''}
597 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
598 'Authorization': 'Bearer {}'.format(token
['id'])}
600 _url
= "{0}/nsd/v1/ns_descriptors_content/{1}".format(
603 r
= requests
.delete(_url
, params
=None,
604 verify
=False, headers
=headers
)
605 except Exception as e
:
607 result
['data'] = str(e
)
610 result
['error'] = False
611 if r
.status_code
!= requests
.codes
.no_content
:
612 result
['data'] = Util
.json_loads_byteified(r
.text
)
615 def vnfd_delete(self
, token
, id):
616 result
= {'error': True, 'data': ''}
617 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
618 'Authorization': 'Bearer {}'.format(token
['id'])}
620 _url
= "{0}/vnfpkgm/v1/vnf_packages_content/{1}".format(
623 r
= requests
.delete(_url
, params
=None,
624 verify
=False, headers
=headers
)
625 except Exception as e
:
627 result
['data'] = str(e
)
630 result
['error'] = False
631 if r
.status_code
!= requests
.codes
.no_content
:
632 result
['data'] = Util
.json_loads_byteified(r
.text
)
635 def nst_onboard(self
, token
, template
):
636 result
= {'error': True, 'data': ''}
637 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
638 'Authorization': 'Bearer {}'.format(token
['id'])}
639 _url
= "{0}/nst/v1/netslice_templates_content".format(self
._base
_path
)
641 fileName
, fileExtension
= os
.path
.splitext(template
.name
)
642 if fileExtension
== '.gz':
643 headers
["Content-Type"] = "application/gzip"
645 headers
["Content-Type"] = "application/yaml"
646 r
= requests
.post(_url
, data
=template
,
647 verify
=False, headers
=headers
)
648 except Exception as e
:
650 result
['data'] = str(e
)
652 if r
.status_code
in (200, 201, 202, 204):
653 result
['error'] = False
654 result
['data'] = Util
.json_loads_byteified(r
.text
)
657 def nsd_onboard(self
, token
, package
):
658 result
= {'error': True, 'data': ''}
659 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
660 'Authorization': 'Bearer {}'.format(token
['id'])}
661 with
open('/tmp/' + package
.name
, 'wb+') as destination
:
662 for chunk
in package
.chunks():
663 destination
.write(chunk
)
664 headers
['Content-File-MD5'] = self
.md5(
665 open('/tmp/' + package
.name
, 'rb'))
666 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
668 r
= requests
.post(_url
, data
=open(
669 '/tmp/' + package
.name
, '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
['error'] = False
676 result
['data'] = Util
.json_loads_byteified(r
.text
)
679 def vnfd_onboard(self
, token
, package
):
680 result
= {'error': True, 'data': ''}
681 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
682 'Authorization': 'Bearer {}'.format(token
['id'])}
683 with
open('/tmp/' + package
.name
, 'wb+') as destination
:
684 for chunk
in package
.chunks():
685 destination
.write(chunk
)
686 headers
['Content-File-MD5'] = self
.md5(
687 open('/tmp/' + package
.name
, 'rb'))
688 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
690 r
= requests
.post(_url
, data
=open(
691 '/tmp/' + package
.name
, 'rb'), verify
=False, headers
=headers
)
692 except Exception as e
:
694 result
['data'] = str(e
)
696 if r
.status_code
in (200, 201, 202, 204):
697 result
['error'] = False
698 result
['data'] = Util
.json_loads_byteified(r
.text
)
701 def nsd_create_pkg_base(self
, token
, pkg_name
):
702 result
= {'error': True, 'data': ''}
703 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
704 'Authorization': 'Bearer {}'.format(token
['id'])}
706 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
709 self
._create
_base
_pkg
('nsd', pkg_name
)
710 headers
['Content-Filename'] = pkg_name
+ '.tar.gz'
711 r
= requests
.post(_url
, data
=open(
712 '/tmp/' + pkg_name
+ '.tar.gz', 'rb'), verify
=False, headers
=headers
)
713 except Exception as e
:
715 result
['data'] = str(e
)
717 if r
.status_code
in (200, 201, 202, 204):
718 result
['data'] = r
.json()
719 result
['error'] = False
720 if r
.status_code
== requests
.codes
.conflict
:
721 result
['data'] = "Invalid ID."
724 def vnfd_create_pkg_base(self
, token
, pkg_name
):
725 result
= {'error': True, 'data': ''}
726 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
727 'Authorization': 'Bearer {}'.format(token
['id'])}
729 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
732 self
._create
_base
_pkg
('vnfd', pkg_name
)
733 r
= requests
.post(_url
, data
=open(
734 '/tmp/' + pkg_name
+ '.tar.gz', 'rb'), verify
=False, headers
=headers
)
735 except Exception as e
:
737 result
['data'] = str(e
)
739 if r
.status_code
in (200, 201, 202, 204):
740 result
['data'] = r
.json()
741 result
['error'] = False
742 if r
.status_code
== requests
.codes
.conflict
:
743 result
['data'] = "Invalid ID."
746 def nsd_clone(self
, token
, id):
747 result
= {'error': True, 'data': ''}
748 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
749 'Authorization': 'Bearer {}'.format(token
['id'])}
751 # get the package onboarded
752 tar_pkg
= self
.get_nsd_pkg(token
, id)
753 tarf
= tarfile
.open(fileobj
=tar_pkg
)
754 tarf
= self
._descriptor
_clone
(tarf
, 'nsd')
755 headers
['Content-File-MD5'] = self
.md5(
756 open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'))
758 _url
= "{0}/nsd/v1/ns_descriptors_content/".format(self
._base
_path
)
761 r
= requests
.post(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'), verify
=False,
763 except Exception as e
:
765 result
['data'] = str(e
)
767 if r
.status_code
in (200, 201, 202, 204):
768 result
['error'] = False
769 if r
.status_code
== requests
.codes
.conflict
:
770 result
['data'] = "Invalid ID."
774 def vnfd_clone(self
, token
, id):
775 result
= {'error': True, 'data': ''}
776 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
777 'Authorization': 'Bearer {}'.format(token
['id'])}
779 # get the package onboarded
780 tar_pkg
= self
.get_vnfd_pkg(token
, id)
781 tarf
= tarfile
.open(fileobj
=tar_pkg
)
783 tarf
= self
._descriptor
_clone
(tarf
, 'vnfd')
784 headers
['Content-File-MD5'] = self
.md5(
785 open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'))
787 _url
= "{0}/vnfpkgm/v1/vnf_packages_content".format(self
._base
_path
)
790 r
= requests
.post(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", 'rb'), verify
=False,
792 except Exception as e
:
794 result
['data'] = str(e
)
796 if r
.status_code
in (200, 201, 202, 204):
797 result
['error'] = False
798 if r
.status_code
== requests
.codes
.conflict
:
799 result
['data'] = "Invalid ID."
803 def nst_content_update(self
, token
, id, template
):
804 result
= {'error': True, 'data': ''}
805 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
806 'Authorization': 'Bearer {}'.format(token
['id'])}
807 _url
= "{0}/nst/v1/netslice_templates/{1}/nst_content".format(
810 r
= requests
.put(_url
, data
=template
,
811 verify
=False, headers
=headers
)
812 except Exception as e
:
814 result
['data'] = str(e
)
816 if r
.status_code
in (200, 201, 202, 204):
817 result
['error'] = False
820 def nsd_update(self
, token
, id, data
):
821 result
= {'error': True, 'data': ''}
822 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
823 'Authorization': 'Bearer {}'.format(token
['id'])}
825 # get the package onboarded
826 tar_pkg
= self
.get_nsd_pkg(token
, id)
827 tarf
= tarfile
.open(fileobj
=tar_pkg
)
829 tarf
= self
._descriptor
_update
(tarf
, data
)
830 headers
['Content-File-MD5'] = self
.md5(
831 open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
833 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(
837 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
839 except Exception as e
:
841 result
['data'] = str(e
)
843 if r
.status_code
in (200, 201, 202, 204):
844 result
['error'] = False
847 result
['data'] = r
.json()
848 except Exception as e
:
853 def vnfd_update(self
, token
, id, data
):
854 result
= {'error': True, 'data': ''}
855 headers
= {"Content-Type": "application/gzip", "accept": "application/json",
856 'Authorization': 'Bearer {}'.format(token
['id'])}
858 # get the package onboarded
859 tar_pkg
= self
.get_vnfd_pkg(token
, id)
860 tarf
= tarfile
.open(fileobj
=tar_pkg
)
862 tarf
= self
._descriptor
_update
(tarf
, data
)
863 headers
['Content-File-MD5'] = self
.md5(
864 open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'))
866 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(
870 r
= requests
.put(_url
, data
=open('/tmp/' + tarf
.getnames()[0] + ".tar.gz", 'rb'), verify
=False,
872 except Exception as e
:
874 result
['data'] = str(e
)
876 if r
.status_code
in (200, 201, 202, 204):
877 result
['error'] = False
880 result
['data'] = r
.json()
881 except Exception as e
:
886 def get_nsd_pkg(self
, token
, id):
887 result
= {'error': True, 'data': ''}
888 headers
= {"accept": "application/zip",
889 'Authorization': 'Bearer {}'.format(token
['id'])}
891 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd_content".format(
894 r
= requests
.get(_url
, params
=None, verify
=False,
895 stream
=True, headers
=headers
)
896 except Exception as e
:
898 result
['data'] = str(e
)
900 if r
.status_code
in (200, 201, 202, 204):
901 result
['error'] = False
902 tarf
= StringIO
.StringIO(r
.content
)
906 def get_vnfd_pkg(self
, token
, id):
907 result
= {'error': True, 'data': ''}
908 headers
= {"accept": "application/zip",
909 'Authorization': 'Bearer {}'.format(token
['id'])}
910 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/package_content".format(
913 r
= requests
.get(_url
, params
=None, verify
=False,
914 stream
=True, headers
=headers
)
915 except Exception as e
:
917 result
['data'] = str(e
)
919 if r
.status_code
in (200, 201, 202, 204):
920 result
['error'] = False
921 tarf
= StringIO
.StringIO(r
.content
)
925 def _descriptor_update(self
, tarf
, data
):
926 # extract the package on a tmp directory
927 tarf
.extractall('/tmp')
928 regex
= re
.compile(r
"^[^/]+(/[^/]+\.(yaml|yml))$", re
.U
)
929 for name
in tarf
.getnames():
930 if regex
.match(name
):
931 with
open('/tmp/' + name
, 'w') as outfile
:
932 yaml
.safe_dump(data
, outfile
, default_flow_style
=False)
935 tarf_temp
= tarfile
.open(
936 '/tmp/' + tarf
.getnames()[0] + ".tar.gz", "w:gz")
939 tarf_temp
.add('/tmp/' + tarinfo
.name
,
940 tarinfo
.name
, recursive
=False)
944 def _create_base_pkg(self
, descriptor_type
, pkg_name
):
945 filename
= '/tmp/'+pkg_name
+'/' + pkg_name
+ '.yaml'
946 if descriptor_type
== 'nsd':
951 "short-name": str(pkg_name
),
952 "vendor": "OSM Composer",
953 "description": str(pkg_name
) + " descriptor",
955 "constituent-vnfd": [],
958 "name": str(pkg_name
)
964 elif descriptor_type
== 'vnfd':
966 "vnfd:vnfd-catalog": {
969 "short-name": str(pkg_name
),
978 "connection-point": [],
979 "name": str(pkg_name
)
985 if not os
.path
.exists(os
.path
.dirname(filename
)):
987 os
.makedirs(os
.path
.dirname(filename
))
988 except OSError as exc
: # Guard against race condition
989 if exc
.errno
!= errno
.EEXIST
:
992 with
open('/tmp/' + pkg_name
+ '/' + pkg_name
+ '.yaml', 'w') as yaml_file
:
993 yaml_file
.write(yaml
.dump(descriptor
, default_flow_style
=False))
995 tarf_temp
= tarfile
.open('/tmp/' + pkg_name
+ '.tar.gz', "w:gz")
996 tarf_temp
.add('/tmp/'+pkg_name
+'/' + pkg_name
+ '.yaml',
997 pkg_name
+ '/' + pkg_name
+ '.yaml', recursive
=False)
1000 def _descriptor_clone(self
, tarf
, descriptor_type
):
1001 # extract the package on a tmp directory
1002 tarf
.extractall('/tmp')
1004 for name
in tarf
.getnames():
1005 if name
.endswith(".yaml") or name
.endswith(".yml"):
1006 with
open('/tmp/' + name
, 'r') as outfile
:
1007 yaml_object
= yaml
.load(outfile
)
1009 if descriptor_type
== 'nsd':
1010 nsd_list
= yaml_object
['nsd:nsd-catalog']['nsd']
1011 for nsd
in nsd_list
:
1012 nsd
['id'] = 'clone_' + nsd
['id']
1013 nsd
['name'] = 'clone_' + nsd
['name']
1014 nsd
['short-name'] = 'clone_' + nsd
['short-name']
1015 elif descriptor_type
== 'vnfd':
1016 vnfd_list
= yaml_object
['vnfd:vnfd-catalog']['vnfd']
1017 for vnfd
in vnfd_list
:
1018 vnfd
['id'] = 'clone_' + vnfd
['id']
1019 vnfd
['name'] = 'clone_' + vnfd
['name']
1020 vnfd
['short-name'] = 'clone_' + vnfd
['short-name']
1022 with
open('/tmp/' + name
, 'w') as yaml_file
:
1024 yaml
.dump(yaml_object
, default_flow_style
=False))
1027 tarf_temp
= tarfile
.open(
1028 '/tmp/' + tarf
.getnames()[0] + "_clone.tar.gz", "w:gz")
1030 for tarinfo
in tarf
:
1031 tarf_temp
.add('/tmp/' + tarinfo
.name
,
1032 tarinfo
.name
, recursive
=False)
1036 def nsd_get(self
, token
, id):
1037 result
= {'error': True, 'data': ''}
1038 headers
= {'Content-Type': 'application/yaml',
1039 'Authorization': 'Bearer {}'.format(token
['id'])}
1040 _url
= "{0}/nsd/v1/ns_descriptors/{1}/nsd".format(self
._base
_path
, id)
1042 r
= requests
.get(_url
, params
=None, verify
=False,
1043 stream
=True, headers
=headers
)
1044 except Exception as e
:
1046 result
['data'] = str(e
)
1048 if r
.status_code
in (200, 201, 202, 204):
1049 result
['error'] = False
1050 return yaml
.load(r
.text
)
1053 result
['data'] = r
.json()
1054 except Exception as e
:
1058 def vnfd_get(self
, token
, id):
1059 result
= {'error': True, 'data': ''}
1060 headers
= {'Content-Type': 'application/yaml',
1061 'Authorization': 'Bearer {}'.format(token
['id'])}
1062 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/vnfd".format(
1063 self
._base
_path
, id)
1065 r
= requests
.get(_url
, params
=None, verify
=False,
1066 stream
=True, headers
=headers
)
1067 except Exception as e
:
1069 result
['data'] = str(e
)
1071 if r
.status_code
in (200, 201, 202, 204):
1072 result
['error'] = False
1073 return yaml
.load(r
.text
)
1076 result
['data'] = r
.json()
1077 except Exception as e
:
1081 def nsd_artifacts(self
, token
, id):
1082 result
= {'error': True, 'data': ''}
1083 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
1084 'Authorization': 'Bearer {}'.format(token
['id'])}
1085 _url
= "{0}/nsd/v1/ns_descriptors/{1}/artifacts".format(
1086 self
._base
_path
, id)
1088 r
= requests
.get(_url
, params
=None, verify
=False,
1089 stream
=True, headers
=headers
)
1090 except Exception as e
:
1092 result
['data'] = str(e
)
1094 if r
.status_code
in (200, 201, 202, 204):
1095 result
['error'] = False
1096 result
['data'] = r
.text
1099 result
['data'] = r
.json()
1100 except Exception as e
:
1105 def vnf_packages_artifacts(self
, token
, id):
1106 result
= {'error': True, 'data': ''}
1107 headers
= {'Content-Type': 'application/yaml', 'accept': 'text/plain',
1108 'Authorization': 'Bearer {}'.format(token
['id'])}
1109 _url
= "{0}/vnfpkgm/v1/vnf_packages/{1}/artifacts".format(
1110 self
._base
_path
, id)
1112 r
= requests
.get(_url
, params
=None, verify
=False,
1113 stream
=True, headers
=headers
)
1114 except Exception as e
:
1116 result
['data'] = str(e
)
1118 if r
.status_code
in (200, 201, 202, 204):
1119 result
['error'] = False
1120 result
['data'] = r
.text
1123 result
['data'] = r
.json()
1124 except Exception as e
:
1129 def nsi_create(self
, token
, nsi_data
):
1130 result
= {'error': True, 'data': ''}
1131 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1132 'Authorization': 'Bearer {}'.format(token
['id'])}
1134 _url
= "{0}/nsilcm/v1/netslice_instances_content".format(
1138 r
= requests
.post(_url
, json
=nsi_data
,
1139 verify
=False, headers
=headers
)
1140 except Exception as e
:
1142 result
['data'] = str(e
)
1144 if r
.status_code
in (200, 201, 202, 204):
1145 result
['error'] = False
1146 result
['data'] = Util
.json_loads_byteified(r
.text
)
1149 def ns_create(self
, token
, ns_data
):
1150 result
= {'error': True, 'data': ''}
1151 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1152 'Authorization': 'Bearer {}'.format(token
['id'])}
1154 _url
= "{0}/nslcm/v1/ns_instances_content".format(self
._base
_path
)
1157 r
= requests
.post(_url
, json
=ns_data
,
1158 verify
=False, headers
=headers
)
1159 except Exception as e
:
1161 result
['data'] = str(e
)
1163 if r
.status_code
in (200, 201, 202, 204):
1164 result
['error'] = False
1165 result
['data'] = Util
.json_loads_byteified(r
.text
)
1168 def pdu_create(self
, token
, pdu_data
):
1169 result
= {'error': True, 'data': ''}
1170 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1171 'Authorization': 'Bearer {}'.format(token
['id'])}
1173 _url
= "{0}/pdu/v1/pdu_descriptors".format(self
._base
_path
)
1176 r
= requests
.post(_url
, json
=pdu_data
,
1177 verify
=False, headers
=headers
)
1178 except Exception as e
:
1180 result
['data'] = str(e
)
1182 if r
.status_code
in (200, 201, 202, 204):
1183 result
['error'] = False
1184 result
['data'] = Util
.json_loads_byteified(r
.text
)
1187 def ns_op_list(self
, token
, id):
1188 result
= {'error': True, 'data': ''}
1189 headers
= {"Content-Type": "application/json", "accept": "application/json",
1190 'Authorization': 'Bearer {}'.format(token
['id'])}
1191 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/?nsInstanceId={1}".format(
1192 self
._base
_path
, id)
1195 r
= requests
.get(_url
, params
=None, verify
=False,
1196 stream
=True, headers
=headers
)
1197 except Exception as e
:
1199 result
['data'] = str(e
)
1201 if r
.status_code
in (200, 201, 202, 204):
1202 result
['error'] = False
1203 result
['data'] = Util
.json_loads_byteified(r
.text
)
1207 def nsi_op_list(self
, token
, id):
1208 result
= {'error': True, 'data': ''}
1209 headers
= {"Content-Type": "application/json", "accept": "application/json",
1210 'Authorization': 'Bearer {}'.format(token
['id'])}
1211 _url
= "{0}/nsilcm/v1/nsi_lcm_op_occs/?netsliceInstanceId={1}".format(
1212 self
._base
_path
, id)
1215 r
= requests
.get(_url
, params
=None, verify
=False,
1216 stream
=True, headers
=headers
)
1217 except Exception as e
:
1219 result
['data'] = str(e
)
1221 if r
.status_code
in (200, 201, 202, 204):
1222 result
['error'] = False
1223 result
['data'] = Util
.json_loads_byteified(r
.text
)
1227 def ns_op(self
, token
, id):
1228 result
= {'error': True, 'data': ''}
1229 headers
= {"Content-Type": "application/json", "accept": "application/json",
1230 'Authorization': 'Bearer {}'.format(token
['id'])}
1231 _url
= "{0}/nslcm/v1/ns_lcm_op_occs/{1}".format(self
._base
_path
, id)
1234 r
= requests
.get(_url
, params
=None, verify
=False,
1235 stream
=True, headers
=headers
)
1236 except Exception as e
:
1238 result
['data'] = str(e
)
1240 if r
.status_code
in (200, 201, 202, 204):
1241 result
['error'] = False
1242 result
['data'] = Util
.json_loads_byteified(r
.text
)
1246 def ns_action(self
, token
, id, action_payload
):
1247 result
= {'error': True, 'data': ''}
1248 headers
= {"Content-Type": "application/json", "accept": "application/json",
1249 'Authorization': 'Bearer {}'.format(token
['id'])}
1251 _url
= "{0}/nslcm/v1/ns_instances/{1}/action".format(
1252 self
._base
_path
, id)
1255 r
= requests
.post(_url
, json
=action_payload
,
1256 verify
=False, headers
=headers
)
1257 except Exception as e
:
1259 result
['data'] = str(e
)
1261 if r
.status_code
in (200, 201, 202, 204):
1262 result
['error'] = False
1263 result
['data'] = Util
.json_loads_byteified(r
.text
)
1266 def nsi_delete(self
, token
, id, force
=None):
1267 result
= {'error': True, 'data': ''}
1268 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1269 'Authorization': 'Bearer {}'.format(token
['id'])}
1272 query_path
= '?FORCE=true'
1273 _url
= "{0}/nsilcm/v1/netslice_instances_content/{1}{2}".format(
1274 self
._base
_path
, id, query_path
)
1276 r
= requests
.delete(_url
, params
=None,
1277 verify
=False, headers
=headers
)
1278 except Exception as e
:
1280 result
['data'] = str(e
)
1283 result
['error'] = False
1284 if r
.status_code
!= requests
.codes
.no_content
:
1285 result
['data'] = Util
.json_loads_byteified(r
.text
)
1288 def ns_delete(self
, token
, id, force
=None):
1289 result
= {'error': True, 'data': ''}
1290 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1291 'Authorization': 'Bearer {}'.format(token
['id'])}
1294 query_path
= '?FORCE=true'
1295 _url
= "{0}/nslcm/v1/ns_instances_content/{1}{2}".format(
1296 self
._base
_path
, id, query_path
)
1298 r
= requests
.delete(_url
, params
=None,
1299 verify
=False, headers
=headers
)
1300 except Exception as e
:
1302 result
['data'] = str(e
)
1305 result
['error'] = False
1306 if r
.status_code
!= requests
.codes
.no_content
:
1307 result
['data'] = Util
.json_loads_byteified(r
.text
)
1310 def pdu_delete(self
, token
, id):
1311 result
= {'error': True, 'data': ''}
1312 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1313 'Authorization': 'Bearer {}'.format(token
['id'])}
1314 _url
= "{0}/pdu/v1/pdu_descriptors/{1}".format(self
._base
_path
, id)
1316 r
= requests
.delete(_url
, params
=None,
1317 verify
=False, headers
=headers
)
1318 except Exception as e
:
1320 result
['data'] = str(e
)
1323 result
['error'] = False
1324 if r
.status_code
!= requests
.codes
.no_content
:
1325 result
['data'] = Util
.json_loads_byteified(r
.text
)
1328 def nsi_get(self
, token
, id):
1329 result
= {'error': True, 'data': ''}
1330 headers
= {"Content-Type": "application/json", "accept": "application/json",
1331 'Authorization': 'Bearer {}'.format(token
['id'])}
1332 _url
= "{0}/nsilcm/v1/netslice_instances/{1}".format(
1333 self
._base
_path
, id)
1336 r
= requests
.get(_url
, params
=None, verify
=False,
1337 stream
=True, headers
=headers
)
1338 except Exception as e
:
1340 result
['data'] = str(e
)
1342 if r
.status_code
in (200, 201, 202, 204):
1343 result
['error'] = False
1344 result
['data'] = Util
.json_loads_byteified(r
.text
)
1347 def ns_get(self
, token
, id):
1348 result
= {'error': True, 'data': ''}
1349 headers
= {"Content-Type": "application/json", "accept": "application/json",
1350 'Authorization': 'Bearer {}'.format(token
['id'])}
1351 _url
= "{0}/nslcm/v1/ns_instances_content/{1}".format(
1352 self
._base
_path
, id)
1355 r
= requests
.get(_url
, params
=None, verify
=False,
1356 stream
=True, headers
=headers
)
1357 except Exception as e
:
1359 result
['data'] = str(e
)
1361 if r
.status_code
in (200, 201, 202, 204):
1362 result
['error'] = False
1363 result
['data'] = Util
.json_loads_byteified(r
.text
)
1366 def vnf_get(self
, token
, id):
1367 result
= {'error': True, 'data': ''}
1368 headers
= {"Content-Type": "application/json", "accept": "application/json",
1369 'Authorization': 'Bearer {}'.format(token
['id'])}
1370 _url
= "{0}/nslcm/v1/vnfrs/{1}".format(self
._base
_path
, id)
1373 r
= requests
.get(_url
, params
=None, verify
=False,
1374 stream
=True, headers
=headers
)
1375 except Exception as e
:
1377 result
['data'] = str(e
)
1379 if r
.status_code
in (200, 201, 202, 204):
1380 result
['error'] = False
1381 result
['data'] = Util
.json_loads_byteified(r
.text
)
1384 def pdu_get(self
, token
, id):
1385 result
= {'error': True, 'data': ''}
1386 headers
= {"Content-Type": "application/json", "accept": "application/json",
1387 'Authorization': 'Bearer {}'.format(token
['id'])}
1388 _url
= "{0}/pdu/v1/pdu_descriptors/{1}".format(self
._base
_path
, id)
1391 r
= requests
.get(_url
, params
=None, verify
=False,
1392 stream
=True, headers
=headers
)
1393 except Exception as e
:
1395 result
['data'] = str(e
)
1397 if r
.status_code
in (200, 201, 202, 204):
1398 result
['error'] = False
1399 result
['data'] = Util
.json_loads_byteified(r
.text
)
1402 def ns_alarm_create(self
, token
, id, alarm_payload
):
1403 result
= {'error': True, 'data': ''}
1404 headers
= {"Content-Type": "application/json",
1405 'Authorization': 'Bearer {}'.format(token
['id'])}
1406 _url
= "{0}/test/message/alarm_request".format(self
._base
_path
)
1408 r
= requests
.post(_url
, json
=alarm_payload
,
1409 verify
=False, headers
=headers
)
1410 except Exception as e
:
1412 result
['data'] = str(e
)
1414 if r
.status_code
in (200, 201, 202, 204):
1415 result
['error'] = False
1416 # result['data'] = Util.json_loads_byteified(r.text)
1417 result
['data'] = r
.text
1420 def ns_metric_export(self
, token
, id, metric_payload
):
1421 result
= {'error': True, 'data': ''}
1422 headers
= {"Content-Type": "application/json",
1423 'Authorization': 'Bearer {}'.format(token
['id'])}
1424 _url
= "{0}/test/message/metric_request".format(self
._base
_path
)
1426 r
= requests
.post(_url
, json
=metric_payload
,
1427 verify
=False, headers
=headers
)
1428 except Exception as e
:
1430 result
['data'] = str(e
)
1432 if r
.status_code
in (200, 201, 202, 204):
1433 result
['error'] = False
1434 # result['data'] = Util.json_loads_byteified(r.text)
1435 result
['data'] = r
.text
1438 def wim_list(self
, token
):
1439 result
= {'error': True, 'data': ''}
1440 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1441 'Authorization': 'Bearer {}'.format(token
['id'])}
1442 _url
= "{0}/admin/v1/wim_accounts".format(self
._base
_path
)
1444 r
= requests
.get(_url
, params
=None, verify
=False,
1445 stream
=True, headers
=headers
)
1446 except Exception as e
:
1448 result
['data'] = str(e
)
1450 if r
.status_code
in (200, 201, 202, 204):
1451 result
['error'] = False
1452 result
['data'] = Util
.json_loads_byteified(r
.text
)
1456 def vim_list(self
, token
):
1457 result
= {'error': True, 'data': ''}
1458 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1459 'Authorization': 'Bearer {}'.format(token
['id'])}
1460 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
1462 r
= requests
.get(_url
, params
=None, verify
=False,
1463 stream
=True, headers
=headers
)
1464 except Exception as e
:
1466 result
['data'] = str(e
)
1468 if r
.status_code
in (200, 201, 202, 204):
1469 result
['error'] = False
1470 result
['data'] = Util
.json_loads_byteified(r
.text
)
1474 def wim_delete(self
, token
, id):
1475 result
= {'error': True, 'data': ''}
1476 headers
= {"accept": "application/json",
1477 'Authorization': 'Bearer {}'.format(token
['id'])}
1478 _url
= "{0}/admin/v1/wim_accounts/{1}".format(self
._base
_path
, id)
1480 r
= requests
.delete(_url
, params
=None,
1481 verify
=False, headers
=headers
)
1482 except Exception as e
:
1484 result
['data'] = str(e
)
1486 if r
.status_code
in (200, 201, 202, 204):
1487 result
['error'] = False
1489 result
['data'] = r
.text
1492 def vim_delete(self
, token
, id):
1493 result
= {'error': True, 'data': ''}
1494 headers
= {"accept": "application/json",
1495 'Authorization': 'Bearer {}'.format(token
['id'])}
1496 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
1498 r
= requests
.delete(_url
, params
=None,
1499 verify
=False, headers
=headers
)
1500 except Exception as e
:
1502 result
['data'] = str(e
)
1504 if r
.status_code
in (200, 201, 202, 204):
1505 result
['error'] = False
1507 result
['data'] = r
.text
1510 def wim_get(self
, token
, id):
1512 result
= {'error': True, 'data': ''}
1513 headers
= {"Content-Type": "application/json", "accept": "application/json",
1514 'Authorization': 'Bearer {}'.format(token
['id'])}
1515 _url
= "{0}/admin/v1/wim_accounts/{1}".format(self
._base
_path
, id)
1518 r
= requests
.get(_url
, params
=None, verify
=False,
1519 stream
=True, headers
=headers
)
1520 except Exception as e
:
1522 result
['data'] = str(e
)
1524 if r
.status_code
in (200, 201, 202, 204):
1525 result
['error'] = False
1526 result
['data'] = Util
.json_loads_byteified(r
.text
)
1529 def vim_get(self
, token
, id):
1531 result
= {'error': True, 'data': ''}
1532 headers
= {"Content-Type": "application/json", "accept": "application/json",
1533 'Authorization': 'Bearer {}'.format(token
['id'])}
1534 _url
= "{0}/admin/v1/vims/{1}".format(self
._base
_path
, id)
1537 r
= requests
.get(_url
, params
=None, verify
=False,
1538 stream
=True, headers
=headers
)
1539 except Exception as e
:
1541 result
['data'] = str(e
)
1543 if r
.status_code
in (200, 201, 202, 204):
1544 result
['error'] = False
1545 result
['data'] = Util
.json_loads_byteified(r
.text
)
1548 def wim_create(self
, token
, wim_data
):
1549 result
= {'error': True, 'data': ''}
1550 headers
= {"Content-Type": "application/json", "accept": "application/json",
1551 'Authorization': 'Bearer {}'.format(token
['id'])}
1553 _url
= "{0}/admin/v1/wim_accounts".format(self
._base
_path
)
1556 r
= requests
.post(_url
, json
=wim_data
,
1557 verify
=False, headers
=headers
)
1558 except Exception as e
:
1560 result
['data'] = str(e
)
1562 if r
.status_code
in (200, 201, 202, 204):
1563 result
['error'] = False
1564 result
['data'] = Util
.json_loads_byteified(r
.text
)
1567 def vim_create(self
, token
, vim_data
):
1569 result
= {'error': True, 'data': ''}
1570 headers
= {"Content-Type": "application/json", "accept": "application/json",
1571 'Authorization': 'Bearer {}'.format(token
['id'])}
1573 _url
= "{0}/admin/v1/vims".format(self
._base
_path
)
1576 r
= requests
.post(_url
, json
=vim_data
,
1577 verify
=False, headers
=headers
)
1578 except Exception as e
:
1580 result
['data'] = str(e
)
1582 if r
.status_code
in (200, 201, 202, 204):
1583 result
['error'] = False
1584 result
['data'] = Util
.json_loads_byteified(r
.text
)
1587 def sdn_list(self
, token
):
1588 result
= {'error': True, 'data': ''}
1589 headers
= {"accept": "application/json",
1590 'Authorization': 'Bearer {}'.format(token
['id'])}
1591 _url
= "{0}/admin/v1/sdns".format(self
._base
_path
)
1593 r
= requests
.get(_url
, params
=None, verify
=False,
1594 stream
=True, headers
=headers
)
1595 except Exception as e
:
1597 result
['data'] = str(e
)
1599 if r
.status_code
in (200, 201, 202, 204):
1600 result
['error'] = False
1601 result
['data'] = Util
.json_loads_byteified(r
.text
)
1604 def sdn_delete(self
, token
, id):
1605 result
= {'error': True, 'data': ''}
1606 headers
= {"accept": "application/json",
1607 'Authorization': 'Bearer {}'.format(token
['id'])}
1608 _url
= "{0}/admin/v1/sdns/{1}".format(self
._base
_path
, id)
1610 r
= requests
.delete(_url
, params
=None,
1611 verify
=False, headers
=headers
)
1612 except Exception as e
:
1614 result
['data'] = str(e
)
1616 if r
.status_code
in (200, 201, 202, 204):
1617 result
['error'] = False
1619 result
['data'] = r
.text
1622 def sdn_get(self
, token
, id):
1623 result
= {'error': True, 'data': ''}
1624 headers
= {"accept": "application/json",
1625 'Authorization': 'Bearer {}'.format(token
['id'])}
1626 _url
= "{0}/admin/v1/sdns/{1}".format(self
._base
_path
, id)
1629 r
= requests
.get(_url
, params
=None, verify
=False,
1630 stream
=True, headers
=headers
)
1631 except Exception as e
:
1633 result
['data'] = str(e
)
1635 if r
.status_code
in (200, 201, 202, 204):
1636 result
['error'] = False
1637 result
['data'] = Util
.json_loads_byteified(r
.text
)
1640 def sdn_create(self
, token
, sdn_data
):
1641 result
= {'error': True, 'data': ''}
1642 headers
= {"Content-Type": "application/json", "accept": "application/json",
1643 'Authorization': 'Bearer {}'.format(token
['id'])}
1645 _url
= "{0}/admin/v1/sdns".format(self
._base
_path
)
1648 r
= requests
.post(_url
, json
=sdn_data
,
1649 verify
=False, headers
=headers
)
1650 except Exception as e
:
1652 result
['data'] = str(e
)
1654 if r
.status_code
in (200, 201, 202, 204):
1655 result
['error'] = False
1656 result
['data'] = Util
.json_loads_byteified(r
.text
)
1659 def k8sc_get(self
, token
, id):
1660 result
= {'error': True, 'data': ''}
1661 headers
= {"accept": "application/json",
1662 'Authorization': 'Bearer {}'.format(token
['id'])}
1663 _url
= "{0}/admin/v1/k8sclusters/{1}".format(self
._base
_path
, id)
1665 r
= requests
.get(_url
, params
=None, verify
=False,
1666 stream
=True, headers
=headers
)
1667 except Exception as e
:
1669 result
['data'] = str(e
)
1671 if r
.status_code
in (200, 201, 202, 204):
1672 result
['error'] = False
1673 result
['data'] = Util
.json_loads_byteified(r
.text
)
1676 def k8sc_list(self
, token
):
1677 result
= {'error': True, 'data': ''}
1678 headers
= {"accept": "application/json",
1679 'Authorization': 'Bearer {}'.format(token
['id'])}
1680 _url
= "{0}/admin/v1/k8sclusters".format(self
._base
_path
)
1682 r
= requests
.get(_url
, params
=None, verify
=False,
1683 stream
=True, headers
=headers
)
1684 except Exception as e
:
1686 result
['data'] = str(e
)
1688 if r
.status_code
in (200, 201, 202, 204):
1689 result
['error'] = False
1690 result
['data'] = Util
.json_loads_byteified(r
.text
)
1693 def k8sc_create(self
, token
, cluster_data
):
1694 result
= {'error': True, 'data': ''}
1695 headers
= {"Content-Type": "application/json", "accept": "application/json",
1696 'Authorization': 'Bearer {}'.format(token
['id'])}
1698 _url
= "{0}/admin/v1/k8sclusters".format(self
._base
_path
)
1701 r
= requests
.post(_url
, json
=cluster_data
,
1702 verify
=False, headers
=headers
)
1703 except Exception as e
:
1705 result
['data'] = str(e
)
1707 if r
.status_code
in (200, 201, 202, 204):
1708 result
['error'] = False
1709 result
['data'] = Util
.json_loads_byteified(r
.text
)
1712 def k8sc_update(self
, token
, id, cluster_data
):
1713 result
= {'error': True, 'data': ''}
1714 headers
= {"Content-Type": "application/json", "accept": "application/json",
1715 'Authorization': 'Bearer {}'.format(token
['id'])}
1717 _url
= "{0}/admin/v1/k8sclusters/{1}".format(self
._base
_path
, id)
1719 r
= requests
.patch(_url
, json
=cluster_data
,
1720 verify
=False, headers
=headers
)
1721 except Exception as e
:
1723 result
['data'] = str(e
)
1725 if r
.status_code
in (200, 201, 202, 204):
1726 result
['error'] = False
1728 result
['data'] = Util
.json_loads_byteified(r
.text
)
1731 def k8sc_delete(self
, token
, id):
1732 result
= {'error': True, 'data': ''}
1733 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1734 'Authorization': 'Bearer {}'.format(token
['id'])}
1736 _url
= "{0}/admin/v1/k8sclusters/{1}".format(self
._base
_path
, id)
1738 r
= requests
.delete(_url
, params
=None,
1739 verify
=False, headers
=headers
)
1740 except Exception as e
:
1742 result
['data'] = str(e
)
1744 if r
.status_code
in (200, 201, 202, 204):
1745 result
['error'] = False
1747 result
['data'] = Util
.json_loads_byteified(r
.text
)
1750 def k8sr_get(self
, token
, id):
1751 result
= {'error': True, 'data': ''}
1752 headers
= {"accept": "application/json",
1753 'Authorization': 'Bearer {}'.format(token
['id'])}
1754 _url
= "{0}/admin/v1/k8srepos/{1}".format(self
._base
_path
, id)
1756 r
= requests
.get(_url
, params
=None, verify
=False,
1757 stream
=True, headers
=headers
)
1758 except Exception as e
:
1760 result
['data'] = str(e
)
1762 if r
.status_code
in (200, 201, 202, 204):
1763 result
['error'] = False
1764 result
['data'] = Util
.json_loads_byteified(r
.text
)
1767 def k8sr_list(self
, token
):
1768 result
= {'error': True, 'data': ''}
1769 headers
= {"accept": "application/json",
1770 'Authorization': 'Bearer {}'.format(token
['id'])}
1771 _url
= "{0}/admin/v1/k8srepos".format(self
._base
_path
)
1773 r
= requests
.get(_url
, params
=None, verify
=False,
1774 stream
=True, headers
=headers
)
1775 except Exception as e
:
1777 result
['data'] = str(e
)
1779 if r
.status_code
in (200, 201, 202, 204):
1780 result
['error'] = False
1781 result
['data'] = Util
.json_loads_byteified(r
.text
)
1784 def k8sr_create(self
, token
, cluster_data
):
1785 result
= {'error': True, 'data': ''}
1786 headers
= {"Content-Type": "application/json", "accept": "application/json",
1787 'Authorization': 'Bearer {}'.format(token
['id'])}
1789 _url
= "{0}/admin/v1/k8srepos".format(self
._base
_path
)
1792 r
= requests
.post(_url
, json
=cluster_data
,
1793 verify
=False, headers
=headers
)
1794 except Exception as e
:
1796 result
['data'] = str(e
)
1798 if r
.status_code
in (200, 201, 202, 204):
1799 result
['error'] = False
1800 result
['data'] = Util
.json_loads_byteified(r
.text
)
1803 def k8sr_update(self
, token
, id, cluster_data
):
1804 result
= {'error': True, 'data': ''}
1805 headers
= {"Content-Type": "application/json", "accept": "application/json",
1806 'Authorization': 'Bearer {}'.format(token
['id'])}
1808 _url
= "{0}/admin/v1/k8srepos/{1}".format(self
._base
_path
, id)
1810 r
= requests
.patch(_url
, json
=cluster_data
,
1811 verify
=False, headers
=headers
)
1812 except Exception as e
:
1814 result
['data'] = str(e
)
1816 if r
.status_code
in (200, 201, 202, 204):
1817 result
['error'] = False
1819 result
['data'] = Util
.json_loads_byteified(r
.text
)
1822 def k8sr_delete(self
, token
, id):
1823 result
= {'error': True, 'data': ''}
1824 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1825 'Authorization': 'Bearer {}'.format(token
['id'])}
1827 _url
= "{0}/admin/v1/k8srepos/{1}".format(self
._base
_path
, id)
1829 r
= requests
.delete(_url
, params
=None,
1830 verify
=False, headers
=headers
)
1831 except Exception as e
:
1833 result
['data'] = str(e
)
1835 if r
.status_code
in (200, 201, 202, 204):
1836 result
['error'] = False
1838 result
['data'] = Util
.json_loads_byteified(r
.text
)
1841 def osmr_get(self
, token
, id):
1842 result
= {'error': True, 'data': ''}
1843 headers
= {"accept": "application/json",
1844 'Authorization': 'Bearer {}'.format(token
['id'])}
1845 _url
= "{0}/admin/v1/osmrepos/{1}".format(self
._base
_path
, id)
1847 r
= requests
.get(_url
, params
=None, verify
=False,
1848 stream
=True, headers
=headers
)
1849 except Exception as e
:
1851 result
['data'] = str(e
)
1853 if r
.status_code
in (200, 201, 202, 204):
1854 result
['error'] = False
1855 result
['data'] = Util
.json_loads_byteified(r
.text
)
1858 def osmr_list(self
, token
):
1859 result
= {'error': True, 'data': ''}
1860 headers
= {"accept": "application/json",
1861 'Authorization': 'Bearer {}'.format(token
['id'])}
1862 _url
= "{0}/admin/v1/osmrepos".format(self
._base
_path
)
1864 r
= requests
.get(_url
, params
=None, verify
=False,
1865 stream
=True, headers
=headers
)
1866 except Exception as e
:
1868 result
['data'] = str(e
)
1870 if r
.status_code
in (200, 201, 202, 204):
1871 result
['error'] = False
1872 result
['data'] = Util
.json_loads_byteified(r
.text
)
1875 def osmr_create(self
, token
, cluster_data
):
1876 result
= {'error': True, 'data': ''}
1877 headers
= {"Content-Type": "application/json", "accept": "application/json",
1878 'Authorization': 'Bearer {}'.format(token
['id'])}
1880 _url
= "{0}/admin/v1/osmrepos".format(self
._base
_path
)
1883 r
= requests
.post(_url
, json
=cluster_data
,
1884 verify
=False, headers
=headers
)
1885 except Exception as e
:
1887 result
['data'] = str(e
)
1889 if r
.status_code
in (200, 201, 202, 204):
1890 result
['error'] = False
1891 result
['data'] = Util
.json_loads_byteified(r
.text
)
1894 def osmr_update(self
, token
, id, cluster_data
):
1895 result
= {'error': True, 'data': ''}
1896 headers
= {"Content-Type": "application/json", "accept": "application/json",
1897 'Authorization': 'Bearer {}'.format(token
['id'])}
1899 _url
= "{0}/admin/v1/osmrepos/{1}".format(self
._base
_path
, id)
1901 r
= requests
.patch(_url
, json
=cluster_data
,
1902 verify
=False, headers
=headers
)
1903 except Exception as e
:
1905 result
['data'] = str(e
)
1907 if r
.status_code
in (200, 201, 202, 204):
1908 result
['error'] = False
1910 result
['data'] = Util
.json_loads_byteified(r
.text
)
1913 def osmr_delete(self
, token
, id):
1914 result
= {'error': True, 'data': ''}
1915 headers
= {"Content-Type": "application/yaml", "accept": "application/json",
1916 'Authorization': 'Bearer {}'.format(token
['id'])}
1918 _url
= "{0}/admin/v1/osmrepos/{1}".format(self
._base
_path
, id)
1920 r
= requests
.delete(_url
, params
=None,
1921 verify
=False, headers
=headers
)
1922 except Exception as e
:
1924 result
['data'] = str(e
)
1926 if r
.status_code
in (200, 201, 202, 204):
1927 result
['error'] = False
1929 result
['data'] = Util
.json_loads_byteified(r
.text
)
1934 hash_md5
= hashlib
.md5()
1935 for chunk
in iter(lambda: f
.read(1024), b
""):
1936 hash_md5
.update(chunk
)
1937 return hash_md5
.hexdigest()