1 # Copyright 2017 ZTE Corporation.
\r
3 # Licensed under the Apache License, Version 2.0 (the "License");
\r
4 # you may not use this file except in compliance with the License.
\r
5 # You may obtain a copy of the License at
\r
7 # http://www.apache.org/licenses/LICENSE-2.0
\r
9 # Unless required by applicable law or agreed to in writing, software
\r
10 # distributed under the License is distributed on an "AS IS" BASIS,
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 # See the License for the specific language governing permissions and
\r
13 # limitations under the License.
\r
17 from lcm.pub.config.config import AAI_BASE_URL, AAI_USER, AAI_PASSWORD
\r
18 from lcm.pub.exceptions import NFLCMException
\r
19 from lcm.pub.utils.restcall import call_req_aai, rest_no_auth
\r
21 logger = logging.getLogger(__name__)
\r
24 def create_ns(global_customer_id, service_type, service_instance_id, data):
\r
25 resource = "/business/customers/customer/%s/service-subscriptions/service-subscription/" \
\r
26 "%s/service-instances/service-instance/%s" % \
\r
27 (global_customer_id, service_type, service_instance_id)
\r
28 ret = call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, "PUT", data)
\r
30 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
\r
31 raise NFLCMException("Ns instance creation exception in AAI")
\r
32 return json.JSONDecoder().decode(ret[1])
\r
34 def delete_ns(global_customer_id, service_type, service_instance_id, data):
\r
35 resource = "/business/customers/customer/%s/service-subscriptions/service-subscription/" \
\r
36 "%s/service-instances/service-instance/%s" % \
\r
37 (global_customer_id, service_type, service_instance_id)
\r
38 ret = call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, "DELETE", data)
\r
40 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
\r
41 raise NFLCMException("Ns instance delete exception in AAI")
\r
42 return json.JSONDecoder().decode(ret[1])
\r
44 def query_ns(global_customer_id, service_type, service_instance_id, data):
\r
45 resource = "/business/customers/customer/%s/service-subscriptions/service-subscription/" \
\r
46 "%s/service-instances/service-instance/%s" % \
\r
47 (global_customer_id, service_type, service_instance_id)
\r
48 ret = call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, "GET", data)
\r
50 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
\r
51 raise NFLCMException("Ns instance query exception in AAI")
\r
52 return json.JSONDecoder().decode(ret[1])
\r
55 def create_vnf(vnf_id, data):
\r
56 resource = "/network/generic-vnfs/generic-vnf/%s" % vnf_id
\r
57 ret = call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, "PUT", data)
\r
59 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
\r
60 raise NFLCMException("Vnf instance creation exception in AAI")
\r
61 return json.JSONDecoder().decode(ret[1])
\r
63 def delete_vnf(vnf_id, data):
\r
64 resource = "/network/generic-vnfs/generic-vnf/%s" % vnf_id
\r
65 ret = call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, "DELETE", data)
\r
67 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
\r
68 raise NFLCMException("Vnf instance delete exception in AAI")
\r
69 return json.JSONDecoder().decode(ret[1])
\r
71 def query_vnf(vnf_id, data):
\r
72 resource = "/network/generic-vnfs/generic-vnf/%s" % vnf_id
\r
73 ret = call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, "GET", data)
\r
75 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
\r
76 raise NFLCMException("Vnf instance query exception in AAI")
\r
77 return json.JSONDecoder().decode(ret[1])
\r
80 def create_vserver(cloud_owner, cloud_region_id, tenant_id, vserver_id, data):
\r
81 resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \
\r
82 "%s/tenants/tenant/%s/vservers/vserver/%s" % \
\r
83 (cloud_owner, cloud_region_id, tenant_id, vserver_id)
\r
84 ret = call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, "PUT", data)
\r
86 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
\r
87 raise NFLCMException("Vserver creation exception in AAI")
\r
88 return json.JSONDecoder().decode(ret[1])
\r
90 def delete_vserver(cloud_owner, cloud_region_id, tenant_id, vserver_id, data):
\r
91 resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \
\r
92 "%s/tenants/tenant/%s/vservers/vserver/%s" % \
\r
93 (cloud_owner, cloud_region_id, tenant_id, vserver_id)
\r
94 ret = call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, "DELETE", data)
\r
96 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
\r
97 raise NFLCMException("Vserver delete exception in AAI")
\r
98 return json.JSONDecoder().decode(ret[1])
\r
100 def query_vserver(cloud_owner, cloud_region_id, tenant_id, vserver_id, data):
\r
101 resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \
\r
102 "%s/tenants/tenant/%s/vservers/vserver/%s" % \
\r
103 (cloud_owner, cloud_region_id, tenant_id, vserver_id)
\r
104 ret = call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, "GET", data)
\r
106 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
\r
107 raise NFLCMException("Vserver query exception in AAI")
\r
108 return json.JSONDecoder().decode(ret[1])
\r