f92ca2d4dcf1f103eddd79bb8f024f3b045e7408
[vfc/gvnfm/vnflcm.git] / lcm / lcm / pub / aaiapi / aai.py
1 # Copyright 2017 ZTE Corporation.\r
2 #\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
6 #\r
7 #         http://www.apache.org/licenses/LICENSE-2.0\r
8 #\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
14 import json\r
15 import logging\r
16 \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
20 \r
21 logger = logging.getLogger(__name__)\r
22 \r
23 \r
24 def create_ns(ns_id, data):\r
25     pass\r
26 \r
27 \r
28 def create_vnf(vnf_id, data):\r
29     pass\r
30 \r
31 \r
32 def create_vserver(cloud_owner, cloud_region_id, tenant_id, vserver_id, data):\r
33     resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \\r
34                "%s/tenants/tenant/%s/vservers/vserver/%s" % \\r
35                (cloud_owner, cloud_region_id, tenant_id, vserver_id)\r
36     ret = call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, "PUT", data)\r
37     if ret[0] != 0:\r
38         logger.error("Status code is %s, detail is %s.", ret[2], ret[1])\r
39         raise NFLCMException("Vserver creation exception in AAI")\r
40     return json.JSONDecoder().decode(ret[1])\r
41 \r
42 def delete_vserver(cloud_owner, cloud_region_id, tenant_id, vserver_id, data):\r
43     resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \\r
44                "%s/tenants/tenant/%s/vservers/vserver/%s" % \\r
45                (cloud_owner, cloud_region_id, tenant_id, vserver_id)\r
46     ret = call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, "DELETE", data)\r
47     if ret[0] != 0:\r
48         logger.error("Status code is %s, detail is %s.", ret[2], ret[1])\r
49         raise NFLCMException("Vserver delete exception in AAI")\r
50     return json.JSONDecoder().decode(ret[1])\r
51 \r
52 def query_vserver(cloud_owner, cloud_region_id, tenant_id, vserver_id, data):\r
53     resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \\r
54                "%s/tenants/tenant/%s/vservers/vserver/%s" % \\r
55                (cloud_owner, cloud_region_id, tenant_id, vserver_id)\r
56     ret = call_req_aai(AAI_BASE_URL, AAI_USER, AAI_PASSWORD, rest_no_auth, resource, "GET", data)\r
57     if ret[0] != 0:\r
58         logger.error("Status code is %s, detail is %s.", ret[2], ret[1])\r
59         raise NFLCMException("Vserver query exception in AAI")\r
60     return json.JSONDecoder().decode(ret[1])\r