+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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.
+
*.pyc
.cache
.eggs
*egg-info
*.gz
-osm_im
osm_im_trees
dists
pool
openapi_schemas: $(OPENAPI_SCHEMAS)
-$(OUT_DIR):
- $(Q)mkdir -p $(OUT_DIR)
- $(Q)touch $(OUT_DIR)/__init__.py
-
$(TREES_DIR):
$(Q)mkdir -p $(TREES_DIR)
-%.py: $(OUT_DIR) yang-ietf
+%.py: yang-ietf
$(Q)echo generating $@ from $*.yang
$(Q)pyang $(PYANG_OPTIONS) --path $(MODEL_DIR) --plugindir $(PYBINDPLUGIN) -f pybind -o $(OUT_DIR)/$@ $(MODEL_DIR)/$*.yang
$(Q)sed -r -i 's|<a href=\"http://www.tail-f.com">|<a href="http://osm.etsi.org">|g' $(TREES_DIR)/$@
$(Q)mv $(TREES_DIR)/$@ $(TREES_DIR)/$*.html
-osm.yaml: $(OUT_DIR) yang-ietf yang2swagger
+osm.yaml: yang-ietf yang2swagger
$(Q)echo generating $@
$(Q)$(JAVA) -jar ${HOME}/.m2/repository/com/mrv/yangtools/swagger-generator-cli/1.1.11/swagger-generator-cli-1.1.11-executable.jar -yang-dir $(MODEL_DIR) -output $(OUT_DIR)/$@
$(Q)cp -n ~/.m2/settings.xml{,.orig} ; wget -q -O - https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml > ~/.m2/settings.xml
clean:
- $(Q)rm -rf dist osm_im.egg-info deb deb_dist *.gz osm-imdocs* yang2swagger $(OUT_DIR) $(TREES_DIR)
+ $(Q)rm -rf dist osm_im.egg-info deb deb_dist *.gz osm-imdocs* yang2swagger $(TREES_DIR)
--- /dev/null
+##
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, 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.
+##
--- /dev/null
+# -*- coding: utf-8 -*-
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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.
+
+import yaml
+import json
+# import logging
+from osm_im.vnfd import vnfd as vnfd_im
+from osm_im.nsd import nsd as nsd_im
+from osm_im.nst import nst as nst_im
+from pyangbind.lib.serialise import pybindJSONDecoder
+import pyangbind.lib.pybindJSON as pybindJSON
+
+class ValidationException(Exception):
+ pass
+
+class Validation():
+
+ def pyangbind_validation(self, item, data, force=False):
+ '''
+ item: vnfd, nst, nsd
+ data: dict object loaded from the descriptor file
+ force: True to skip unknown fields in the descriptor
+ '''
+ if item == "vnfd":
+ myobj = vnfd_im()
+ elif item == "nsd":
+ myobj = nsd_im()
+ elif item == "nst":
+ myobj = nst_im()
+ else:
+ raise ValidationException("Not possible to validate '{}' item".format(item))
+
+ try:
+ pybindJSONDecoder.load_ietf_json(data, None, None, obj=myobj,
+ path_helper=True, skip_unknown=force)
+ out = pybindJSON.dumps(myobj, mode="ietf")
+ desc_out = yaml.safe_load(out)
+ return desc_out
+ except Exception as e:
+ raise ValidationException("Error in pyangbind validation: {}".format(str(e)))
+
+ def yaml_validation(self, descriptor):
+ try:
+ data = yaml.safe_load(descriptor)
+ except Exception as e:
+ raise ValidationException("Error in YAML validation. Not a proper YAML file")
+ if 'vnfd:vnfd-catalog' in data:
+ item = "vnfd"
+ elif 'nsd:nsd-catalog' in data:
+ item = "nsd"
+ elif 'nst' in data:
+ item = "nst"
+ else:
+ raise ValidationException("Error in YAML validation. Not possible to determine the type of descriptor in the first line. Expected values: vnfd:vnfd-catalog, nsd:nsd-catalog, nst")
+
+ return item, data
+
+ def descriptor_validation(self, descriptor):
+ item, data = self.yaml_validation(descriptor)
+ self.pyangbind_validation(item, data)
+
self.pipinstall('pyang')
self.pipinstall('pyangbind')
import pyangbind
- print("Creating dir {}/{} for python artifacts".format(os.getcwd(), self.im_dir))
+ print("Using dir {}/{} for python artifacts".format(os.getcwd(), self.im_dir))
path = "{}/{}".format(os.getcwd(), self.im_dir)
- if not os.path.exists(path):
- os.makedirs(path)
- open("{}/{}/__init__.py".format(os.getcwd(), self.im_dir), 'a').close()
for files_item in ['vnfd', 'nsd', 'nst']:
protoc_command = ["pyang",
"-Werror",