Skip to content
Snippets Groups Projects
Commit 87b5aa6f authored by Jose Luis Carcel's avatar Jose Luis Carcel
Browse files

Update - Morpheus Client Extension

parent 654eb432
No related branches found
No related tags found
2 merge requests!359Release TeraFlowSDN 5.0,!338Resolve "(EVIDEN) SmartNIC support"
Showing
with 40 additions and 24 deletions
...@@ -12,12 +12,13 @@ ...@@ -12,12 +12,13 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import copy import copy, logging
from typing import Dict, List, Optional, Tuple from typing import Dict, List, Optional, Tuple
from common.DeviceTypes import DeviceTypeEnum from common.DeviceTypes import DeviceTypeEnum
from common.proto.context_pb2 import DeviceDriverEnum, DeviceOperationalStatusEnum from common.proto.context_pb2 import DeviceDriverEnum, DeviceOperationalStatusEnum
from common.tools.object_factory.ConfigRule import json_config_rule_set from common.tools.object_factory.ConfigRule import json_config_rule_set
LOGGER = logging.getLogger(__name__)
DEVICE_DISABLED = DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_DISABLED DEVICE_DISABLED = DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_DISABLED
DEVICE_EMUDC_TYPE = DeviceTypeEnum.EMULATED_DATACENTER.value DEVICE_EMUDC_TYPE = DeviceTypeEnum.EMULATED_DATACENTER.value
...@@ -62,13 +63,13 @@ def json_device( ...@@ -62,13 +63,13 @@ def json_device(
): ):
result = { result = {
'device_id' : json_device_id(device_uuid), 'device_id' : json_device_id(device_uuid),
'name' : name,
'device_type' : device_type, 'device_type' : device_type,
'device_config' : {'config_rules': copy.deepcopy(config_rules)}, 'device_config' : {'config_rules': copy.deepcopy(config_rules)},
'device_operational_status': status, 'device_operational_status': status,
'device_drivers' : copy.deepcopy(drivers), 'device_drivers' : copy.deepcopy(drivers),
'device_endpoints' : copy.deepcopy(endpoints), 'device_endpoints' : copy.deepcopy(endpoints),
} }
if name is not None: result['name'] = name
return result return result
def json_device_emulated_packet_router_disabled( def json_device_emulated_packet_router_disabled(
......
...@@ -20,8 +20,11 @@ from common.type_checkers.Checkers import chk_string, chk_type ...@@ -20,8 +20,11 @@ from common.type_checkers.Checkers import chk_string, chk_type
from device.service.driver_api._Driver import _Driver from device.service.driver_api._Driver import _Driver
from . import ALL_RESOURCE_KEYS from . import ALL_RESOURCE_KEYS
from .Tools import create_connectivity_service, find_key, config_getter, delete_connectivity_service 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__) LOGGER = logging.getLogger(__name__)
from device.service.driver_api._Driver import RESOURCE_ENDPOINTS, RESOURCE_SERVICES, RESOURCE_INTERFACES
DRIVER_NAME = 'smartnic' DRIVER_NAME = 'smartnic'
METRICS_POOL = MetricsPool('Device', 'Driver', labels={'driver': DRIVER_NAME}) METRICS_POOL = MetricsPool('Device', 'Driver', labels={'driver': DRIVER_NAME})
...@@ -75,8 +78,9 @@ class SmartnicDriver(_Driver): ...@@ -75,8 +78,9 @@ class SmartnicDriver(_Driver):
for i, resource_key in enumerate(resource_keys): for i, resource_key in enumerate(resource_keys):
str_resource_name = 'resource_key[#{:d}]'.format(i) str_resource_name = 'resource_key[#{:d}]'.format(i)
chk_string(str_resource_name, resource_key, allow_empty=False) chk_string(str_resource_name, resource_key, allow_empty=False)
results.extend(config_getter( if resource_key == RESOURCE_ENDPOINTS:
self.__tapi_root, resource_key, timeout=self.__timeout)) results.extend(config_getter(
self.__tapi_root, resource_key, timeout=self.__timeout))
return results return results
@metered_subclass_method(METRICS_POOL) @metered_subclass_method(METRICS_POOL)
...@@ -87,9 +91,9 @@ class SmartnicDriver(_Driver): ...@@ -87,9 +91,9 @@ class SmartnicDriver(_Driver):
with self.__lock: with self.__lock:
for resource in resources: for resource in resources:
LOGGER.info('resource = {:s}'.format(str(resource))) 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( data = create_connectivity_service(
self.__tapi_root, config_rules, timeout=self.__timeout) self.__tapi_root, resource[1], timeout=self.__timeout)
results.extend(data) results.extend(data)
return results return results
......
...@@ -50,6 +50,11 @@ def config_getter( ...@@ -50,6 +50,11 @@ def config_getter(
result = [] result = []
try: try:
response = requests.get(url, timeout=timeout, verify=False) 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: except requests.exceptions.Timeout:
LOGGER.exception('Timeout connecting {:s}'.format(url)) LOGGER.exception('Timeout connecting {:s}'.format(url))
return result return result
...@@ -57,7 +62,6 @@ def config_getter( ...@@ -57,7 +62,6 @@ def config_getter(
LOGGER.exception('Exception retrieving {:s}'.format(resource_key)) LOGGER.exception('Exception retrieving {:s}'.format(resource_key))
result.append((resource_key, e)) result.append((resource_key, e))
return result return result
return response
# try: # try:
# context = json.loads(response.content) # context = json.loads(response.content)
...@@ -72,13 +76,13 @@ def create_connectivity_service( ...@@ -72,13 +76,13 @@ def create_connectivity_service(
root_url, config_rules, timeout : Optional[int] = None, auth : Optional[HTTPBasicAuth] = None 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'} headers = {'content-type': 'application/json'}
results = [] results = []
try: try:
LOGGER.info('Configuring Smartnic rules') LOGGER.info('Configuring Smartnic rules')
response = requests.post( 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))) LOGGER.info('SmartNIC Probes response: {:s}'.format(str(response)))
except Exception as e: # pylint: disable=broad-except except Exception as e: # pylint: disable=broad-except
LOGGER.exception('Exception creating ConfigRule') LOGGER.exception('Exception creating ConfigRule')
...@@ -92,7 +96,7 @@ def create_connectivity_service( ...@@ -92,7 +96,7 @@ def create_connectivity_service(
def delete_connectivity_service(root_url, config_rules, timeout : Optional[int] = None, auth : Optional[HTTPBasicAuth] = None 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 = [] results = []
try: try:
response = requests.delete(url=url, timeout=timeout, verify=False) response = requests.delete(url=url, timeout=timeout, verify=False)
......
...@@ -14,7 +14,5 @@ ...@@ -14,7 +14,5 @@
from device.service.driver_api._Driver import RESOURCE_ENDPOINTS, RESOURCE_SERVICES, RESOURCE_INTERFACES from device.service.driver_api._Driver import RESOURCE_ENDPOINTS, RESOURCE_SERVICES, RESOURCE_INTERFACES
ALL_RESOURCE_KEYS = [ ALL_RESOURCE_KEYS = [
RESOURCE_ENDPOINTS,
RESOURCE_SERVICES,
RESOURCE_INTERFACES RESOURCE_INTERFACES
] ]
...@@ -181,10 +181,10 @@ class Device(_Resource): ...@@ -181,10 +181,10 @@ class Device(_Resource):
return format_grpc_to_json(self.device_client.AddDevice(grpc_device( return format_grpc_to_json(self.device_client.AddDevice(grpc_device(
device_uuid = device['device_id']['device_uuid']['uuid'], device_uuid = device['device_id']['device_uuid']['uuid'],
device_type = device['device_type'], device_type = device['device_type'],
config_rules = device['device_config']['config_rules'],
status = device['device_operational_status'], 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 def put(self, device_uuid : str): # pylint: disable=unused-argument
...@@ -192,12 +192,17 @@ class Device(_Resource): ...@@ -192,12 +192,17 @@ class Device(_Resource):
return format_grpc_to_json(self.device_client.ConfigureDevice(grpc_device( return format_grpc_to_json(self.device_client.ConfigureDevice(grpc_device(
device_uuid = device['device_id']['device_uuid']['uuid'], device_uuid = device['device_id']['device_uuid']['uuid'],
device_type = device['device_type'], device_type = device['device_type'],
device_config = device['device_config']['config_rules'], status = device['device_operational_status'],
device_operational_status = device['device_operational_status'], endpoints = device['device_endpoints'],
device_drivers = device['device_drivers'], config_rules = device['device_config']['config_rules'],
device_endpoints = device['device_endpoints'] 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): class LinkIds(_Resource):
def get(self): def get(self):
......
...@@ -12,12 +12,14 @@ ...@@ -12,12 +12,14 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging
from flask.json import jsonify from flask.json import jsonify
from common.proto.context_pb2 import ( from common.proto.context_pb2 import (
ConnectionId, ContextId, DeviceDriverEnum, Device, DeviceId, DeviceOperationalStatusEnum, LinkId, ServiceId, SliceId, TopologyId, Service, ServiceStatusEnum ConnectionId, ContextId, DeviceDriverEnum, Device, DeviceId, DeviceOperationalStatusEnum, LinkId, ServiceId, SliceId, TopologyId, Service, ServiceStatusEnum
) )
from common.proto.policy_pb2 import PolicyRuleId 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.Connection import json_connection_id
from common.tools.object_factory.Context import json_context_id from common.tools.object_factory.Context import json_context_id
from common.tools.object_factory.ConfigRule import json_config_rule 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 ...@@ -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.Slice import json_slice_id
from common.tools.object_factory.Topology import json_topology_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): def format_grpc_to_json(grpc_reply):
return jsonify(grpc_message_to_json(grpc_reply)) return jsonify(grpc_message_to_json(grpc_reply))
...@@ -44,8 +48,9 @@ def grpc_device_id(device_uuid): ...@@ -44,8 +48,9 @@ def grpc_device_id(device_uuid):
return DeviceId(**json_device_id(device_uuid)) return DeviceId(**json_device_id(device_uuid))
def grpc_device( 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_rules = [
json_config_rule( json_config_rule(
config_rule['action'], config_rule['action'],
...@@ -68,8 +73,7 @@ def grpc_device( ...@@ -68,8 +73,7 @@ def grpc_device(
for endpoint in endpoints for endpoint in endpoints
] if endpoints else [] ] if endpoints else []
return Device(**json_device( return Device(**json_device(
device_uuid, device_type, json_config_rules, json_status, device_uuid, device_type, json_status, None, json_endpoints, json_config_rules, json_drivers))
json_drivers, json_endpoints))
def grpc_link_id(link_uuid): def grpc_link_id(link_uuid):
return LinkId(**json_link_id(link_uuid)) return LinkId(**json_link_id(link_uuid))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment