diff --git a/src/service/service/service_handlers/l3nm_openconfig/ConfigRules.py b/src/service/service/service_handlers/l3nm_openconfig/ConfigRules.py index 716d0413abc0ed4897c5825f7471946ea7d28aa3..7527932877f47a092a35f286defb3744e05db109 100644 --- a/src/service/service/service_handlers/l3nm_openconfig/ConfigRules.py +++ b/src/service/service/service_handlers/l3nm_openconfig/ConfigRules.py @@ -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' @@ -199,21 +208,23 @@ def teardown_config_rules( ) -> List[Dict]: if service_settings is None: return [] - if device_settings is None: return [] + if device_settings is None: return [] if endpoint_settings is None: return [] json_settings : Dict = service_settings.value 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' diff --git a/src/service/service/service_handlers/l3nm_openconfig/ConfigRules_test_ocnos.py b/src/service/service/service_handlers/l3nm_openconfig/ConfigRules_test_ocnos.py index 1f2593b0d494ab42c9af250c18642a380b68bbcd..5fa1d0b5b6931902b4ac50847c90bf67738032ba 100644 --- a/src/service/service/service_handlers/l3nm_openconfig/ConfigRules_test_ocnos.py +++ b/src/service/service/service_handlers/l3nm_openconfig/ConfigRules_test_ocnos.py @@ -22,12 +22,12 @@ def setup_config_rules( ) -> List[Dict]: if service_settings is None: return [] + if device_settings is None: return [] if endpoint_settings is None: return [] - if device_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 device_settings is None: return [] if endpoint_settings is None: return [] - if device_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)