import shutil
import urllib
-import paramiko
+# import paramiko
from toscaparser.tosca_template import ToscaTemplate
from toscaparser.properties import Property
from toscaparser.functions import Function, Concat, GetInput, get_function, function_mappings
try:
os.remove(file_name)
except Exception as e:
- logger.error("Failed to parse package, error: %s", e.message)
+ logger.error("Failed to parse package, error: %s", e.args[0])
def _validate_input_params(self, path, params):
valid_params = {}
if params:
tmp = self._create_tosca_template(path, None)
if isinstance(params, dict):
- for key, value in params.items():
+ for key, value in list(params.items()):
if hasattr(tmp, 'inputs') and len(tmp.inputs) > 0:
for input_def in tmp.inputs:
if (input_def.name == key):
no_required_paras_check=True,
debug_mode=True)
except Exception as e:
- print e.message
+ print(e.args[0])
finally:
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 as e:
- logger.error("Failed to create tosca template, error: %s", e.message)
- print "-----------------------------"
- print '\n'.join(['%s:%s' % item for item in tosca_tpl.__dict__.items()])
- print "-----------------------------"
+ logger.error("Failed to create tosca template, error: %s", e.args[0])
+ print("-----------------------------")
+ print('\n'.join(['%s:%s' % item for item in list(tosca_tpl.__dict__.items())]))
+ print("-----------------------------")
return tosca_tpl
def _check_download_file(self, path):
path = path.encode("utf-8")
tmps = str.split(path, '/')
localFileName = tmps[len(tmps) - 1]
- urllib.urlretrieve(path, localFileName)
+ urllib.request.urlretrieve(path, localFileName)
return localFileName
def downloadFileFromFtpServer(self, path):
self.ftp_get(userName, userPwd, hostIp, hostPort, remoteFileName, localFileName)
return localFileName
- def sftp_get(self, userName, userPwd, hostIp, hostPort, remoteFileName, localFileName):
- # return
- t = None
- try:
- t = paramiko.Transport(hostIp, int(hostPort))
- t.connect(username=userName, password=userPwd)
- sftp = paramiko.SFTPClient.from_transport(t)
- sftp.get(remoteFileName, localFileName)
- finally:
- if t is not None:
- t.close()
+ # def sftp_get(self, userName, userPwd, hostIp, hostPort, remoteFileName, localFileName):
+ # # return
+ # t = None
+ # try:
+ # t = paramiko.Transport(hostIp, int(hostPort))
+ # t.connect(username=userName, password=userPwd)
+ # sftp = paramiko.SFTPClient.from_transport(t)
+ # sftp.get(remoteFileName, localFileName)
+ # finally:
+ # if t is not None:
+ # t.close()
def ftp_get(self, userName, userPwd, hostIp, hostPort, remoteFileName, localFileName):
f = None
def buildProperties(self, nodeTemplate, parsed_params):
properties = {}
isMappingParams = parsed_params and len(parsed_params) > 0
- for k, item in nodeTemplate.get_properties().items():
+ for k, item in list(nodeTemplate.get_properties().items()):
properties[k] = item.value
if isinstance(item.value, GetInput):
if item.value.result() and isMappingParams:
tmp[item.value.name] = item.value.input_name
properties[k] = tmp
if ATTRIBUTES in nodeTemplate.entity_tpl:
- for k, item in nodeTemplate.entity_tpl[ATTRIBUTES].items():
+ for k, item in list(nodeTemplate.entity_tpl[ATTRIBUTES].items()):
properties[k] = str(item)
return properties
properties = nodeTemplate.get_properties()
_properties = {}
if isinstance(properties, dict):
- for name, prop in properties.items():
+ for name, prop in list(properties.items()):
if isinstance(prop, Property):
if isinstance(prop.value, Function):
if isinstance(prop.value, Concat): # support one layer inner function.
value_str += arg
elif isinstance(arg, dict):
raw_func = {}
- for k, v in arg.items():
+ for k, v in list(arg.items()):
func_args = []
func_args.append(v)
raw_func[k] = func_args
value_str += arg
elif isinstance(arg, dict):
raw_func = {}
- for k, v in arg.items():
+ for k, v in list(arg.items()):
func_args = []
func_args.append(v)
raw_func[k] = func_args
def verify_properties(self, props, inputs, parsed_params):
ret_props = {}
if (props and len(props) > 0):
- for key, value in props.items():
+ for key, value in list(props.items()):
ret_props[key] = self._verify_value(value, inputs, parsed_params)
# if isinstance(value, str):
# ret_props[key] = self._verify_string(inputs, parsed_params, value);
def build_requirements(self, node_template):
rets = []
for req in node_template.requirements:
- for req_name, req_value in req.items():
+ for req_name, req_value in list(req.items()):
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.
requirements = []
if REQUIREMENTS in node:
for item in node[REQUIREMENTS]:
- for key, value in item.items():
+ for key, value in list(item.items()):
if key == requirementName:
requirements.append(value)
return requirements
rets = []
if ARTIFACTS in node and len(node[ARTIFACTS]) > 0:
artifacts = node[ARTIFACTS]
- for name, value in artifacts.items():
+ for name, value in list(artifacts.items()):
ret = {}
ret['artifact_name'] = name
ret['file'] = value
for type_require in type_requires:
type_require_set.update(type_require)
for requirement in node.requirements:
- for k in requirement.keys():
+ for k in list(requirement.keys()):
if type_require_set[k].get('relationship', None) in relations[0] or type_require_set[k].get('capability', None) in relations[0]:
if isinstance(requirement[k], dict):
next_node = requirement[k].get('node', None)
metadata = None
substitution_mappings = tosca.tpl['topology_template'].get('substitution_mappings', None)
if substitution_mappings:
- node['type'] = substitution_mappings['node_type']
- node['properties'] = substitution_mappings.get('properties', {})
- node['requirements'] = substitution_mappings.get('requirements', {})
- node['capabilities'] = substitution_mappings.get('capabilities', {})
- metadata = substitution_mappings.get('metadata', {})
+ nodeType = substitution_mappings['node_type']
+ logger.debug("nodeType %s", nodeType)
+ if "node_types" in tosca.tpl:
+ node_types = tosca.tpl['node_types'].get(nodeType, None)
+ derivedFrom = node_types.get('derived_from', "")
+ node['type'] = derivedFrom
+ node['properties'] = node_types.get('properties', {})
+ node['requirements'] = node_types.get('requirements', {})
+ node['capabilities'] = node_types.get('capabilities', {})
+ metadata = node_types.get('metadata', {})
+
+ if "type" not in node or node['type'] == "":
+ node['type'] = nodeType
+ node['properties'] = substitution_mappings.get('properties', {})
+ node['requirements'] = substitution_mappings.get('requirements', {})
+ node['capabilities'] = substitution_mappings.get('capabilities', {})
+ metadata = substitution_mappings.get('metadata', {})
+
node['metadata'] = metadata if metadata and metadata != {} else self.buildMetadata(tosca)
return node