Exemple #1
0
def get_remote_mac():
    """Gets the requestors MAC address from arp cache.

    This is used, when the dhcp lease file is not up-to-date soon enough
    to extract the MAC address from the IP address assigned by dhcp.
    """
    remote_host, remote_port = tftp.get_remote_address()
    return find_mac_via_arp(remote_host)
Exemple #2
0
    def get_boot_image(self, params, client, remote_ip):
        """Get the boot image for the params on this rack controller.

        Calls `MarkNodeFailed` for the machine if its a known machine.
        """
        is_ephemeral = False
        try:
            osystem_obj = OperatingSystemRegistry.get_item(
                params["osystem"], default=None
            )
            purposes = osystem_obj.get_boot_image_purposes(
                params["arch"],
                params["subarch"],
                params.get("release", ""),
                params.get("label", ""),
            )
            if "ephemeral" in purposes:
                is_ephemeral = True
        except Exception:
            pass

        # Check to see if the we are PXE booting a device.
        if params["purpose"] == "local-device":
            mac = network.find_mac_via_arp(remote_ip)
            log.info(
                "Device %s with MAC address %s is PXE booting; "
                "instructing the device to boot locally."
                % (params["hostname"], mac)
            )
            # Set purpose back to local now that we have the message logged.
            params["purpose"] = "local"

        system_id = params.pop("system_id", None)
        if params["purpose"] == "local" and not is_ephemeral:
            # Local purpose doesn't use a boot image so just set the label
            # to "local".
            params["label"] = "local"
            return params
        else:
            if params["purpose"] == "local" and is_ephemeral:
                params["purpose"] = "ephemeral"
            boot_image = get_boot_image(params)
            if boot_image is None:
                # No matching boot image.
                description = "Missing boot image %s/%s/%s/%s." % (
                    params["osystem"],
                    params["arch"],
                    params["subarch"],
                    params["release"],
                )
                # Call MarkNodeFailed if this was a known machine.
                if system_id is not None:
                    d = client(
                        MarkNodeFailed,
                        system_id=system_id,
                        error_description=description,
                    )
                    d.addErrback(
                        log.err,
                        "Failed to mark machine failed: %s" % description,
                    )
                else:
                    maaslog.error(
                        "Enlistment failed to boot %s; missing required boot "
                        "image %s/%s/%s/%s."
                        % (
                            remote_ip,
                            params["osystem"],
                            params["arch"],
                            params["subarch"],
                            params["release"],
                        )
                    )
                params["label"] = "no-such-image"
            else:
                params["label"] = boot_image["label"]
            return params