1 # Copyright 2016 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.config.config import AAI_BASE_URL, AAI_USER, AAI_PASSWD
20 from lcm.pub.utils import restcall
21 logger = logging.getLogger(__name__)
24 def call_aai(resource, method, content=''):
25 additional_headers = {
26 'X-FromAppId': 'VFC-CATALOG',
27 'X-TransactionId': str(uuid.uuid1())
29 return restcall.call_req(AAI_BASE_URL,
32 restcall.rest_no_auth,
39 def split_vim_to_owner_region(vim_id):
40 split_vim = vim_id.split('_')
41 cloud_owner = split_vim[0]
42 cloud_region = "".join(split_vim[1:])
43 return cloud_owner, cloud_region
46 def get_flavor_info(vim_id):
47 cloud_owner, cloud_region = split_vim_to_owner_region(vim_id)
48 resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/%s/flavors?depth=all" % \
49 (cloud_owner, cloud_region)
51 ret = call_aai(resource, "GET")
53 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
56 return json.JSONDecoder().decode(ret[1]) if ret[1] else ret[1]
59 def delete_aai_flavor(vim_id, tenant_id, flavor_id):
60 cloud_owner, cloud_region = split_vim_to_owner_region(vim_id)
61 resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/%s/flavors/flavor/%s" % \
62 (cloud_owner, cloud_region, flavor_id)
64 ret = call_aai(resource, "DELETE")
66 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
69 return json.JSONDecoder().decode(ret[1]) if ret[1] else ret[1]