diff --git a/src/common/tools/object_factory/Device.py b/src/common/tools/object_factory/Device.py index b3182e30201673d5285cc02d5a78e5a0136a6dc1..5a7ff398aa760a852b161c4b7836acf04717620a 100644 --- a/src/common/tools/object_factory/Device.py +++ b/src/common/tools/object_factory/Device.py @@ -12,12 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import copy +import copy, logging from typing import Dict, List, Optional, Tuple from common.DeviceTypes import DeviceTypeEnum from common.proto.context_pb2 import DeviceDriverEnum, DeviceOperationalStatusEnum from common.tools.object_factory.ConfigRule import json_config_rule_set +LOGGER = logging.getLogger(__name__) DEVICE_DISABLED = DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_DISABLED DEVICE_EMUDC_TYPE = DeviceTypeEnum.EMULATED_DATACENTER.value @@ -62,13 +63,13 @@ def json_device( ): result = { 'device_id' : json_device_id(device_uuid), + 'name' : name, 'device_type' : device_type, 'device_config' : {'config_rules': copy.deepcopy(config_rules)}, 'device_operational_status': status, 'device_drivers' : copy.deepcopy(drivers), 'device_endpoints' : copy.deepcopy(endpoints), } - if name is not None: result['name'] = name return result def json_device_emulated_packet_router_disabled( diff --git a/src/device/service/drivers/smartnic/SmartnicDriver.py b/src/device/service/drivers/smartnic/SmartnicDriver.py index 4bad52db42eb6743205289b9fce7903b9ab6453b..f827bbbffbe248fa5cd97503f33ef61957252870 100644 --- a/src/device/service/drivers/smartnic/SmartnicDriver.py +++ b/src/device/service/drivers/smartnic/SmartnicDriver.py @@ -20,8 +20,11 @@ from common.type_checkers.Checkers import chk_string, chk_type from device.service.driver_api._Driver import _Driver from . import ALL_RESOURCE_KEYS from .Tools import create_connectivity_service, find_key, config_getter, delete_connectivity_service +from common.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_string + LOGGER = logging.getLogger(__name__) +from device.service.driver_api._Driver import RESOURCE_ENDPOINTS, RESOURCE_SERVICES, RESOURCE_INTERFACES DRIVER_NAME = 'smartnic' METRICS_POOL = MetricsPool('Device', 'Driver', labels={'driver': DRIVER_NAME}) @@ -75,8 +78,9 @@ class SmartnicDriver(_Driver): for i, resource_key in enumerate(resource_keys): str_resource_name = 'resource_key[#{:d}]'.format(i) chk_string(str_resource_name, resource_key, allow_empty=False) - results.extend(config_getter( - self.__tapi_root, resource_key, timeout=self.__timeout)) + if resource_key == RESOURCE_ENDPOINTS: + results.extend(config_getter( + self.__tapi_root, resource_key, timeout=self.__timeout)) return results @metered_subclass_method(METRICS_POOL) @@ -87,9 +91,9 @@ class SmartnicDriver(_Driver): with self.__lock: for resource in resources: LOGGER.info('resource = {:s}'.format(str(resource))) - config_rules = find_key(resource, 'config_rules') + #config_rules = find_key(resource, 'config_rules') data = create_connectivity_service( - self.__tapi_root, config_rules, timeout=self.__timeout) + self.__tapi_root, resource[1], timeout=self.__timeout) results.extend(data) return results diff --git a/src/device/service/drivers/smartnic/Tools.py b/src/device/service/drivers/smartnic/Tools.py index 54961bbdda9da7abf639acc56339df9770d3fb36..bd155441c4dd90e999b59ceb3b9432ab659b715c 100644 --- a/src/device/service/drivers/smartnic/Tools.py +++ b/src/device/service/drivers/smartnic/Tools.py @@ -50,6 +50,11 @@ def config_getter( result = [] try: response = requests.get(url, timeout=timeout, verify=False) + data = response.json() + for item in data: + tupla = ('/endpoints/endpoint', item) + result.append(tupla) + return result except requests.exceptions.Timeout: LOGGER.exception('Timeout connecting {:s}'.format(url)) return result @@ -57,7 +62,6 @@ def config_getter( LOGGER.exception('Exception retrieving {:s}'.format(resource_key)) result.append((resource_key, e)) return result - return response # try: # context = json.loads(response.content) @@ -72,13 +76,13 @@ def create_connectivity_service( root_url, config_rules, timeout : Optional[int] = None, auth : Optional[HTTPBasicAuth] = None ): - url = '{:s}/configure'.format(root_url) + url = '{:s}/manage-probe/configure'.format(root_url) headers = {'content-type': 'application/json'} results = [] try: LOGGER.info('Configuring Smartnic rules') response = requests.post( - url=url, data=json.dumps(config_rules), timeout=timeout, headers=headers, verify=False) + url=url, data=config_rules, timeout=timeout, headers=headers, verify=False) LOGGER.info('SmartNIC Probes response: {:s}'.format(str(response))) except Exception as e: # pylint: disable=broad-except LOGGER.exception('Exception creating ConfigRule') @@ -92,7 +96,7 @@ def create_connectivity_service( def delete_connectivity_service(root_url, config_rules, timeout : Optional[int] = None, auth : Optional[HTTPBasicAuth] = None ): - url = '{:s}/configure'.format(root_url) + url = '{:s}/manage-probe/configure'.format(root_url) results = [] try: response = requests.delete(url=url, timeout=timeout, verify=False) diff --git a/src/device/service/drivers/smartnic/__init__.py b/src/device/service/drivers/smartnic/__init__.py index bc88d00faa09fe4e97f36927ae348a132a75d0cb..b3626c633b35a793de8fde7a69b95dae0cda511f 100644 --- a/src/device/service/drivers/smartnic/__init__.py +++ b/src/device/service/drivers/smartnic/__init__.py @@ -14,7 +14,5 @@ from device.service.driver_api._Driver import RESOURCE_ENDPOINTS, RESOURCE_SERVICES, RESOURCE_INTERFACES ALL_RESOURCE_KEYS = [ - RESOURCE_ENDPOINTS, - RESOURCE_SERVICES, RESOURCE_INTERFACES ] diff --git a/src/device/service/drivers/smartnic_probes/ietf-yang-types.yang b/src/device/service/drivers/smartnic/ietf-yang-types.yang similarity index 100% rename from src/device/service/drivers/smartnic_probes/ietf-yang-types.yang rename to src/device/service/drivers/smartnic/ietf-yang-types.yang diff --git a/src/device/service/drivers/smartnic_probes/openconfig-extensions.yang b/src/device/service/drivers/smartnic/openconfig-extensions.yang similarity index 100% rename from src/device/service/drivers/smartnic_probes/openconfig-extensions.yang rename to src/device/service/drivers/smartnic/openconfig-extensions.yang diff --git a/src/device/service/drivers/smartnic_probes/openconfig-inet-types.yang b/src/device/service/drivers/smartnic/openconfig-inet-types.yang similarity index 100% rename from src/device/service/drivers/smartnic_probes/openconfig-inet-types.yang rename to src/device/service/drivers/smartnic/openconfig-inet-types.yang diff --git a/src/device/service/drivers/smartnic_probes/openconfig-probes-types.yang b/src/device/service/drivers/smartnic/openconfig-probes-types.yang similarity index 100% rename from src/device/service/drivers/smartnic_probes/openconfig-probes-types.yang rename to src/device/service/drivers/smartnic/openconfig-probes-types.yang diff --git a/src/device/service/drivers/smartnic_probes/openconfig-probes.yang b/src/device/service/drivers/smartnic/openconfig-probes.yang similarity index 100% rename from src/device/service/drivers/smartnic_probes/openconfig-probes.yang rename to src/device/service/drivers/smartnic/openconfig-probes.yang diff --git a/src/device/service/drivers/smartnic_probes/openconfig-types.yang b/src/device/service/drivers/smartnic/openconfig-types.yang similarity index 100% rename from src/device/service/drivers/smartnic_probes/openconfig-types.yang rename to src/device/service/drivers/smartnic/openconfig-types.yang diff --git a/src/device/service/drivers/smartnic_probes/probes-agent.yang b/src/device/service/drivers/smartnic/probes-agent.yang similarity index 100% rename from src/device/service/drivers/smartnic_probes/probes-agent.yang rename to src/device/service/drivers/smartnic/probes-agent.yang diff --git a/src/device/service/drivers/smartnic_probes/references_probes_libraries.txt b/src/device/service/drivers/smartnic/references_probes_libraries.txt similarity index 100% rename from src/device/service/drivers/smartnic_probes/references_probes_libraries.txt rename to src/device/service/drivers/smartnic/references_probes_libraries.txt diff --git a/src/device/service/drivers/smartnic_probes/.gitkeep b/src/device/service/drivers/smartnic_probes/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/src/device/service/drivers/smartnic_probes/smartnics_probes_agent/.gitkeep b/src/device/service/drivers/smartnic_probes/smartnics_probes_agent/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/src/nbi/service/rest_server/nbi_plugins/agent_probes/Resources.py b/src/nbi/service/rest_server/nbi_plugins/agent_probes/Resources.py index 2b0a537cc67d95c44b10344d1127a6eb5099c3ed..daafd79aba4f759d44998c7375521b24a33231e9 100644 --- a/src/nbi/service/rest_server/nbi_plugins/agent_probes/Resources.py +++ b/src/nbi/service/rest_server/nbi_plugins/agent_probes/Resources.py @@ -181,10 +181,10 @@ class Device(_Resource): return format_grpc_to_json(self.device_client.AddDevice(grpc_device( device_uuid = device['device_id']['device_uuid']['uuid'], device_type = device['device_type'], - config_rules = device['device_config']['config_rules'], status = device['device_operational_status'], - drivers = device['device_drivers'], - endpoints = device['device_endpoints'] + endpoints = device['device_endpoints'], + config_rules = device['device_config']['config_rules'], + drivers = device['device_drivers'] ))) def put(self, device_uuid : str): # pylint: disable=unused-argument @@ -192,12 +192,17 @@ class Device(_Resource): return format_grpc_to_json(self.device_client.ConfigureDevice(grpc_device( device_uuid = device['device_id']['device_uuid']['uuid'], device_type = device['device_type'], - device_config = device['device_config']['config_rules'], - device_operational_status = device['device_operational_status'], - device_drivers = device['device_drivers'], - device_endpoints = device['device_endpoints'] + status = device['device_operational_status'], + endpoints = device['device_endpoints'], + config_rules = device['device_config']['config_rules'], + drivers = device['device_drivers'] + ))) + + def delete(self, device_uuid : str): + device = request.get_json()['devices'][0] + return format_grpc_to_json(self.device_client.DeleteDevice(grpc_device( + device_uuid = device['device_id']['device_uuid']['uuid'] ))) - class LinkIds(_Resource): def get(self): diff --git a/src/nbi/service/rest_server/nbi_plugins/agent_probes/Tools.py b/src/nbi/service/rest_server/nbi_plugins/agent_probes/Tools.py index 17b6dcdfd02ac41447b550dcb7dda8db2a3c0463..6cffbb5cc5e9522393d9dfece70e61f79ff0b90f 100644 --- a/src/nbi/service/rest_server/nbi_plugins/agent_probes/Tools.py +++ b/src/nbi/service/rest_server/nbi_plugins/agent_probes/Tools.py @@ -12,12 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. +import logging from flask.json import jsonify from common.proto.context_pb2 import ( ConnectionId, ContextId, DeviceDriverEnum, Device, DeviceId, DeviceOperationalStatusEnum, LinkId, ServiceId, SliceId, TopologyId, Service, ServiceStatusEnum ) from common.proto.policy_pb2 import PolicyRuleId -from common.tools.grpc.Tools import grpc_message_to_json +from common.proto.context_pb2 import ConfigActionEnum +from common.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_string from common.tools.object_factory.Connection import json_connection_id from common.tools.object_factory.Context import json_context_id from common.tools.object_factory.ConfigRule import json_config_rule @@ -30,6 +32,8 @@ from common.tools.object_factory.Service import json_service_id, json_service from common.tools.object_factory.Slice import json_slice_id from common.tools.object_factory.Topology import json_topology_id +LOGGER = logging.getLogger(__name__) +LOGGER.setLevel(logging.DEBUG) def format_grpc_to_json(grpc_reply): return jsonify(grpc_message_to_json(grpc_reply)) @@ -44,8 +48,9 @@ def grpc_device_id(device_uuid): return DeviceId(**json_device_id(device_uuid)) def grpc_device( - device_uuid, device_type, config_rules=None, status=None, drivers=None, endpoints=None + device_uuid, device_type, status, endpoints=None, config_rules=None, drivers=None ): + json_config_rules = [ json_config_rule( config_rule['action'], @@ -68,8 +73,7 @@ def grpc_device( for endpoint in endpoints ] if endpoints else [] return Device(**json_device( - device_uuid, device_type, json_config_rules, json_status, - json_drivers, json_endpoints)) + device_uuid, device_type, json_status, None, json_endpoints, json_config_rules, json_drivers)) def grpc_link_id(link_uuid): return LinkId(**json_link_id(link_uuid))