Skip to content
Snippets Groups Projects
Commit 6c633636 authored by Mohammad Ismaeel's avatar Mohammad Ismaeel
Browse files

reading from context

parent 6655cdbe
No related branches found
No related tags found
2 merge requests!294Release TeraFlowSDN 4.0,!284Resolve: "(CNIT) Multi-Granular Optical Nodes and Optical Transpoders management"
No preview for this file type
......@@ -36,12 +36,13 @@ class SlotType(TypeDecorator):
slot={}
for k,v in value.items():
slot[k]=v
logging.info(f"dict from slotType {slot}")
value = json.dumps(slot)
return value
def process_result_value(self, value, dialect):
logging.info(f"dict from slotType {value}")
if value is not None:
value = json.loads(value)
return value
......
......@@ -208,16 +208,39 @@ class GetFlows(Resource):
except:
return "Error", 404
@optical.route('/GetTopology/<path:topology_id>',methods=(['GET']))
@optical.route('/GetTopology/<path:context_id>/<path:topology_id>',methods=['GET'])
@optical.response(200, 'Success')
@optical.response(404, 'Error, not found')
class GetTopology(Resource):
@staticmethod
def get(topology_id:TopologyId):
def get(context_id:str,topology_id:str):
topog_id = TopologyId()
topog_id.topology_uuid.uuid=topology_id
topog_id.context_id.context_uuid.uuid=context_id
try:
nodes , links = readTopologyDataFromContext(topology_id)
print(f"nodes {nodes} and links {links}")
links_dict={"optical_links":[]}
node_dict = {}
i=0
nodes , topo = readTopologyDataFromContext(topog_id)
for node in nodes :
links_dict["optical_links"].append(node)
for device in topo :
dic = {}
dic= {
"id":device.device_id.device_uuid.uuid,
"ip":f"10.30.2.{207+i}",
"port":"50001",
"type":"OC-ROADM" if device.device_type =="optical-roadm" else "OC-ROADM",
"driver": "OpticalOC"
}
node_dict[device.name]=dic
i+=1
print(f"refresh_opticacontroller optical_links_dict {links_dict}")
print(f"refresh_opticacontroller node_dict {node_dict}")
rsa = RSA(node_dict, links_dict)
return "Done"
except Exception as e:
print(f"err {e}")
......@@ -232,7 +255,7 @@ if __name__ == '__main__':
nodes_dict, links_dict = readTopologyData(nodes_json, topology_json)
rsa = RSA(nodes_dict, links_dict)
#rsa = RSA(nodes_dict, links_dict)
#print(rsa.init_link_slots2(testing))
app.run(host='0.0.0.0', port=10060)
......@@ -254,8 +254,8 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
DEFAULT_TOPOLOGY_NAME, context_id_x)
topology_details = context_client.GetTopologyDetails(
TopologyId(**topology_id_x))
#refresh_opticalcontroller(TopologyId(**topology_id_x))
refresh_opticalcontroller(topology_id_x)
# devices = get_devices_in_topology(context_client, TopologyId(**topology_id_x), ContextId(**context_id_x))
devices = topology_details.devices
context_uuid_x = topology_details.topology_id.context_id.context_uuid.uuid
......
......@@ -32,7 +32,7 @@ from service.service.service_handler_api.Exceptions import (
)
from service.service.service_handler_api.ServiceHandlerFactory import ServiceHandlerFactory, get_service_handler_class
from service.service.tools.ObjectKeys import get_connection_key, get_device_key, get_service_key
from service.service.tools.object_uuid import opticalconfig_get_uuid
if TYPE_CHECKING:
from service.service.service_handler_api._ServiceHandler import _ServiceHandler
......@@ -120,24 +120,27 @@ class TaskExecutor:
def configure_optical_device(self, device : Device, settings : str, flows : list, is_opticalband : bool):
device_key = get_device_key(device.device_id)
optical_config_id = OpticalConfigId()
optical_config_id.opticalconfig_uuid = device.device_id.device_uuid.uuid
optical_config_id.opticalconfig_uuid = opticalconfig_get_uuid(device.device_id)
optical_config = OpticalConfig()
setting = settings.value if settings else ""
new_config = {}
try:
result = self._context_client.SelectOpticalConfig(optical_config_id)
LOGGER.info(f"configure_optical_device {result}")
new_config = json.loads(result.config)
if result is not None :
new_config["new_config"] = setting
new_config["is_opticalband"] = is_opticalband
new_config["flow"] = flows
result.config = str(new_config)
result.config = json.dumps(new_config)
optical_config.CopyFrom(result)
self._device_client.ConfigureOpticalDevice(optical_config)
self._store_grpc_object(CacheableObjectType.DEVICE, device_key, device)
except Exception as e:
LOGGER.info("error in config my config %s",e)
LOGGER.info("error in configure_optical_device %s",e)
def get_device_controller(self, device : Device) -> Optional[Device]:
#json_controller = None
......
......@@ -77,11 +77,15 @@ def get_device_name_from_uuid(devices: List[Device], device_uuid: str):
return device_name
return ""
def refresh_opticalcontroller (topology_id:TopologyId):
headers = {"Content-Type": "application/json"}
urlx = "http://{}:{}/GetTopology/{}".format(OPTICAL_IP, OPTICAL_PORT,topology_id)
res = requests.get(urlx, headers=headers)
logging.info(f"Refresh opticalcontroller {res}")
def refresh_opticalcontroller (topology_id:dict):
logging.info(f"t_id {topology_id}")
topo_id_str= topology_id["topology_uuid"]["uuid"]
cxt_id_str=topology_id["context_id"]["context_uuid"]["uuid"]
headers = {"Content-Type": "application/json"}
urlx = f"http://{OPTICAL_IP}:{OPTICAL_PORT}/OpticalTFS/GetTopology/{cxt_id_str}/{topo_id_str}"
res = requests.get(urlx, headers=headers)
logging.info(f"Refresh opticalcontroller {res}")
def add_lightpath(src, dst, bitrate, bidir, ob_band) -> str:
if not testing:
......
from common.method_wrappers.ServiceExceptions import InvalidArgumentsException
from typing import Optional, Union
from uuid import UUID, uuid4, uuid5
from common.proto.context_pb2 import DeviceId
NAMESPACE_TFS = UUID('200e3a1f-2223-534f-a100-758e29c37f40')
def get_uuid_from_string(str_uuid_or_name : Union[str, UUID], prefix_for_name : Optional[str] = None) -> str:
# if UUID given, assume it is already a valid UUID
if isinstance(str_uuid_or_name, UUID): return str_uuid_or_name
if not isinstance(str_uuid_or_name, str):
MSG = 'Parameter({:s}) cannot be used to produce a UUID'
raise Exception(MSG.format(str(repr(str_uuid_or_name))))
try:
# try to parse as UUID
return str(UUID(str_uuid_or_name))
except: # pylint: disable=bare-except
# produce a UUID within TFS namespace from parameter
if prefix_for_name is not None:
str_uuid_or_name = '{:s}/{:s}'.format(prefix_for_name, str_uuid_or_name)
return str(uuid5(NAMESPACE_TFS, str_uuid_or_name))
def opticalconfig_get_uuid ( device_id: DeviceId) -> str :
device_uuid = device_id.device_uuid.uuid
if (len(device_uuid)>0):
return get_uuid_from_string(f"{device_uuid}_opticalconfig")
raise InvalidArgumentsException([
('DeviceId ', device_id),
], extra_details=['device_id is required to produce a OpticalConfig UUID'])
\ No newline at end of file
......@@ -33,21 +33,21 @@
</div>
<div class="col-sm-12">
<div class="col-sm-12">
<div class="row">
<div class="row mb-3 ">
<div class="col-sm-3">
<button type="button" class="btn btn-success" onclick="window.location.href='{{ url_for('opticalconfig.home') }}'">
<i class="bi bi-box-arrow-in-left"></i>
Back to device list
</button>
<div class="col-sm-3">
<button type="button" class="btn btn-success" onclick="window.location.href='{{ url_for('opticalconfig.home') }}'">
<i class="bi bi-box-arrow-in-left"></i>
Back to device list
</button>
</div>
<div class="col-sm-3">
<!-- <button type="button" class="btn btn-danger"><i class="bi bi-x-square"></i>Delete device</button> -->
<button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal">
<i class="bi bi-x-square"></i>
Delete Optical Config
</button>
</div>
<div class="col-sm-3">
<!-- <button type="button" class="btn btn-danger"><i class="bi bi-x-square"></i>Delete device</button> -->
<button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal">
<i class="bi bi-x-square"></i>
Delete Optical Config
</button>
</div>
</div>
</div>
<div class="col-sm-12">
......
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