Beispiel #1
0
    def _create_metadata_artifact(self, size, vol_format, prealloc, disk_type,
                                  desc, parent):
        if self._oop.fileUtils.pathExists(self.meta_path):
            raise se.VolumeAlreadyExists("metadata exists: %r" %
                                         self.meta_path)

        if self._oop.fileUtils.pathExists(self.meta_volatile_path):
            raise se.DomainHasGarbage("metadata artifact exists: %r" %
                                      self.meta_volatile_path)

        parent_vol_id = parent.vol_id if parent else sc.BLANK_UUID
        # Create the metadata artifact.  The metadata file is created with a
        # special extension to prevent these artifacts from being recognized as
        # a volume until FileVolumeArtifacts.commit() is called.
        meta = VolumeMetadata(
            self.sd_manifest.sdUUID,
            self.img_id,
            parent_vol_id,
            size / sc.BLOCK_SIZE,  # Size is stored as number of blocks
            sc.type2name(vol_format),
            sc.type2name(prealloc),
            sc.type2name(sc.LEAF_VOL),
            disk_type,
            desc,
            sc.LEGAL_VOL)
        self._oop.writeFile(self.meta_volatile_path, meta.storage_format())
    def _create_metadata_artifact(self, size, vol_format, prealloc, disk_type,
                                  desc, parent):
        if self._oop.fileUtils.pathExists(self.meta_path):
            raise se.VolumeAlreadyExists("metadata exists: %r" %
                                         self.meta_path)

        if self._oop.fileUtils.pathExists(self.meta_volatile_path):
            raise se.DomainHasGarbage("metadata artifact exists: %r" %
                                      self.meta_volatile_path)

        parent_vol_id = parent.vol_id if parent else sc.BLANK_UUID
        # Create the metadata artifact.  The metadata file is created with a
        # special extension to prevent these artifacts from being recognized as
        # a volume until FileVolumeArtifacts.commit() is called.
        meta = VolumeMetadata(
            self.sd_manifest.sdUUID,
            self.img_id,
            parent_vol_id,
            size / sc.BLOCK_SIZE,  # Size is stored as number of blocks
            sc.type2name(vol_format),
            sc.type2name(prealloc),
            sc.type2name(sc.LEAF_VOL),
            disk_type,
            desc,
            sc.LEGAL_VOL)
        self._oop.writeFile(self.meta_volatile_path, meta.storage_format())
Beispiel #3
0
 def newMetadata(cls,
                 metaId,
                 sdUUID,
                 imgUUID,
                 puuid,
                 size,
                 format,
                 type,
                 voltype,
                 disktype,
                 desc="",
                 legality=sc.ILLEGAL_VOL):
     meta = VolumeMetadata(sdUUID, imgUUID, puuid, size, format, type,
                           voltype, disktype, desc, legality)
     cls.createMetadata(metaId, meta.legacy_info())
     return meta
Beispiel #4
0
    def _parse_metadata_file(self, filepath):
        img_dir, filename = os.path.split(filepath)
        vol_uuid = os.path.splitext(filename)[0]
        img_uuid = os.path.basename(img_dir)

        try:
            # Parse the meta file's key=value pairs and get the metadata dict.
            data = self.oop.readFile(filepath, direct=True)
            md_lines = data.rstrip(b"\0").splitlines()
            md = VolumeMetadata.from_lines(md_lines).dump()
            # Set volume status when done.
            md["status"] = sc.VOL_STATUS_OK
        except Exception as e:
            self.log.warning("Failed to parse meta file for volume %s/%s: %s",
                             self.sdUUID, vol_uuid, e)
            md = {"image": img_uuid, "status": sc.VOL_STATUS_INVALID}

        # Get volume size.
        try:
            vol_size = self.getVolumeSize(img_uuid, vol_uuid)
            md["truesize"] = vol_size.truesize
            md["apparentsize"] = vol_size.apparentsize
        except Exception as e:
            self.log.warning("Failed to get size for volume %s/%s: %s",
                             self.sdUUID, vol_uuid, e)
            md["status"] = sc.VOL_STATUS_INVALID

        # Check if volume was marked as removed and override its status.
        if img_uuid.startswith(sc.REMOVED_IMAGE_PREFIX):
            md["status"] = sc.VOL_STATUS_REMOVED

        return vol_uuid, md
Beispiel #5
0
 def setDescription(self, descr):
     """
     Set Volume Description
         'descr' - volume description
     """
     descr = VolumeMetadata.validate_description(descr)
     self.log.info("volUUID = %s descr = %s ", self.volUUID, descr)
     self.setMetaParam(sc.DESCRIPTION, descr)
Beispiel #6
0
 def setDescription(self, descr):
     """
     Set Volume Description
         'descr' - volume description
     """
     descr = VolumeMetadata.validate_description(descr)
     self.log.info("volUUID = %s descr = %s ", self.volUUID, descr)
     self.setMetaParam(sc.DESCRIPTION, descr)
Beispiel #7
0
    def validate_metadata(self, env, md_slot, artifacts):
        path = env.lvm.lvPath(artifacts.sd_manifest.sdUUID, sd.METADATA)
        offset = md_slot * sc.METADATA_SIZE
        md_lines = misc.readblock(path, offset, sc.METADATA_SIZE)
        md = VolumeMetadata.from_lines(md_lines)

        # Test a few fields just to check that metadata was written
        self.assertEqual(artifacts.sd_manifest.sdUUID, md.domain)
        self.assertEqual(artifacts.img_id, md.image)
    def validate_metadata(self, env, md_slot, artifacts):
        path = env.lvm.lvPath(artifacts.sd_manifest.sdUUID, sd.METADATA)
        offset = md_slot * sc.METADATA_SIZE
        md_lines = misc.readblock(path, offset, sc.METADATA_SIZE)
        md = VolumeMetadata.from_lines(md_lines)

        # Test a few fields just to check that metadata was written
        self.assertEqual(artifacts.sd_manifest.sdUUID, md.domain)
        self.assertEqual(artifacts.img_id, md.image)
Beispiel #9
0
    def validate_metadata(self, env, artifacts):
        meta_path = artifacts.meta_volatile_path
        self.assertTrue(os.path.exists(meta_path))
        with open(meta_path) as f:
            md_lines = f.readlines()
        md = VolumeMetadata.from_lines(md_lines)

        # Test a few fields just to check that metadata was written
        self.assertEqual(artifacts.sd_manifest.sdUUID, md.domain)
        self.assertEqual(artifacts.img_id, md.image)
    def validate_metadata(self, env, artifacts):
        meta_path = artifacts.meta_volatile_path
        self.assertTrue(os.path.exists(meta_path))
        with open(meta_path) as f:
            md_lines = f.readlines()
        md = VolumeMetadata.from_lines(md_lines)

        # Test a few fields just to check that metadata was written
        self.assertEqual(artifacts.sd_manifest.sdUUID, md.domain)
        self.assertEqual(artifacts.img_id, md.image)
Beispiel #11
0
    def getMetadata(self, metaId=None):
        """
        Get Meta data array of key,values lines
        """
        if not metaId:
            metaId = self.getMetadataId()

        _, slot = metaId
        sd = sdCache.produce_manifest(self.sdUUID)
        try:
            lines = sd.read_metadata_block(slot).splitlines()
        except Exception as e:
            self.log.error(e, exc_info=True)
            raise se.VolumeMetadataReadError("%s: %s" % (metaId, e))

        md = VolumeMetadata.from_lines(lines)
        return md
Beispiel #12
0
    def getMetadata(self, metaId=None):
        """
        Get Meta data array of key,values lines
        """
        if not metaId:
            metaId = self.getMetadataId()

        _, slot = metaId
        sd = sdCache.produce_manifest(self.sdUUID)
        try:
            lines = sd.read_metadata_block(slot).splitlines()
        except Exception as e:
            self.log.error(e, exc_info=True)
            raise se.VolumeMetadataReadError("%s: %s" % (metaId, e))

        md = VolumeMetadata.from_lines(lines)
        return md
Beispiel #13
0
    def getMetadata(self, metaId=None):
        """
        Get Meta data array of key,values lines
        """
        if not metaId:
            metaId = self.getMetadataId()

        _, offs = metaId
        sd = sdCache.produce_manifest(self.sdUUID)
        try:
            lines = misc.readblock(sd.metadata_volume_path(),
                                   offs * sc.METADATA_SIZE, sc.METADATA_SIZE)
        except Exception as e:
            self.log.error(e, exc_info=True)
            raise se.VolumeMetadataReadError("%s: %s" % (metaId, e))

        md = VolumeMetadata.from_lines(lines)
        return md.legacy_info()
Beispiel #14
0
    def getMetadata(self, metaId=None):
        """
        Get Meta data array of key,values lines
        """
        if not metaId:
            metaId = self.getMetadataId()

        volPath, = metaId
        metaPath = self.getMetaVolumePath(volPath)

        try:
            lines = self.oop.directReadLines(metaPath)
        except Exception as e:
            self.log.error(e, exc_info=True)
            raise se.VolumeMetadataReadError("%s: %s" % (metaId, e))

        md = VolumeMetadata.from_lines(lines)
        return md
Beispiel #15
0
    def getMetadata(self, metaId=None):
        """
        Get Meta data array of key,values lines
        """
        if not metaId:
            metaId = self.getMetadataId()

        vgname, offs = metaId

        try:
            lines = misc.readblock(lvm.lvPath(vgname, sd.METADATA),
                                   offs * sc.METADATA_SIZE, sc.METADATA_SIZE)
        except Exception as e:
            self.log.error(e, exc_info=True)
            raise se.VolumeMetadataReadError("%s: %s" % (metaId, e))

        md = VolumeMetadata.from_lines(lines)
        return md.legacy_info()
Beispiel #16
0
    def getMetadata(self, metaId=None):
        """
        Get Meta data array of key,values lines
        """
        if not metaId:
            metaId = self.getMetadataId()

        volPath, = metaId
        metaPath = self._getMetaVolumePath(volPath)

        try:
            lines = self.oop.directReadLines(metaPath)
        except Exception as e:
            self.log.error(e, exc_info=True)
            raise se.VolumeMetadataReadError("%s: %s" % (metaId, e))

        md = VolumeMetadata.from_lines(lines)
        return md.legacy_info()
Beispiel #17
0
    def getMetadata(self, metaId=None):
        """
        Get Meta data array of key,values lines
        """
        if not metaId:
            metaId = self.getMetadataId()

        vgname, offs = metaId

        try:
            lines = misc.readblock(lvm.lvPath(vgname, sd.METADATA),
                                   offs * sc.METADATA_SIZE,
                                   sc.METADATA_SIZE)
        except Exception as e:
            self.log.error(e, exc_info=True)
            raise se.VolumeMetadataReadError("%s: %s" % (metaId, e))

        md = VolumeMetadata.from_lines(lines)
        return md.legacy_info()
Beispiel #18
0
    def getMetadata(self, metaId=None):
        """
        Get Meta data array of key,values lines
        """
        if not metaId:
            metaId = self.getMetadataId()

        volPath, = metaId
        metaPath = self.getMetaVolumePath(volPath)

        try:
            data = self.oop.readFile(metaPath, direct=True)
        except Exception as e:
            self.log.error(e, exc_info=True)
            raise se.VolumeMetadataReadError("%s: %s" % (metaId, e))

        data = data.rstrip(b"\0")
        lines = data.splitlines()
        md = VolumeMetadata.from_lines(lines)
        return md
Beispiel #19
0
 def newMetadata(cls, metaId, sdUUID, imgUUID, puuid, size, format, type,
                 voltype, disktype, desc="", legality=sc.ILLEGAL_VOL):
     meta = VolumeMetadata(sdUUID, imgUUID, puuid, size, format, type,
                           voltype, disktype, desc, legality)
     cls.createMetadata(metaId, meta.legacy_info())
     return meta