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(ns_id, data):
\r
28 def create_vnf(vnf_id, data):
\r
29 resource = "/network/generic-vnfs/generic-vnf/%s" % vnf_id
\r
30 ret = call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, "PUT", data)
\r
32 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
\r
33 raise NFLCMException("Vnf instance creation exception in AAI")
\r
34 return json.JSONDecoder().decode(ret[1])
\r
36 def delete_vnf(vnf_id, data):
\r
37 resource = "/network/generic-vnfs/generic-vnf/%s" % vnf_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("Vnf instance delete exception in AAI")
\r
42 return json.JSONDecoder().decode(ret[1])
\r
44 def query_vnf(vnf_id, data):
\r
45 resource = "/network/generic-vnfs/generic-vnf/%s" % vnf_id
\r
46 ret = call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, "GET", data)
\r
48 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
\r
49 raise NFLCMException("Vnf instance query exception in AAI")
\r
50 return json.JSONDecoder().decode(ret[1])
\r
53 def create_vserver(cloud_owner, cloud_region_id, tenant_id, vserver_id, data):
\r
54 resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \
\r
55 "%s/tenants/tenant/%s/vservers/vserver/%s" % \
\r
56 (cloud_owner, cloud_region_id, tenant_id, vserver_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("Vserver creation exception in AAI")
\r
61 return json.JSONDecoder().decode(ret[1])
\r
63 def delete_vserver(cloud_owner, cloud_region_id, tenant_id, vserver_id, data):
\r
64 resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \
\r
65 "%s/tenants/tenant/%s/vservers/vserver/%s" % \
\r
66 (cloud_owner, cloud_region_id, tenant_id, vserver_id)
\r
67 ret = call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, "DELETE", data)
\r
69 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
\r
70 raise NFLCMException("Vserver delete exception in AAI")
\r
71 return json.JSONDecoder().decode(ret[1])
\r
73 def query_vserver(cloud_owner, cloud_region_id, tenant_id, vserver_id, data):
\r
74 resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \
\r
75 "%s/tenants/tenant/%s/vservers/vserver/%s" % \
\r
76 (cloud_owner, cloud_region_id, tenant_id, vserver_id)
\r
77 ret = call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, "GET", data)
\r
79 logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
\r
80 raise NFLCMException("Vserver query exception in AAI")
\r
81 return json.JSONDecoder().decode(ret[1])
\r