Commit a3349a3a authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Common - Tools - Context Queries:

- updated definition of constant DEFAULT_CONTEXT_UUID to DEFAULT_CONTEXT_NAME
- updated definition of constant DEFAULT_TOPOLOGY_UUID to DEFAULT_TOPOLOGY_NAME
- updated definition of constant INTERDOMAIN_TOPOLOGY_UUID to INTERDOMAIN_TOPOLOGY_NAME
parent 3b82181e
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@

import logging
from typing import Dict, List, Set, Tuple
from common.Constants import DEFAULT_CONTEXT_UUID, DEFAULT_TOPOLOGY_UUID, INTERDOMAIN_TOPOLOGY_UUID
from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME, INTERDOMAIN_TOPOLOGY_NAME
from common.DeviceTypes import DeviceTypeEnum
from common.proto.context_pb2 import ContextId, Device, Empty, EndPointId, ServiceTypeEnum, Slice
from common.proto.pathcomp_pb2 import PathCompRequest
@@ -28,7 +28,7 @@ from pathcomp.frontend.client.PathCompClient import PathCompClient

LOGGER = logging.getLogger(__name__)

ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_UUID))
ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_NAME))
DATACENTER_DEVICE_TYPES = {DeviceTypeEnum.DATACENTER, DeviceTypeEnum.EMULATED_DATACENTER}

def get_local_device_uuids(context_client : ContextClient) -> Set[str]:
@@ -37,15 +37,15 @@ def get_local_device_uuids(context_client : ContextClient) -> Set[str]:
    LOGGER.info('[get_local_device_uuids] topologies.keys()={:s}'.format(str(topologies.keys())))

    local_topology_uuids = set(topologies.keys())
    local_topology_uuids.discard(INTERDOMAIN_TOPOLOGY_UUID)
    local_topology_uuids.discard(INTERDOMAIN_TOPOLOGY_NAME)
    LOGGER.info('[get_local_device_uuids] local_topology_uuids={:s}'.format(str(local_topology_uuids)))

    local_device_uuids = set()

    # add topology names except DEFAULT_TOPOLOGY_UUID and INTERDOMAIN_TOPOLOGY_UUID; they are abstracted as a
    # add topology names except DEFAULT_TOPOLOGY_NAME and INTERDOMAIN_TOPOLOGY_NAME; they are abstracted as a
    # local device in inter-domain and the name of the topology is used as abstract device name
    for local_topology_uuid in local_topology_uuids:
        if local_topology_uuid == DEFAULT_TOPOLOGY_UUID: continue
        if local_topology_uuid == DEFAULT_TOPOLOGY_NAME: continue
        local_device_uuids.add(local_topology_uuid)

    # add physical devices in the local topologies
@@ -60,8 +60,8 @@ def get_local_device_uuids(context_client : ContextClient) -> Set[str]:
    return local_device_uuids

def get_interdomain_device_uuids(context_client : ContextClient) -> Set[str]:
    context_uuid = DEFAULT_CONTEXT_UUID
    topology_uuid = INTERDOMAIN_TOPOLOGY_UUID
    context_uuid = DEFAULT_CONTEXT_NAME
    topology_uuid = INTERDOMAIN_TOPOLOGY_NAME
    interdomain_topology = get_topology(context_client, topology_uuid, context_uuid=context_uuid)
    if interdomain_topology is None:
        MSG = '[get_interdomain_device_uuids] {:s}/{:s} topology not found'
@@ -186,13 +186,13 @@ def get_device_to_domain_map(context_client : ContextClient) -> Dict[str, str]:
        context_id = context.context_id
        context_uuid = context_id.context_uuid.uuid
        topologies = context_client.ListTopologies(context_id)
        if context_uuid == DEFAULT_CONTEXT_UUID:
        if context_uuid == DEFAULT_CONTEXT_NAME:
            for topology in topologies.topologies:
                topology_id = topology.topology_id
                topology_uuid = topology_id.topology_uuid.uuid
                if topology_uuid in {DEFAULT_TOPOLOGY_UUID, INTERDOMAIN_TOPOLOGY_UUID}: continue
                if topology_uuid in {DEFAULT_TOPOLOGY_NAME, INTERDOMAIN_TOPOLOGY_NAME}: continue

                # add topology names except DEFAULT_TOPOLOGY_UUID and INTERDOMAIN_TOPOLOGY_UUID; they are
                # add topology names except DEFAULT_TOPOLOGY_NAME and INTERDOMAIN_TOPOLOGY_NAME; they are
                # abstracted as a local device in inter-domain and the name of the topology is used as
                # abstract device name
                devices_to_domains[topology_uuid] = topology_uuid
@@ -208,7 +208,7 @@ def get_device_to_domain_map(context_client : ContextClient) -> Dict[str, str]:
                topology_uuid = topology_id.topology_uuid.uuid

                # if topology is not interdomain
                if topology_uuid in {INTERDOMAIN_TOPOLOGY_UUID}: continue
                if topology_uuid in {INTERDOMAIN_TOPOLOGY_NAME}: continue

                # add devices to the remote domain list
                for device_id in topology.device_ids:
@@ -224,7 +224,7 @@ def compute_traversed_domains(
    local_device_uuids = get_local_device_uuids(context_client)
    LOGGER.info('[compute_traversed_domains] local_device_uuids={:s}'.format(str(local_device_uuids)))

    interdomain_devices = get_devices_in_topology(context_client, ADMIN_CONTEXT_ID, INTERDOMAIN_TOPOLOGY_UUID)
    interdomain_devices = get_devices_in_topology(context_client, ADMIN_CONTEXT_ID, INTERDOMAIN_TOPOLOGY_NAME)
    interdomain_devices = {
        device.device_id.device_uuid.uuid : device
        for device in interdomain_devices
+2 −2
Original line number Diff line number Diff line
@@ -14,14 +14,14 @@

import grpc, logging
from typing import Optional
from common.Constants import DEFAULT_CONTEXT_UUID
from common.Constants import DEFAULT_CONTEXT_NAME
from common.proto.context_pb2 import Service, ServiceId
from context.client.ContextClient import ContextClient

LOGGER = logging.getLogger(__name__)

def get_service(
        context_client : ContextClient, service_uuid : str, context_uuid : str = DEFAULT_CONTEXT_UUID,
        context_client : ContextClient, service_uuid : str, context_uuid : str = DEFAULT_CONTEXT_NAME,
        rw_copy : bool = False
    ) -> Optional[Service]:
    try:
+2 −2
Original line number Diff line number Diff line
@@ -14,14 +14,14 @@

import grpc, logging
from typing import Optional
from common.Constants import DEFAULT_CONTEXT_UUID
from common.Constants import DEFAULT_CONTEXT_NAME
from common.proto.context_pb2 import Slice, SliceId
from context.client.ContextClient import ContextClient

LOGGER = logging.getLogger(__name__)

def get_slice(
        context_client : ContextClient, slice_uuid : str, context_uuid : str = DEFAULT_CONTEXT_UUID,
        context_client : ContextClient, slice_uuid : str, context_uuid : str = DEFAULT_CONTEXT_NAME,
        rw_copy : bool = False
    ) -> Optional[Slice]:
    try:
+2 −2
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@

import grpc, logging
from typing import List, Optional
from common.Constants import DEFAULT_CONTEXT_UUID
from common.Constants import DEFAULT_CONTEXT_NAME
from common.proto.context_pb2 import ContextId, Topology, TopologyId
from common.tools.object_factory.Context import json_context_id
from common.tools.object_factory.Topology import json_topology
@@ -45,7 +45,7 @@ def create_missing_topologies(
        context_client.SetTopology(grpc_topology)

def get_topology(
        context_client : ContextClient, topology_uuid : str, context_uuid : str = DEFAULT_CONTEXT_UUID,
        context_client : ContextClient, topology_uuid : str, context_uuid : str = DEFAULT_CONTEXT_NAME,
        rw_copy : bool = False
    ) -> Optional[Topology]:
    try: