Esempio n. 1
0
def bondings_caps(running_config):
    ovs_bonding_caps = {}
    dhcpv4ifaces, dhcpv6ifaces = dhcp.get_dhclient_ifaces()
    routes = netinfo_routes.get_routes()
    for bonding, attrs in iter_ovs_bonds(running_config.bonds):
        options = get_bond_options(attrs.get('options'), keep_custom=True)
        net_info = _get_net_info(attrs, bonding, dhcpv4ifaces, dhcpv6ifaces,
                                 routes)
        net_info['slaves'] = attrs.get('nics')
        net_info['active_slave'] = _get_active_slave(bonding)
        net_info['opts'] = options
        ovs_bonding_caps[bonding] = net_info
    return ovs_bonding_caps
Esempio n. 2
0
def bondings_caps(running_config):
    ovs_bonding_caps = {}
    dhcpv4ifaces, dhcpv6ifaces = dhcp.get_dhclient_ifaces()
    routes = netinfo_routes.get_routes()
    for bonding, attrs in iter_ovs_bonds(running_config.bonds):
        options = get_bond_options(attrs.get('options'), keep_custom=True)
        net_info = _get_net_info(attrs, bonding, dhcpv4ifaces, dhcpv6ifaces,
                                 routes)
        net_info['slaves'] = attrs.get('nics')
        net_info['active_slave'] = _get_active_slave(bonding)
        net_info['opts'] = options
        ovs_bonding_caps[bonding] = net_info
    return ovs_bonding_caps
Esempio n. 3
0
def networks_caps(running_config):
    ovs_networks_caps = {}
    dhcpv4ifaces, dhcpv6ifaces = dhcp.get_dhclient_ifaces()
    routes = netinfo_routes.get_routes()
    for network, attrs in iter_ovs_nets(running_config.networks):
        interface = network if 'vlan' in attrs else BRIDGE_NAME
        net_info = _get_net_info(attrs, interface, dhcpv4ifaces, dhcpv6ifaces,
                                 routes)
        net_info['iface'] = network
        net_info['bridged'] = True
        net_info['ports'] = _get_ports(network, attrs)
        net_info['stp'] = _get_stp(interface)
        ovs_networks_caps[network] = net_info
    return ovs_networks_caps
Esempio n. 4
0
def networks_caps(running_config):
    ovs_networks_caps = {}
    dhcpv4ifaces, dhcpv6ifaces = dhcp.get_dhclient_ifaces()
    routes = netinfo_routes.get_routes()
    for network, attrs in iter_ovs_nets(running_config.networks):
        interface = network if 'vlan' in attrs else BRIDGE_NAME
        net_info = _get_net_info(attrs, interface, dhcpv4ifaces, dhcpv6ifaces,
                                 routes)
        net_info['iface'] = network
        net_info['bridged'] = True
        net_info['ports'] = _get_ports(network, attrs)
        net_info['stp'] = _get_stp(interface)
        ovs_networks_caps[network] = net_info
    return ovs_networks_caps
Esempio n. 5
0
def vlans_caps(running_config):
    ovs_vlans_caps = {}
    dhcpv4ifaces, dhcpv6ifaces = dhcp.get_dhclient_ifaces()
    routes = netinfo_routes.get_routes()
    for network, attrs in iter_ovs_nets(running_config.networks):
        vlan = attrs.get('vlan')
        if vlan is not None:
            net_info = _get_net_info(attrs, network, dhcpv4ifaces,
                                     dhcpv6ifaces, routes)
            iface = attrs.get('bonding') or attrs.get('nic')
            net_info['iface'] = iface
            net_info['bridged'] = True
            net_info['vlanid'] = int(vlan)
            ovs_vlans_caps['%s.%s' % (iface, vlan)] = net_info
    return ovs_vlans_caps
Esempio n. 6
0
def vlans_caps(running_config):
    ovs_vlans_caps = {}
    dhcpv4ifaces, dhcpv6ifaces = dhcp.get_dhclient_ifaces()
    routes = netinfo_routes.get_routes()
    for network, attrs in iter_ovs_nets(running_config.networks):
        vlan = attrs.get('vlan')
        if vlan is not None:
            net_info = _get_net_info(attrs, network, dhcpv4ifaces,
                                     dhcpv6ifaces, routes)
            iface = attrs.get('bonding') or attrs.get('nic')
            net_info['iface'] = iface
            net_info['bridged'] = True
            net_info['vlanid'] = int(vlan)
            ovs_vlans_caps['%s.%s' % (iface, vlan)] = net_info
    return ovs_vlans_caps
Esempio n. 7
0
    def testGetDhclientIfaces(self):
        LEASES = (
            'lease {{\n'
            '  interface "valid";\n'
            '  expire {active_datetime:%w %Y/%m/%d %H:%M:%S};\n'
            '}}\n'
            'lease {{\n'
            '  interface "valid2";\n'
            '  expire epoch {active:.0f}; # Sat Jan 31 20:04:20 2037\n'
            '}}\n'  # human-readable date is just a comment
            'lease {{\n'
            '  interface "valid3";\n'
            '  expire never;\n'
            '}}\n'
            'lease {{\n'
            '  interface "expired";\n'
            '  expire {expired_datetime:%w %Y/%m/%d %H:%M:%S};\n'
            '}}\n'
            'lease {{\n'
            '  interface "expired2";\n'
            '  expire epoch {expired:.0f}; # Fri Jan 31 20:04:20 2014\n'
            '}}\n'
            'lease6 {{\n'
            '  interface "valid4";\n'
            '  ia-na [some MAC address] {{\n'
            '    iaaddr [some IPv6 address] {{\n'
            '      starts {now:.0f};\n'
            '      max-life 60;\n'  # the lease has a minute left
            '    }}\n'
            '  }}\n'
            '}}\n'
            'lease6 {{\n'
            '  interface "expired3";\n'
            '  ia-na [some MAC address] {{\n'
            '    iaaddr [some IPv6 address] {{\n'
            '      starts {expired:.0f};\n'
            '      max-life 30;\n'  # the lease expired half a minute ago
            '    }}\n'
            '  }}\n'
            '}}\n')

        with namedTemporaryDir() as tmp_dir:
            lease_file = os.path.join(tmp_dir, 'test.lease')
            with open(lease_file, 'w') as f:
                now = time.time()
                last_minute = now - 60
                next_minute = now + 60

                f.write(
                    LEASES.format(
                        active_datetime=datetime.utcfromtimestamp(next_minute),
                        active=next_minute,
                        expired_datetime=datetime.utcfromtimestamp(
                            last_minute),
                        expired=last_minute,
                        now=now))

            dhcpv4_ifaces, dhcpv6_ifaces = \
                dhcp.get_dhclient_ifaces([lease_file])

        self.assertIn('valid', dhcpv4_ifaces)
        self.assertIn('valid2', dhcpv4_ifaces)
        self.assertIn('valid3', dhcpv4_ifaces)
        self.assertNotIn('expired', dhcpv4_ifaces)
        self.assertNotIn('expired2', dhcpv4_ifaces)
        self.assertIn('valid4', dhcpv6_ifaces)
        self.assertNotIn('expired3', dhcpv6_ifaces)
Esempio n. 8
0
    def testGetDhclientIfaces(self):
        LEASES = (
            'lease {{\n'
            '  interface "valid";\n'
            '  expire {active_datetime:%w %Y/%m/%d %H:%M:%S};\n'
            '}}\n'
            'lease {{\n'
            '  interface "valid2";\n'
            '  expire epoch {active:.0f}; # Sat Jan 31 20:04:20 2037\n'
            '}}\n'                   # human-readable date is just a comment
            'lease {{\n'
            '  interface "valid3";\n'
            '  expire never;\n'
            '}}\n'
            'lease {{\n'
            '  interface "expired";\n'
            '  expire {expired_datetime:%w %Y/%m/%d %H:%M:%S};\n'
            '}}\n'
            'lease {{\n'
            '  interface "expired2";\n'
            '  expire epoch {expired:.0f}; # Fri Jan 31 20:04:20 2014\n'
            '}}\n'
            'lease6 {{\n'
            '  interface "valid4";\n'
            '  ia-na [some MAC address] {{\n'
            '    iaaddr [some IPv6 address] {{\n'
            '      starts {now:.0f};\n'
            '      max-life 60;\n'  # the lease has a minute left
            '    }}\n'
            '  }}\n'
            '}}\n'
            'lease6 {{\n'
            '  interface "expired3";\n'
            '  ia-na [some MAC address] {{\n'
            '    iaaddr [some IPv6 address] {{\n'
            '      starts {expired:.0f};\n'
            '      max-life 30;\n'  # the lease expired half a minute ago
            '    }}\n'
            '  }}\n'
            '}}\n'
        )

        with namedTemporaryDir() as tmp_dir:
            lease_file = os.path.join(tmp_dir, 'test.lease')
            with open(lease_file, 'w') as f:
                now = time.time()
                last_minute = now - 60
                next_minute = now + 60

                f.write(LEASES.format(
                    active_datetime=datetime.utcfromtimestamp(next_minute),
                    active=next_minute,
                    expired_datetime=datetime.utcfromtimestamp(last_minute),
                    expired=last_minute,
                    now=now
                ))

            dhcpv4_ifaces, dhcpv6_ifaces = \
                dhcp.get_dhclient_ifaces([lease_file])

        self.assertIn('valid', dhcpv4_ifaces)
        self.assertIn('valid2', dhcpv4_ifaces)
        self.assertIn('valid3', dhcpv4_ifaces)
        self.assertNotIn('expired', dhcpv4_ifaces)
        self.assertNotIn('expired2', dhcpv4_ifaces)
        self.assertIn('valid4', dhcpv6_ifaces)
        self.assertNotIn('expired3', dhcpv6_ifaces)