summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-09-26 13:23:05 +0800
committerFu Jinhua <fu.jinhua@zte.com.cn>2017-09-26 06:08:53 +0000
commitd82867b83d980c4d83e452c400ec98ca7e84cf02 (patch)
treedf2e0b632c7ced81098e854f1340a6d384d20e56
parent4e44bbcf4bca14060fb2c9ba704a16527e675c24 (diff)
Fix vfc-catalog/toscaparser pep8 issue
Change-Id: I34557c4493fb71b857386c222c43c8485ede24d0 Issue-ID: VFC-456 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r--lcm/pub/utils/toscaparser/basemodel.py49
-rw-r--r--lcm/pub/utils/toscaparser/dataentityext.py3
-rw-r--r--lcm/pub/utils/toscaparser/nsdmodel.py12
-rw-r--r--lcm/pub/utils/toscaparser/vnfdmodel.py9
-rw-r--r--lcm/pub/utils/values.py1
5 files changed, 35 insertions, 39 deletions
diff --git a/lcm/pub/utils/toscaparser/basemodel.py b/lcm/pub/utils/toscaparser/basemodel.py
index c912b1f7..b80b275f 100644
--- a/lcm/pub/utils/toscaparser/basemodel.py
+++ b/lcm/pub/utils/toscaparser/basemodel.py
@@ -15,6 +15,7 @@
import copy
import ftplib
import json
+import logging
import os
import re
import shutil
@@ -26,6 +27,8 @@ from toscaparser.tosca_template import ToscaTemplate
from lcm.pub.utils.toscaparser.dataentityext import DataEntityExt
+logger = logging.getLogger(__name__)
+
class BaseInfoModel(object):
@@ -36,17 +39,17 @@ class BaseInfoModel(object):
valid_params = self._validate_input_params(file_name, params)
return self._create_tosca_template(file_name, valid_params)
finally:
- if file_name != None and file_name != path and os.path.exists(file_name):
+ if file_name is not None and file_name != path and os.path.exists(file_name):
try:
os.remove(file_name)
- except Exception, e:
- pass
+ except Exception as e:
+ logger.error("Failed to parse package, error: %s", e.message)
def _validate_input_params(self, path, params):
valid_params = {}
if params and len(params) > 0:
tmp = self._create_tosca_template(path, None)
- for key,value in params.items():
+ for key, value in params.items():
if hasattr(tmp, 'inputs') and len(tmp.inputs) > 0:
for input_def in tmp.inputs:
if (input_def.name == key):
@@ -63,11 +66,11 @@ class BaseInfoModel(object):
print "-----------------------------"
return tosca_tpl
finally:
- if tosca_tpl != None and hasattr(tosca_tpl, "temp_dir") and os.path.exists(tosca_tpl.temp_dir):
+ if tosca_tpl is not None and hasattr(tosca_tpl, "temp_dir") and os.path.exists(tosca_tpl.temp_dir):
try:
shutil.rmtree(tosca_tpl.temp_dir)
- except Exception, e:
- pass
+ except Exception as e:
+ logger.error("Failed to create tosca template, error: %s", e.message)
def _check_download_file(self, path):
if (path.startswith("ftp") or path.startswith("sftp")):
@@ -126,10 +129,9 @@ class BaseInfoModel(object):
sftp = paramiko.SFTPClient.from_transport(t)
sftp.get(remoteFileName, localFileName)
finally:
- if t != None:
+ if t is not None:
t.close()
-
def ftp_get(self, userName, userPwd, hostIp, hostPort, remoteFileName, localFileName):
f = None
try:
@@ -140,7 +142,7 @@ class BaseInfoModel(object):
ftp.retrbinary('RETR ' + remoteFileName, f.write, 1024)
f.close()
finally:
- if f != None:
+ if f is not None:
f.close()
def buidMetadata(self, tosca):
@@ -164,7 +166,6 @@ class BaseInfoModel(object):
properties[k] = str(item)
return properties
-
def verify_properties(self, props, inputs, parsed_params):
ret_props = {}
if (props and len(props) > 0):
@@ -189,26 +190,24 @@ class BaseInfoModel(object):
if (isinstance(req_value, dict)):
if ('node' in req_value and req_value['node'] not in node_template.templates):
continue # No target requirement for aria parser, not add to result.
- rets.append({req_name : req_value})
+ rets.append({req_name: req_value})
return rets
def buildCapabilities(self, nodeTemplate, inputs, ret):
capabilities = json.dumps(nodeTemplate.entity_tpl.get('capabilities', None))
- match = re.findall(r'\{"get_input":\s*"([\w|\-]+)"\}',capabilities)
+ match = re.findall(r'\{"get_input":\s*"([\w|\-]+)"\}', capabilities)
for m in match:
- aa= [input_def for input_def in inputs
- if m == input_def.name][0]
- capabilities = re.sub(r'\{"get_input":\s*"([\w|\-]+)"\}', json.dumps(aa.default), capabilities,1)
+ aa = [input_def for input_def in inputs if m == input_def.name][0]
+ capabilities = re.sub(r'\{"get_input":\s*"([\w|\-]+)"\}', json.dumps(aa.default), capabilities, 1)
if capabilities != 'null':
ret['capabilities'] = json.loads(capabilities)
def buildArtifacts(self, nodeTemplate, inputs, ret):
artifacts = json.dumps(nodeTemplate.entity_tpl.get('artifacts', None))
- match = re.findall(r'\{"get_input":\s*"([\w|\-]+)"\}',artifacts)
+ match = re.findall(r'\{"get_input":\s*"([\w|\-]+)"\}', artifacts)
for m in match:
- aa= [input_def for input_def in inputs
- if m == input_def.name][0]
- artifacts = re.sub(r'\{"get_input":\s*"([\w|\-]+)"\}', json.dumps(aa.default), artifacts,1)
+ aa = [input_def for input_def in inputs if m == input_def.name][0]
+ artifacts = re.sub(r'\{"get_input":\s*"([\w|\-]+)"\}', json.dumps(aa.default), artifacts, 1)
if artifacts != 'null':
ret['artifacts'] = json.loads(artifacts)
@@ -227,8 +226,9 @@ class BaseInfoModel(object):
return node['nodeType'].upper().find('.CP.') >= 0 or node['nodeType'].upper().endswith('.CP')
def isVl(self, node):
- return node['nodeType'].upper().find('.VIRTUALLINK.') >= 0 or node['nodeType'].upper().find('.VL.') >= 0 or \
- node['nodeType'].upper().endswith('.VIRTUALLINK') or node['nodeType'].upper().endswith('.VL')
+ isvl = node['nodeType'].upper().find('.VIRTUALLINK.') >= 0 or node['nodeType'].upper().find('.VL.') >= 0
+ isvl = isvl or node['nodeType'].upper().endswith('.VIRTUALLINK') or node['nodeType'].upper().endswith('.VL')
+ return isvl
def isService(self, node):
return node['nodeType'].upper().find('.SERVICE.') >= 0 or node['nodeType'].upper().endswith('.SERVICE')
@@ -252,7 +252,6 @@ class BaseInfoModel(object):
def getVirtualbindings(self, node):
return self.getRequirementByName(node, 'virtualbinding')
-
def getRequirementByName(self, node, requirementName):
requirements = []
if 'requirements' in node:
@@ -267,8 +266,8 @@ class BaseInfoModel(object):
if 'requirements' in node:
for item in node['requirements']:
for key, value in item.items():
- if key.upper().find('VIRTUALLINK') >=0:
- rets.append({"key_name":key, "vl_id":self.get_requirement_node_name(value)})
+ if key.upper().find('VIRTUALLINK') >= 0:
+ rets.append({"key_name": key, "vl_id": self.get_requirement_node_name(value)})
return rets
def _verify_value(self, value, inputs, parsed_params):
diff --git a/lcm/pub/utils/toscaparser/dataentityext.py b/lcm/pub/utils/toscaparser/dataentityext.py
index 6ca20668..825e93bb 100644
--- a/lcm/pub/utils/toscaparser/dataentityext.py
+++ b/lcm/pub/utils/toscaparser/dataentityext.py
@@ -16,8 +16,8 @@ from toscaparser.dataentity import DataEntity
from toscaparser.elements.constraints import Schema
from toscaparser.common.exception import ExceptionCollector
-class DataEntityExt(object):
+class DataEntityExt(object):
'''A complex data value entity ext.'''
@staticmethod
def validate_datatype(type, value, entry_schema=None, custom_def=None):
@@ -29,6 +29,5 @@ class DataEntityExt(object):
return float(value)
except Exception:
ExceptionCollector.appendException(ValueError(('"%s" is not an float.') % value))
-
return DataEntity.validate_datatype(type, value, entry_schema, custom_def)
return value
diff --git a/lcm/pub/utils/toscaparser/nsdmodel.py b/lcm/pub/utils/toscaparser/nsdmodel.py
index e13f0265..9792dd99 100644
--- a/lcm/pub/utils/toscaparser/nsdmodel.py
+++ b/lcm/pub/utils/toscaparser/nsdmodel.py
@@ -44,7 +44,6 @@ class EtsiNsdInfoModel(BaseInfoModel):
self.ns_flavours = self.get_all_flavour(tosca.topology_template.groups)
self.nested_ns = self.get_all_nested_ns(nodeTemplates)
-
def buildInputs(self, top_inputs):
ret = {}
for tmpinput in top_inputs:
@@ -57,7 +56,7 @@ class EtsiNsdInfoModel(BaseInfoModel):
return ret
def buildNode(self, nodeTemplate, inputs, parsed_params):
- ret ={}
+ ret = {}
ret['name'] = nodeTemplate.name
ret['nodeType'] = nodeTemplate.type
if 'description' in nodeTemplate.entity_tpl:
@@ -70,7 +69,8 @@ class EtsiNsdInfoModel(BaseInfoModel):
self.buildCapabilities(nodeTemplate, inputs, ret)
self.buildArtifacts(nodeTemplate, inputs, ret)
interfaces = self.build_interfaces(nodeTemplate)
- if interfaces: ret['interfaces'] = interfaces
+ if interfaces:
+ ret['interfaces'] = interfaces
return ret
def _get_all_vnf(self, nodeTemplates):
@@ -111,7 +111,7 @@ class EtsiNsdInfoModel(BaseInfoModel):
for key, value in item.items():
if key.upper().startswith('VIRTUALBINDING'):
req_node_name = self.get_requirement_node_name(value)
- if req_node_name != None and req_node_name == node['name']:
+ if req_node_name is not None and req_node_name == node['name']:
cps.append(tmpnode)
return cps
@@ -171,9 +171,9 @@ class EtsiNsdInfoModel(BaseInfoModel):
cp_vl = {}
cp_vl['vl_id'] = self.get_prop_from_obj(req, 'node')
relationship = self.get_prop_from_obj(req, 'relationship')
- if relationship != None:
+ if relationship is not None:
properties = self.get_prop_from_obj(relationship, 'properties')
- if properties != None and isinstance(properties, dict):
+ if properties is not None and isinstance(properties, dict):
for key, value in properties.items():
cp_vl[key] = value
return cp_vl
diff --git a/lcm/pub/utils/toscaparser/vnfdmodel.py b/lcm/pub/utils/toscaparser/vnfdmodel.py
index f26ec967..a665efe7 100644
--- a/lcm/pub/utils/toscaparser/vnfdmodel.py
+++ b/lcm/pub/utils/toscaparser/vnfdmodel.py
@@ -47,7 +47,6 @@ class EtsiVnfdInfoModel(EtsiNsdInfoModel):
self.vnf_exposed = self.get_all_endpoint_exposed(tosca.topology_template)
self.vnf_flavours = self.get_all_flavour(tosca.topology_template.groups)
-
def _get_all_services(self, nodeTemplates):
ret = []
for node in nodeTemplates:
@@ -177,13 +176,13 @@ class EtsiVnfdInfoModel(EtsiNsdInfoModel):
ret['dependencies'] = map(lambda x: self.get_requirement_node_name(x), self.getNodeDependencys(node))
nfv_compute = self.getCapabilityByName(node, 'nfv_compute')
- if nfv_compute != None and 'properties' in nfv_compute:
+ if nfv_compute is not None and 'properties' in nfv_compute:
ret['nfv_compute'] = nfv_compute['properties']
ret['vls'] = self.get_linked_vl_ids(node, nodeTemplates)
scalable = self.getCapabilityByName(node, 'scalable')
- if scalable != None and 'properties' in scalable:
+ if scalable is not None and 'properties' in scalable:
ret['scalable'] = scalable['properties']
ret['cps'] = self.getVirtalBindingCpIds(node, nodeTemplates)
@@ -296,8 +295,8 @@ class EtsiVnfdInfoModel(EtsiNsdInfoModel):
policies = []
scaling_policies = self.get_scaling_policies(top_policies)
healing_policies = self.get_healing_policies(top_policies)
- policies.append({"scaling":scaling_policies, 'healing':healing_policies})
+ policies.append({"scaling": scaling_policies, 'healing': healing_policies})
return policies
def get_healing_policies(self, top_policies):
- return self.get_policies_by_keyword(top_policies,'.HEALING')
+ return self.get_policies_by_keyword(top_policies, '.HEALING')
diff --git a/lcm/pub/utils/values.py b/lcm/pub/utils/values.py
index 27d71a53..10700d02 100644
--- a/lcm/pub/utils/values.py
+++ b/lcm/pub/utils/values.py
@@ -22,4 +22,3 @@ def ignore_case_get(args, key, def_val=""):
if old_key.upper() == key.upper():
return args[old_key]
return def_val
-