Update report resoure code and other files
[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
15 import json
16 import logging
17
18 from lcm.pub.exceptions import NFLCMException
19 from lcm.pub.utils.restcall import req_by_msb
20
21 logger = logging.getLogger(__name__)
22
23
24 def get_packageinfo_by_vnfdid(vnfdid):
25     ret = req_by_msb("api/gvnfmdriver/v1/vnfpackages", "GET")  # TODO
26     if ret[0] != 0:
27         logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
28         raise NFLCMException("Failed to query package_info of vnfdid(%s) from nslcm." % vnfdid)
29     return json.JSONDecoder().decode(ret[1])
30
31
32 def apply_grant_to_nfvo(data):
33     ret = req_by_msb("api/gvnfmdriver/v1/resource/grant", "PUT", data)
34     if ret[0] != 0:
35         logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
36         raise NFLCMException("Nf instancing apply grant exception")
37     return json.JSONDecoder().decode(ret[1])
38
39
40 def notify_lcm_to_nfvo(data):
41     ret = req_by_msb("api/gvnfmdriver/v1/vnfs/lifecyclechangesnotification", "POST", data)
42     if ret[0] != 0:
43         logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
44         raise NFLCMException("Nf lcm notify exception")
45     return ret[1]