Commit 87b5aa6f authored by Jose Luis Carcel's avatar Jose Luis Carcel
Browse files

Update - Morpheus Client Extension

parent 654eb432
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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(
+8 −4
Original line number Diff line number Diff line
@@ -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,6 +78,7 @@ 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)
                if resource_key == RESOURCE_ENDPOINTS:
                    results.extend(config_getter(
                        self.__tapi_root, resource_key, timeout=self.__timeout))
        return results
@@ -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

+8 −4
Original line number Diff line number Diff line
@@ -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)
+0 −2
Original line number Diff line number Diff line
@@ -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
]
Loading