def test_networks(self): networks = parse_lxd_networks(SAMPLE_LXD_NETWORKS) self.assertEqual( networks, { "eth0": { "type": "broadcast", "enabled": True, "addresses": ["192.168.0.3/24", "2001:db8:a::123/64"], "mac": "00:00:00:00:00:01", "parents": [], }, "eth1": { "type": "broadcast", "enabled": False, "addresses": ["172.17.42.1/16"], "mac": "00:00:00:00:00:02", "parents": [], }, "eth2": { "type": "broadcast", "enabled": False, "addresses": ["172.17.12.1/16"], "mac": "00:00:00:00:00:03", "parents": [], }, "lo": { "type": "loopback", "enabled": True, "addresses": ["127.0.0.1/8", "::1/128"], "mac": "", "parents": [], }, }, )
def test_networks_bridge(self): network_details = { "br0": { "addresses": [], "hwaddr": "00:00:00:00:00:01", "state": "up", "type": "broadcast", "bond": None, "bridge": { "upper_devices": ["eth0", "eth1"], }, "vlan": None, }, } networks = parse_lxd_networks(network_details) self.assertEqual( networks, { "br0": { "type": "bridge", "enabled": True, "addresses": [], "mac": "00:00:00:00:00:01", "parents": ["eth0", "eth1"], }, }, )
def test_networks(self): networks = parse_lxd_networks(SAMPLE_LXD_NETWORKS) self.assertEqual( networks, { "eth0": { "enabled": True, "inet": ["192.168.0.3/24"], "inet6": ["2001:db8:a::123/64"], "mac": "00:00:00:00:00:01", "name": "eth0", }, "eth1": { "enabled": False, "inet": ["172.17.42.1/16"], "inet6": [], "mac": "00:00:00:00:00:02", "name": "eth1", }, "eth2": { "enabled": False, "inet": ["172.17.12.1/16"], "inet6": [], "mac": "00:00:00:00:00:03", "name": "eth2", }, "lo": { "enabled": True, "inet": ["127.0.0.1/8"], "inet6": ["::1/128"], "name": "lo", }, }, )
def get_ip_addr(): """Returns this system's local IP address information as a dictionary. :raises:ExternalProcessError: if IP address information could not be gathered. """ output = call_and_check([get_resources_bin_path()]) ifaces = parse_lxd_networks(json.loads(output)["networks"]) _update_interface_type(ifaces) _annotate_with_proc_net_bonding_original_macs(ifaces) return ifaces
def _parse_interfaces(node, data): """Return a dict of interfaces keyed by MAC address.""" interfaces = {} resources = data["resources"] ifaces_info = parse_lxd_networks(data["networks"]) def process_port(card, port): mac = port.get("address") if mac in (None, SWITCH_OPENBMC_MAC): # Ignore loopback (with no MAC) and OpenBMC interfaces on switches # which all share the same, hard-coded OpenBMC MAC address. return interface = { "name": port.get("id"), "link_connected": port.get("link_detected"), "interface_speed": _parse_interface_speed(port), "link_speed": port.get("link_speed", 0), "numa_node": card.get("numa_node", 0), "vendor": card.get("vendor"), "product": card.get("product"), "firmware_version": card.get("firmware_version"), "sriov_max_vf": card.get("sriov", {}).get("maximum_vfs", 0), } # Assign the IP addresses to this interface link = ifaces_info.get(interface["name"]) interface["ips"] = link["addresses"] if link else [] if mac in interfaces: raise DuplicateMACs( f"Duplicated MAC address({mac}) on " f"{interfaces[mac]['name']} and {interface['name']}") interfaces[mac] = interface network_cards = resources.get("network", {}).get("cards", {}) for card in network_cards: for port in card.get("ports", []): process_port(card, port) # don't sync VFs for deployed machines, MAAS has no way of representing # VFs, since they would persist when the machine is released and break # subsequent deploys. if node.status != NODE_STATUS.DEPLOYED: # entry can be present but None vfs = card.get("sriov", {}).get("vfs") or {} for vf in vfs: for vf_port in vf.get("ports", []): process_port(vf, vf_port) return interfaces
def parse_interfaces(node, data): """Return a dict of interfaces keyed by MAC address.""" interfaces = {} resources = data["resources"] ifaces_info = parse_lxd_networks(data["networks"]) def process_port(card, port): mac = port.get("address") interface = { "name": port.get("id"), "link_connected": port.get("link_detected"), "interface_speed": _parse_interface_speed(port), "link_speed": port.get("link_speed", 0), "numa_node": card.get("numa_node", 0), "vendor": card.get("vendor"), "product": card.get("product"), "firmware_version": card.get("firmware_version"), "sriov_max_vf": card.get("sriov", {}).get("maximum_vfs", 0), "pci_address": card.get("pci_address"), "usb_address": card.get("usb_address"), } # Assign the IP addresses to this interface link = ifaces_info.get(interface["name"]) interface["ips"] = link["addresses"] if link else [] interfaces[mac] = interface network_cards = resources.get("network", {}).get("cards", {}) for card in network_cards: for port in card.get("ports", []): process_port(card, port) # don't sync VFs for deployed machines, MAAS has no way of representing # VFs, since they would persist when the machine is released and break # subsequent deploys. if node.status != NODE_STATUS.DEPLOYED: # entry can be present but None vfs = card.get("sriov", {}).get("vfs") or {} for vf in vfs: for vf_port in vf.get("ports", []): process_port(vf, vf_port) return interfaces
def test_networks_missing_vlan_key(self): network_details = { "if0": { "addresses": [], "hwaddr": "00:00:00:00:00:01", "state": "up", "type": "broadcast", "bond": None, "bridge": None, }, } networks = parse_lxd_networks(network_details) self.assertEqual( networks, { "if0": { "type": "broadcast", "enabled": True, "addresses": [], "mac": "00:00:00:00:00:01", "parents": [], }, }, )