From: ying.yunlong Date: Wed, 16 Aug 2017 08:13:13 +0000 (+0800) Subject: Add parse package logic X-Git-Tag: v1.0.0~183^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F99%2F7699%2F2;p=vfc%2Fnfvo%2Flcm.git Add parse package logic Call tosca parser to parse nsd and vnfd package. Change-Id: I07ae89e314f70e99d929fc2eb929d6549d819b57 Issue-ID: VFC-97 Signed-off-by: ying.yunlong --- diff --git a/lcm/pub/utils/toscaparser/parser.py b/lcm/pub/utils/toscaparser/parser.py index e1692ed4..9b7e655b 100644 --- a/lcm/pub/utils/toscaparser/parser.py +++ b/lcm/pub/utils/toscaparser/parser.py @@ -11,24 +11,42 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from os import R_OK, access +from lcm.pub.exceptions import NSLCMException def parse_nsd_model(path, input_parameters): - check_file_exist(path) - nsd_tpl = parse_nsd_csar(path, input_parameters) + isexist = check_file_exist(path) + if isexist: + nsd_tpl = parse_nsd_csar(path, input_parameters) + else: + raise NSLCMException('%s is not exist.' % path) return nsd_tpl def parse_vnfd_model(path, input_parameters): - check_file_exist(path) - vnfd_tpl = parse_vnfd_csar(path, input_parameters) + isexist = check_file_exist(path) + if isexist: + vnfd_tpl = parse_vnfd_csar(path, input_parameters) + else: + raise NSLCMException('%s is not exist.' % path) return vnfd_tpl def check_file_exist(path): - pass + if path.exists(path) and path.isfile(path) and access(path, R_OK): + return True + else: + return False def parse_nsd_csar(path, input_parameters=[], a_file=True): - pass + nsd_object = None + from toscaparser.tosca_template import ToscaTemplate + nsd_object = ToscaTemplate(path, input_parameters) + return nsd_object + def parse_vnfd_csar(path, input_parameters=[], a_file=True): - pass \ No newline at end of file + vnfd_object = None + from toscaparser.tosca_template import ToscaTemplate + vnfd_object = ToscaTemplate(path, input_parameters) + return vnfd_object \ No newline at end of file