Ejemplo n.º 1
0
    def from_lines(cls, lines):
        md = {}
        for line in lines:
            if line.startswith("EOF"):
                break
            if '=' not in line:
                continue
            key, value = line.split('=', 1)
            md[key.strip()] = value.strip()

        try:
            return cls(
                domain=md[constants.DOMAIN],
                image=md[constants.IMAGE],
                puuid=md[constants.PUUID],
                size=int(md[constants.SIZE]),
                format=md[constants.FORMAT],
                type=md[constants.TYPE],
                voltype=md[constants.VOLTYPE],
                disktype=md[constants.DISKTYPE],
                description=md[constants.DESCRIPTION],
                legality=md[constants.LEGALITY],
                ctime=int(md[constants.CTIME]),
                mtime=int(md[constants.MTIME]),
                # generation was added to the set of metadata keys well
                # after the above fields.  Therefore, it may not exist
                # on storage for pre-existing volumes.  In that case we
                # report a default value of 0 which will be written to
                # the volume metadata on the next metadata change.
                generation=int(
                    md.get(constants.GENERATION,
                           constants.DEFAULT_GENERATION)))
        except KeyError as e:
            raise exception.MetaDataKeyNotFoundError(
                "Missing metadata key: %s: found: %s" % (e, md))
Ejemplo n.º 2
0
    def from_lines(cls, lines):
        md = {}
        for line in lines:
            if line.startswith("EOF"):
                break
            if '=' not in line:
                continue
            key, value = line.split('=', 1)
            md[key.strip()] = value.strip()

        try:
            return cls(domain=md[constants.DOMAIN],
                       image=md[constants.IMAGE],
                       puuid=md[constants.PUUID],
                       size=int(md[constants.SIZE]),
                       format=md[constants.FORMAT],
                       type=md[constants.TYPE],
                       voltype=md[constants.VOLTYPE],
                       disktype=md[constants.DISKTYPE],
                       description=md[constants.DESCRIPTION],
                       legality=md[constants.LEGALITY],
                       ctime=int(md[constants.CTIME]),
                       mtime=int(md[constants.MTIME]))
        except KeyError as e:
            raise exception.MetaDataKeyNotFoundError(
                "Missing metadata key: %s: found: %s" % (e, md))
Ejemplo n.º 3
0
 def getMetaParam(self, key):
     """
     Get a value of a specific key
     """
     meta = self.getMetadata()
     try:
         return meta[key]
     except KeyError:
         raise se.MetaDataKeyNotFoundError(str(meta) + ":" + str(key))
Ejemplo n.º 4
0
    def from_lines(cls, lines):
        '''
        Instantiates a VolumeMetadata object from storage read bytes.

        Args:
            lines: list of key=value entries given as bytes read from storage
            metadata section. "EOF" entry terminates parsing.
        '''
        md = {}
        for line in lines:
            line = line.decode("utf-8")
            if line.startswith("EOF"):
                break
            if '=' not in line:
                continue
            key, value = line.split('=', 1)
            md[key.strip()] = value.strip()

        try:
            # We work internally in bytes, even if old format store
            # value in blocks, we will read SIZE instead of CAPACITY
            # from non-converted volumes and use it
            if sc.CAPACITY in md:
                capacity = int(md[sc.CAPACITY])
            else:
                capacity = int(md[_SIZE]) * sc.BLOCK_SIZE_512

            return cls(
                domain=md[sc.DOMAIN],
                image=md[sc.IMAGE],
                puuid=md[sc.PUUID],
                capacity=capacity,
                format=md[sc.FORMAT],
                type=md[sc.TYPE],
                voltype=md[sc.VOLTYPE],
                disktype=md[sc.DISKTYPE],
                description=md[sc.DESCRIPTION],
                legality=md[sc.LEGALITY],
                ctime=int(md[sc.CTIME]),
                # generation was added to the set of metadata keys well
                # after the above fields.  Therefore, it may not exist
                # on storage for pre-existing volumes.  In that case we
                # report a default value of 0 which will be written to
                # the volume metadata on the next metadata change.
                generation=int(md.get(sc.GENERATION, sc.DEFAULT_GENERATION)))
        except KeyError as e:
            if "NONE" in md:
                # Before 4.20.34-1 (ovirt 4.2.5) volume metadata could be
                # cleared by writing invalid metadata when deleting a volume.
                # See https://bugzilla.redhat.com/1574631.
                raise exception.MetadataCleared("lines={}".format(lines))

            raise exception.MetaDataKeyNotFoundError("key={} lines={}".format(
                e, lines))
Ejemplo n.º 5
0
    def from_lines(cls, lines):
        md = {}
        for line in lines:
            if line.startswith("EOF"):
                break
            if '=' not in line:
                continue
            key, value = line.split('=', 1)
            md[key.strip()] = value.strip()

        try:
            # We work internally in bytes, even if old format store
            # value in blocks, we will read SIZE instead of CAPACITY
            # from non-converted volumes and use it
            if sc.CAPACITY in md:
                capacity = int(md[sc.CAPACITY])
            else:
                capacity = int(md[sc.SIZE]) * sc.BLOCK_SIZE_512

            return cls(
                domain=md[sc.DOMAIN],
                image=md[sc.IMAGE],
                puuid=md[sc.PUUID],
                capacity=capacity,
                format=md[sc.FORMAT],
                type=md[sc.TYPE],
                voltype=md[sc.VOLTYPE],
                disktype=md[sc.DISKTYPE],
                description=md[sc.DESCRIPTION],
                legality=md[sc.LEGALITY],
                ctime=int(md[sc.CTIME]),
                # generation was added to the set of metadata keys well
                # after the above fields.  Therefore, it may not exist
                # on storage for pre-existing volumes.  In that case we
                # report a default value of 0 which will be written to
                # the volume metadata on the next metadata change.
                generation=int(md.get(sc.GENERATION, sc.DEFAULT_GENERATION)))
        except KeyError as e:
            raise exception.MetaDataKeyNotFoundError(
                "Missing metadata key: %s: found: %s" % (e, md))
Ejemplo n.º 6
0
Archivo: sd.py Proyecto: benipeled/vdsm
 def getVersion(self):
     try:
         version = self.getMetaParam(DMDK_VERSION)
     except KeyError:
         raise se.MetaDataKeyNotFoundError("key={}".format(DMDK_VERSION))
     return version