diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | lcm/ns/ns_manual_scale.py | 38 | ||||
-rw-r--r-- | lcm/ns/vnfs/grant_vnfs.py | 4 | ||||
-rw-r--r-- | lcm/ns/vnfs/scale_vnfs.py | 49 | ||||
-rw-r--r-- | lcm/pub/msapi/sdncdriver.py | 38 | ||||
-rw-r--r-- | lcm/pub/utils/scaleaspect.py | 34 |
6 files changed, 61 insertions, 105 deletions
@@ -1,3 +1,4 @@ logs/*.log *.pyc -.idea
\ No newline at end of file +.idea +.tox diff --git a/lcm/ns/ns_manual_scale.py b/lcm/ns/ns_manual_scale.py index 71897aee..2870ed7a 100644 --- a/lcm/ns/ns_manual_scale.py +++ b/lcm/ns/ns_manual_scale.py @@ -36,9 +36,7 @@ class NSManualScaleService(threading.Thread): self.ns_instance_id = ns_instance_id self.request_data = request_data self.job_id = job_id - self.scale_type = '' self.scale_vnf_data = '' - self.scale_ns_data = '' def run(self): try: @@ -60,24 +58,16 @@ class NSManualScaleService(threading.Thread): self.update_job(100, desc='ns scale success') def check_and_set_params(self): - self.scale_type = ignore_case_get(self.request_data, 'scaleType') - if not self.scale_type or self.scale_type != SCALE_TYPE[0]: - logger.error( - 'scaleType parameter does not exist or value is incorrect. It must be SCALE_NS.') - raise NSLCMException( - 'scaleType parameter does not exist or value incorrect. It must be SCALE_NS.') + scale_type = ignore_case_get(self.request_data, 'scaleType') + if scale_type != SCALE_TYPE[0]: + raise NSLCMException('scaleType should be SCALE_NS.') - # Get data if SCALE_NS - self.scale_ns_data = ignore_case_get(self.request_data, 'scaleNsData') + scale_ns_data = ignore_case_get(self.request_data, 'scaleNsData') self.scale_vnf_data = get_scale_vnf_data_info_list( - self.scale_ns_data, self.ns_instance_id) + scale_ns_data, self.ns_instance_id) logger.debug('scale_vnf_data = %s' % self.scale_vnf_data) - # Get data if SCALE_VNF if not self.scale_vnf_data: - logger.error( - 'scaleVnfData parameter does not exist or value incorrect') - raise NSLCMException( - 'scaleVnfData parameter does not exist or value incorrect') + raise NSLCMException('Failed to get scaleVnfData parameter') def do_vnfs_scale(self): for i in range(len(self.scale_vnf_data)): @@ -95,18 +85,14 @@ class NSManualScaleService(threading.Thread): desc='nf[%s] scale handle end' % vnf_scale_params.get('vnfInstanceId')) else: - logger.error('nf scale failed') - raise NSLCMException('nf scale failed') + raise NSLCMException('VNF scale failed') def prepare_vnf_scale_params(self, vnf_data): - vnf_instance_id = ignore_case_get(vnf_data, 'vnfInstanceId') - scale_by_step_data = ignore_case_get(vnf_data, 'scaleByStepData') - result = { - "vnfInstanceId": vnf_instance_id, - "scaleVnfData": scale_by_step_data, + return { + "vnfInstanceId": ignore_case_get(vnf_data, 'vnfInstanceId'), + "scaleVnfData": ignore_case_get(vnf_data, 'scaleByStepData'), "nsInstanceId": self.ns_instance_id } - return result def do_vnf_scale(self, vnf_scale_params, progress_range): nf_inst_id = vnf_scale_params.get('vnfInstanceId') @@ -129,10 +115,8 @@ class NSManualScaleService(threading.Thread): end_time = datetime.datetime.now() if job_result.progress == 100: return JOB_MODEL_STATUS.FINISHED - elif job_result.progress > 100: + if job_result.progress > 100: return JOB_MODEL_STATUS.ERROR - else: - continue return JOB_MODEL_STATUS.TIMEOUT def update_job(self, progress, desc=''): diff --git a/lcm/ns/vnfs/grant_vnfs.py b/lcm/ns/vnfs/grant_vnfs.py index 87a800ec..7f2d44e5 100644 --- a/lcm/ns/vnfs/grant_vnfs.py +++ b/lcm/ns/vnfs/grant_vnfs.py @@ -96,10 +96,10 @@ class GrantVnfs(object): resourceTemplate = { "virtualComputeDescriptor": { "virtualCpu": { - "numVirtualCpu": int(vdu["nfv_compute"]["num_cpus"]) + "numVirtualCpu": int(vdu["virtual_compute"]["virtual_cpu"]["num_virtual_cpu"]) }, "virtualMemory": { - "virtualMemSize": int(vdu["nfv_compute"]["mem_size"]) + "virtualMemSize": int(vdu["virtual_compute"]["virtual_memory"]["virtual_mem_size"]) } }, "virtualStorageDescriptor": { diff --git a/lcm/ns/vnfs/scale_vnfs.py b/lcm/ns/vnfs/scale_vnfs.py index 5b4e978a..9848c1ab 100644 --- a/lcm/ns/vnfs/scale_vnfs.py +++ b/lcm/ns/vnfs/scale_vnfs.py @@ -36,8 +36,6 @@ class NFManualScaleService(threading.Thread): self.data = data self.job_id = JobUtil.create_job( "NF", JOB_TYPE.MANUAL_SCALE_VNF, vnf_instance_id) - self.scale_vnf_data = '' - self.nf_model = {} self.nf_scale_params = [] self.m_nf_inst_id = '' self.vnfm_inst_id = '' @@ -50,58 +48,44 @@ class NFManualScaleService(threading.Thread): except Exception as ex: logger.error(ex.message) logger.error(traceback.format_exc()) - JobUtil.add_job_status(self.job_id, JOB_ERROR, 'nf scale fail') + JobUtil.add_job_status(self.job_id, JOB_ERROR, 'VNF scale failed') finally: self.update_nf_status() def do_biz(self): - self.update_job(1, desc='nf scale start') + self.update_job(1, desc='VNF scale start') self.update_nf_status(VNF_STATUS.SCALING) self.get_and_check_params() self.send_nf_scaling_requests() - self.update_job(100, desc='nf scale success') + self.update_job(100, desc='VNF scale success') def get_and_check_params(self): nf_info = NfInstModel.objects.filter(nfinstid=self.vnf_instance_id) if not nf_info: - logger.error( - 'NF instance[id=%s] does not exist' % - self.vnf_instance_id) raise NSLCMException( 'NF instance[id=%s] does not exist' % self.vnf_instance_id) logger.debug('vnfd_model = %s, vnf_instance_id = %s' % (nf_info[0].vnfd_model, self.vnf_instance_id)) - self.nf_model = json.loads(nf_info[0].vnfd_model) + nf_model = json.loads(nf_info[0].vnfd_model) self.m_nf_inst_id = nf_info[0].mnfinstid self.vnfm_inst_id = nf_info[0].vnfm_inst_id - self.scale_vnf_data = ignore_case_get(self.data, 'scaleVnfData') - if not self.scale_vnf_data: - logger.error( - 'scaleVnfData parameter does not exist or value incorrect') - raise NSLCMException( - 'scaleVnfData parameter does not exist or value incorrect') + scale_vnf_data = ignore_case_get(self.data, 'scaleVnfData') + if not scale_vnf_data: + raise NSLCMException('scaleVnfData parameter does not exist') - scale_type = ignore_case_get(self.scale_vnf_data, 'type') - aspect_id = ignore_case_get(self.scale_vnf_data, 'aspectId') - number_of_steps = ignore_case_get(self.scale_vnf_data, 'numberOfSteps') self.nf_scale_params.append({ - 'type': scale_type, - 'aspectId': aspect_id, - 'numberOfSteps': number_of_steps, - 'additionalParam': {'vnfdModel': self.nf_model} + 'type': ignore_case_get(scale_vnf_data, 'type'), + 'aspectId': ignore_case_get(scale_vnf_data, 'aspectId'), + 'numberOfSteps': ignore_case_get(scale_vnf_data, 'numberOfSteps'), + 'additionalParam': {'vnfdModel': nf_model} }) def send_nf_scaling_requests(self): - for i in range(len(self.nf_scale_params)): - progress_range = [10 + - 80 / - len(self.nf_scale_params) * - i, 10 + - 80 / - len(self.nf_scale_params) * - (i + - 1)] + nf_scale_num = len(self.nf_scale_params) + for i in range(nf_scale_num): + progress_range = [10 + 80 / nf_scale_num * i, + 10 + 80 / nf_scale_num * (i + 1)] self.send_nf_scaling_request( self.nf_scale_params[i], progress_range) @@ -118,8 +102,7 @@ class NFManualScaleService(threading.Thread): timeout=1200, mode='1') if ret != JOB_MODEL_STATUS.FINISHED: - logger.error('[NF scale] nf scale failed') - raise NSLCMException("nf scale failed") + raise NSLCMException("VNF scale failed") def update_nf_status(self, status=VNF_STATUS.ACTIVE): NfInstModel.objects.filter( diff --git a/lcm/pub/msapi/sdncdriver.py b/lcm/pub/msapi/sdncdriver.py index 8d2c7583..ff981f66 100644 --- a/lcm/pub/msapi/sdncdriver.py +++ b/lcm/pub/msapi/sdncdriver.py @@ -23,26 +23,26 @@ logger = logging.getLogger(__name__) def delete_port_chain(req_param): url = "/api/sdncdriver/v1/delchain" - str = "delete port chain" - delete_func(req_param, url, str) + desc = "delete port chain" + delete_func(req_param, url, desc) def delete_flow_classifier(req_param): url = "/api/sdncdriver/v1/delclassifier" - str = "delete flow classifier" - delete_func(req_param, url, str) + desc = "delete flow classifier" + delete_func(req_param, url, desc) def delete_port_pair_group(req_param): url = "/api/sdncdriver/v1/delportpairgroup" - str = "delete port pair" - delete_func(req_param, url, str) + desc = "delete port pair" + delete_func(req_param, url, desc) def delete_port_pair(req_param): url = "/api/sdncdriver/v1/delportpair" - str = "delete port pair" - delete_func(req_param, url, str) + desc = "delete port pair" + delete_func(req_param, url, desc) def delete_func(req_param, url, str): @@ -54,32 +54,32 @@ def delete_func(req_param, url, str): def create_flow_classfier(data): url = "/api/ztesdncdriver/v1/createflowclassfier" - str = "create flow classfier" - return create(data, url, str) + desc = "create flow classfier" + return create(data, url, desc) def create_port_pair(data): url = "/api/ztesdncdriver/v1/createportpair" - str = "create port pair" - return create(data, url, str) + desc = "create port pair" + return create(data, url, desc) def create_port_pair_group(data): url = "/api/ztesdncdriver/v1/createportpairgroup" - str = "create port pair group" - return create(data, url, str) + desc = "create port pair group" + return create(data, url, desc) def create_port_chain(data): url = "/api/ztesdncdriver/v1/createportchain" - str = "create port chain" - return create(data, url, str) + desc = "create port chain" + return create(data, url, desc) -def create(req_param, url, str): +def create(req_param, url, desc): ret = req_by_msb(url, "POST", json.dumps(req_param)) if ret[0] != 0: - logger.error("Failed to %s to sdncdriver. detail is %s.", str, ret[1]) - raise NSLCMException('Failed to %s to sdncdriver.' % str) + logger.error("Failed to %s to sdncdriver. detail is %s.", desc, ret[1]) + raise NSLCMException('Failed to %s to sdncdriver.' % desc) resp_body = json.loads(ret[1]) return resp_body["id"] diff --git a/lcm/pub/utils/scaleaspect.py b/lcm/pub/utils/scaleaspect.py index cf78092f..9a50f7b2 100644 --- a/lcm/pub/utils/scaleaspect.py +++ b/lcm/pub/utils/scaleaspect.py @@ -20,6 +20,7 @@ from lcm.pub.database.models import NfInstModel from lcm.pub.database.models import NSInstModel from lcm.ns.vnfs.const import VNF_STATUS from lcm.pub.msapi import catalog +from lcm.pub.utils.values import ignore_case_get logger = logging.getLogger(__name__) @@ -35,40 +36,27 @@ scale_vnf_data_mapping = { } -def ignorcase_get(args, key): - if not key: - return "" - if not args: - return "" - if key in args: - return args[key] - for old_key in args: - if old_key.upper() == key.upper(): - return args[old_key] - return "" - - def mapping_conv(keyword_map, rest_return): resp_data = {} for param in keyword_map: if keyword_map[param]: if isinstance(keyword_map[param], dict): resp_data[param] = mapping_conv( - keyword_map[param], ignorcase_get( + keyword_map[param], ignore_case_get( rest_return, param)) else: - resp_data[param] = ignorcase_get(rest_return, param) + resp_data[param] = ignore_case_get(rest_return, param) return resp_data def get_vnf_scale_info(filename, ns_instanceId, aspect, step): json_data = get_json_data(filename) - scale_options = ignorcase_get(json_data, "scale_options") + scale_options = ignore_case_get(json_data, "scale_options") for i in range(scale_options.__len__()): ns_scale_option = scale_options[i] - if (ignorcase_get(ns_scale_option, "ns_instanceId") == ns_instanceId) \ - and (ignorcase_get(ns_scale_option, "ns_scale_aspect") == aspect): - ns_scale_info_list = ignorcase_get( + if (ignore_case_get(ns_scale_option, "ns_instanceId") == ns_instanceId) \ + and (ignore_case_get(ns_scale_option, "ns_scale_aspect") == aspect): + ns_scale_info_list = ignore_case_get( ns_scale_option, "ns_scale_info_list") for j in range(ns_scale_info_list.__len__()): ns_scale_info = ns_scale_info_list[j] @@ -194,12 +182,12 @@ def get_scale_vnf_data_info_list(scaleNsData, ns_InstanceId): # Get the vnf scaling info from the scaling_map.json according to the ns package id. def get_scale_vnf_data_from_json(scalingmap_json, nsd_id, aspect, step): - scale_options = ignorcase_get(scalingmap_json, "scale_options") + scale_options = ignore_case_get(scalingmap_json, "scale_options") for i in range(scale_options.__len__()): ns_scale_option = scale_options[i] - if (ignorcase_get(ns_scale_option, "nsd_id") == nsd_id) and ( - ignorcase_get(ns_scale_option, "ns_scale_aspect") == aspect): - ns_scale_info_list = ignorcase_get( + if (ignore_case_get(ns_scale_option, "nsd_id") == nsd_id) and ( + ignore_case_get(ns_scale_option, "ns_scale_aspect") == aspect): + ns_scale_info_list = ignore_case_get( ns_scale_option, "ns_scale_info") for j in range(ns_scale_info_list.__len__()): ns_scale_info = ns_scale_info_list[j] |