예제 #1
0
def extract_metadata(metadata, params):
    """Examine the maas.meta file for any required metadata.

    :param metadata: contents of the maas.meta file
    :param params: A dict of path components for the image
        (architecture, subarchitecture, kflavor, release and label).
    :return: a dict of name/value metadata pairs.  Currently, only
        "subarches" is extracted.
    """
    mapping = BootImageMapping.load_json(metadata)
    subarch = params["subarchitecture"]
    split_subarch = subarch.split('-')
    if len(split_subarch) > 2:
        kflavor = split_subarch[2]
    else:
        kflavor = 'generic'

    image = ImageSpec(
        os=params["osystem"],
        arch=params["architecture"],
        subarch=subarch,
        kflavor=kflavor,
        release=params["release"],
        label=params["label"],
    )
    try:
        # On upgrade from 1.5 to 1.6, the subarches does not exist in the
        # maas.meta file . Without this catch boot images will fail to
        # report until the boot images are imported again.
        subarches = mapping.mapping[image]['subarches']
    except KeyError:
        return {}

    return dict(supported_subarches=subarches)
예제 #2
0
def make_image_spec(os=None,
                    arch=None,
                    subarch=None,
                    kflavor=None,
                    release=None,
                    label=None):
    if os is None:
        os = factory.make_name('os')
    if arch is None:
        arch = factory.make_name('arch')
    if subarch is None:
        subarch = factory.make_name('subarch')
    if kflavor is None:
        kflavor = factory.make_name('kflavor')
    if release is None:
        release = factory.make_name('release')
    if label is None:
        label = factory.make_name('label')
    return ImageSpec(
        os,
        arch,
        subarch,
        kflavor,
        release,
        label,
    )
예제 #3
0
def gen_image_spec_with_resource(os, data):
    """Generate image and resource for given operating system and data."""
    for arch in data:
        for subarch in data[arch]:
            for kflavor in data[arch][subarch]:
                for release in data[arch][subarch][kflavor]:
                    for label in data[arch][subarch][kflavor][release]:
                        image = ImageSpec(
                            os=os, arch=arch, subarch=subarch,
                            kflavor=kflavor, release=release, label=label)
                        resource = data[arch][subarch][kflavor][release][label]
                        yield image, resource
예제 #4
0
 def make_meta_file(self, image_params, image_resource, tftproot):
     image = ImageSpec(os=image_params["osystem"],
                       arch=image_params["architecture"],
                       subarch=image_params["subarchitecture"],
                       kflavor="generic",
                       release=image_params["release"],
                       label=image_params["label"])
     mapping = BootImageMapping()
     mapping.setdefault(image, image_resource)
     maas_meta = mapping.dump_json()
     filepath = os.path.join(tftproot, "maas.meta")
     with open(filepath, "w", encoding="utf-8") as f:
         f.write(maas_meta)
예제 #5
0
def gen_image_spec_with_resource_legacy(os, data):
    """Generate image and resource for given operating system and data.

    Prior to 2.1 we didn't store the kflavor. This reads the old format so
    users aren't forced to reimport all images on upgrade. 'generic' is used
    as the kflavor as prior to 2.1 MAAS only supported generic kernels."""
    for arch in data:
        for subarch in data[arch]:
            for release in data[arch][subarch]:
                for label in data[arch][subarch][release]:
                    image = ImageSpec(
                        os=os, arch=arch, subarch=subarch,
                        kflavor='generic', release=release, label=label)
                    resource = data[arch][subarch][release][label]
                    yield image, resource
예제 #6
0
def make_image_spec(
    os=None, arch=None, subarch=None, kflavor=None, release=None, label=None
):
    if os is None:
        os = factory.make_name("os")
    if arch is None:
        arch = factory.make_name("arch")
    if subarch is None:
        subarch = factory.make_name("subarch")
    if kflavor is None:
        kflavor = factory.make_name("kflavor")
    if release is None:
        release = factory.make_name("release")
    if label is None:
        label = factory.make_name("label")
    return ImageSpec(os, arch, subarch, kflavor, release, label)
예제 #7
0
    def insert_item(self, data, src, target, pedigree, contentsource):
        """Overridable from `BasicMirrorWriter`."""
        item = products_exdata(src, pedigree)
        if self.validate_products and not validate_product(item, pedigree[0]):
            maaslog.warning("Ignoring unsupported product %s" % pedigree[0])
            return
        os = get_os_from_product(item)
        arch = item["arch"]
        subarches = item.get("subarches", "generic")
        if item.get("bootloader-type") is None:
            release = item["release"]
            kflavor = item.get("kflavor", "generic")
        else:
            release = item["bootloader-type"]
            kflavor = "bootloader"
        label = item["label"]
        base_image = ImageSpec(os, arch, None, kflavor, release, label)
        compact_item = clean_up_repo_item(item)

        if os == "ubuntu-core":
            # For Ubuntu Core we only want one entry per release/arch/gadget
            gadget = item.get("gadget_snap", "generic")
            kflavor = item.get("kernel_snap", "generic")
            release = "%s-%s" % (release, gadget)
            self.boot_images_dict.setdefault(
                base_image._replace(
                    subarch="generic", kflavor=kflavor, release=release
                ),
                compact_item,
            )
        else:
            for subarch in subarches.split(","):
                self.boot_images_dict.setdefault(
                    base_image._replace(subarch=subarch), compact_item
                )

            # HWE resources need to map to a specfic resource, and not just to
            # any of the supported subarchitectures for that resource.
            subarch = item.get("subarch", "generic")
            self.boot_images_dict.set(
                base_image._replace(subarch=subarch), compact_item
            )

            if os == "ubuntu" and item.get("version") is not None:
                # HWE resources with generic, should map to the HWE that ships
                # with that release. Starting with Xenial kernels changed from
                # using the naming format hwe-<letter> to ga-<version>. Look
                # for both.
                hwe_archs = ["ga-%s" % item["version"], "hwe-%s" % release[0]]
                if subarch in hwe_archs and "generic" in subarches:
                    self.boot_images_dict.set(
                        base_image._replace(subarch="generic"), compact_item
                    )
예제 #8
0
파일: factory.py 프로젝트: zhangrb/maas
def make_image_spec(os=None,
                    arch=None,
                    subarch=None,
                    release=None,
                    kflavor=None,
                    label=None):
    """Return an `ImageSpec` with random values."""
    if os is None:
        os = factory.make_name('os')
    if arch is None:
        arch = factory.make_name('arch')
    if subarch is None:
        subarch = factory.make_name('subarch')
    if kflavor is None:
        kflavor = 'generic'
    if release is None:
        release = factory.make_name('release')
    if label is None:
        label = factory.make_name('label')
    return ImageSpec(os, arch, subarch, kflavor, release, label)
예제 #9
0
def make_image_spec(os=None,
                    arch=None,
                    subarch=None,
                    release=None,
                    kflavor=None,
                    label=None):
    """Return an `ImageSpec` with random values."""
    if os is None:
        os = factory.make_name("os")
    if arch is None:
        arch = factory.make_name("arch")
    if subarch is None:
        subarch = factory.make_name("subarch")
    if kflavor is None:
        kflavor = "generic"
    if release is None:
        release = factory.make_name("release")
    if label is None:
        label = factory.make_name("label")
    return ImageSpec(os, arch, subarch, kflavor, release, label)
예제 #10
0
    def test_extract_ephemeral_image_params_with_metadata(self):
        path, osystem, arch, subarch, release, label = self._make_path()

        # Patch OperatingSystemRegistry to return a fixed list of
        # values.
        purpose1 = factory.make_name("purpose")
        purpose2 = factory.make_name("purpose")
        xi_purpose = "ephemeral"
        xi_path = factory.make_name("xi_path")
        xi_type = factory.make_name("xi_type")
        purposes = [purpose1, purpose2, xi_purpose]
        self._patch_osystem_registry(purposes,
                                     xinstall_params=(xi_path, xi_type))

        # Create some maas.meta content.
        image = ImageSpec(os=osystem,
                          arch=arch,
                          subarch=subarch,
                          kflavor='generic',
                          release=release,
                          label=label)
        image_resource = dict(subarches=factory.make_name("subarches"))
        mapping = BootImageMapping()
        mapping.setdefault(image, image_resource)
        maas_meta = mapping.dump_json()

        params = extract_image_params(path, maas_meta)

        self.assertItemsEqual([
            {
                "osystem": osystem,
                "architecture": arch,
                "subarchitecture": subarch,
                "release": release,
                "label": label,
                "purpose": purpose1,
                "xinstall_path": '',
                "xinstall_type": '',
                "supported_subarches": image_resource["subarches"],
            },
            {
                "osystem": osystem,
                "architecture": arch,
                "subarchitecture": subarch,
                "release": release,
                "label": label,
                "purpose": purpose2,
                "xinstall_path": '',
                "xinstall_type": '',
                "supported_subarches": image_resource["subarches"],
            },
            {
                "osystem": osystem,
                "architecture": arch,
                "subarchitecture": subarch,
                "release": release,
                "label": label,
                "purpose": xi_purpose,
                "xinstall_path": xi_path,
                "xinstall_type": xi_type,
                "supported_subarches": image_resource["subarches"],
            },
        ], params)