コード例 #1
0
ファイル: fileSD.py プロジェクト: kobihk/vdsm
    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
コード例 #2
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)
コード例 #3
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)
コード例 #4
0
ファイル: blockVolume.py プロジェクト: nirs/vdsm
    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
コード例 #5
0
ファイル: fileVolume.py プロジェクト: andrewlukoshko/vdsm
    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()
コード例 #6
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()
コード例 #7
0
ファイル: blockVolume.py プロジェクト: andrewlukoshko/vdsm
    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()
コード例 #8
0
ファイル: fileVolume.py プロジェクト: chaodongqu/vdsm
    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