Ejemplo n.º 1
0
    def collectMetaFiles(mountPoint):
        try:
            # removes the path to the data center's mount directory from
            # the mount point.
            if mountPoint.startswith(sc.REPO_MOUNT_DIR):
                client_name = mountPoint[len(sc.REPO_MOUNT_DIR):]

            # Since glob treats values between brackets as character ranges,
            # and since IPV6 addresses contain brackets, we should escape the
            # mountPoint that we pass to glob.
            # <data-center>/mnt/mountpoint/<uuid>/dom_mdm
            mdPattern = os.path.join(glob_escape(mountPoint),
                                     UUID_GLOB_PATTERN, sd.DOMAIN_META_DATA)

            metaFiles = oop.getProcessPool(client_name).glob.glob(mdPattern)

            for metaFile in metaFiles:
                if (os.path.basename(os.path.dirname(metaFile)) !=
                        sd.MASTER_FS_DIR):
                    sdUUID = os.path.basename(os.path.dirname(metaFile))

                    return (sdUUID, os.path.dirname(metaFile))

        except Exception:
            log.warn("Could not collect metadata file for domain path %s",
                     mountPoint,
                     exc_info=True)
Ejemplo n.º 2
0
    def collectMetaFiles(mountPoint):
        try:
            # /rhev/*/mnt/server:_path -> server:_path
            # /rhev/*/mnt/glusterSD/server:_path -> glusterSD/server:_path
            client_name = mountPoint.replace(sc.REPO_MOUNT_DIR, "").lstrip("/")

            # Since glob treats values between brackets as character ranges,
            # and since IPV6 addresses contain brackets, we should escape the
            # mountPoint that we pass to glob.
            # <data-center>/mnt/mountpoint/<uuid>/dom_mdm
            mdPattern = os.path.join(glob_escape(mountPoint),
                                     UUID_GLOB_PATTERN, sd.DOMAIN_META_DATA)

            metaFiles = oop.getProcessPool(client_name).glob.glob(mdPattern)

            for metaFile in metaFiles:
                if (os.path.basename(os.path.dirname(metaFile)) !=
                        sd.MASTER_FS_DIR):
                    sdUUID = os.path.basename(os.path.dirname(metaFile))

                    return (sdUUID, os.path.dirname(metaFile))

        except Exception:
            log.warn("Could not collect metadata file for domain path %s",
                     mountPoint,
                     exc_info=True)
Ejemplo n.º 3
0
Archivo: fileSD.py Proyecto: oVirt/vdsm
    def collectMetaFiles(mountPoint):
        try:
            # removes the path to the data center's mount directory from
            # the mount point.
            if mountPoint.startswith(sc.REPO_MOUNT_DIR):
                client_name = mountPoint[len(sc.REPO_MOUNT_DIR):]

            # Since glob treats values between brackets as character ranges,
            # and since IPV6 addresses contain brackets, we should escape the
            # mountPoint that we pass to glob.
            # <data-center>/mnt/mountpoint/<uuid>/dom_mdm
            mdPattern = os.path.join(
                glob_escape(mountPoint),
                UUID_GLOB_PATTERN,
                sd.DOMAIN_META_DATA)

            metaFiles = oop.getProcessPool(client_name).glob.glob(mdPattern)

            for metaFile in metaFiles:
                if (os.path.basename(os.path.dirname(metaFile)) !=
                        sd.MASTER_FS_DIR):
                    sdUUID = os.path.basename(os.path.dirname(metaFile))

                    return (sdUUID, os.path.dirname(metaFile))

        except Exception:
            log.warn("Could not collect metadata file for domain path %s",
                     mountPoint, exc_info=True)
Ejemplo n.º 4
0
 def getAllImages(self):
     """
     Fetch the set of the Image UUIDs in the SD.
     """
     # Get Volumes of an image
     pattern = os.path.join(glob_escape(self.mountpoint), self.sdUUID,
                            sd.DOMAIN_IMAGES, UUID_GLOB_PATTERN)
     files = self.oop.glob.glob(pattern)
     images = set()
     for i in files:
         if self.oop.os.path.isdir(i):
             images.add(os.path.basename(i))
     return images
Ejemplo n.º 5
0
 def getImageVolumes(cls, sdUUID, imgUUID):
     """
     Fetch the list of the Volumes UUIDs,
     not including the shared base (template)
     """
     sd = sdCache.produce_manifest(sdUUID)
     img_dir = sd.getImageDir(imgUUID)
     pattern = os.path.join(glob_escape(img_dir), "*.meta")
     files = oop.getProcessPool(sdUUID).glob.glob(pattern)
     volList = []
     for i in files:
         volid = os.path.splitext(os.path.basename(i))[0]
         if (sd.produceVolume(imgUUID, volid).getImage() == imgUUID):
             volList.append(volid)
     return volList
Ejemplo n.º 6
0
    def _dump_volumes(self):
        result = {}
        # Glob *.meta files directly without an iterator which
        # may break if a metadata file fails on path validation.
        meta_files_pattern = os.path.join(glob_escape(self.mountpoint),
                                          self.sdUUID, sd.DOMAIN_IMAGES,
                                          UUID_GLOB_PATTERN,
                                          "*" + fileVolume.META_FILEEXT)

        self.log.debug("Looking up files %s", meta_files_pattern)
        for path in self.oop.glob.glob(meta_files_pattern):
            vol_uuid, md = self._parse_metadata_file(path)
            result[vol_uuid] = md

        return result
Ejemplo n.º 7
0
 def getImageVolumes(cls, sdUUID, imgUUID):
     """
     Fetch the list of the Volumes UUIDs,
     not including the shared base (template)
     """
     sd = sdCache.produce_manifest(sdUUID)
     img_dir = sd.getImageDir(imgUUID)
     pattern = os.path.join(glob_escape(img_dir), "*.meta")
     files = oop.getProcessPool(sdUUID).glob.glob(pattern)
     volList = []
     for i in files:
         volid = os.path.splitext(os.path.basename(i))[0]
         if (sd.produceVolume(imgUUID, volid).getImage() == imgUUID):
             volList.append(volid)
     return volList
Ejemplo n.º 8
0
    def getChildren(self):
        """ Return children volume UUIDs.

        This API is not suitable for use with a template's base volume.
        """
        imgDir, _ = os.path.split(self.volumePath)
        metaPattern = os.path.join(glob_escape(imgDir), "*.meta")
        metaPaths = oop.getProcessPool(self.sdUUID).glob.glob(metaPattern)
        pattern = "%s.*%s" % (sc.PUUID, self.volUUID)
        matches = grepCmd(pattern, metaPaths)
        if matches:
            children = []
            for line in matches:
                volMeta = os.path.basename(line.rsplit(':', 1)[0])
                children.append(os.path.splitext(volMeta)[0])  # volUUID
        else:
            children = tuple()

        return tuple(children)
Ejemplo n.º 9
0
    def getChildren(self):
        """ Return children volume UUIDs.

        This API is not suitable for use with a template's base volume.
        """
        imgDir, _ = os.path.split(self.volumePath)
        metaPattern = os.path.join(glob_escape(imgDir), "*.meta")
        metaPaths = oop.getProcessPool(self.sdUUID).glob.glob(metaPattern)
        pattern = "%s.*%s" % (sc.PUUID, self.volUUID)
        matches = grepCmd(pattern, metaPaths)
        if matches:
            children = []
            for line in matches:
                volMeta = os.path.basename(line.rsplit(':', 1)[0])
                children.append(os.path.splitext(volMeta)[0])  # volUUID
        else:
            children = tuple()

        return tuple(children)
Ejemplo n.º 10
0
Archivo: fileSD.py Proyecto: EdDev/vdsm
    def collectMetaFiles(possibleDomain):
        try:
            # Since glob treats values between brackets as character ranges,
            # and since IPV6 addresses contain brackets, we should escape the
            # possibleDomain that we pass to glob.
            metaFiles = oop.getProcessPool(possibleDomain).glob.glob(
                os.path.join(glob_escape(possibleDomain),
                             constants.UUID_GLOB_PATTERN,
                             sd.DOMAIN_META_DATA))

            for metaFile in metaFiles:
                if (os.path.basename(os.path.dirname(metaFile)) !=
                        sd.MASTER_FS_DIR):
                    sdUUID = os.path.basename(os.path.dirname(metaFile))

                    return (sdUUID, os.path.dirname(metaFile))

        except Exception:
            log.warn("Could not collect metadata file for domain path %s",
                     possibleDomain, exc_info=True)
Ejemplo n.º 11
0
    def collectMetaFiles(possibleDomain):
        try:
            # Since glob treats values between brackets as character ranges,
            # and since IPV6 addresses contain brackets, we should escape the
            # possibleDomain that we pass to glob.
            metaFiles = oop.getProcessPool(possibleDomain).glob.glob(
                os.path.join(glob_escape(possibleDomain), UUID_GLOB_PATTERN,
                             sd.DOMAIN_META_DATA))

            for metaFile in metaFiles:
                if (os.path.basename(os.path.dirname(metaFile)) !=
                        sd.MASTER_FS_DIR):
                    sdUUID = os.path.basename(os.path.dirname(metaFile))

                    return (sdUUID, os.path.dirname(metaFile))

        except Exception:
            log.warn("Could not collect metadata file for domain path %s",
                     possibleDomain,
                     exc_info=True)
Ejemplo n.º 12
0
    def getAllVolumes(self):
        """
        Return dict {volUUID: ((imgUUIDs,), parentUUID)} of the domain.

        (imgUUIDs,) is a tuple of all the images that contain a certain
        volUUID.  For non-templates volumes, this tuple consists of a single
        image.  For template volume it consists of all the images that are
        based on the template volume. In that case, the first imgUUID in the
        tuple is the self-image of the template.

        The parent of a non-template volume cannot be determined in file domain
        without reading  the metadata. However, in order to have an output
        compatible to block domain, we report parent as None.

        Template volumes have no parent, and thus we report BLANK_UUID as their
        parentUUID.
        """
        volMetaPattern = os.path.join(glob_escape(self.mountpoint),
                                      self.sdUUID, sd.DOMAIN_IMAGES, "*",
                                      "*.meta")
        volMetaPaths = self.oop.glob.glob(volMetaPattern)

        # First create mapping from images to volumes
        images = collections.defaultdict(list)
        for metaPath in volMetaPaths:
            head, tail = os.path.split(metaPath)
            volUUID, volExt = os.path.splitext(tail)
            imgUUID = os.path.basename(head)
            images[imgUUID].append(volUUID)

        # Using images to volumes mapping, we can create volumes to images
        # mapping, detecting template volumes and template images, based on
        # these rules:
        #
        # Template volumes are hard linked in every image directory
        # which is derived from that template, therefore:
        #
        # 1. A template volume which is in use will appear at least twice
        #    (in the template image dir and in the derived image dir)
        #
        # 2. Any volume which appears more than once in the dir tree is
        #    by definition a template volume.
        #
        # 3. Any image which has more than 1 volume is not a template
        #    image.

        volumes = {}
        for imgUUID, volUUIDs in six.iteritems(images):
            for volUUID in volUUIDs:
                if volUUID in volumes:
                    # This must be a template volume (rule 2)
                    volumes[volUUID]['parent'] = sd.BLANK_UUID
                    if len(volUUIDs) > 1:
                        # This image is not a template (rule 3)
                        volumes[volUUID]['imgs'].append(imgUUID)
                    else:
                        # This image is a template (rule 3)
                        volumes[volUUID]['imgs'].insert(0, imgUUID)
                else:
                    volumes[volUUID] = {'imgs': [imgUUID], 'parent': None}

        return dict((k, sd.ImgsPar(tuple(v['imgs']), v['parent']))
                    for k, v in six.iteritems(volumes))
Ejemplo n.º 13
0
Archivo: fileSD.py Proyecto: oVirt/vdsm
    def getAllVolumes(self):
        """
        Return dict {volUUID: ((imgUUIDs,), parentUUID)} of the domain.

        (imgUUIDs,) is a tuple of all the images that contain a certain
        volUUID.  For non-templates volumes, this tuple consists of a single
        image.  For template volume it consists of all the images that are
        based on the template volume. In that case, the first imgUUID in the
        tuple is the self-image of the template.

        The parent of a non-template volume cannot be determined in file domain
        without reading  the metadata. However, in order to have an output
        compatible to block domain, we report parent as None.

        Template volumes have no parent, and thus we report BLANK_UUID as their
        parentUUID.
        """
        volMetaPattern = os.path.join(glob_escape(self.mountpoint),
                                      self.sdUUID,
                                      sd.DOMAIN_IMAGES, "*", "*.meta")
        volMetaPaths = self.oop.glob.glob(volMetaPattern)

        # First create mapping from images to volumes
        images = collections.defaultdict(list)
        for metaPath in volMetaPaths:
            head, tail = os.path.split(metaPath)
            volUUID, volExt = os.path.splitext(tail)
            imgUUID = os.path.basename(head)
            images[imgUUID].append(volUUID)

        # Using images to volumes mapping, we can create volumes to images
        # mapping, detecting template volumes and template images, based on
        # these rules:
        #
        # Template volumes are hard linked in every image directory
        # which is derived from that template, therefore:
        #
        # 1. A template volume which is in use will appear at least twice
        #    (in the template image dir and in the derived image dir)
        #
        # 2. Any volume which appears more than once in the dir tree is
        #    by definition a template volume.
        #
        # 3. Any image which has more than 1 volume is not a template
        #    image.

        volumes = {}
        for imgUUID, volUUIDs in six.iteritems(images):
            for volUUID in volUUIDs:
                if volUUID in volumes:
                    # This must be a template volume (rule 2)
                    volumes[volUUID]['parent'] = sd.BLANK_UUID
                    if len(volUUIDs) > 1:
                        # This image is not a template (rule 3)
                        volumes[volUUID]['imgs'].append(imgUUID)
                    else:
                        # This image is a template (rule 3)
                        volumes[volUUID]['imgs'].insert(0, imgUUID)
                else:
                    volumes[volUUID] = {'imgs': [imgUUID], 'parent': None}

        return dict((k, sd.ImgsPar(tuple(v['imgs']), v['parent']))
                    for k, v in six.iteritems(volumes))
Ejemplo n.º 14
0
 def test_escape(self, arg, expected):
     self.assertEqual(glob_escape(arg), expected)
Ejemplo n.º 15
0
 def test_escape(self, arg, expected):
     self.assertEqual(glob_escape(arg), expected)