1 # Copyright 2017 ZTE Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
19 from lcm.pub.exceptions import NSLCMException
20 from lcm.pub.utils import restcall
21 from lcm.pub.config.config import AAI_BASE_URL, AAI_USER, AAI_PASSWD
23 logger = logging.getLogger(__name__)
26 def call_aai(resource, method, content=''):
27 additional_headers = {
28 'X-FromAppId': 'VFC-NFVO-LCM',
29 'X-TransactionId': str(uuid.uuid1())
31 return restcall.call_req(base_url=AAI_BASE_URL,
34 auth_type=restcall.rest_no_auth,
38 additional_headers=additional_headers)
40 def create_ns_aai(global_customer_id, service_type, service_instance_id, data):
41 resource = "/business/customers/customer/%s/service-subscriptions/service-subscription/" \
42 "%s/service-instances/service-instance/%s" % \
43 (global_customer_id, service_type, service_instance_id)
44 ret = call_aai(resource, "PUT", data)
46 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
47 raise NSLCMException("Ns instance creation exception in AAI")
48 return json.JSONDecoder().decode(ret[1])
50 def delete_ns_aai(global_customer_id, service_type, service_instance_id, data):
51 resource = "/business/customers/customer/%s/service-subscriptions/service-subscription/" \
52 "%s/service-instances/service-instance/%s" % \
53 (global_customer_id, service_type, service_instance_id)
54 ret = call_aai(resource, "DELETE", data)
56 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
57 raise NSLCMException("Ns instance delete exception in AAI")
58 return json.JSONDecoder().decode(ret[1])
60 def query_ns_aai(global_customer_id, service_type, service_instance_id, data):
61 resource = "/business/customers/customer/%s/service-subscriptions/service-subscription/" \
62 "%s/service-instances/service-instance/%s" % \
63 (global_customer_id, service_type, service_instance_id)
64 ret = call_aai(resource, "GET", data)
66 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
67 raise NSLCMException("Ns instance query exception in AAI")
68 return json.JSONDecoder().decode(ret[1])