summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2017-09-30 08:54:54 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2017-09-30 08:54:54 +0800
commit822518291cb97450b1d255d10a9a5b358fd2eeb3 (patch)
treed18094dc31f3e11983bbc90c45ecebe1411633f8 /lcm
parentf445aeff90fb3038c063def87e888e50b4e107a4 (diff)
Fix vnflcm new tosca util pep8 error
Change-Id: I08fdbc844511c21a6e2ba1084fbd138ce13b7069 Issue-Id: VFC-482 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
Diffstat (limited to 'lcm')
-rw-r--r--lcm/lcm/pub/utils/jobutil.py4
-rw-r--r--lcm/lcm/pub/utils/toscautil_new.py62
2 files changed, 37 insertions, 29 deletions
diff --git a/lcm/lcm/pub/utils/jobutil.py b/lcm/lcm/pub/utils/jobutil.py
index 3efc4635..5d387737 100644
--- a/lcm/lcm/pub/utils/jobutil.py
+++ b/lcm/lcm/pub/utils/jobutil.py
@@ -43,7 +43,7 @@ class JobUtil(object):
@staticmethod
def query_job_status(job_id, index_id=-1):
- #logger.info("Query job status, jobid =[%s], responseid [%d]" % (job_id, index_id))
+ # logger.info("Query job status, jobid =[%s], responseid [%d]" % (job_id, index_id))
jobs = []
if index_id < 0:
row = JobStatusModel.objects.filter(jobid=job_id).order_by("-indexid").first()
@@ -53,7 +53,7 @@ class JobUtil(object):
[jobs.append(job) for job in JobStatusModel.objects.filter(jobid=job_id).order_by("-indexid")
if job.indexid > index_id]
- #logger.info("Query job status, rows=%s" % str(jobs))
+ # logger.info("Query job status, rows=%s" % str(jobs))
return jobs
@staticmethod
diff --git a/lcm/lcm/pub/utils/toscautil_new.py b/lcm/lcm/pub/utils/toscautil_new.py
index 279fb09b..63e44a67 100644
--- a/lcm/lcm/pub/utils/toscautil_new.py
+++ b/lcm/lcm/pub/utils/toscautil_new.py
@@ -14,6 +14,7 @@
import json
+
def safe_get(key_val, key):
return key_val[key] if key in key_val else ""
@@ -37,7 +38,7 @@ def find_related_node(node_id, src_json_model, requirement_name):
for model_tpl in safe_get(src_json_model, "node_templates"):
for rt in safe_get(model_tpl, 'requirement_templates'):
if safe_get(rt, 'name') == requirement_name and \
- safe_get(rt, 'target_node_template_name') == node_id:
+ safe_get(rt, 'target_node_template_name') == node_id:
related_nodes.append(model_tpl['name'])
return related_nodes
@@ -46,17 +47,19 @@ def convert_props(src_node, dest_node):
if 'properties' in src_node and src_node['properties']:
for prop_name, prop_info in src_node['properties'].items():
if 'value' in prop_info:
- dest_node['properties'][prop_name] = prop_info['value']
+ dest_node['properties'][prop_name] = prop_info['value']
def convert_metadata(src_json):
return src_json['metadata'] if 'metadata' in src_json else {}
+
def convert_factor_unit(value):
if isinstance(value, (str, unicode)):
return value
return "%s %s" % (value["factor"], value["unit"])
+
def convert_inputs(src_json):
inputs = {}
if 'inputs' in src_json:
@@ -75,19 +78,19 @@ def convert_inputs(src_json):
def convert_vnf_node(src_node, src_json_model):
vnf_node = {'type': src_node['type_name'], 'vnf_id': src_node['template_name'],
- 'description': '', 'properties': {}, 'dependencies': [], 'networks': []}
+ 'description': '', 'properties': {}, 'dependencies': [], 'networks': []}
convert_props(src_node, vnf_node)
for model_tpl in safe_get(src_json_model, "node_templates"):
if model_tpl['name'] != vnf_node['vnf_id']:
continue
vnf_node['dependencies'] = [{
'key_name': requirement['name'],
- 'vl_id': requirement['target_node_template_name']} for \
- requirement in safe_get(model_tpl, 'requirement_templates') if \
+ 'vl_id': requirement['target_node_template_name']} for
+ requirement in safe_get(model_tpl, 'requirement_templates') if
safe_get(requirement, 'target_capability_name') == 'virtual_linkable']
- vnf_node['networks'] = [requirement['target_node_template_name'] for \
- requirement in safe_get(model_tpl, 'requirement_templates') if \
- safe_get(requirement, 'name') == 'dependency']
+ vnf_node['networks'] = [requirement['target_node_template_name'] for
+ requirement in safe_get(model_tpl, 'requirement_templates') if
+ safe_get(requirement, 'name') == 'dependency']
return vnf_node
@@ -141,8 +144,8 @@ def convert_router_node(src_node, src_node_list):
def convert_fp_node(src_node, src_node_list, src_json_model):
- fp_node = {'fp_id': src_node['template_name'], 'description': '',
- 'properties': {}, 'forwarder_list': []}
+ fp_node = {'fp_id': src_node['template_name'], 'description': '',
+ 'properties': {}, 'forwarder_list': []}
convert_props(src_node, fp_node)
for relation in safe_get(src_node, 'relationships'):
if safe_get(relation, 'name') != 'forwarder':
@@ -168,8 +171,8 @@ def convert_fp_node(src_node, src_node_list, src_json_model):
def convert_vnffg_group(src_group, src_group_list, src_node_list):
- vnffg = {'vnffg_id': src_group['template_name'], 'description': '',
- 'properties': {}, 'members': []}
+ vnffg = {'vnffg_id': src_group['template_name'], 'description': '',
+ 'properties': {}, 'members': []}
convert_props(src_group, vnffg)
for member_node_id in src_group['member_node_ids']:
vnffg['members'].append(find_node_name(member_node_id, src_node_list))
@@ -177,32 +180,34 @@ def convert_vnffg_group(src_group, src_group_list, src_node_list):
def convert_imagefile_node(src_node, src_node_list):
- image_node = {'image_file_id': src_node['template_name'], 'description': '',
- 'properties': {}}
+ image_node = {'image_file_id': src_node['template_name'], 'description': '',
+ 'properties': {}}
convert_props(src_node, image_node)
return image_node
def convert_localstorage_node(src_node, src_node_list):
- localstorage_node = {'local_storage_id': src_node['template_name'], 'description': '',
- 'properties': {}}
+ localstorage_node = {'local_storage_id': src_node['template_name'], 'description': '',
+ 'properties': {}}
convert_props(src_node, localstorage_node)
return localstorage_node
+
def convert_volumestorage_node(src_node, src_node_list):
volumestorage_node = {
- 'volume_storage_id': src_node['id'],
- 'description': "",
+ 'volume_storage_id': src_node['id'],
+ 'description': "",
'properties': {}}
convert_props(src_node, volumestorage_node)
volumestorage_node["properties"]["size"] = convert_factor_unit(
volumestorage_node["properties"]["size_of_storage"])
return volumestorage_node
+
def convert_vdu_node(src_node, src_node_list, src_json_model):
vdu_node = {'vdu_id': src_node['template_name'], 'description': '', 'properties': {},
- 'image_file': '', 'local_storages': [], 'dependencies': [], 'nfv_compute': {},
- 'vls': [], 'artifacts': [], 'volume_storages': []}
+ 'image_file': '', 'local_storages': [], 'dependencies': [], 'nfv_compute': {},
+ 'vls': [], 'artifacts': [], 'volume_storages': []}
convert_props(src_node, vdu_node)
for relation in src_node.get('relationships', ''):
@@ -226,7 +231,7 @@ def convert_vdu_node(src_node, src_node_list, src_json_model):
if prop_name == "virtual_cpu":
vdu_node['nfv_compute']['num_cpus'] = prop_info["value"]["num_virtual_cpu"]
vdu_node['nfv_compute']['cpu_frequency'] = convert_factor_unit(
- prop_info["value"]["virtual_cpu_clock"])
+ prop_info["value"]["virtual_cpu_clock"])
elif prop_name == "virtual_memory":
vdu_node['nfv_compute']['mem_size'] = convert_factor_unit(
prop_info["value"]["virtual_mem_size"])
@@ -249,8 +254,8 @@ def convert_vdu_node(src_node, src_node_list, src_json_model):
vdu_node['vls'].append(vl_node_name)
for item in safe_get(src_node, 'artifacts'):
- artifact = {'artifact_name': item['name'], 'type': item['type_name'],
- 'file': item['source_path'], 'properties': {}}
+ artifact = {'artifact_name': item['name'], 'type': item['type_name'],
+ 'file': item['source_path'], 'properties': {}}
convert_props(item, artifact)
for key in artifact['properties']:
if 'factor' in artifact['properties'][key] and 'unit' in artifact['properties'][key]:
@@ -264,10 +269,10 @@ def convert_vdu_node(src_node, src_node_list, src_json_model):
def convert_exposed_node(src_json, src_nodes, exposed):
for item in safe_get(safe_get(src_json, 'substitution'), 'requirements'):
exposed['external_cps'].append({'key_name': item['mapped_name'],
- "cp_id": find_node_name(item['node_id'], src_nodes)})
+ "cp_id": find_node_name(item['node_id'], src_nodes)})
for item in safe_get(safe_get(src_json, 'substitution'), 'capabilities'):
exposed['forward_cps'].append({'key_name': item['mapped_name'],
- "cp_id": find_node_name(item['node_id'], src_nodes)})
+ "cp_id": find_node_name(item['node_id'], src_nodes)})
def convert_vnffgs(src_json_inst, src_nodes):
@@ -279,6 +284,7 @@ def convert_vnffgs(src_json_inst, src_nodes):
vnffgs.append(convert_vnffg_group(group, src_groups, src_nodes))
return vnffgs
+
def merge_imagefile_node(img_nodes, vdu_nodes):
for vdu_node in vdu_nodes:
for artifact in vdu_node.get("artifacts", []):
@@ -293,6 +299,7 @@ def merge_imagefile_node(img_nodes, vdu_nodes):
"properties": artifact["properties"]
})
+
def convert_common(src_json, target_json):
if isinstance(src_json, (unicode, str)):
src_json_dict = json.loads(src_json)
@@ -313,7 +320,7 @@ def convert_common(src_json, target_json):
def convert_nsd_model(src_json):
target_json = {'vnfs': [], 'pnfs': [], 'fps': []}
src_json_inst, src_json_model = convert_common(src_json, target_json)
-
+
src_nodes = src_json_inst['nodes']
for node in src_nodes:
type_name = node['type_name']
@@ -361,12 +368,13 @@ def convert_vnfd_model(src_json):
target_json['cps'].append(convert_cp_node(node, src_nodes, 'VNFD'))
elif type_name.endswith('.Router'):
target_json['routers'].append(convert_router_node(node, src_nodes))
-
+
target_json['vnf_exposed'] = {'external_cps': [], 'forward_cps': []}
convert_exposed_node(src_json_inst, src_nodes, target_json['vnf_exposed'])
merge_imagefile_node(target_json['image_files'], target_json['vdus'])
return json.dumps(target_json)
+
if __name__ == '__main__':
src_json = json.dumps({
"instance": {