Add parse package logic 99/7699/2
authorying.yunlong <ying.yunlong@zte.com.cn>
Wed, 16 Aug 2017 08:13:13 +0000 (16:13 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Wed, 16 Aug 2017 09:35:59 +0000 (17:35 +0800)
Call tosca parser to parse nsd and
vnfd package.

Change-Id: I07ae89e314f70e99d929fc2eb929d6549d819b57
Issue-ID: VFC-97
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
lcm/pub/utils/toscaparser/parser.py

index e1692ed..9b7e655 100644 (file)
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
 # See the License for the specific language governing permissions and\r
 # limitations under the License.\r
+from os import R_OK, access\r
 \r
+from lcm.pub.exceptions import NSLCMException\r
 \r
 def parse_nsd_model(path, input_parameters):\r
-    check_file_exist(path)\r
-    nsd_tpl = parse_nsd_csar(path, input_parameters)\r
+    isexist = check_file_exist(path)\r
+    if isexist:\r
+        nsd_tpl = parse_nsd_csar(path, input_parameters)\r
+    else:\r
+        raise NSLCMException('%s is not exist.' % path)\r
     return nsd_tpl\r
 \r
 \r
 def parse_vnfd_model(path, input_parameters):\r
-    check_file_exist(path)\r
-    vnfd_tpl = parse_vnfd_csar(path, input_parameters)\r
+    isexist = check_file_exist(path)\r
+    if isexist:\r
+        vnfd_tpl = parse_vnfd_csar(path, input_parameters)\r
+    else:\r
+        raise NSLCMException('%s is not exist.' % path)\r
     return vnfd_tpl\r
 \r
 def check_file_exist(path):\r
-    pass\r
+    if path.exists(path) and path.isfile(path) and access(path, R_OK):\r
+        return True\r
+    else:\r
+        return False\r
 \r
 def parse_nsd_csar(path, input_parameters=[], a_file=True):\r
-    pass\r
+    nsd_object = None\r
+    from toscaparser.tosca_template import ToscaTemplate\r
+    nsd_object = ToscaTemplate(path, input_parameters)\r
+    return nsd_object\r
+\r
 \r
 def parse_vnfd_csar(path, input_parameters=[], a_file=True):\r
-    pass
\ No newline at end of file
+    vnfd_object = None\r
+    from toscaparser.tosca_template import ToscaTemplate\r
+    vnfd_object = ToscaTemplate(path, input_parameters)\r
+    return vnfd_object
\ No newline at end of file