aboutsummaryrefslogtreecommitdiffstats
path: root/ice_validator/preload_vnfapi
diff options
context:
space:
mode:
Diffstat (limited to 'ice_validator/preload_vnfapi')
-rw-r--r--ice_validator/preload_vnfapi/__init__.py39
-rw-r--r--ice_validator/preload_vnfapi/vnfapi_data/preload_template.json30
-rw-r--r--ice_validator/preload_vnfapi/vnfapi_data/vf-module-parameter.json4
-rw-r--r--ice_validator/preload_vnfapi/vnfapi_data/vm-network.json12
-rw-r--r--ice_validator/preload_vnfapi/vnfapi_data/vm.json8
-rw-r--r--ice_validator/preload_vnfapi/vnfapi_data/vnf-network.json4
-rw-r--r--ice_validator/preload_vnfapi/vnfapi_generator.py160
7 files changed, 257 insertions, 0 deletions
diff --git a/ice_validator/preload_vnfapi/__init__.py b/ice_validator/preload_vnfapi/__init__.py
new file mode 100644
index 0000000..021c8fe
--- /dev/null
+++ b/ice_validator/preload_vnfapi/__init__.py
@@ -0,0 +1,39 @@
+# -*- coding: utf8 -*-
+# ============LICENSE_START====================================================
+# org.onap.vvp/validation-scripts
+# ===================================================================
+# Copyright © 2019 AT&T Intellectual Property. All rights reserved.
+# ===================================================================
+#
+# Unless otherwise specified, all software contained herein is licensed
+# under the Apache License, Version 2.0 (the "License");
+# you may not use this software 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.
+#
+#
+#
+# Unless otherwise specified, all documentation contained herein is licensed
+# under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+# you may not use this documentation except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://creativecommons.org/licenses/by/4.0/
+#
+# Unless required by applicable law or agreed to in writing, documentation
+# 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.
+#
+# ============LICENSE_END============================================
+from .vnfapi_generator import VnfApiPreloadGenerator
+
+__all__ = ["VnfApiPreloadGenerator"]
diff --git a/ice_validator/preload_vnfapi/vnfapi_data/preload_template.json b/ice_validator/preload_vnfapi/vnfapi_data/preload_template.json
new file mode 100644
index 0000000..dfa6cf2
--- /dev/null
+++ b/ice_validator/preload_vnfapi/vnfapi_data/preload_template.json
@@ -0,0 +1,30 @@
+{
+ "input": {
+ "request-information": {
+ "request-id": "robot12",
+ "order-version": "1",
+ "notification-url": "openecomp.org",
+ "order-number": "1",
+ "request-action": "PreloadVNFRequest"
+ },
+ "sdnc-request-header": {
+ "svc-request-id": "robot12",
+ "svc-notification-url": "http://openecomp.org:8080/adapters/rest/SDNCNotify",
+ "svc-action": "reserve"
+ },
+ "vnf-topology-information": {
+ "vnf-topology-identifier": {
+ "vnf-name": "",
+ "vnf-type": "",
+ "generic-vnf-type": "",
+ "generic-vnf-name": ""
+ },
+ "vnf-assignments": {
+ "availability-zones": [],
+ "vnf-networks": [],
+ "vnf-vms": []
+ },
+ "vnf-parameters": []
+ }
+ }
+} \ No newline at end of file
diff --git a/ice_validator/preload_vnfapi/vnfapi_data/vf-module-parameter.json b/ice_validator/preload_vnfapi/vnfapi_data/vf-module-parameter.json
new file mode 100644
index 0000000..a7ad3b8
--- /dev/null
+++ b/ice_validator/preload_vnfapi/vnfapi_data/vf-module-parameter.json
@@ -0,0 +1,4 @@
+{
+ "vnf-parameter-name": "",
+ "vnf-parameter-value": ""
+}
diff --git a/ice_validator/preload_vnfapi/vnfapi_data/vm-network.json b/ice_validator/preload_vnfapi/vnfapi_data/vm-network.json
new file mode 100644
index 0000000..52231c3
--- /dev/null
+++ b/ice_validator/preload_vnfapi/vnfapi_data/vm-network.json
@@ -0,0 +1,12 @@
+{
+ "network-role": "",
+ "network-role-tag": "",
+ "ip-count": 0,
+ "ip-count-ipv6": 0,
+ "floating-ip": "",
+ "floating-ip-v6": "",
+ "network-ips": [],
+ "network-ips-v6": [],
+ "network-macs": [],
+ "interface-route-prefixes": []
+}
diff --git a/ice_validator/preload_vnfapi/vnfapi_data/vm.json b/ice_validator/preload_vnfapi/vnfapi_data/vm.json
new file mode 100644
index 0000000..d00e048
--- /dev/null
+++ b/ice_validator/preload_vnfapi/vnfapi_data/vm.json
@@ -0,0 +1,8 @@
+{
+ "vm-type": "",
+ "vm-count": 0,
+ "vm-names": {
+ "vm-name": []
+ },
+ "vm-networks": []
+}
diff --git a/ice_validator/preload_vnfapi/vnfapi_data/vnf-network.json b/ice_validator/preload_vnfapi/vnfapi_data/vnf-network.json
new file mode 100644
index 0000000..89af15f
--- /dev/null
+++ b/ice_validator/preload_vnfapi/vnfapi_data/vnf-network.json
@@ -0,0 +1,4 @@
+{
+ "network-role": "",
+ "network-name": ""
+}
diff --git a/ice_validator/preload_vnfapi/vnfapi_generator.py b/ice_validator/preload_vnfapi/vnfapi_generator.py
new file mode 100644
index 0000000..bf4c61c
--- /dev/null
+++ b/ice_validator/preload_vnfapi/vnfapi_generator.py
@@ -0,0 +1,160 @@
+# -*- coding: utf8 -*-
+# ============LICENSE_START====================================================
+# org.onap.vvp/validation-scripts
+# ===================================================================
+# Copyright © 2019 AT&T Intellectual Property. All rights reserved.
+# ===================================================================
+#
+# Unless otherwise specified, all software contained herein is licensed
+# under the Apache License, Version 2.0 (the "License");
+# you may not use this software 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.
+#
+#
+#
+# Unless otherwise specified, all documentation contained herein is licensed
+# under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+# you may not use this documentation except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://creativecommons.org/licenses/by/4.0/
+#
+# Unless required by applicable law or agreed to in writing, documentation
+# 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.
+#
+# ============LICENSE_END============================================
+#
+#
+
+import json
+import os
+
+from preload import (
+ AbstractPreloadGenerator,
+ get_json_template,
+ get_or_create_template,
+ replace,
+)
+
+THIS_DIR = os.path.dirname(os.path.abspath(__file__))
+DATA_DIR = os.path.join(THIS_DIR, "vnfapi_data")
+
+
+def add_fixed_ips(network_template, port):
+ for ip in port.fixed_ips:
+ if ip.ip_version == 4:
+ network_template["network-ips"].append({"ip-address": replace(ip.param)})
+ network_template["ip-count"] += 1
+ else:
+ network_template["network-ips-v6"].append({"ip-address": replace(ip.param)})
+ network_template["ip-count-ipv6"] += 1
+
+
+def add_floating_ips(network_template, network):
+ # only one floating IP is really supported, in the preload model
+ # so for now we'll just use the last one. We might revisit this
+ # and if multiple floating params exist, then come up with an
+ # approach to pick just one
+ for ip in network.floating_ips:
+ key = "floating-ip" if ip.ip_version == 4 else "floating-ip-v6"
+ network_template[key] = replace(ip.param)
+
+
+def get_or_create_network_template(network_role, vm_networks):
+ """
+ If the network role already exists in vm_networks, then
+ return that otherwise create a blank template and return that
+ """
+ return get_or_create_template(
+ DATA_DIR, "network-role", network_role, vm_networks, "vm-network"
+ )
+
+
+class VnfApiPreloadGenerator(AbstractPreloadGenerator):
+ @classmethod
+ def supports_output_passing(cls):
+ return False
+
+ @classmethod
+ def format_name(cls):
+ return "VNF-API"
+
+ @classmethod
+ def output_sub_dir(cls):
+ return "vnfapi"
+
+ def generate_module(self, vnf_module):
+ preload = get_json_template(DATA_DIR, "preload_template")
+ self._populate(preload, vnf_module)
+ outfile = "{}/{}.json".format(self.output_dir, vnf_module.vnf_name)
+ with open(outfile, "w") as f:
+ json.dump(preload, f, indent=4)
+
+ def _populate(self, preload, vnf_module):
+ self._add_availability_zones(preload, vnf_module)
+ self._add_vnf_networks(preload, vnf_module)
+ self._add_vms(preload, vnf_module)
+ self._add_parameters(preload, vnf_module)
+
+ @staticmethod
+ def _add_availability_zones(preload, vnf_module):
+ zones = preload["input"]["vnf-topology-information"]["vnf-assignments"][
+ "availability-zones"
+ ]
+ for zone in vnf_module.availability_zones:
+ zones.append({"availability-zone": replace(zone)})
+
+ @staticmethod
+ def _add_vnf_networks(preload, vnf_module):
+ networks = preload["input"]["vnf-topology-information"]["vnf-assignments"][
+ "vnf-networks"
+ ]
+ for network in vnf_module.networks:
+ network_data = {
+ "network-role": network.network_role,
+ "network-name": replace(
+ "network name for {}".format(network.name_param)
+ ),
+ }
+ for subnet in network.subnet_params:
+ key = "ipv6-subnet-id" if "_v6_" in subnet else "subnet-id"
+ network_data[key] = subnet
+ networks.append(network_data)
+
+ @staticmethod
+ def _add_vms(preload, vnf_module):
+ vm_list = preload["input"]["vnf-topology-information"]["vnf-assignments"][
+ "vnf-vms"
+ ]
+ for vm in vnf_module.virtual_machine_types:
+ vm_template = get_json_template(DATA_DIR, "vm")
+ vm_template["vm-type"] = vm.vm_type
+ vm_template["vm-count"] = vm.vm_count
+ vm_template["vm-names"]["vm-name"].extend(map(replace, vm.names))
+ vm_list.append(vm_template)
+ vm_networks = vm_template["vm-networks"]
+ for port in vm.ports:
+ role = port.network.network_role
+ network_template = get_or_create_network_template(role, vm_networks)
+ network_template["network-role"] = role
+ network_template["network-role-tag"] = role
+ network_template["use-dhcp"] = "Y" if port.uses_dhcp else "N"
+ add_fixed_ips(network_template, port)
+ add_floating_ips(network_template, port)
+
+ @staticmethod
+ def _add_parameters(preload, vnf_module):
+ params = preload["input"]["vnf-topology-information"]["vnf-parameters"]
+ for key, value in vnf_module.preload_parameters.items():
+ params.append({"vnf-parameter-name": key, "vnf-parameter-value": value})