diff options
Diffstat (limited to 'src/onapsdk/sdnc')
5 files changed, 294 insertions, 0 deletions
diff --git a/src/onapsdk/sdnc/__init__.py b/src/onapsdk/sdnc/__init__.py new file mode 100644 index 0000000..8bc40e8 --- /dev/null +++ b/src/onapsdk/sdnc/__init__.py @@ -0,0 +1,15 @@ +"""SDNC package.""" +# Copyright 2022 Orange, Deutsche Telekom AG +# +# 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. +from .preload import NetworkPreload, VfModulePreload diff --git a/src/onapsdk/sdnc/preload.py b/src/onapsdk/sdnc/preload.py new file mode 100644 index 0000000..8b00e5c --- /dev/null +++ b/src/onapsdk/sdnc/preload.py @@ -0,0 +1,148 @@ +"""SDNC preload module.""" +# Copyright 2022 Orange, Deutsche Telekom AG +# +# 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. +from typing import Any, Dict, Iterable + +from onapsdk.utils.headers_creator import headers_sdnc_creator +from onapsdk.utils.jinja import jinja_env + +from .sdnc_element import SdncElement + + +class Preload(SdncElement): + """Preload base class.""" + + headers: Dict[str, str] = headers_sdnc_creator(SdncElement.headers) + + +class PreloadInformation(Preload): + """Preload information.""" + + def __init__(self, preload_id: str, preload_type: str, preload_data: Dict[str, Any]) -> None: + """Preload information initialization. + + Args: + preload_id (str): Preload id + preload_type (str): Preload type + preload_data (Dict[str, Any]): Preload data + """ + super().__init__() + self.preload_id: str = preload_id + self.preload_type: str = preload_type + self.preload_data: Dict[str, Any] = preload_data + + def __repr__(self) -> str: # noqa + """Preload information human readble string. + + Returns: + str: Preload information description + + """ + return (f"PreloadInformation(preload_id={self.preload_id}, " + f"preload_type={self.preload_type}, " + f"preload_data={self.preload_data})") + + @classmethod + def get_all(cls) -> Iterable["PreloadInformation"]: + """Get all preload informations. + + Get all uploaded preloads. + + Yields: + PreloadInformation: Preload information object + + """ + for preload_information in \ + cls.send_message_json(\ + "GET",\ + "Get SDNC preload information",\ + f"{cls.base_url}/restconf/operational/GENERIC-RESOURCE-API:preload-information" + ).get('preload-information', {}).get('preload-list', []): + yield PreloadInformation(preload_id=preload_information["preload-id"], + preload_type=preload_information["preload-type"], + preload_data=preload_information["preload-data"]) + + +class NetworkPreload(Preload): + """Class to upload network module preload.""" + + @classmethod + def upload_network_preload(cls, + network: "Network", + network_instance_name: str, + subnets: Iterable["Subnet"] = None) -> None: + """Upload network preload. + + Args: + network: Network object + network_instance_name (str): network instance name + subnets (Iterable[Subnet], optional): Iterable object of Subnet. + Defaults to None. + + """ + cls.send_message_json( + "POST", + "Upload Network preload using GENERIC-RESOURCE-API", + (f"{cls.base_url}/restconf/operations/" + "GENERIC-RESOURCE-API:preload-network-topology-operation"), + data=jinja_env().get_template( + "instantiate_network_ala_carte_upload_preload_gr_api.json.j2"). + render( + network=network, + network_instance_name=network_instance_name, + subnets=subnets if subnets else [] + ) + ) + + +class VfModulePreload(Preload): + """Class to upload vf module preload.""" + + @classmethod + def upload_vf_module_preload(cls, # pylint: disable=too-many-arguments + vnf_instance: "VnfInstance", + vf_module_instance_name: str, + vf_module: "VfModule", + vnf_parameters: Iterable["InstantiationParameter"] = None) -> None: + """Upload vf module preload. + + Args: + vnf_instance: VnfInstance object + vf_module_instance_name (str): VF module instance name + vf_module (VfModule): VF module + vnf_parameters (Iterable[InstantiationParameter], optional): Iterable object + of InstantiationParameter. Defaults to None. + + """ + vnf_para = [] + if vnf_parameters: + for vnf_parameter in vnf_parameters: + vnf_para.append({ + "name": vnf_parameter.name, + "value": vnf_parameter.value + }) + cls.send_message_json( + "POST", + "Upload VF module preload using GENERIC-RESOURCE-API", + (f"{cls.base_url}/restconf/operations/" + "GENERIC-RESOURCE-API:preload-vf-module-topology-operation"), + data=jinja_env().get_template( + "instantiate_vf_module_ala_carte_upload_preload_gr_api.json.j2"). + render( + vnf_instance=vnf_instance, + vf_module_instance_name=vf_module_instance_name, + vf_module=vf_module, + vnf_parameters=vnf_para + ) + ) diff --git a/src/onapsdk/sdnc/sdnc_element.py b/src/onapsdk/sdnc/sdnc_element.py new file mode 100644 index 0000000..84f56d9 --- /dev/null +++ b/src/onapsdk/sdnc/sdnc_element.py @@ -0,0 +1,48 @@ +"""SDNC base module.""" +# Copyright 2022 Orange, Deutsche Telekom AG +# +# 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. +from onapsdk.configuration import settings +from onapsdk.onap_service import OnapService +from onapsdk.utils.gui import GuiItem, GuiList + + +class SdncElement(OnapService): + """SDNC base class.""" + + base_url = settings.SDNC_URL + + @classmethod + def get_guis(cls) -> GuiItem: + """Retrieve the status of the SDNC GUIs. + + There are 2 GUIS + - SDNC DG Builder + - SDNC ODL + + Return the list of GUIs + """ + guilist = GuiList([]) + url = settings.SDNC_DG_GUI_SERVICE + response = cls.send_message( + "GET", "Get SDNC GUI DG Status", url) + guilist.add(GuiItem( + url, + response.status_code)) + url = settings.SDNC_ODL_GUI_SERVICE + response = cls.send_message( + "GET", "Get SDNC ODL GUI Status", url) + guilist.add(GuiItem( + url, + response.status_code)) + return guilist diff --git a/src/onapsdk/sdnc/templates/instantiate_network_ala_carte_upload_preload_gr_api.json.j2 b/src/onapsdk/sdnc/templates/instantiate_network_ala_carte_upload_preload_gr_api.json.j2 new file mode 100644 index 0000000..9eead38 --- /dev/null +++ b/src/onapsdk/sdnc/templates/instantiate_network_ala_carte_upload_preload_gr_api.json.j2 @@ -0,0 +1,42 @@ +{ + "input": { + "preload-network-topology-information": { + "network-policy": [], + "route-table-reference": [], + "vpn-bindings": [], + "network-topology-identifier-structure": { + "network-role": "integration_test_net", + "network-technology": "neutron", + "network-name": "{{ network_instance_name }}", + "network-type": "Generic NeutronNet" + }, + "is-external-network": false, + "is-shared-network": false, + "is-provider-network": false, + "physical-network-name": "Not Aplicable", + "subnets": [ + {% for subnet in subnets %} + { + "subnet-name": "{{ subnet.name }}", + "start-address": "{{ subnet.start_address }}", + "cidr-mask": "{{ subnet.cidr_mask }}", + "ip-version": "{{ subnet.ip_version }}", + {% if subnet.dhcp_enabled %} + "dhcp-enabled": "Y", + "dhcp-start-address": "{{ subnet.dhcp_start_address }}", + "dhcp-end-address": "{{ subnet.dhcp_end_address }}", + {% else %} + "dhcp-enabled": "N", + {% endif %} + "gateway-address": "{{ subnet.gateway_address }}" + }{% if not loop.last %},{% endif %} + {% endfor %} + ] + }, + "sdnc-request-header": { + "svc-request-id": "test", + "svc-notification-url": "http:\/\/onap.org:8080\/adapters\/rest\/SDNCNotify", + "svc-action": "reserve" + } + } +} diff --git a/src/onapsdk/sdnc/templates/instantiate_vf_module_ala_carte_upload_preload_gr_api.json.j2 b/src/onapsdk/sdnc/templates/instantiate_vf_module_ala_carte_upload_preload_gr_api.json.j2 new file mode 100644 index 0000000..eaa5936 --- /dev/null +++ b/src/onapsdk/sdnc/templates/instantiate_vf_module_ala_carte_upload_preload_gr_api.json.j2 @@ -0,0 +1,41 @@ +{ + "input":{ + "preload-vf-module-topology-information":{ + "vf-module-topology":{ + "vf-module-topology-identifier":{ + "vf-module-name":"{{vf_module_instance_name}}" + }, + "vf-module-parameters": { + "param": {{ vnf_parameters }} + } + }, + "vnf-topology-identifier-structure":{ + "vnf-name":"{{vnf_instance.vnf_name}}", + "vnf-type":"{{vnf_instance.vnf_type}}" + }, + "vnf-resource-assignments":{ + "availability-zones":{ + "availability-zone":[ + "nova" + ], + "max-count":1 + }, + "vnf-networks":{ + "vnf-network":[] + } + } + }, + "request-information":{ + "request-id":"test", + "order-version":"1", + "notification-url":"onap.org", + "order-number":"1", + "request-action":"PreloadVfModuleRequest" + }, + "sdnc-request-header":{ + "svc-request-id":"test", + "svc-notification-url":"http:\/\/onap.org:8080\/adapters\/rest\/SDNCNotify", + "svc-action":"reserve" + } + } +} |