Beispiel #1
0
 def get_volume_mountpoint(self):
     volume = create_nova_volume_client(self.context).volumes.get(volume_id)
     mountpoint = volume.attachments[0]['device']
     if mountpoint[0] is not "/":
         return "/%s" % mountpoint
     else:
         return mountpoint
Beispiel #2
0
 def load(context):
     client = create_nova_volume_client(context)
     rdstorages = client.rdstorage.list()
     for rdstorage in rdstorages:
         LOG.debug("rdstorage=" + str(rdstorage))
     return [StorageDevice(storage_info)
             for storage_info in rdstorages]
Beispiel #3
0
    def load(context):
        if context is None:
            raise TypeError("Argument context not defined.")
        client = create_nova_client(context)
        servers = client.servers.list()
        volume_client = create_nova_volume_client(context)
        try:
            volumes = volume_client.volumes.list(detailed=False)
        except nova_exceptions.NotFound:
            volumes = []

        db_infos = DBInstance.find_all()
        limit = int(context.limit or Instances.DEFAULT_LIMIT)
        if limit > Instances.DEFAULT_LIMIT:
            limit = Instances.DEFAULT_LIMIT
        data_view = DBInstance.find_by_pagination('instances', db_infos, "foo",
                                                  limit=limit,
                                                  marker=context.marker)
        next_marker = data_view.next_page_marker

        ret = []
        find_server = create_server_list_matcher(servers)
        find_volumes = create_volumes_list_matcher(volumes)
        for db in db_infos:
            LOG.debug("checking for db [id=%s, compute_instance_id=%s]" %
                      (db.id, db.compute_instance_id))
        for db in data_view.collection:
            try:
                # TODO(hub-cap): Figure out if this is actually correct.
                # We are not sure if we should be doing some validation.
                # Basically if the server find returns nothing, but we
                # have something, there is a mismatch between what the
                # nova db has compared to what we have. We should have
                # a way to handle this.
                server = find_server(db.id, db.compute_instance_id)
                volumes = find_volumes(server.id)
                status = InstanceServiceStatus.find_by(instance_id=db.id)
                LOG.info(_("Server api_status(%s)") %
                           (status.status.api_status))

                if not status.status:
                    LOG.info(_("Server status could not be read for "
                               "instance id(%s)") % (db.compute_instance_id))
                    continue
                if status.status.api_status in ['SHUTDOWN']:
                    LOG.info(_("Server was shutdown id(%s)") %
                           (db.compute_instance_id))
                    continue
            except rd_exceptions.ComputeInstanceNotFound:
                LOG.info(_("Could not find server %s") %
                           db.compute_instance_id)
                continue
            except ModelNotFoundError:
                LOG.info(_("Status entry not found either failed to start "
                           "or instance was deleted"))
                continue
            ret.append(Instance(context, db, server, status, volumes))
        return ret, next_marker
Beispiel #4
0
    def _create_volume(self, volume_size):
        LOG.info("Entering create_volume")
        LOG.debug(_("Starting to create the volume for the instance"))

        volume_support = config.Config.get("reddwarf_volume_support", 'False')
        LOG.debug(_("reddwarf volume support = %s") % volume_support)
        if (volume_size is None or
                utils.bool_from_string(volume_support) is False):
            volume_info = {
                'block_device': None,
                'device_path': None,
                'mount_point': None,
                'volumes': None,
            }
            return volume_info

        volume_client = create_nova_volume_client(self.context)
        volume_desc = ("mysql volume for %s" % self.id)
        volume_ref = volume_client.volumes.create(
            volume_size,
            display_name="mysql-%s" % self.id,
            display_description=volume_desc)

        # Record the volume ID in case something goes wrong.
        self.update_db(volume_id=volume_ref.id)

        utils.poll_until(
            lambda: volume_client.volumes.get(volume_ref.id),
            lambda v_ref: v_ref.status in ['available', 'error'],
            sleep_time=2,
            time_out=2 * 60)

        v_ref = volume_client.volumes.get(volume_ref.id)
        if v_ref.status in ['error']:
            raise VolumeCreationFailure()
        LOG.debug(_("Created volume %s") % v_ref)
        # The mapping is in the format:
        # <id>:[<type>]:[<size(GB)>]:[<delete_on_terminate>]
        # setting the delete_on_terminate instance to true=1
        mapping = "%s:%s:%s:%s" % (v_ref.id, '', v_ref.size, 1)
        bdm = config.Config.get('block_device_mapping', 'vdb')
        block_device = {bdm: mapping}
        volumes = [{'id': v_ref.id,
                    'size': v_ref.size}]
        LOG.debug("block_device = %s" % block_device)
        LOG.debug("volume = %s" % volumes)

        device_path = config.Config.get('device_path', '/dev/vdb')
        mount_point = config.Config.get('mount_point', '/var/lib/mysql')
        LOG.debug(_("device_path = %s") % device_path)
        LOG.debug(_("mount_point = %s") % mount_point)

        volume_info = {'block_device': block_device,
                       'device_path': device_path,
                       'mount_point': mount_point,
                       'volumes': volumes}
        return volume_info
Beispiel #5
0
    def _create_volume(cls, context, db_info, volume_size):
        volume_support = config.Config.get("reddwarf_volume_support", 'False')
        LOG.debug(_("reddwarf volume support = %s") % volume_support)
        if utils.bool_from_string(volume_support):
            LOG.debug(_("Starting to create the volume for the instance"))
            volume_client = create_nova_volume_client(context)
            volume_desc = ("mysql volume for %s" % db_info.id)
            volume_ref = volume_client.volumes.create(
                                        volume_size,
                                        display_name="mysql-%s" % db_info.id,
                                        display_description=volume_desc)
            # Record the volume ID in case something goes wrong.
            db_info.volume_id = volume_ref.id
            db_info.save()
            #TODO(cp16net) this is bad to wait here for the volume create
            # before returning but this was a quick way to get it working
            # for now we need this to go into the task manager
            v_ref = volume_client.volumes.get(volume_ref.id)
            while not v_ref.status in ['available', 'error']:
                LOG.debug(_("waiting for volume [volume.status=%s]") %
                            v_ref.status)
                greenthread.sleep(1)
                v_ref = volume_client.volumes.get(volume_ref.id)

            if v_ref.status in ['error']:
                raise rd_exceptions.VolumeCreationFailure()
            LOG.debug(_("Created volume %s") % v_ref)
            # The mapping is in the format:
            # <id>:[<type>]:[<size(GB)>]:[<delete_on_terminate>]
            # setting the delete_on_terminate instance to true=1
            mapping = "%s:%s:%s:%s" % (v_ref.id, '', v_ref.size, 1)
            bdm = CONFIG.get('block_device_mapping', 'vdb')
            block_device = {bdm: mapping}
            volumes = [{'id': v_ref.id,
                       'size': v_ref.size}]
            LOG.debug("block_device = %s" % block_device)
            LOG.debug("volume = %s" % volumes)

            device_path = CONFIG.get('device_path', '/dev/vdb')
            mount_point = CONFIG.get('mount_point', '/var/lib/mysql')
            LOG.debug(_("device_path = %s") % device_path)
            LOG.debug(_("mount_point = %s") % mount_point)
        else:
            LOG.debug(_("Skipping setting up the volume"))
            block_device = None
            device_path = None
            mount_point = None
            volumes = None
            #end volume_support
        #block_device = ""
        #device_path = /dev/vdb
        #mount_point = /var/lib/mysql
        volume_info = {'block_device': block_device,
                       'device_path': device_path,
                       'mount_point': mount_point,
                       'volumes': volumes}
        return volume_info
Beispiel #6
0
 def load(cls, context, id):
     instance = load_mgmt_instance(cls, context, id)
     client = create_nova_volume_client(context)
     try:
         instance.volume = client.volumes.get(instance.volume_id)
     except Exception as ex:
         instance.volume = None
     instance.root_history = mysql_models.RootHistory.load(context=context,
                                                           instance_id=id)
     return instance
Beispiel #7
0
    def _create_volume(cls, context, db_info, volume_size):
        volume_support = config.Config.get("reddwarf_volume_support", 'False')
        LOG.debug(_("reddwarf volume support = %s") % volume_support)
        if utils.bool_from_string(volume_support):
            LOG.debug(_("Starting to create the volume for the instance"))
            volume_client = create_nova_volume_client(context)
            volume_desc = ("mysql volume for %s" % db_info.id)
            volume_ref = volume_client.volumes.create(
                                        volume_size,
                                        display_name="mysql-%s" % db_info.id,
                                        display_description=volume_desc)
            #TODO(cp16net) this is bad to wait here for the volume create
            # before returning but this was a quick way to get it working
            # for now we need this to go into the task manager
            v_ref = volume_client.volumes.get(volume_ref.id)
            while not v_ref.status in ['available', 'error']:
                LOG.debug(_("waiting for volume [volume.status=%s]") %
                            v_ref.status)
                greenthread.sleep(1)
                v_ref = volume_client.volumes.get(volume_ref.id)

            if v_ref.status in ['error']:
                raise rd_exceptions.ReddwarfError(
                                    _("Could not create volume"))
            LOG.debug(_("Created volume %s") % v_ref)
            # The mapping is in the format:
            # <id>:[<type>]:[<size(GB)>]:[<delete_on_terminate>]
            # setting the delete_on_terminate instance to true=1
            mapping = "%s:%s:%s:%s" % (v_ref.id, '', v_ref.size, 1)
            # TODO(rnirmal) This mapping device needs to be configurable.
            # and we may have to do a little more trickery here.
            # We don't know what's the next device available on the
            # guest. Also in cases for ovz where this is mounted on
            # the host, that's not going to work for us.
            block_device = {'vdb': mapping}
            volume = [{'id': v_ref.id,
                       'size': v_ref.size}]
            LOG.debug("block_device = %s" % block_device)
            LOG.debug("volume = %s" % volume)

            device_path = CONFIG.get('device_path')
            mount_point = CONFIG.get('mount_point')
            LOG.debug(_("device_path = %s") % device_path)
            LOG.debug(_("mount_point = %s") % mount_point)
        else:
            LOG.debug(_("Skipping setting up the volume"))
            block_device = None
            device_path = None
            mount_point = None
            volume = None
            #end volume_support
        volume_info = {'block_device': block_device,
                       'device_path': device_path,
                       'mount_point': mount_point}
        return volume, volume_info
Beispiel #8
0
 def load(cls, context, id):
     instance = load_mgmt_instance(cls, context, id)
     client = create_nova_volume_client(context)
     try:
         instance.volume = client.volumes.get(instance.volume_id)
     except Exception as ex:
         instance.volume = None
     # Populate the volume_used attribute from the guest agent.
     instance_models.load_guest_info(instance, context, id)
     instance.root_history = mysql_models.RootHistory.load(context=context, instance_id=id)
     return instance
Beispiel #9
0
    def _create_volume(self, volume_size):
        LOG.info("Entering create_volume")
        LOG.debug(_("Starting to create the volume for the instance"))

        volume_support = config.Config.get("reddwarf_volume_support", "False")
        LOG.debug(_("reddwarf volume support = %s") % volume_support)
        if volume_size is None or utils.bool_from_string(volume_support) is False:
            volume_info = {"block_device": None, "device_path": None, "mount_point": None, "volumes": None}
            return volume_info

        volume_client = create_nova_volume_client(self.context)
        volume_desc = "mysql volume for %s" % self.id
        volume_ref = volume_client.volumes.create(
            volume_size, display_name="mysql-%s" % self.id, display_description=volume_desc
        )

        # Record the volume ID in case something goes wrong.
        self.update_db(volume_id=volume_ref.id)

        utils.poll_until(
            lambda: volume_client.volumes.get(volume_ref.id),
            lambda v_ref: v_ref.status in ["available", "error"],
            sleep_time=2,
            time_out=2 * 60,
        )

        v_ref = volume_client.volumes.get(volume_ref.id)
        if v_ref.status in ["error"]:
            raise VolumeCreationFailure()
        LOG.debug(_("Created volume %s") % v_ref)
        # The mapping is in the format:
        # <id>:[<type>]:[<size(GB)>]:[<delete_on_terminate>]
        # setting the delete_on_terminate instance to true=1
        mapping = "%s:%s:%s:%s" % (v_ref.id, "", v_ref.size, 1)
        bdm = config.Config.get("block_device_mapping", "vdb")
        block_device = {bdm: mapping}
        volumes = [{"id": v_ref.id, "size": v_ref.size}]
        LOG.debug("block_device = %s" % block_device)
        LOG.debug("volume = %s" % volumes)

        device_path = config.Config.get("device_path", "/dev/vdb")
        mount_point = config.Config.get("mount_point", "/var/lib/mysql")
        LOG.debug(_("device_path = %s") % device_path)
        LOG.debug(_("mount_point = %s") % mount_point)

        volume_info = {
            "block_device": block_device,
            "device_path": device_path,
            "mount_point": mount_point,
            "volumes": volumes,
        }
        return volume_info
Beispiel #10
0
    def _create_volume(self, volume_size):
        LOG.info("Entering create_volume")
        LOG.debug(_("Starting to create the volume for the instance"))

        volume_client = create_nova_volume_client(self.context)
        volume_desc = ("mysql volume for %s" % self.id)
        volume_ref = volume_client.volumes.create(
            volume_size,
            display_name="mysql-%s" % self.id,
            display_description=volume_desc)

        # Record the volume ID in case something goes wrong.
        self.update_db(volume_id=volume_ref.id)

        utils.poll_until(
            lambda: volume_client.volumes.get(volume_ref.id),
            lambda v_ref: v_ref.status in ['available', 'error'],
            sleep_time=2,
            time_out=VOLUME_TIME_OUT)

        v_ref = volume_client.volumes.get(volume_ref.id)
        if v_ref.status in ['error']:
            raise VolumeCreationFailure()
        LOG.debug(_("Created volume %s") % v_ref)
        # The mapping is in the format:
        # <id>:[<type>]:[<size(GB)>]:[<delete_on_terminate>]
        # setting the delete_on_terminate instance to true=1
        mapping = "%s:%s:%s:%s" % (v_ref.id, '', v_ref.size, 1)
        bdm = CONF.block_device_mapping
        block_device = {bdm: mapping}
        volumes = [{'id': v_ref.id,
                    'size': v_ref.size}]
        LOG.debug("block_device = %s" % block_device)
        LOG.debug("volume = %s" % volumes)

        device_path = CONF.device_path
        mount_point = CONF.mount_point
        LOG.debug(_("device_path = %s") % device_path)
        LOG.debug(_("mount_point = %s") % mount_point)

        volume_info = {'block_device': block_device,
                       'device_path': device_path,
                       'mount_point': mount_point,
                       'volumes': volumes}
        return volume_info
Beispiel #11
0
    def _create_volume(self, volume_size):
        LOG.info("Entering create_volume")
        LOG.debug(_("Starting to create the volume for the instance"))

        volume_client = create_nova_volume_client(self.context)
        volume_desc = ("mysql volume for %s" % self.id)
        volume_ref = volume_client.volumes.create(
            volume_size,
            display_name="mysql-%s" % self.id,
            display_description=volume_desc)

        # Record the volume ID in case something goes wrong.
        self.update_db(volume_id=volume_ref.id)

        utils.poll_until(lambda: volume_client.volumes.get(volume_ref.id),
                         lambda v_ref: v_ref.status in ['available', 'error'],
                         sleep_time=2,
                         time_out=VOLUME_TIME_OUT)

        v_ref = volume_client.volumes.get(volume_ref.id)
        if v_ref.status in ['error']:
            raise VolumeCreationFailure()
        LOG.debug(_("Created volume %s") % v_ref)
        # The mapping is in the format:
        # <id>:[<type>]:[<size(GB)>]:[<delete_on_terminate>]
        # setting the delete_on_terminate instance to true=1
        mapping = "%s:%s:%s:%s" % (v_ref.id, '', v_ref.size, 1)
        bdm = CONF.block_device_mapping
        block_device = {bdm: mapping}
        volumes = [{'id': v_ref.id, 'size': v_ref.size}]
        LOG.debug("block_device = %s" % block_device)
        LOG.debug("volume = %s" % volumes)

        device_path = CONF.device_path
        mount_point = CONF.mount_point
        LOG.debug(_("device_path = %s") % device_path)
        LOG.debug(_("mount_point = %s") % mount_point)

        volume_info = {
            'block_device': block_device,
            'device_path': device_path,
            'mount_point': mount_point,
            'volumes': volumes
        }
        return volume_info
Beispiel #12
0
 def load(context, id):
     if context is None:
         raise TypeError("Argument context not defined.")
     elif id is None:
         raise TypeError("Argument id not defined.")
     try:
         db_info = inst_models.DBInstance.find_by(id=id)
     except exception.NotFound:
         raise exception.NotFound(uuid=id)
     server, volumes = inst_models.load_server_with_volumes(context,
                                             db_info.id,
                                             db_info.compute_instance_id)
     nova_client = remote.create_nova_client(context)
     volume_client = remote.create_nova_volume_client(context)
     guest = remote.create_guest_client(context, id)
     return InstanceTasks(context, db_info, server, volumes,
                          nova_client=nova_client,
                          volume_client=volume_client, guest=guest)
Beispiel #13
0
def load_volumes(context, server_id, client=None):
    volume_support = config.Config.get("reddwarf_volume_support", 'False')
    if utils.bool_from_string(volume_support):
        if client is None:
            client = create_nova_client(context)
        volume_client = create_nova_volume_client(context)
        try:
            volumes = []
            volumes_info = client.volumes.get_server_volumes(server_id)
            volume_ids = [attachments.volumeId for attachments in
                          volumes_info]
            for volume_id in volume_ids:
                volume_info = volume_client.volumes.get(volume_id)
                volume = {'id': volume_info.id,
                          'size': volume_info.size}
                volumes.append(volume)
        except nova_exceptions.NotFound, e:
            LOG.debug("Could not find nova server_id(%s)" % server_id)
            raise rd_exceptions.VolumeAttachmentsNotFound(server_id=server_id)
        except nova_exceptions.ClientException, e:
            raise rd_exceptions.ReddwarfError(str(e))
Beispiel #14
0
 def volume_client(self):
     if not self._volume_client:
         self._volume_client = create_nova_volume_client(self.context)
     return self._volume_client
Beispiel #15
0
 def volume_client(self):
     if not self._volume_client:
         self._volume_client = create_nova_volume_client(self.context)
     return self._volume_client
Beispiel #16
0
 def load(context):
     client = create_nova_volume_client(context)
     rdstorages = client.rdstorage.list()
     for rdstorage in rdstorages:
         LOG.debug("rdstorage=" + str(rdstorage))
     return [StorageDevice(storage_info) for storage_info in rdstorages]