예제 #1
0
 def test_get_default_interface_parent_none(self):
     if1 = KnownHostInterface(
         ifname="eth0",
         attach_type=InterfaceAttachType.MACVLAN,
         attach_name="eth0",
         dhcp_enabled=False,
     )
     if2 = KnownHostInterface(
         ifname="br0",
         attach_type=InterfaceAttachType.BRIDGE,
         attach_name="br0",
         dhcp_enabled=False,
     )
     driver = make_pod_driver_base()
     self.assertIsNone(driver.get_default_interface_parent([if1, if2]))
예제 #2
0
파일: pods.py 프로젝트: zhangrb/maas
def get_known_host_interfaces(host: Node) -> list:
    """Given the specified host node, calculates each KnownHostInterface.

    :return: a list of KnownHostInterface objects for the specified Node.
    """
    interfaces = host.interface_set.all()
    result = []
    for interface in interfaces:
        ifname = interface.name
        if interface.type == INTERFACE_TYPE.BRIDGE:
            attach_type = InterfaceAttachType.BRIDGE
        else:
            attach_type = InterfaceAttachType.MACVLAN
        dhcp_enabled = False
        vlan = interface.vlan
        if vlan is not None:
            if vlan.dhcp_on:
                dhcp_enabled = True
            elif vlan.relay_vlan is not None:
                if vlan.relay_vlan.dhcp_on:
                    dhcp_enabled = True
        result.append(
            KnownHostInterface(ifname=ifname,
                               attach_type=attach_type,
                               dhcp_enabled=dhcp_enabled))
    return result
예제 #3
0
 def make_interface(attach_type):
     name = factory.make_name()
     return KnownHostInterface(
         ifname=name,
         attach_type=attach_type,
         attach_name=name,
         dhcp_enabled=True,
     )
예제 #4
0
 def test_get_default_interface_parent_only_dhcp_enabled(self):
     if1 = KnownHostInterface(
         ifname="eth0",
         attach_type=InterfaceAttachType.MACVLAN,
         attach_name="eth0",
         dhcp_enabled=False,
     )
     if2 = KnownHostInterface(
         ifname="br0",
         attach_type=InterfaceAttachType.BRIDGE,
         attach_name="br0",
         dhcp_enabled=False,
     )
     if3 = KnownHostInterface(
         ifname="eth1",
         attach_type=InterfaceAttachType.MACVLAN,
         attach_name="eth1",
         dhcp_enabled=True,
     )
     driver = make_pod_driver_base()
     self.assertEqual(driver.get_default_interface_parent([if1, if2, if3]),
                      if3)
예제 #5
0
파일: pods.py 프로젝트: th3architect/maas
def get_known_host_interfaces(pod: Pod) -> list:
    """Given the specified pod, calculates its host's KnownHostInterfaces.

    :return: a list of KnownHostInterface objects for the specified pod.
    """
    host = pod.host
    if host is None:
        return []
    interfaces = host.interface_set.all()
    result = []
    for interface in interfaces:
        ifname = interface.name
        attach_name = ifname
        attach_vlan = None
        if interface.type == INTERFACE_TYPE.BRIDGE:
            attach_type = InterfaceAttachType.BRIDGE
        else:
            if pod.power_type == "lxd" and interface_supports_sriov(interface):
                # For LXD we prefer SR-IOV over MACVLAN if the NIC
                # supports it. In the future, we should support both and
                # allow the user to choose what to use, since SR-IOV
                # needs to be setup properly before it can be used.
                attach_type = InterfaceAttachType.SRIOV
                if interface.type == INTERFACE_TYPE.VLAN:
                    attach_name = interface.parents.get().name
                    attach_vlan = interface.vlan.vid
            else:
                attach_type = InterfaceAttachType.MACVLAN
        dhcp_enabled = False
        vlan = interface.vlan
        if vlan is not None:
            if vlan.dhcp_on:
                dhcp_enabled = True
            elif vlan.relay_vlan is not None:
                if vlan.relay_vlan.dhcp_on:
                    dhcp_enabled = True
        result.append(
            KnownHostInterface(
                ifname=ifname,
                attach_type=attach_type,
                attach_name=attach_name,
                attach_vlan=attach_vlan,
                dhcp_enabled=dhcp_enabled,
            )
        )
    return result
예제 #6
0
 def test_machine_asdict(self):
     hostname = factory.make_name("hostname")
     cores = random.randint(1, 8)
     cpu_speed = random.randint(1000, 2000)
     memory = random.randint(4096, 8192)
     interfaces = [RequestedMachineInterface() for _ in range(3)]
     known_host_interfaces = [KnownHostInterface() for _ in range(3)]
     block_devices = [
         RequestedMachineBlockDevice(
             size=random.randint(512, 1024),
             tags=[factory.make_name("tag") for _ in range(3)],
         ) for _ in range(3)
     ]
     machine = RequestedMachine(
         hostname=hostname,
         architecture="amd64/generic",
         cores=cores,
         cpu_speed=cpu_speed,
         memory=memory,
         interfaces=interfaces,
         known_host_interfaces=known_host_interfaces,
         block_devices=block_devices,
     )
     self.assertThat(
         machine.asdict(),
         MatchesDict({
             "hostname":
             Equals(hostname),
             "architecture":
             Equals("amd64/generic"),
             "cores":
             Equals(cores),
             "cpu_speed":
             Equals(cpu_speed),
             "memory":
             Equals(memory),
             "interfaces":
             MatchesListwise([
                 MatchesDict({
                     "ifname":
                     Is(None),
                     "requested_ips":
                     Equals([]),
                     "ip_mode":
                     Is(None),
                     "attach_name":
                     Equals(interface.attach_name),
                     "attach_type":
                     Equals(interface.attach_type),
                     "attach_options":
                     Equals(interface.attach_options),
                 }) for interface in interfaces
             ]),
             "known_host_interfaces":
             MatchesListwise([
                 MatchesDict({
                     "ifname":
                     Equals(known_host_interface.ifname),
                     "attach_type":
                     Equals(known_host_interface.attach_type),
                     "dhcp_enabled":
                     Equals(False),
                 }) for known_host_interface in known_host_interfaces
             ]),
             "block_devices":
             MatchesListwise([
                 MatchesDict({
                     "size": Equals(block_device.size),
                     "tags": Equals(block_device.tags),
                 }) for block_device in block_devices
             ]),
         }),
     )