示例#1
0
 def add_vrrp_group(self,
                    vlan_number,
                    group_id,
                    ips=None,
                    priority=None,
                    hello_interval=None,
                    dead_interval=None,
                    track_id=None,
                    track_decrement=None):
     self.real_switch.add_vrrp_group(vlan_number,
                                     group_id,
                                     ips=ips,
                                     priority=priority,
                                     hello_interval=hello_interval,
                                     dead_interval=dead_interval,
                                     track_id=track_id,
                                     track_decrement=track_decrement)
     self.vlans_cache[vlan_number].vrrp_groups.append(
         VrrpGroup(id=group_id,
                   ips=ips,
                   priority=priority,
                   hello_interval=hello_interval,
                   dead_interval=dead_interval,
                   track_id=track_id,
                   track_decrement=track_decrement))
示例#2
0
    def test_remove_vrrp_group(self):
        self.real_switch_mock.should_receive("get_vlans").once() \
            .and_return([Vlan(1, vrrp_groups=[VrrpGroup(id=2)])])
        self.switch.get_vlans()

        self.real_switch_mock.should_receive("remove_vrrp_group").once() \
            .with_args(1, 2)

        self.switch.remove_vrrp_group(1, 2)

        assert_that(self.switch.get_vlans(), is_([Vlan(1, vrrp_groups=[])]))
示例#3
0
def _to_vrrp_group(vrrp_node):
    priority = first_text(vrrp_node.xpath("priority"))
    track_decrement = first_text(vrrp_node.xpath("track/route/priority-cost"))

    return VrrpGroup(
        id=int(first_text(vrrp_node.xpath("name"))),
        ips=[IPAddress(ip.text) for ip in vrrp_node.xpath("virtual-address")],
        priority=int(priority) if priority is not None else None,
        track_id=first_text(vrrp_node.xpath("track/route/route_address")),
        track_decrement=int(track_decrement)
        if track_decrement is not None else None,
    )
示例#4
0
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
示例#5
0
    def test_add_vrrp_group(self):
        self.real_switch_mock.should_receive("get_vlans").once() \
            .and_return([Vlan(1)])
        self.switch.get_vlans()

        self.real_switch_mock.should_receive("add_vrrp_group").once() \
            .with_args(1, 2, ips=None, priority=23, hello_interval=None,
                       dead_interval=None, track_id=None, track_decrement=None)

        self.switch.add_vrrp_group(1, 2, priority=23)

        assert_that(self.switch.get_vlans(),
                    is_([Vlan(1, vrrp_groups=[VrrpGroup(id=2, priority=23)])]))
示例#6
0
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
示例#7
0
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
示例#8
0
文件: cisco.py 项目: emmurd/netman
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
示例#9
0
def to_core(serialized):
    return VrrpGroup(ips=[IPAddress(ip) for ip in serialized.pop('ips')],
                     **serialized)