diff options
author | Lovett, Trevor <trevor.lovett@att.com> | 2019-07-30 08:50:48 -0700 |
---|---|---|
committer | Lovett, Trevor (tl2972) <tl2972@att.com> | 2019-08-16 16:42:09 -0500 |
commit | 940ae7b0283191d590de40b71a9136bebc80e83c (patch) | |
tree | 8924052bded9411f87212969e1e51ee388e2be20 /ice_validator/preload_grapi | |
parent | 14c5243cbbb0652ee9ad99519d7d456f5a6c88f4 (diff) |
[VVP] Adding preload generation functionality
preload.py discovers and loads implementations of
AbstractPreloadGenerator from any module on sys.path prefixed with
preload_*
Initial support is provided for VNF-API and GR-API. The templates
will provide a guide for users to provide their values.
Known limitations:
- No support for Contrail. Preload will be created, but contrail
parameters will be skipped. This will be addressed in the future.
Issue-ID: VVP-227
Signed-off-by: stark, steven <steven.stark@att.com>
Change-Id: I081d50ac379062fbf1bffebd687e920220d32571
Signed-off-by: Lovett, Trevor <trevor.lovett@att.com>
Signed-off-by: Lovett, Trevor (tl2972) <tl2972@att.com>
Diffstat (limited to 'ice_validator/preload_grapi')
7 files changed, 310 insertions, 0 deletions
diff --git a/ice_validator/preload_grapi/__init__.py b/ice_validator/preload_grapi/__init__.py new file mode 100644 index 0000000..2e4e0ec --- /dev/null +++ b/ice_validator/preload_grapi/__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 .grapi_generator import GrApiPreloadGenerator + +__all__ = ["GrApiPreloadGenerator"] diff --git a/ice_validator/preload_grapi/grapi_data/preload_template.json b/ice_validator/preload_grapi/grapi_data/preload_template.json new file mode 100644 index 0000000..0ef9025 --- /dev/null +++ b/ice_validator/preload_grapi/grapi_data/preload_template.json @@ -0,0 +1,44 @@ +{ + "input": { + "request-information": { + "request-id": "robot12", + "order-version": "1", + "notification-url": "openecomp.org", + "order-number": "1", + "request-action": "PreloadVfModuleRequest" + }, + "sdnc-request-header": { + "svc-request-id": "robot12", + "svc-notification-url": "http://openecomp.org:8080/adapters/rest/SDNCNotify", + "svc-action": "reserve" + }, + "preload-vf-module-topology-information": { + "vnf-topology-identifier-structure": { + "vnf-name": "", + "vnf-type": "" + }, + "vnf-resource-assignments": { + "availability-zones": { + "availability-zone": [] + }, + "vnf-networks": { + "vnf-network": [] + } + }, + "vf-module-topology": { + "vf-module-assignments": { + "vms": { + "vm": [] + } + }, + "vf-module-topology-identifier": { + "vf-module-type": "", + "vf-module-name": "" + }, + "vf-module-parameters": { + "param": [] + } + } + } + } +} diff --git a/ice_validator/preload_grapi/grapi_data/vf-module-parameter.json b/ice_validator/preload_grapi/grapi_data/vf-module-parameter.json new file mode 100644 index 0000000..01fd01d --- /dev/null +++ b/ice_validator/preload_grapi/grapi_data/vf-module-parameter.json @@ -0,0 +1,4 @@ +{ + "name": "", + "value": "" +} diff --git a/ice_validator/preload_grapi/grapi_data/vm-network.json b/ice_validator/preload_grapi/grapi_data/vm-network.json new file mode 100644 index 0000000..d9849b8 --- /dev/null +++ b/ice_validator/preload_grapi/grapi_data/vm-network.json @@ -0,0 +1,33 @@ +{ + "network-role": "", + "network-information-items": { + "network-information-item": [ + { + "ip-version": "4", + "use-dhcp": "N", + "ip-count": 0, + "network-ips": { + "network-ip": [] + } + }, + { + "ip-version": "6", + "use-dhcp": "N", + "ip-count": 0, + "network-ips": { + "network-ip": [] + } + } + ] + }, + "mac-addresses": { + "mac-address": [] + }, + "floating-ips": { + "floating-ip-v4": [], + "floating-ip-v6": [] + }, + "interface-route-prefixes": { + "interface-route-prefix": [] + } +} diff --git a/ice_validator/preload_grapi/grapi_data/vm.json b/ice_validator/preload_grapi/grapi_data/vm.json new file mode 100644 index 0000000..20f1d9e --- /dev/null +++ b/ice_validator/preload_grapi/grapi_data/vm.json @@ -0,0 +1,10 @@ +{ + "vm-type": "", + "vm-count": 0, + "vm-names": { + "vm-name": [] + }, + "vm-networks": { + "vm-network": [] + } +} diff --git a/ice_validator/preload_grapi/grapi_data/vnf-network.json b/ice_validator/preload_grapi/grapi_data/vnf-network.json new file mode 100644 index 0000000..89af15f --- /dev/null +++ b/ice_validator/preload_grapi/grapi_data/vnf-network.json @@ -0,0 +1,4 @@ +{ + "network-role": "", + "network-name": "" +} diff --git a/ice_validator/preload_grapi/grapi_generator.py b/ice_validator/preload_grapi/grapi_generator.py new file mode 100644 index 0000000..bc338c3 --- /dev/null +++ b/ice_validator/preload_grapi/grapi_generator.py @@ -0,0 +1,176 @@ +# -*- 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_or_create_template, + get_json_template, + replace, +) + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) +DATA_DIR = os.path.join(THIS_DIR, "grapi_data") + + +def get_or_create_network_template(network, 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, vm_networks, "vm-network" + ) + + +def add_fixed_ips(network_template, fixed_ips, uses_dhcp): + items = network_template["network-information-items"]["network-information-item"] + ipv4s = next(item for item in items if item["ip-version"] == "4") + ipv6s = next(item for item in items if item["ip-version"] == "6") + if uses_dhcp: + ipv4s["use-dhcp"] = "Y" + ipv6s["use-dhcp"] = "Y" + for ip in fixed_ips: + target = ipv4s if ip.ip_version == 4 else ipv6s + ips = target["network-ips"]["network-ip"] + if ip.param not in ips: + ips.append(replace(ip.param)) + target["ip-count"] += 1 + + +def add_floating_ips(network_template, floating_ips): + for ip in floating_ips: + key = "floating-ip-v4" if ip.ip_version == 4 else "floating-ip-v6" + ips = network_template["floating-ips"][key] + value = replace(ip.param) + if value not in ips: + ips.append(value) + + +class GrApiPreloadGenerator(AbstractPreloadGenerator): + @classmethod + def supports_output_passing(cls): + return True + + @classmethod + def format_name(cls): + return "GR-API" + + @classmethod + def output_sub_dir(cls): + return "grapi" + + def generate_module(self, vnf_module): + template = get_json_template(DATA_DIR, "preload_template") + self._populate(template, vnf_module) + vnf_name = vnf_module.vnf_name + outfile = "{}/{}.json".format(self.output_dir, vnf_name) + with open(outfile, "w") as f: + json.dump(template, f, indent=4) + + def _populate(self, preload, vnf_module): + self._add_vnf_metadata(preload) + self._add_vms(preload, vnf_module) + self._add_availability_zones(preload, vnf_module) + self._add_parameters(preload, vnf_module) + self._add_vnf_networks(preload, vnf_module) + + @staticmethod + def _add_vms(preload, vnf_module): + vms = preload["input"]["preload-vf-module-topology-information"][ + "vf-module-topology" + ]["vf-module-assignments"]["vms"]["vm"] + for vm in vnf_module.virtual_machine_types: + vm_template = get_json_template(DATA_DIR, "vm") + vms.append(vm_template) + vm_template["vm-type"] = vm.vm_type + vm_template["vm-names"]["vm-name"].extend(map(replace, vm.names)) + vm_template["vm-count"] = vm.vm_count + vm_networks = vm_template["vm-networks"]["vm-network"] + 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 + add_fixed_ips(network_template, port.fixed_ips, port.uses_dhcp) + add_floating_ips(network_template, port.floating_ips) + + @staticmethod + def _add_availability_zones(preload, vnf_module): + zones = preload["input"]["preload-vf-module-topology-information"][ + "vnf-resource-assignments" + ]["availability-zones"]["availability-zone"] + zones.extend(map(replace, vnf_module.availability_zones)) + + @staticmethod + def _add_parameters(preload, vnf_module): + params = [ + {"name": key, "value": value} + for key, value in vnf_module.preload_parameters.items() + ] + preload["input"]["preload-vf-module-topology-information"][ + "vf-module-topology" + ]["vf-module-parameters"]["param"].extend(params) + + @staticmethod + def _add_vnf_networks(preload, vnf_module): + networks = preload["input"]["preload-vf-module-topology-information"][ + "vnf-resource-assignments" + ]["vnf-networks"]["vnf-network"] + for network in vnf_module.networks: + network_data = { + "network-role": network.network_role, + "network-name": replace("network name of {}".format(network.name_param)), + } + if network.subnet_params: + network_data["subnets-data"] = {"subnet-data": []} + subnet_data = network_data["subnets-data"]["subnet-data"] + for subnet_param in network.subnet_params: + subnet_data.append({"subnet-id": replace(subnet_param)}) + networks.append(network_data) + + @staticmethod + def _add_vnf_metadata(preload): + topology = preload["input"]["preload-vf-module-topology-information"] + vnf_meta = topology["vnf-topology-identifier-structure"] + vnf_meta["vnf-name"] = replace("vnf_name") + vnf_meta["vnf-type"] = replace("Concatenation of " + "<Service Name>/<VF Instance Name> " + "MUST MATCH SDC") + module_meta = topology["vf-module-topology"]["vf-module-topology-identifier"] + module_meta["vf-module-name"] = replace("vf_module_name") + module_meta["vf-module-type"] = replace("<vfModuleModelName> from CSAR or SDC") |