Loading src/device/service/drivers/openconfig/templates/Acl.py +33 −31 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ from .Tools import add_value_from_tag LOGGER = logging.getLogger(__name__) XPATH_ACL_SET = "//ocacl:acl/ocacl:acl-sets/ocacl:acl-set" XPATH_A_ACL_ENTRY = ".//ocacl:acl-entries/ocacl:ecl-entry" XPATH_A_ACL_ENTRY = ".//ocacl:acl-entries/ocacl:acl-entry" XPATH_A_IPv4 = ".//ocacl:ipv4/ocacl:config" XPATH_A_TRANSPORT = ".//ocacl:transport/ocacl:config" XPATH_A_ACTIONS = ".//ocacl:actions/ocacl:config" Loading @@ -34,29 +34,31 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: response = [] acl = {} name = {} for xml_acl in xml_data.xpath(XPATH_ACL_SET, namespaces=NAMESPACES): #LOGGER.info('xml_acl = {:s}'.format(str(ET.tostring(xml_acl)))) acl_name = xml_acl.find('ocacl:name', namespaces=NAMESPACES) if acl_name is None or acl_name.text is None: continue add_value_from_tag(acl, 'name', acl_name) add_value_from_tag(name, 'name', acl_name) acl_type = xml_acl.find('ocacl:type', namespaces=NAMESPACES) add_value_from_tag(acl, 'type', acl_type) for xml_acl_entries in xml_acl.xpath(XPATH_A_ACL_ENTRY, namespaces=NAMESPACES): acl_id = xml_acl_entries.find('ocacl:sequence_id', namespaces=NAMESPACES) add_value_from_tag(acl, 'sequence_id', acl_id) acl_id = xml_acl_entries.find('ocacl:sequence-id', namespaces=NAMESPACES) add_value_from_tag(acl, 'sequence-id', acl_id) LOGGER.info('xml_acl_id = {:s}'.format(str(ET.tostring(acl_id)))) for xml_ipv4 in xml_acl_entries.xpath(XPATH_A_IPv4, namespaces=NAMESPACES): ipv4_source = xml_ipv4.find('ocacl:source_address', namespaces=NAMESPACES) add_value_from_tag(acl, 'source_address' , ipv4_source) ipv4_source = xml_ipv4.find('ocacl:source-address', namespaces=NAMESPACES) add_value_from_tag(acl, 'source-address' , ipv4_source) ipv4_destination = xml_ipv4.find('ocacl:destination_address', namespaces=NAMESPACES) add_value_from_tag(acl, 'destination_address' , ipv4_destination) ipv4_destination = xml_ipv4.find('ocacl:destination-address', namespaces=NAMESPACES) add_value_from_tag(acl, 'destination-address' , ipv4_destination) ipv4_protocol = xml_ipv4.find('ocacl:protocol', namespaces=NAMESPACES) add_value_from_tag(acl, 'protocol' , ipv4_protocol) Loading @@ -64,30 +66,30 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: ipv4_dscp = xml_ipv4.find('ocacl:dscp', namespaces=NAMESPACES) add_value_from_tag(acl, 'dscp' , ipv4_dscp) ipv4_hop_limit = xml_ipv4.find('ocacl:hop_limit', namespaces=NAMESPACES) add_value_from_tag(acl, 'hop_limit' , ipv4_hop_limit) ipv4_hop_limit = xml_ipv4.find('ocacl:hop-limit', namespaces=NAMESPACES) add_value_from_tag(acl, 'hop-limit' , ipv4_hop_limit) for xml_transport in xml_acl_entries.xpath(XPATH_A_TRANSPORT, namespaces=NAMESPACES): transport_source = xml_transport.find('ocacl:source_port', namespaces=NAMESPACES) add_value_from_tag(acl, 'source_port' ,transport_source) transport_source = xml_transport.find('ocacl:source-port', namespaces=NAMESPACES) add_value_from_tag(acl, 'source-port' ,transport_source) transport_destination = xml_transport.find('ocacl:destination_port', namespaces=NAMESPACES) add_value_from_tag(acl, 'destination_port' ,transport_destination) transport_destination = xml_transport.find('ocacl:destination-port', namespaces=NAMESPACES) add_value_from_tag(acl, 'destination-port' ,transport_destination) transport_tcp_flags = xml_transport.find('ocacl:tcp_flags', namespaces=NAMESPACES) add_value_from_tag(acl, 'tcp_flags' ,transport_tcp_flags) transport_tcp_flags = xml_transport.find('ocacl:tcp-flags', namespaces=NAMESPACES) add_value_from_tag(acl, 'tcp-flags' ,transport_tcp_flags) for xml_action in xml_acl_entries.xpath(XPATH_A_ACTIONS, namespaces=NAMESPACES): action = xml_action.find('ocacl:forwarding_action', namespaces=NAMESPACES) add_value_from_tag(acl, 'forwarding_action' ,action) action = xml_action.find('ocacl:forwarding-action', namespaces=NAMESPACES) add_value_from_tag(acl, 'forwarding-action' ,action) log_action = xml_action.find('ocacl:log_action', namespaces=NAMESPACES) add_value_from_tag(acl, 'log_action' ,log_action) log_action = xml_action.find('ocacl:log-action', namespaces=NAMESPACES) add_value_from_tag(acl, 'log-action' ,log_action) resource_key = '/acl/acl-set[{:s}][{:s}]/acl-entry[{:s}]'.format( acl['name'], acl['type'], acl['sequence-id']) name['name'], acl['type'], acl['sequence-id']) response.append((resource_key,acl)) for xml_interface in xml_data.xpath(XPATH_INTERFACE, namespaces=NAMESPACES): Loading @@ -99,25 +101,25 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: for xml_ingress in xml_interface.xpath(XPATH_I_INGRESS, namespaces=NAMESPACES): i_name = xml_ingress.find('ocacl:set_name_ingress', namespaces=NAMESPACES) add_value_from_tag(interface, 'ingress_set_name' , i_name) i_name = xml_ingress.find('ocacl:set-name-ingress', namespaces=NAMESPACES) add_value_from_tag(interface, 'ingress-set-name' , i_name) i_type = xml_ingress.find('ocacl:type_ingress', namespaces=NAMESPACES) add_value_from_tag(interface, 'ingress_type' , i_type) i_type = xml_ingress.find('ocacl:type-ingress', namespaces=NAMESPACES) add_value_from_tag(interface, 'ingress-type' , i_type) resource_key = '/acl/interfaces/ingress[{:s}][{:s}]'.format( acl['name'], acl['type']) name['name'], acl['type']) response.append((resource_key,interface)) for xml_egress in xml_interface.xpath(XPATH_I_EGRESS, namespaces=NAMESPACES): e_name = xml_egress.find('ocacl:set_name_egress', namespaces=NAMESPACES) add_value_from_tag(interface, 'egress_set_name' , e_name) e_name = xml_egress.find('ocacl:set-name-egress', namespaces=NAMESPACES) add_value_from_tag(interface, 'egress-set-name' , e_name) e_type = xml_egress.find('ocacl:type_egress', namespaces=NAMESPACES) add_value_from_tag(interface, 'egress_type' , e_type) e_type = xml_egress.find('ocacl:type-egress', namespaces=NAMESPACES) add_value_from_tag(interface, 'egress-type' , e_type) resource_key = '/acl/interfaces/egress[{:s}][{:s}]'.format( acl['name'], acl['type']) name['name'], acl['type']) response.append((resource_key,interface)) return response src/device/service/drivers/openconfig/templates/Inventory.py +5 −1 Original line number Diff line number Diff line Loading @@ -76,6 +76,10 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: if not component_location is None: add_value_from_tag(inventory['attributes'], 'location', component_location) component_id = xml_component.find('ocp:state/ocp:id', namespaces=NAMESPACES) if not component_id is None: add_value_from_tag(inventory['attributes'], 'id', component_id) component_type = xml_component.find('ocp:state/ocp:type', namespaces=NAMESPACES) if component_type is not None: component_type.text = component_type.text.replace('oc-platform-types:','') Loading Loading @@ -109,7 +113,7 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: component_mfg_name = xml_component.find('ocp:state/ocp:mfg-name', namespaces=NAMESPACES) if not component_mfg_name is None: add_value_from_tag(inventory['attributes'], 'manufacturer-name', component_mfg_name) add_value_from_tag(inventory['attributes'], 'mfg-name', component_mfg_name) component_removable = xml_component.find('ocp:state/ocp:removable', namespaces=NAMESPACES) if not component_removable is None: Loading src/device/service/drivers/openconfig/templates/NetworkInstances.py +17 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ XPATH_NETWORK_INSTANCES = "//ocni:network-instances/ocni:network-instance" XPATH_NI_PROTOCOLS = ".//ocni:protocols/ocni:protocol" XPATH_NI_TABLE_CONNECTS = ".//ocni:table-connections/ocni:table-connection" XPATH_NI_INTERFACE = ".//ocni:interfaces/ocni:interface" XPATH_NI_IIP_AP = ".//ocni:inter-instance-policies/ocni:apply-policy" XPATH_NI_IIP_AP_IMPORT = ".//ocni:config/ocni:import-policy" XPATH_NI_IIP_AP_EXPORT = ".//ocni:config/ocni:export-policy" Loading Loading @@ -136,6 +138,21 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: table_connection['address_family']) response.append((resource_key, table_connection)) for xml_interface in xml_network_instance.xpath(XPATH_NI_INTERFACE, namespaces=NAMESPACES): LOGGER.info('xml_interfaces = {:s}'.format(str(ET.tostring(xml_interface)))) interface = {} name_iface = xml_interface.find('ocni:config/ocni:interface', namespaces=NAMESPACES) if name_iface is None or name_iface.text is None: continue add_value_from_tag(interface, 'name_iface', name_iface) name_subiface = xml_interface.find('ocni:config/ocni:subinterface', namespaces=NAMESPACES) add_value_from_tag(interface, 'name_subiface', name_subiface) resource_key = '/network_instance[{:s}]/interface[{:s}]'.format( network_instance['name'], interface['name_iface']) response.append((resource_key, interface)) for xml_iip_ap in xml_network_instance.xpath(XPATH_NI_IIP_AP, namespaces=NAMESPACES): #LOGGER.info('xml_iip_ap = {:s}'.format(str(ET.tostring(xml_iip_ap)))) Loading src/nbi/service/__main__.py +3 −0 Original line number Diff line number Diff line Loading @@ -18,9 +18,11 @@ from common.Constants import ServiceNameEnum from common.Settings import ( ENVVAR_SUFIX_SERVICE_HOST, ENVVAR_SUFIX_SERVICE_PORT_GRPC, get_env_var_name, get_log_level, get_metrics_port, wait_for_environment_variables) from .NbiService import NbiService from .rest_server.RestServer import RestServer from .rest_server.nbi_plugins.etsi_bwm import register_etsi_bwm_api from .rest_server.nbi_plugins.ietf_hardware import register_ietf_hardware from .rest_server.nbi_plugins.ietf_l2vpn import register_ietf_l2vpn from .rest_server.nbi_plugins.ietf_l3vpn import register_ietf_l3vpn from .rest_server.nbi_plugins.ietf_network import register_ietf_network Loading Loading @@ -63,6 +65,7 @@ def main(): rest_server = RestServer() register_etsi_bwm_api(rest_server) register_ietf_hardware(rest_server) register_ietf_l2vpn(rest_server) # Registering L2VPN entrypoint register_ietf_l3vpn(rest_server) # Registering L3VPN entrypoint register_ietf_network(rest_server) Loading src/nbi/service/rest_server/nbi_plugins/ietf_hardware/Hardware.py 0 → 100644 +53 −0 Original line number Diff line number Diff line # Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) # # 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 logging from flask import request from flask.json import jsonify from flask_restful import Resource from common.tools.context_queries.Device import get_device from context.client.ContextClient import ContextClient from ..tools.Authentication import HTTP_AUTH from ..tools.HttpStatusCodes import HTTP_OK, HTTP_SERVERERROR from .YangHandler import YangHandler LOGGER = logging.getLogger(__name__) class Hardware(Resource): @HTTP_AUTH.login_required def get(self, device_uuid : str): LOGGER.debug('Device UUID: {:s}'.format(str(device_uuid))) LOGGER.debug('Request: {:s}'.format(str(request))) try: context_client = ContextClient() device = get_device( context_client, device_uuid, rw_copy=False, include_endpoints=False, include_config_rules=False, include_components=True ) if device is None: raise Exception('Device({:s}) not found in database'.format(str(device_uuid))) yang_handler = YangHandler() hardware_reply = yang_handler.compose(device) yang_handler.destroy() response = jsonify(hardware_reply) response.status_code = HTTP_OK except Exception as e: # pylint: disable=broad-except MSG = 'Something went wrong Retrieving Hardware of Device({:s})' LOGGER.exception(MSG.format(str(device_uuid))) response = jsonify({'error': str(e)}) response.status_code = HTTP_SERVERERROR return response No newline at end of file Loading
src/device/service/drivers/openconfig/templates/Acl.py +33 −31 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ from .Tools import add_value_from_tag LOGGER = logging.getLogger(__name__) XPATH_ACL_SET = "//ocacl:acl/ocacl:acl-sets/ocacl:acl-set" XPATH_A_ACL_ENTRY = ".//ocacl:acl-entries/ocacl:ecl-entry" XPATH_A_ACL_ENTRY = ".//ocacl:acl-entries/ocacl:acl-entry" XPATH_A_IPv4 = ".//ocacl:ipv4/ocacl:config" XPATH_A_TRANSPORT = ".//ocacl:transport/ocacl:config" XPATH_A_ACTIONS = ".//ocacl:actions/ocacl:config" Loading @@ -34,29 +34,31 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: response = [] acl = {} name = {} for xml_acl in xml_data.xpath(XPATH_ACL_SET, namespaces=NAMESPACES): #LOGGER.info('xml_acl = {:s}'.format(str(ET.tostring(xml_acl)))) acl_name = xml_acl.find('ocacl:name', namespaces=NAMESPACES) if acl_name is None or acl_name.text is None: continue add_value_from_tag(acl, 'name', acl_name) add_value_from_tag(name, 'name', acl_name) acl_type = xml_acl.find('ocacl:type', namespaces=NAMESPACES) add_value_from_tag(acl, 'type', acl_type) for xml_acl_entries in xml_acl.xpath(XPATH_A_ACL_ENTRY, namespaces=NAMESPACES): acl_id = xml_acl_entries.find('ocacl:sequence_id', namespaces=NAMESPACES) add_value_from_tag(acl, 'sequence_id', acl_id) acl_id = xml_acl_entries.find('ocacl:sequence-id', namespaces=NAMESPACES) add_value_from_tag(acl, 'sequence-id', acl_id) LOGGER.info('xml_acl_id = {:s}'.format(str(ET.tostring(acl_id)))) for xml_ipv4 in xml_acl_entries.xpath(XPATH_A_IPv4, namespaces=NAMESPACES): ipv4_source = xml_ipv4.find('ocacl:source_address', namespaces=NAMESPACES) add_value_from_tag(acl, 'source_address' , ipv4_source) ipv4_source = xml_ipv4.find('ocacl:source-address', namespaces=NAMESPACES) add_value_from_tag(acl, 'source-address' , ipv4_source) ipv4_destination = xml_ipv4.find('ocacl:destination_address', namespaces=NAMESPACES) add_value_from_tag(acl, 'destination_address' , ipv4_destination) ipv4_destination = xml_ipv4.find('ocacl:destination-address', namespaces=NAMESPACES) add_value_from_tag(acl, 'destination-address' , ipv4_destination) ipv4_protocol = xml_ipv4.find('ocacl:protocol', namespaces=NAMESPACES) add_value_from_tag(acl, 'protocol' , ipv4_protocol) Loading @@ -64,30 +66,30 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: ipv4_dscp = xml_ipv4.find('ocacl:dscp', namespaces=NAMESPACES) add_value_from_tag(acl, 'dscp' , ipv4_dscp) ipv4_hop_limit = xml_ipv4.find('ocacl:hop_limit', namespaces=NAMESPACES) add_value_from_tag(acl, 'hop_limit' , ipv4_hop_limit) ipv4_hop_limit = xml_ipv4.find('ocacl:hop-limit', namespaces=NAMESPACES) add_value_from_tag(acl, 'hop-limit' , ipv4_hop_limit) for xml_transport in xml_acl_entries.xpath(XPATH_A_TRANSPORT, namespaces=NAMESPACES): transport_source = xml_transport.find('ocacl:source_port', namespaces=NAMESPACES) add_value_from_tag(acl, 'source_port' ,transport_source) transport_source = xml_transport.find('ocacl:source-port', namespaces=NAMESPACES) add_value_from_tag(acl, 'source-port' ,transport_source) transport_destination = xml_transport.find('ocacl:destination_port', namespaces=NAMESPACES) add_value_from_tag(acl, 'destination_port' ,transport_destination) transport_destination = xml_transport.find('ocacl:destination-port', namespaces=NAMESPACES) add_value_from_tag(acl, 'destination-port' ,transport_destination) transport_tcp_flags = xml_transport.find('ocacl:tcp_flags', namespaces=NAMESPACES) add_value_from_tag(acl, 'tcp_flags' ,transport_tcp_flags) transport_tcp_flags = xml_transport.find('ocacl:tcp-flags', namespaces=NAMESPACES) add_value_from_tag(acl, 'tcp-flags' ,transport_tcp_flags) for xml_action in xml_acl_entries.xpath(XPATH_A_ACTIONS, namespaces=NAMESPACES): action = xml_action.find('ocacl:forwarding_action', namespaces=NAMESPACES) add_value_from_tag(acl, 'forwarding_action' ,action) action = xml_action.find('ocacl:forwarding-action', namespaces=NAMESPACES) add_value_from_tag(acl, 'forwarding-action' ,action) log_action = xml_action.find('ocacl:log_action', namespaces=NAMESPACES) add_value_from_tag(acl, 'log_action' ,log_action) log_action = xml_action.find('ocacl:log-action', namespaces=NAMESPACES) add_value_from_tag(acl, 'log-action' ,log_action) resource_key = '/acl/acl-set[{:s}][{:s}]/acl-entry[{:s}]'.format( acl['name'], acl['type'], acl['sequence-id']) name['name'], acl['type'], acl['sequence-id']) response.append((resource_key,acl)) for xml_interface in xml_data.xpath(XPATH_INTERFACE, namespaces=NAMESPACES): Loading @@ -99,25 +101,25 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: for xml_ingress in xml_interface.xpath(XPATH_I_INGRESS, namespaces=NAMESPACES): i_name = xml_ingress.find('ocacl:set_name_ingress', namespaces=NAMESPACES) add_value_from_tag(interface, 'ingress_set_name' , i_name) i_name = xml_ingress.find('ocacl:set-name-ingress', namespaces=NAMESPACES) add_value_from_tag(interface, 'ingress-set-name' , i_name) i_type = xml_ingress.find('ocacl:type_ingress', namespaces=NAMESPACES) add_value_from_tag(interface, 'ingress_type' , i_type) i_type = xml_ingress.find('ocacl:type-ingress', namespaces=NAMESPACES) add_value_from_tag(interface, 'ingress-type' , i_type) resource_key = '/acl/interfaces/ingress[{:s}][{:s}]'.format( acl['name'], acl['type']) name['name'], acl['type']) response.append((resource_key,interface)) for xml_egress in xml_interface.xpath(XPATH_I_EGRESS, namespaces=NAMESPACES): e_name = xml_egress.find('ocacl:set_name_egress', namespaces=NAMESPACES) add_value_from_tag(interface, 'egress_set_name' , e_name) e_name = xml_egress.find('ocacl:set-name-egress', namespaces=NAMESPACES) add_value_from_tag(interface, 'egress-set-name' , e_name) e_type = xml_egress.find('ocacl:type_egress', namespaces=NAMESPACES) add_value_from_tag(interface, 'egress_type' , e_type) e_type = xml_egress.find('ocacl:type-egress', namespaces=NAMESPACES) add_value_from_tag(interface, 'egress-type' , e_type) resource_key = '/acl/interfaces/egress[{:s}][{:s}]'.format( acl['name'], acl['type']) name['name'], acl['type']) response.append((resource_key,interface)) return response
src/device/service/drivers/openconfig/templates/Inventory.py +5 −1 Original line number Diff line number Diff line Loading @@ -76,6 +76,10 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: if not component_location is None: add_value_from_tag(inventory['attributes'], 'location', component_location) component_id = xml_component.find('ocp:state/ocp:id', namespaces=NAMESPACES) if not component_id is None: add_value_from_tag(inventory['attributes'], 'id', component_id) component_type = xml_component.find('ocp:state/ocp:type', namespaces=NAMESPACES) if component_type is not None: component_type.text = component_type.text.replace('oc-platform-types:','') Loading Loading @@ -109,7 +113,7 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: component_mfg_name = xml_component.find('ocp:state/ocp:mfg-name', namespaces=NAMESPACES) if not component_mfg_name is None: add_value_from_tag(inventory['attributes'], 'manufacturer-name', component_mfg_name) add_value_from_tag(inventory['attributes'], 'mfg-name', component_mfg_name) component_removable = xml_component.find('ocp:state/ocp:removable', namespaces=NAMESPACES) if not component_removable is None: Loading
src/device/service/drivers/openconfig/templates/NetworkInstances.py +17 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ XPATH_NETWORK_INSTANCES = "//ocni:network-instances/ocni:network-instance" XPATH_NI_PROTOCOLS = ".//ocni:protocols/ocni:protocol" XPATH_NI_TABLE_CONNECTS = ".//ocni:table-connections/ocni:table-connection" XPATH_NI_INTERFACE = ".//ocni:interfaces/ocni:interface" XPATH_NI_IIP_AP = ".//ocni:inter-instance-policies/ocni:apply-policy" XPATH_NI_IIP_AP_IMPORT = ".//ocni:config/ocni:import-policy" XPATH_NI_IIP_AP_EXPORT = ".//ocni:config/ocni:export-policy" Loading Loading @@ -136,6 +138,21 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: table_connection['address_family']) response.append((resource_key, table_connection)) for xml_interface in xml_network_instance.xpath(XPATH_NI_INTERFACE, namespaces=NAMESPACES): LOGGER.info('xml_interfaces = {:s}'.format(str(ET.tostring(xml_interface)))) interface = {} name_iface = xml_interface.find('ocni:config/ocni:interface', namespaces=NAMESPACES) if name_iface is None or name_iface.text is None: continue add_value_from_tag(interface, 'name_iface', name_iface) name_subiface = xml_interface.find('ocni:config/ocni:subinterface', namespaces=NAMESPACES) add_value_from_tag(interface, 'name_subiface', name_subiface) resource_key = '/network_instance[{:s}]/interface[{:s}]'.format( network_instance['name'], interface['name_iface']) response.append((resource_key, interface)) for xml_iip_ap in xml_network_instance.xpath(XPATH_NI_IIP_AP, namespaces=NAMESPACES): #LOGGER.info('xml_iip_ap = {:s}'.format(str(ET.tostring(xml_iip_ap)))) Loading
src/nbi/service/__main__.py +3 −0 Original line number Diff line number Diff line Loading @@ -18,9 +18,11 @@ from common.Constants import ServiceNameEnum from common.Settings import ( ENVVAR_SUFIX_SERVICE_HOST, ENVVAR_SUFIX_SERVICE_PORT_GRPC, get_env_var_name, get_log_level, get_metrics_port, wait_for_environment_variables) from .NbiService import NbiService from .rest_server.RestServer import RestServer from .rest_server.nbi_plugins.etsi_bwm import register_etsi_bwm_api from .rest_server.nbi_plugins.ietf_hardware import register_ietf_hardware from .rest_server.nbi_plugins.ietf_l2vpn import register_ietf_l2vpn from .rest_server.nbi_plugins.ietf_l3vpn import register_ietf_l3vpn from .rest_server.nbi_plugins.ietf_network import register_ietf_network Loading Loading @@ -63,6 +65,7 @@ def main(): rest_server = RestServer() register_etsi_bwm_api(rest_server) register_ietf_hardware(rest_server) register_ietf_l2vpn(rest_server) # Registering L2VPN entrypoint register_ietf_l3vpn(rest_server) # Registering L3VPN entrypoint register_ietf_network(rest_server) Loading
src/nbi/service/rest_server/nbi_plugins/ietf_hardware/Hardware.py 0 → 100644 +53 −0 Original line number Diff line number Diff line # Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) # # 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 logging from flask import request from flask.json import jsonify from flask_restful import Resource from common.tools.context_queries.Device import get_device from context.client.ContextClient import ContextClient from ..tools.Authentication import HTTP_AUTH from ..tools.HttpStatusCodes import HTTP_OK, HTTP_SERVERERROR from .YangHandler import YangHandler LOGGER = logging.getLogger(__name__) class Hardware(Resource): @HTTP_AUTH.login_required def get(self, device_uuid : str): LOGGER.debug('Device UUID: {:s}'.format(str(device_uuid))) LOGGER.debug('Request: {:s}'.format(str(request))) try: context_client = ContextClient() device = get_device( context_client, device_uuid, rw_copy=False, include_endpoints=False, include_config_rules=False, include_components=True ) if device is None: raise Exception('Device({:s}) not found in database'.format(str(device_uuid))) yang_handler = YangHandler() hardware_reply = yang_handler.compose(device) yang_handler.destroy() response = jsonify(hardware_reply) response.status_code = HTTP_OK except Exception as e: # pylint: disable=broad-except MSG = 'Something went wrong Retrieving Hardware of Device({:s})' LOGGER.exception(MSG.format(str(device_uuid))) response = jsonify({'error': str(e)}) response.status_code = HTTP_SERVERERROR return response No newline at end of file