Commit c40e680c authored by Mohamad Rahhal's avatar Mohamad Rahhal
Browse files

Merge branch 'feat/389-cttc-spine-leaf-component' of...

Merge branch 'feat/389-cttc-spine-leaf-component' of https://labs.etsi.org/rep/tfs/controller into feat/390-cttc-integration-of-spine-leaf-fabric-management
parents 34286adb 8827f9c4
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ import os
from common.proto.context_pb2 import ConfigRule
from common.proto.spineleaf_pb2 import DeployDeviceConfigRequest
from common.tools.context_queries.Device import get_device
from common.tools.object_factory.ConfigRule import json_config_rule_set
from common.tools.object_factory.ConfigRule import json_config_rule_set, json_config_rule_delete
from context.client.ContextClient import ContextClient
from device.client.DeviceClient import DeviceClient
from spine_leaf.client.SpineLeafClient import SpineLeafClient
@@ -36,6 +36,10 @@ SPINE_LEAFSERVICE_HOST = os.getenv("SPINE_LEAFSERVICE_SERVICE_HOST", "10.152.183
SPINE_LEAFSERVICE_PORT = int(os.getenv("SPINE_LEAFSERVICE_SERVICE_PORT_GRPC", "10095"))


def is_deconfigure_enabled() -> bool:
    return os.getenv("DECONFIGURE", "false").lower() in ("1", "true", "yes")


def parse_spineleaf_rule(entry):
    if isinstance(entry, (list, tuple)) and len(entry) == 2:
        resource_key, resource_value = entry
@@ -94,9 +98,8 @@ class ApplySpineLeafConfig:
                    continue

                resource_key, resource_value = parsed
                config_rules.append(
                    ConfigRule(**json_config_rule_set(resource_key, resource_value))
                )
                rule_factory = json_config_rule_delete if is_deconfigure_enabled() else json_config_rule_set
                config_rules.append(ConfigRule(**rule_factory(resource_key, resource_value)))

            LOGGER.info("Normalized config rules: %s", config_rules)

@@ -120,7 +123,12 @@ class ApplySpineLeafConfig:
                result = device_client.ConfigureDevice(device)
                LOGGER.info("ConfigureDevice result: %s", result)
            else:
                LOGGER.info("Dry-run: not applying configuration to device %s. Set APPLY_CONFIG=1 to apply.", request.device_uuid)
                mode = "deconfiguration" if is_deconfigure_enabled() else "configuration"
                LOGGER.info(
                    "Dry-run: not applying %s to device %s. Set APPLY_CONFIG=1 to apply.",
                    mode,
                    request.device_uuid,
                )
        finally:
            device_client.close()
            context_client.close()