def bondings_caps(running_config): ovs_bonding_caps = {} dhcpv4ifaces, dhcpv6ifaces = netinfo._get_dhclient_ifaces() routes = netinfo._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
def bondings_caps(running_config): ovs_bonding_caps = {} dhcpv4ifaces, dhcpv6ifaces = netinfo._get_dhclient_ifaces() routes = netinfo._get_routes() for bonding, attrs in running_config.bonds.items(): if is_ovs_bond(attrs): 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
def networks_caps(running_config): ovs_networks_caps = {} dhcpv4ifaces, dhcpv6ifaces = netinfo._get_dhclient_ifaces() routes = netinfo._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'] = _list_ports(interface) net_info['stp'] = _get_stp(interface) ovs_networks_caps[network] = net_info return ovs_networks_caps
def bridges_caps(running_config): ovs_bridges_caps = {} dhcpv4ifaces, dhcpv6ifaces = netinfo._get_dhclient_ifaces() routes = netinfo._get_routes() for network, attrs in running_config.networks.items(): if is_ovs_network(attrs): interface = network if "vlan" in attrs else BRIDGE_NAME net_info = _get_net_info(attrs, interface, dhcpv4ifaces, dhcpv6ifaces, routes) net_info["bridged"] = True net_info["ports"] = [] # TODO attached nics + vms nets net_info["opts"] = {} # TODO netinfo.bridgeOpts does not work here net_info["stp"] = _get_stp(interface) ovs_bridges_caps[network] = net_info return ovs_bridges_caps
def vlans_caps(running_config): ovs_vlans_caps = {} dhcpv4ifaces, dhcpv6ifaces = netinfo._get_dhclient_ifaces() routes = netinfo._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'] = vlan ovs_vlans_caps['%s.%s' % (iface, vlan)] = net_info return ovs_vlans_caps
def vlans_caps(running_config): ovs_vlans_caps = {} dhcpv4ifaces, dhcpv6ifaces = netinfo._get_dhclient_ifaces() routes = netinfo._get_routes() for network, attrs in running_config.networks.items(): if is_ovs_network(attrs): 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"] = vlan ovs_vlans_caps["%s.%s" % (iface, vlan)] = net_info return ovs_vlans_caps
def bridges_caps(running_config): ovs_bridges_caps = {} dhcpv4ifaces, dhcpv6ifaces = netinfo._get_dhclient_ifaces() routes = netinfo._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['bridged'] = True net_info['ports'] = _get_ports(network, attrs) # TODO netinfo._bridge_options does not work here net_info['opts'] = {} net_info['stp'] = _get_stp(interface) ovs_bridges_caps[network] = net_info return ovs_bridges_caps
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 = \ netinfo._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)
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 "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 "valid3";\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 = \ netinfo._get_dhclient_ifaces([lease_file]) self.assertIn('valid', dhcpv4_ifaces) self.assertIn('valid2', dhcpv4_ifaces) self.assertNotIn('expired', dhcpv4_ifaces) self.assertNotIn('expired2', dhcpv4_ifaces) self.assertIn('valid3', dhcpv6_ifaces) self.assertNotIn('expired3', dhcpv6_ifaces)