Example #1
0
    def storage_format(self, domain_version):
        """
        Format metadata string in storage format.

        Raises MetadataOverflowError if formatted metadata is too long.

        NOTE: Not used yet! We need to drop legacy_info() and pass
        VolumeMetadata instance instead of a dict to use this code.
        """

        info = dict(self.iteritems())
        if domain_version < 5:
            # Always zero on pre v5 domains
            # We need to keep MTIME available on pre v5
            # domains, as other code is expecting that
            # field to exists and will fail without it.
            info[sc.MTIME] = 0

        keys = sorted(info.keys())
        lines = ["%s=%s\n" % (key, info[key]) for key in keys]
        lines.append("EOF\n")
        data = "".join(lines)
        if len(data) > sc.METADATA_SIZE:
            raise exception.MetadataOverflowError(data)
        return data
Example #2
0
    def storage_format(self, domain_version, **overrides):
        """
        Format metadata string in storage format.

        VolumeMetadata is quite restrictive and doesn't allows
        you to make an invalid metadata, but sometimes, for example
        for a format conversion, you need some additional fields to
        be written to the storage. Those fields can be added using
        overrides dict.

        Raises MetadataOverflowError if formatted metadata is too long.

        NOTE: Not used yet! We need to drop legacy_info() and pass
        VolumeMetadata instance instead of a dict to use this code.
        """

        info = {
            sc.CTIME: str(self.ctime),
            sc.DESCRIPTION: self.description,
            sc.DISKTYPE: self.disktype,
            sc.DOMAIN: self.domain,
            sc.FORMAT: self.format,
            sc.GENERATION: self.generation,
            sc.IMAGE: self.image,
            sc.LEGALITY: self.legality,
            sc.PUUID: self.puuid,
            sc.TYPE: self.type,
            sc.VOLTYPE: self.voltype,
        }
        if domain_version < 5:
            # Always zero on pre v5 domains
            # We need to keep MTIME available on pre v5
            # domains, as other code is expecting that
            # field to exists and will fail without it.
            info[sc.MTIME] = 0

            # Pre v5 domains should have SIZE in blocks
            # instead of CAPACITY in bytes
            info[sc.SIZE] = self.size
        else:
            info[sc.CAPACITY] = self.capacity

        info.update(overrides)

        keys = sorted(info.keys())
        lines = ["%s=%s\n" % (key, info[key]) for key in keys]
        lines.append("EOF\n")
        data = "".join(lines)
        if len(data) > sc.METADATA_SIZE:
            raise exception.MetadataOverflowError(data)
        return data
Example #3
0
    def storage_format(self):
        """
        Format metadata string in storage format.

        Raises MetadataOverflowError if formatted metadata is too long.
        """
        info = self.legacy_info()
        keys = sorted(info.keys())
        lines = ["%s=%s\n" % (key, info[key]) for key in keys]
        lines.append("EOF\n")
        data = "".join(lines)
        if len(data) > constants.METADATA_SIZE:
            raise exception.MetadataOverflowError(data)
        return data
Example #4
0
    def formatMetadata(cls, meta):
        """
        Format metadata string in storage format.

        Raises MetadataOverflowError if formatted metadata is too long.
        """
        # TODO: Adopt VolumeMetadata.storage_format()
        lines = [
            "%s=%s\n" % (key.strip(), str(value).strip())
            for key, value in meta.iteritems()
        ]
        lines.append("EOF\n")
        data = "".join(lines)
        if len(data) > sc.METADATA_SIZE:
            raise se.MetadataOverflowError(data)
        return data