diff options
author | ying.yunlong <ying.yunlong@zte.com.cn> | 2017-08-31 11:00:45 +0800 |
---|---|---|
committer | ying.yunlong <ying.yunlong@zte.com.cn> | 2017-08-31 11:00:45 +0800 |
commit | 89015151e92f998e6e07499bd75a552158c5fbb1 (patch) | |
tree | 7908c90149c16e8a9f5ac2fb06bb3090d55394ab | |
parent | d0f37b0127353503145291d06436bf5656631845 (diff) |
Add sftp and ftp download
Implement download nsd or vnfd
package by sftp or ftp.
Change-Id: I5d45ae22a358a3ff1363bf3e0b23fa989e72841b
Issue-ID: VFC-141
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r-- | lcm/pub/utils/toscaparser/basemodel.py | 44 | ||||
-rw-r--r-- | lcm/pub/utils/toscaparser/nsdmodel.py | 1 | ||||
-rw-r--r-- | requirements.txt | 1 |
3 files changed, 46 insertions, 0 deletions
diff --git a/lcm/pub/utils/toscaparser/basemodel.py b/lcm/pub/utils/toscaparser/basemodel.py index dbb76310..351f0935 100644 --- a/lcm/pub/utils/toscaparser/basemodel.py +++ b/lcm/pub/utils/toscaparser/basemodel.py @@ -13,12 +13,14 @@ # limitations under the License. import copy +import ftplib import json import os import re import shutil import urllib +import paramiko from toscaparser.functions import GetInput from toscaparser.tosca_template import ToscaTemplate @@ -115,6 +117,32 @@ class BaseInfoModel(object): 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 != None: + t.close() + + + def ftp_get(self, userName, userPwd, hostIp, hostPort, remoteFileName, localFileName): + f = None + try: + ftp = ftplib.FTP() + ftp.connect(hostIp, hostPort) + ftp.login(userName, userPwd) + f = open(localFileName, 'wb') + ftp.retrbinary('RETR ' + remoteFileName, f.write, 1024) + f.close() + finally: + if f != None: + f.close() + def buidMetadata(self, tosca): if 'metadata' in tosca.tpl: self.metadata = copy.deepcopy(tosca.tpl['metadata']) @@ -282,3 +310,19 @@ class BaseInfoModel(object): if node['name'] == name: return node return None + + def get_all_nested_ns(self, nodes): + nss = [] + for node in nodes: + if self.is_nested_ns(node): + ns = {} + ns['ns_id'] = node['name'] + ns['description'] = node['description'] + ns['properties'] = node['properties'] + ns['networks'] = self.get_networks(node) + + nss.append(ns) + return nss + + def is_nested_ns(self, node): + return node['nodeType'].upper().find('.NS.') >= 0 or node['nodeType'].upper().endswith('.NS') diff --git a/lcm/pub/utils/toscaparser/nsdmodel.py b/lcm/pub/utils/toscaparser/nsdmodel.py index b25c5e0f..e13f0265 100644 --- a/lcm/pub/utils/toscaparser/nsdmodel.py +++ b/lcm/pub/utils/toscaparser/nsdmodel.py @@ -42,6 +42,7 @@ class EtsiNsdInfoModel(BaseInfoModel): self.ns_exposed = self.get_all_endpoint_exposed(tosca.topology_template) self.policies = self._get_policies_scaling(tosca.topology_template.policies) 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): diff --git a/requirements.txt b/requirements.txt index e9f7ce6b..9fb0e899 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,4 +26,5 @@ mock==2.0.0 unittest_xml_reporting==1.12.0 # for parser +paramiko==2.0.2 nfv-toscaparser==0.5.0.dev95 |