Ejemplo n.º 1
0
    def _get_vm_base_image(self, image_scanner, vm_dir):
        image_id = None
        file_name_hint = None
        # Look for the vmdk file
        for vm_file in os.listdir(vm_dir):
            # Skip non vmdk files or directories
            if not vm_file.endswith(".vmdk"):
                continue
            # Skip vmdk delta files
            if vm_file.endswith("delta.vmdk"):
                continue
            # Skip vmdk flat file
            if vm_file.endswith("flat.vmdk"):
                continue
            vmdk_pathname = os.path.join(vm_dir, vm_file)
            self._logger.info("found vmdk: %s" % vmdk_pathname)
            try:
                vmdk_dictionary = parse_vmdk(vmdk_pathname)
                # In vmdk of linked clone, parentFileNameHint points to base image.
                # If there is no file_name_hint, skip it
                if image_scanner.FILE_NAME_HINT not in vmdk_dictionary:
                    self._logger.info(
                        "skipping vmdk(%s) due to missing parent hint" %
                        vmdk_pathname)
                    continue
                file_name_hint = vmdk_dictionary[image_scanner.FILE_NAME_HINT]
                image_id = self._image_manager.get_image_id_from_path(
                    file_name_hint)
            except Exception as ex:
                self._logger.warn("skipping vmdk(%s) due to exception: %s" %
                                  (vmdk_pathname, ex))
            break

        return image_id, file_name_hint
Ejemplo n.º 2
0
    def _collect_active_images(self, image_scanner, root):
        """
        :param root: top directory
        :return: dictionary of used images, key is image id
        """
        # Log messages with prefix: "IMAGE SCANNER" are for debugging
        # and will be removed after basic testing
        self._logger.info("IMAGE SCANNER: calling collect_active_images()")
        # Compute scan rest interval
        rest_interval_sec = image_scanner.get_vm_scan_rest_interval()
        active_images = dict()
        for curdir, dirs, files in os.walk(root):

            # On a directory change check if it still needs to run
            if image_scanner.is_stopped():
                return active_images

            # If this contains only other directories skip it
            if len(files) == 0:
                continue

            # Look for the vmdk file
            for vm_file in files:
                self._logger.info("IMAGE SCANNER: current file %s" % vm_file)
                # Skip non vmdk files
                if not vm_file.endswith(".vmdk"):
                    continue
                # Skip vmdk delta files
                if vm_file.endswith("delta.vmdk"):
                    continue
                # Skip vmdk flat file
                if vm_file.endswith("flat.vmdk"):
                    continue
                vmdk_pathname = os.path.join(curdir, vm_file)
                self._logger.info("IMAGE SCANNER: found vmdk: %s" %
                                  vmdk_pathname)
                try:
                    vmdk_dictionary = parse_vmdk(vmdk_pathname)
                    # If there is no file_name_hint, skip it
                    if image_scanner.FILE_NAME_HINT not in vmdk_dictionary:
                        # This should be a common occurrence
                        # the log level should debug
                        self._logger.info("IMAGE_SCANNER: Vm scan, "
                                          "skipping file: %s "
                                          "missing parent hint" %
                                          vmdk_pathname)
                        continue
                    file_name_hint = \
                        vmdk_dictionary[image_scanner.FILE_NAME_HINT]
                    image_id = image_scanner.image_manager.\
                        get_image_id_from_path(file_name_hint)
                    if image_id not in active_images:
                        self._logger.info(
                            "IMAGE SCANNER: adding image_id: %s" % image_id)
                        active_images[image_id] = file_name_hint
                except Exception as ex:
                    self._logger.warn("Vm scan, skipping file: %s : %s" %
                                      (vmdk_pathname, ex))
            waste_time(rest_interval_sec)
        return active_images
Ejemplo n.º 3
0
    def _get_vm_base_image(self, image_scanner, vm_dir):
        image_id = None
        file_name_hint = None
        # Look for the vmdk file
        for vm_file in os.listdir(vm_dir):
            # Skip non vmdk files or directories
            if not vm_file.endswith(".vmdk"):
                continue
            # Skip vmdk delta files
            if vm_file.endswith("delta.vmdk"):
                continue
            # Skip vmdk flat file
            if vm_file.endswith("flat.vmdk"):
                continue
            vmdk_pathname = os.path.join(vm_dir, vm_file)
            self._logger.info("found vmdk: %s" % vmdk_pathname)
            try:
                vmdk_dictionary = parse_vmdk(vmdk_pathname)
                # In vmdk of linked clone, parentFileNameHint points to base image.
                # If there is no file_name_hint, skip it
                if image_scanner.FILE_NAME_HINT not in vmdk_dictionary:
                    self._logger.info("skipping vmdk(%s) due to missing parent hint" % vmdk_pathname)
                    continue
                file_name_hint = vmdk_dictionary[image_scanner.FILE_NAME_HINT]
                image_id = self._image_manager.get_image_id_from_path(file_name_hint)
            except Exception as ex:
                self._logger.warn("skipping vmdk(%s) due to exception: %s" % (vmdk_pathname, ex))
            break

        return image_id, file_name_hint
Ejemplo n.º 4
0
    def _collect_active_images(self, image_scanner, root):
        """
        :param root: top directory
        :return: dictionary of used images, key is image id
        """
        # Log messages with prefix: "IMAGE SCANNER" are for debugging
        # and will be removed after basic testing
        self._logger.info("IMAGE SCANNER: calling collect_active_images()")
        # Compute scan rest interval
        rest_interval_sec = image_scanner.get_vm_scan_rest_interval()
        active_images = dict()
        for curdir, dirs, files in os.walk(root):

            # On a directory change check if it still needs to run
            if image_scanner.is_stopped():
                return active_images

            # If this contains only other directories skip it
            if len(files) == 0:
                continue

            # Look for the vmdk file
            for vm_file in files:
                self._logger.info("IMAGE SCANNER: current file %s" % vm_file)
                # Skip non vmdk files
                if not vm_file.endswith(".vmdk"):
                    continue
                # Skip vmdk delta files
                if vm_file.endswith("delta.vmdk"):
                    continue
                # Skip vmdk flat file
                if vm_file.endswith("flat.vmdk"):
                    continue
                vmdk_pathname = os.path.join(curdir, vm_file)
                self._logger.info("IMAGE SCANNER: found vmdk: %s"
                                  % vmdk_pathname)
                try:
                    vmdk_dictionary = parse_vmdk(vmdk_pathname)
                    # If there is no file_name_hint, skip it
                    if image_scanner.FILE_NAME_HINT not in vmdk_dictionary:
                        # This should be a common occurrence
                        # the log level should debug
                        self._logger.info("IMAGE_SCANNER: Vm scan, "
                                          "skipping file: %s "
                                          "missing parent hint"
                                          % vmdk_pathname)
                        continue
                    file_name_hint = \
                        vmdk_dictionary[image_scanner.FILE_NAME_HINT]
                    image_id = image_scanner.image_manager.\
                        get_image_id_from_path(file_name_hint)
                    if image_id not in active_images:
                        self._logger.info(
                            "IMAGE SCANNER: adding image_id: %s" % image_id)
                        active_images[image_id] = file_name_hint
                except Exception as ex:
                    self._logger.warn("Vm scan, skipping file: %s : %s"
                                      % (vmdk_pathname, ex))
            waste_time(rest_interval_sec)
        return active_images
Ejemplo n.º 5
0
 def test_parse_vmdk(self):
     vmdk_pathname = os.path.join(self.test_dir, 'good.vmdk')
     dictionary = parse_vmdk(vmdk_pathname)
     assert_that(dictionary["version"] == "1")
     assert_that(dictionary["encoding"] == "UTF-8")
     assert_that(dictionary["CID"] == "fffffffe")
     assert_that(dictionary["parentCID"] == "fffffffe")
     assert_that(dictionary["isNativeSnapshot"] == "no")
     assert_that(dictionary["createType"] == "vmfsSparse")
     assert_that(dictionary["parentFileNameHint"] ==
                 "/vmfs/volumes/555ca9f8-9f24fa2c-41c1-0025b5414043/"
                 "image_92e62599-6689-4a8f-ba2a-633914b5048e/92e"
                 "62599-6689-4a8f-ba2a-633914b5048e.vmdk")
Ejemplo n.º 6
0
 def test_parse_vmdk(self):
     vmdk_pathname = os.path.join(self.test_dir, 'good.vmdk')
     dictionary = parse_vmdk(vmdk_pathname)
     assert_that(dictionary["version"] == "1")
     assert_that(dictionary["encoding"] == "UTF-8")
     assert_that(dictionary["CID"] == "fffffffe")
     assert_that(dictionary["parentCID"] == "fffffffe")
     assert_that(dictionary["isNativeSnapshot"] == "no")
     assert_that(dictionary["createType"] == "vmfsSparse")
     assert_that(dictionary["parentFileNameHint"] ==
                 "/vmfs/volumes/555ca9f8-9f24fa2c-41c1-0025b5414043/"
                 "image_92e62599-6689-4a8f-ba2a-633914b5048e/92e"
                 "62599-6689-4a8f-ba2a-633914b5048e.vmdk")