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.
17 from lcm.pub.exceptions import NSLCMException
18 from lcm.pub.utils.restcall import req_by_msb
19 from lcm.pub.utils.values import ignore_case_get
20 from lcm.pub.msapi.extsys import get_vnfm_by_id
22 logger = logging.getLogger(__name__)
25 def send_nf_init_request(vnfm_inst_id, req_param):
26 vnfm = get_vnfm_by_id(vnfm_inst_id)
27 uri = '/api/%s/v1/%s/vnfs' % (vnfm["type"], vnfm_inst_id)
28 ret = req_by_msb(uri, "POST", req_param)
30 logger.error("Failed to send nf init req:%s,%s", ret[2], ret[1])
31 raise NSLCMException('Failed to send nf init request to VNFM(%s)' % vnfm_inst_id)
32 return json.JSONDecoder().decode(ret[1])
34 def send_nf_terminate_request(vnfm_inst_id, vnf_inst_id, req_param):
35 vnfm = get_vnfm_by_id(vnfm_inst_id)
36 uri = '/api/%s/v1/%s/vnfs/%s/terminate' % (vnfm["type"], vnfm_inst_id, vnf_inst_id)
37 ret = req_by_msb(uri, "POST", req_param)
39 logger.error("Failed to send nf terminate req:%s,%s", ret[2], ret[1])
40 raise NSLCMException('Failed to send nf terminate request to VNFM(%s)' % vnfm_inst_id)
41 return json.JSONDecoder().decode(ret[1]) if ret[1] else {}
43 def query_vnfm_job(vnfm_inst_id, job_id, response_id=0):
44 vnfm = get_vnfm_by_id(vnfm_inst_id)
46 uri = '/api/%s/v1/%s/jobs/%s?responseId=%s' % (vnfm["type"],
47 vnfm_inst_id, job_id, response_id)
49 rsp = req_by_msb(uri, "GET")
50 if str(rsp[2]) == '404':
53 logger.warning('retry_time=%s, detail message:%s' % (retry_time, rsp[1]))
59 raise NSLCMException('Failed to query job from VNFM!')
60 return True, json.JSONDecoder().decode(rsp[1])
62 def send_nf_scaling_request(vnfm_inst_id, vnf_inst_id, req_param):
63 vnfm = get_vnfm_by_id(vnfm_inst_id)
64 uri = '/api/%s/v1/%s/vnfs/%s/scale' % (vnfm["type"], vnfm_inst_id, vnf_inst_id)
65 ret = req_by_msb(uri, "POST", req_param)
67 logger.error("Failed to send nf scale req:%s,%s", ret[2], ret[1])
68 raise NSLCMException('Failed to send nf scale request to VNFM(%s)' % vnfm_inst_id)
69 return json.JSONDecoder().decode(ret[1])