Commit 89e73d9b authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Service component - L3NM OpenConfig Service Handler:

- intermediate step towards supporting configuration of OcNOS devices
parent 658b71b0
Loading
Loading
Loading
Loading
+17 −6
Original line number Diff line number Diff line
@@ -12,10 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Dict, List, Tuple
from typing import Any, Dict, List, Optional, Tuple
from common.tools.object_factory.ConfigRule import json_config_rule_delete, json_config_rule_set
from service.service.service_handler_api.AnyTreeTools import TreeNode

def get_value(field_name : str, *containers, default=None) -> Optional[Any]:
    if len(containers) == 0: raise Exception('No containers specified')
    for container in containers:
        if field_name not in container: continue
        return container[field_name]
    return default

def setup_config_rules(
    service_uuid : str, connection_uuid : str, device_uuid : str, endpoint_uuid : str, endpoint_name : str,
    service_settings : TreeNode, device_settings : TreeNode, endpoint_settings : TreeNode, endpoint_acls : List [Tuple]
@@ -29,9 +36,11 @@ def setup_config_rules(
    json_device_settings   : Dict = device_settings.value
    json_endpoint_settings : Dict = endpoint_settings.value

    mtu                       = json_settings.get('mtu',                          1450     )  # 1512
    settings = (json_settings, json_endpoint_settings, json_device_settings)

    mtu                       = get_value('mtu', *settings, default=1450)   # 1512
    #address_families         = json_settings.get('address_families',             []       )  # ['IPV4']
    bgp_as                    = json_settings.get('bgp_as',                       65000    )  # 65000
    bgp_as                    = get_value('bgp_as', *settings, default=65000)   # 65000

    router_id                 = json_endpoint_settings.get('router_id',           '0.0.0.0')  # '10.95.0.10'
    route_distinguisher       = json_settings.get('route_distinguisher',          '65000:101'    )  # '60001:801'
@@ -206,14 +215,16 @@ def teardown_config_rules(
    json_device_settings   : Dict = device_settings.value
    json_endpoint_settings : Dict = endpoint_settings.value

    settings = (json_settings, json_endpoint_settings, json_device_settings)

    service_short_uuid        = service_uuid.split('-')[-1]
    network_instance_name     = '{:s}-NetInst'.format(service_short_uuid)
    #network_interface_desc    = '{:s}-NetIf'.format(service_uuid)
    #network_subinterface_desc = '{:s}-NetSubIf'.format(service_uuid)

    #mtu                 = json_settings.get('mtu',                          1450     )  # 1512
    #mtu                       = get_value('mtu', *settings, default=1450)   # 1512
    #address_families    = json_settings.get('address_families',             []       )  # ['IPV4']
    #bgp_as              = json_settings.get('bgp_as',                       65000    )  # 65000
    #bgp_as                    = get_value('bgp_as', *settings, default=65000)   # 65000
    route_distinguisher = json_settings.get('route_distinguisher',          '0:0'    )  # '60001:801'
    #sub_interface_index = json_endpoint_settings.get('sub_interface_index', 0        )  # 1
    #router_id           = json_endpoint_settings.get('router_id',           '0.0.0.0')  # '10.95.0.10'
+4 −4
Original line number Diff line number Diff line
@@ -22,12 +22,12 @@ def setup_config_rules(
) -> List[Dict]:

    if service_settings  is None: return []
    if endpoint_settings is None: return []
    if device_settings   is None: return []
    if endpoint_settings is None: return []

    json_settings          : Dict = service_settings.value
    json_endpoint_settings : Dict = endpoint_settings.value
    json_device_settings   : Dict = device_settings.value
    json_endpoint_settings : Dict = endpoint_settings.value

    mtu                       = json_settings.get('mtu',                          1450     )  # 1512
    #address_families         = json_settings.get('address_families',             []       )  # ['IPV4']
@@ -233,12 +233,12 @@ def teardown_config_rules(
) -> List[Dict]:

    if service_settings  is None: return []
    if endpoint_settings is None: return []
    if device_settings   is None: return []
    if endpoint_settings is None: return []

    json_settings          : Dict = service_settings.value
    json_endpoint_settings : Dict = endpoint_settings.value
    json_device_settings   : Dict = device_settings.value
    json_endpoint_settings : Dict = endpoint_settings.value

    service_short_uuid        = service_uuid.split('-')[-1]
    # network_instance_name     = '{:s}-NetInst'.format(service_short_uuid)