Commit c8fc9fe9 authored by Pablo Armingol's avatar Pablo Armingol
Browse files

feat: integrate device querying functionality and update optical path...

feat: integrate device querying functionality and update optical path provisioning with controller IP
parent 6e25d4e9
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import logging
import uuid
from common.proto.context_pb2 import Service, ConfigRule, ConfigActionEnum
from common.proto.pathcomp_pb2 import PathCompReply
from .TopologyTools import get_device_with_driver


LOGGER = logging.getLogger(__name__)
@@ -395,20 +396,20 @@ def compute_optical_path(service: Service) -> PathCompReply:
            "src-ip-mask": str(nodes[src_name]["ip-mask"]),
            "src-vlan-id": nodes[src_name]["vlan-id"],
        }
        if device_name:
            content["device_name"] = device_name

        for i, dest in enumerate(dest_list):
            if dest in nodes:
                content[f"dest{i+1}-node-uuid"] = dest
                content[f"dest{i+1}-ip-address"] = nodes[dest]["ip-address"]
                content[f"dest{i+1}-ip-mask"] = str(nodes[dest]["ip-mask"])
                content[f"dest{i+1}-vlan-id"] = nodes[dest]["vlan-id"]
        controller_ip = get_device_with_driver()
                
        provisionamiento["actions"].append({
            "type": "CONFIG_VPNL3",
            "layer": "IP",
            "content": content,
            "controller-uuid": "IP Controller"
            "controller_uuid": controller_ip
        })

    config_rules.append(provisionamiento)
+35 −1
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging, math
import logging, math, os, socket, requests
from typing import Dict, Optional
from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME, ServiceNameEnum
from common.Settings import ENVVAR_SUFIX_SERVICE_HOST, ENVVAR_SUFIX_SERVICE_PORT_GRPC, find_environment_variables, get_env_var_name
@@ -25,6 +25,7 @@ from common.tools.grpc.Tools import grpc_message_to_json_string
from context.client.ContextClient import ContextClient
from forecaster.client.ForecasterClient import ForecasterClient


LOGGER = logging.getLogger(__name__)

def get_service_schedule(service : Service) -> Optional[Constraint_Schedule]:
@@ -96,3 +97,36 @@ def get_pathcomp_topology_details(request : PathCompRequest, allow_forecasting :
            link.attributes.total_capacity_gbps = total_capacity_gbps

    return topology_details

# The HOST IP of the TFS controller is needed to query the devices and get the 
# IP address of the controller to be used in the path provisioning.
ENVVAR_TFS_API_HOST = '10.95.89.50'



def get_device_with_driver(driver_name: str = 'DEVICEDRIVER_IETF_L3VPN', timeout: int = 10):
    """Query the TFS controller REST API and return the _connect/address value of the first device with the given driver.

    Example: GET http://<vm-ip>/tfs-api/devices

    Returns the _connect/address string or None.
    """
    url = f'http://{ENVVAR_TFS_API_HOST}:80/tfs-api/devices'
    try:
        logging.debug("Requesting devices from %s", url)
        resp = requests.get(url, timeout=timeout)
        resp.raise_for_status()
        data = resp.json()
    except Exception as e:
        logging.warning("Error fetching devices from %s: %s", url, e)
        return None

    devices = data.get('devices', []) if isinstance(data, dict) else []
    for dev in devices:
        drivers = dev.get('device_drivers') or []
        if isinstance(drivers, list) and driver_name in drivers:
            device_name = dev.get('name')
            return device_name

    logging.info("No device with driver %s found on %s", driver_name, url)
    return None