Modify api file of gvnfm vnflcm
[vfc/gvnfm/vnflcm.git] / lcm / lcm / pub / msapi / gvnfmdriver.py
1 # Copyright 2017 ZTE Corporation.
2 #
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
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14 import json
15 import logging
16
17 from lcm.pub.exceptions import NFLCMException
18 from lcm.pub.utils.restcall import req_by_msb
19
20 logger = logging.getLogger(__name__)
21
22
23 def get_packageinfo_by_vnfdid(vnfdid):
24     ret = req_by_msb("openoapi/gvnfmdriver/v1/vnfpackages", "GET")  # TODO
25     if ret[0] != 0:
26         logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
27         raise NFLCMException("Failed to query package_info of vnfdid(%s) from nslcm." % vnfdid)
28     return json.JSONDecoder().decode(ret[1])
29
30
31 def apply_grant_to_nfvo(data):
32     ret = req_by_msb("openoapi/gvnfmdriver/v1/resource/grant", "PUT", data)
33     if ret[0] != 0:
34         logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
35         raise NFLCMException("Nf instancing apply grant exception")
36     return json.JSONDecoder().decode(ret[1])
37
38
39 def notify_lcm_to_nfvo(data):
40     ret = req_by_msb("openoapi/gvnfmdriver/v1/vnfs/lifecyclechangesnotification", "POST", data)
41     if ret[0] != 0:
42         logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
43         raise NFLCMException("Nf lcm notify exception")
44     return json.JSONDecoder().decode(ret[1])