def add_interface_vlan_data(target_vlan, int_vlan_data): vrrp_group = None for line in int_vlan_data[1:]: if vrrp_group is not None and not line.startswith(" "): vrrp_group = False if regex.match("^ ip address ([^\s]*)", line): target_vlan.ips.append(BrocadeIPNetwork(regex[0], is_secondary=line.endswith("secondary"))) elif regex.match("^ ip access-group ([^\s]*) ([^\s]*)", line): direction = {'in': IN, 'out': OUT}[regex[1]] target_vlan.access_groups[direction] = regex[0] elif regex.match("^ vrf forwarding ([^\s]*)", line): target_vlan.vrf_forwarding = regex[0] elif regex.match("^ (?:ip|ipv6) vrrp-extended vrid ([^\s]*)", line): vrrp_group = next((group for group in target_vlan.vrrp_groups if str(group.id) == regex[0]), None) if vrrp_group is None: vrrp_group = VrrpGroup(id=int(regex[0])) target_vlan.vrrp_groups.append(vrrp_group) elif regex.match("^ (?:ip|ipv6)-address ([^\s]*)", line): vrrp_group.ips.append(IPAddress(regex[0])) elif regex.match("^ backup priority ([^\s]*) track-priority ([^\s]*)", line): vrrp_group.priority = int(regex[0]) vrrp_group.track_decrement = int(regex[1]) elif regex.match("^ hello-interval ([^\s]*)", line): vrrp_group.hello_interval = int(regex[0]) elif regex.match("^ dead-interval ([^\s]*)", line): vrrp_group.dead_interval = int(regex[0]) elif regex.match("^ track-port (.*)", line): vrrp_group.track_id = regex[0] elif regex.match("^ activate", line): vrrp_group = None elif regex.match("^ ip helper-address ([^\s]*)", line): target_vlan.dhcp_relay_servers.append(IPAddress(regex[0])) elif regex.match("^ no ip redirect", line): target_vlan.icmp_redirects = False
def apply_interface_running_config_data(vlan, data): for line in data: if regex.match("^ ip address ([^\s]*) ([^\s]*)(.*)", line): ip = IPNetwork("{}/{}".format(regex[0], regex[1])) if "secondary" not in regex[2]: vlan.ips.insert(0, ip) else: vlan.ips.append(ip) elif regex.match("^ ip access-group ([^\s]*) ([^\s]*).*", line): if regex[1] == "in": vlan.access_groups[IN] = regex[0] else: vlan.access_groups[OUT] = regex[0] elif regex.match("^ ip vrf forwarding ([^\s]*).*", line): vlan.vrf_forwarding = regex[0] elif regex.match("^ standby ([\d]+) (.*)", line): vrrp_group = next( (group for group in vlan.vrrp_groups if str(group.id) == regex[0]), None) if vrrp_group is None: vrrp_group = VrrpGroup(id=int(regex[0])) vlan.vrrp_groups.append(vrrp_group) vrrp_info = regex[1].strip() if regex.match("^ip ([^\s]*).*", vrrp_info): vrrp_group.ips.append(IPAddress(regex[0])) elif regex.match("^timers ([^\s]*) ([^\s]*)", vrrp_info): vrrp_group.hello_interval = int(regex[0]) vrrp_group.dead_interval = int(regex[1]) elif regex.match("^priority ([^\s]*)", vrrp_info): vrrp_group.priority = int(regex[0]) elif regex.match("^track ([^\s]*) decrement ([^\s]*)", vrrp_info): vrrp_group.track_id = regex[0] vrrp_group.track_decrement = int(regex[1]) elif regex.match("^ ip helper-address ([^\s]*)", line): vlan.dhcp_relay_servers.append(IPAddress(regex[0])) elif regex.match("^ no ip proxy-arp", line): vlan.arp_routing = False elif regex.match("^ no ip redirects", line): vlan.icmp_redirects = False elif regex.match("^ ip verify unicast source reachable-via rx", line): vlan.unicast_rpf_mode = STRICT elif regex.match("^ ntp disable", line): vlan.ntp = False
def apply_interface_running_config_data(vlan, data): for line in data: if regex.match("^ ip address ([^\s]*) ([^\s]*)(.*)", line): ip = IPNetwork("{}/{}".format(regex[0], regex[1])) if "secondary" not in regex[2]: vlan.ips.insert(0, ip) else: vlan.ips.append(ip) elif regex.match("^ ip access-group ([^\s]*) ([^\s]*).*", line): if regex[1] == "in": vlan.access_groups[IN] = regex[0] else: vlan.access_groups[OUT] = regex[0] elif regex.match("^ ip vrf forwarding ([^\s]*).*", line): vlan.vrf_forwarding = regex[0] elif regex.match("^ standby ([^\s]*)(.*)", line): vrrp_group = next((group for group in vlan.vrrp_groups if str(group.id) == regex[0]), None) if vrrp_group is None: vrrp_group = VrrpGroup(id=int(regex[0])) vlan.vrrp_groups.append(vrrp_group) vrrp_info = regex[1].strip() if regex.match("^ip ([^\s]*).*", vrrp_info): vrrp_group.ips.append(IPAddress(regex[0])) elif regex.match("^timers ([^\s]*) ([^\s]*)", vrrp_info): vrrp_group.hello_interval = int(regex[0]) vrrp_group.dead_interval = int(regex[1]) elif regex.match("^priority ([^\s]*)", vrrp_info): vrrp_group.priority = int(regex[0]) elif regex.match("^track ([^\s]*) decrement ([^\s]*)", vrrp_info): vrrp_group.track_id = regex[0] vrrp_group.track_decrement = int(regex[1]) elif regex.match("^ ip helper-address ([^\s]*)", line): vlan.dhcp_relay_servers.append(IPAddress(regex[0])) elif regex.match("^ no ip redirects", line): vlan.icmp_redirects = False
def add_interface_vlan_data(target_vlan, int_vlan_data): vrrp_group = None for line in int_vlan_data[1:]: if vrrp_group is not None and not line.startswith(" "): vrrp_group = False if regex.match("^ ip address ([^\s]*)", line): target_vlan.ips.append( BrocadeIPNetwork(regex[0], is_secondary=line.endswith("secondary"))) elif regex.match("^ ip access-group ([^\s]*) ([^\s]*)", line): direction = {'in': IN, 'out': OUT}[regex[1]] target_vlan.access_groups[direction] = regex[0] elif regex.match("^ vrf forwarding ([^\s]*)", line): target_vlan.vrf_forwarding = regex[0] elif regex.match("^ ip vrrp-extended vrid ([^\s]*)", line): vrrp_group = next((group for group in target_vlan.vrrp_groups if str(group.id) == regex[0]), None) if vrrp_group is None: vrrp_group = VrrpGroup(id=int(regex[0])) target_vlan.vrrp_groups.append(vrrp_group) elif regex.match("^ ip-address ([^\s]*)", line): vrrp_group.ips.append(IPAddress(regex[0])) if vrrp_group: if regex.match( "^ backup priority ([^\s]*) track-priority ([^\s]*)", line): vrrp_group.priority = int(regex[0]) vrrp_group.track_decrement = int(regex[1]) elif regex.match("^ hello-interval ([^\s]*)", line): vrrp_group.hello_interval = int(regex[0]) elif regex.match("^ dead-interval ([^\s]*)", line): vrrp_group.dead_interval = int(regex[0]) elif regex.match("^ track-port (.*)", line): vrrp_group.track_id = regex[0] elif regex.match("^ activate", line): vrrp_group = None elif regex.match("^ ip helper-address ([^\s]*)", line): target_vlan.dhcp_relay_servers.append(IPAddress(regex[0])) elif regex.match("^ no ip redirect", line): target_vlan.icmp_redirects = False