def handle_physical_interface_mac(template_config, subnet): tag_name = tag_name_util.get_ethIIIf_tag(subnet) property_value = { "className": "EthIIIf", "tagName": tag_name, "propertyValueList": { "UseDefaultPhyMac": "TRUE" } } property_value_list = config_utils.get_property_value_list(template_config) property_value_list.append(property_value)
def build_eth_config(subnet, template_config): plLogger.LogInfo("build_eth_config: ") config_utils.init_config(template_config) mac_port_step = None if subnet["mac_config"]["_type"] != "Profile::UniqueMacConfig": mac_port_step = subnet["mac_config"]["mac_port_step"] mac_config = subnet["mac_config"] dev_count = subnet["device_count_per_port"] if mac_config["_type"] == "Profile::UniqueMacConfig": if dev_count > 1: # randomize mac is handled outside of this command return else: handle_physical_interface_mac(template_config, subnet) return plLogger.LogInfo(str(mac_config)) mac = str(mac_config["mac"]) mac_step = str(mac_config["mac_step"]) tag_name = tag_name_util.get_ethIIIf_tag(subnet) property_value = { "className": "EthIIIf", "tagName": tag_name, "propertyValueList": { "SrcMacStep": mac_step } } property_value_list = config_utils.get_property_value_list(template_config) property_value_list.append(property_value) stm_property_modifier = { "className": "EthIIIf", "tagName": tag_name + ".SourceMac", "parentTagName": tag_name, "propertyName": "SourceMac", "propertyValueList": { "Start": mac, "Step": mac_port_step, "ResetOnNewTargetObject": False } } stm_property_modifier_list = config_utils.get_stm_property_modifier_list( template_config ) stm_property_modifier_list.append(stm_property_modifier)
def create_config(subnet, template_name, tag_prefix): template_config = {} config_utils.init_config(template_config) template_config["baseTemplateFile"] = template_name template_config["tagPrefix"] = tag_prefix tag_name = tag_name_util.get_dev_tag(subnet) property_value = { "className": "EmulatedDevice", "tagName": tag_name, "propertyValueList": { "DeviceCount": str(subnet["device_count_per_port"]) } } property_value_list = config_utils.get_property_value_list(template_config) property_value_list.append(property_value) return template_config
def build_dhcp_config(subnet, template_config): plLogger.LogInfo("build_dhcp_config: ") if not subnet["dhcp_enabled"]: plLogger.LogInfo("dhcp disabled") return config_utils.init_config(template_config) tag_name = None dev_tag_name = tag_name_util.get_dev_tag(subnet) if subnet["ip_config"]["_type"] == "Profile::Ipv4Config": tag_name = tag_name_util.get_dhcpv4_tag(subnet) else: raise Exception("DHCP for Ipv6 is not supported") merge_list = config_utils.get_merge_list(template_config) merge_list.append( { "mergeSourceTemplateFile": "Access_Protocols.xml", "mergeSourceTag": tag_name, "mergeTargetTag": dev_tag_name } ) if subnet["gateway_config"]["_type"] == "Profile::GatewayDhcpConfig": option_list = ["1", "3", "6", "15", "33", "44"] property_value = { "className": "Dhcpv4BlockConfig", "tagName": tag_name, "propertyValueList": { "OptionList": option_list, "EnableRouterOption": "TRUE" } } property_value_list = config_utils.get_property_value_list( template_config ) property_value_list.append(property_value)
def build_ipv4_config(subnet, template_config): plLogger.LogInfo("build_ipv4_config: ") config_utils.init_config(template_config) gateway_type = subnet["gateway_config"]["_type"] ip_config = subnet["ip_config"] ipv4_port_step = ip_config["ipv4_port_step"] gateway_ipv4_port_step = None gateway_mac_port_step = None gateway_config = subnet["gateway_config"] if gateway_type == "Profile::GatewayArpConfig": gw_ip_config = gateway_config.get("ip_config") gateway_ipv4_port_step = gw_ip_config["ipv4_port_step"] elif gateway_type == "Profile::GatewayMacConfig": gateway_mac_port_step = gateway_config["mac_port_step"] gateway_config = subnet["gateway_config"] ip_config = subnet["ip_config"] gateway_type = gateway_config["_type"] gw_ip_config = gateway_config.get("ip_config") ipv4 = str(ip_config["ipv4"]) ipv4_step = str(ip_config["ipv4_step"]) prefix = str(ip_config["prefix"]) pri = 0 if "control_plane_priority" in ip_config: pri_str = str(ip_config["control_plane_priority"]) if pri_str == "routine": pri = 0 elif pri_str == "high": pri = 32 else: pri = 0 # Modify the Ipv4If parameters # Attach StmPropertyModifier objects to the Address and Gateway # fields. # Address tag_name = tag_name_util.get_ipv4If_tag(subnet) stm_property_modifier_list = config_utils.get_stm_property_modifier_list( template_config ) property_value_list = config_utils.get_property_value_list(template_config) ipv4_stm_property_modifier = { "className": "Ipv4If", "tagName": tag_name + ".Address", "parentTagName": tag_name, "propertyName": "Address", "propertyValueList": { "Start": ipv4, "Step": ipv4_port_step, "ResetOnNewTargetObject": False } } stm_property_modifier_list.append(ipv4_stm_property_modifier) # Gateway # Profile::GatewayDhcpConfig is handled in dhcp_builder if gateway_type == "Profile::GatewayArpConfig": process_gateway_arp_config(subnet, template_config, gateway_ipv4_port_step) elif gateway_type == "Profile::GatewayMacConfig": process_gateway_mac_config(subnet, template_config, gateway_mac_port_step) # Modify any other parameters not on the StmPropertyModifier ipv4_property_value = { "className": "Ipv4If", "tagName": tag_name, "propertyValueList": { "AddrStep": ipv4_step, "PrefixLength": prefix, "Tos": str(pri) } } if gateway_type == "Profile::GatewayArpConfig": gw_step = str(gw_ip_config["ipv4_step"]) ipv4_property_value["propertyValueList"]["GatewayStep"] = gw_step elif gateway_type == "Profile::GatewayMacConfig": ipv4_property_value["propertyValueList"]["ResolveGatewayMac"] = "FALSE" property_value_list.append(ipv4_property_value)