コード例 #1
0
ファイル: baseimage_new.py プロジェクト: vmthunder/virtman
    def destroy_base_image(self):
        LOG.debug("Virtman: destroy base_image = %s, peer_id = %s" %
                  (self.image_name, self.peer_id))
        # if base_image.is_local_has_image:
        #     return False
        if self.is_login:
            Volt.logout_master(self)

        if self.has_target:
            if iscsi.is_connected(self.target_id):
                LOG.debug("Virtman: destroy base image Failed! iscsi target "
                          "for this base image is connected.")
                return False
            try:
                Target.delete_target(self)
            except Exception as ex:
                LOG.debug("Virtman: delete target for base image %s fail, "
                          "due to %s" % (self.image_name, ex))
                return False

        if self.origin_path:
            try:
                Origin.delete_origin(self)
            except Exception as ex:
                LOG.debug("Virtman: delete origin for base image %s fail, "
                          "due to %s" % (self.image_name, ex))
                return False

        time.sleep(1)

        if self.cached_path:
            try:
                Cache.delete_cache(self)
            except Exception as ex:
                LOG.debug("Virtman: delete cache for base image %s fail, "
                          "due to %s" % (self.image_name, ex))
                return False

        if self.multipath_path:
            try:
                self.delete_multipath()
            except Exception as ex:
                LOG.debug("Virtman: delete multipath for base image %s fail, "
                          "due to %s" % (self.image_name, ex))
                return False
        try:
            for key in self.paths.keys():
                Path.disconnect(self.paths[key])
                del self.paths[key]
            LOG.debug("Virtman: destroy base image SUCCESS! base_image = %s, "
                      "peer_id = %s" % (self.image_name,
                                        self.peer_id))
            return True
        except Exception as ex:
            LOG.debug("Virtman: destroy base image %s fail, due to %s" %
                      (self.image_name, ex))
            return False
コード例 #2
0
ファイル: baseimage.py プロジェクト: vmthunder/virtman
    def rebuild_multipath(self, parent_connections):
        """
        :param parent_connections: list
        """
        LOG.debug("Virtman: begin to rebuild multipath...")
        # If it has image on the local node or no path to connect, connect to
        # root
        if self.is_local_has_image or len(parent_connections) == 0:
            parent_connections = self.image_connections
            LOG.debug("Virtman: the parents were modified! now parents = %s" %
                      parent_connections)

        # Get keys of paths to remove, and add new paths
        paths_to_remove = []
        for key in self.paths.keys():
            found = False
            for connection in parent_connections:
                if key == Path.connection_to_str(connection):
                    found = True
                    break
            if not found:
                paths_to_remove.append(key)
        for connection in parent_connections:
            if not isinstance(connection, dict):
                raise (Exception("Unknown %s type of %s " %
                                 (type(connection), connection)))
            key = Path.connection_to_str(connection)
            if key not in self.paths:
                self.paths[key] = Path(connection)

        # Connect new paths
        for key in self.paths.keys():
            if key not in paths_to_remove and not self.paths[key].connected:
                self.paths[key].connect()

        # Rebuild multipath device
        disks = [self.paths[key].device_path for key in self.paths.keys()
                 if key not in paths_to_remove and self.paths[key].connected]
        if len(disks) > 0:
            if not self.has_multipath:
                self._create_multipath(disks)
            else:
                self._reload_multipath(disks)
            # TODO:fix here, wait for multipath device ready
            time.sleep(2)

        # Disconnect paths to remove
        for key in paths_to_remove:
            if self.paths[key].connected:
                self.paths[key].disconnect()
            del self.paths[key]

        LOG.debug("Virtman: rebuild multipath completed, multipath = %s" %
                  self.multipath_path)
コード例 #3
0
ファイル: test_baseimage.py プロジェクト: vmthunder/virtman
 def __str__(self):
     return Path.connection_to_str(self.connection)