Esempio n. 1
0
def mark_volumes_deleted(config, volume_ids):
    def get_opt(name):
        return (getattr(config.src_storage, name)
                or getattr(config.src_mysql, name))

    db_config = {
        opt: get_opt(opt)
        for opt in ('db_user', 'db_password', 'db_host', 'db_port',
                    'db_connection')
    }
    db_name = config.src_storage.db_name
    conn = mysql_connector.MysqlConnector(db_config, db_name)
    src_db = cinder_db.CinderDBBroker(conn)
    result = []
    with conn.transaction():
        for volume_id in volume_ids:
            volume = src_db.get_cinder_volume(volume_id)
            if volume is None:
                LOG.error("Volume '%s' not found.", volume_id)
                result.append((volume_id, None, 'not found'))
                continue
            if volume.deleted:
                LOG.warning("Volume '%s' is already deleted.", volume_id)
                result.append((volume.id, volume.deleted_at, 'skipped'))
                continue
            LOG.debug("Mark volume '%s' as deleted.", volume_id)
            volume = src_db.delete_volume(volume_id)
            result.append((volume.id, volume.deleted_at, 'deleted'))
    return result
Esempio n. 2
0
    def from_context(cls, context):
        vmax_ip = context.cloud_config.storage.vmax_ip
        vmax_port = context.cloud_config.storage.vmax_port
        vmax_user = context.cloud_config.storage.vmax_user
        vmax_password = context.cloud_config.storage.vmax_password
        vmax_port_groups = context.cloud_config.storage.vmax_port_groups
        vmax_fast_policy = context.cloud_config.storage.vmax_fast_policy
        vmax_pool_name = context.cloud_config.storage.vmax_pool_name
        vmax_iscsi_my_ip = context.cloud_config.storage.iscsi_my_ip
        vmax_initiator_name = context.cloud_config.storage.initiator_name

        volume_name_template = context.cloud_config.storage.\
            volume_name_template
        backend_timeout = context.cloud_config.migrate.storage_backend_timeout

        vmax_config_opts = [opt for opt in list(locals().keys())
                            if opt.startswith('vmax_')]
        missing_opts = [opt for opt in vmax_config_opts if opt is None]
        if any(missing_opts):
            msg = ("Invalid configuration specified for EMC storage backend, "
                   "following options must be specified: {}")
            msg = msg.format(', '.join(missing_opts))
            LOG.error(msg)
            raise exception.InvalidConfigException(msg)

        cinder = context.resources[utils.STORAGE_RESOURCE]

        vmax_connector = EMCConnector(vmax_ip,
                                      vmax_port,
                                      vmax_user,
                                      vmax_password,
                                      vmax_port_groups,
                                      vmax_fast_policy,
                                      vmax_pool_name,
                                      backend_timeout,
                                      volume_name_template,
                                      vmax_initiator_name)

        num_retries = context.cloud_config.migrate.retry
        sudo_pass = context.cloud_config.migrate.local_sudo_password
        timeout = context.cloud_config.migrate.storage_backend_timeout

        iscsi_connector = iscsi.ISCSIConnector(num_retries=num_retries,
                                               local_sudo_password=sudo_pass,
                                               storage_backend_timeout=timeout)
        db = cinder_db.CinderDBBroker(cinder.mysql_connector)

        return cls(vmax_connector, db, iscsi_connector, vmax_iscsi_my_ip)
Esempio n. 3
0
 def reuse_source_volume(self, src_volume):
     """Creates volume on destination with same id from source"""
     volume_id = src_volume['id']
     original_size = src_volume['size']
     src_volume_object = self.dst_cinder_backend.get_volume_object(
         self.dst_cloud, volume_id)
     LOG.debug("Backing file for source volume on destination cloud: %s",
               src_volume_object)
     fake_volume = copy.deepcopy(src_volume)
     fake_volume['size'] = 1
     dst_volume, dst_volume_object = self._create_volume(fake_volume)
     user = self.dst_cloud.cloud_config.cloud.ssh_user
     password = self.dst_cloud.cloud_config.cloud.ssh_sudo_password
     rr = remote_runner.RemoteRunner(dst_volume_object.host, user,
                                     password=password, sudo=True,
                                     ignore_errors=True)
     files.remote_rm(rr, dst_volume_object.path)
     dst_cinder = self.dst_cloud.resources[utils.STORAGE_RESOURCE]
     dst_db = cinder_db.CinderDBBroker(dst_cinder.mysql_connector)
     dst_db.update_volume_id(dst_volume.id, volume_id)
     if original_size > 1:
         inc_size = original_size - 1
         project_id = dst_db.get_cinder_volume(volume_id).project_id
         dst_db.inc_quota_usages(project_id, 'gigabytes', inc_size)
         volume_type = (None
                        if dst_volume.volume_type == 'None'
                        else dst_volume.volume_type)
         if volume_type:
             dst_db.inc_quota_usages(project_id,
                                     'gigabytes_%s' % volume_type, inc_size)
     provider_location = self.dst_cinder_backend.get_provider_location(
         self.dst_cloud,
         dst_volume_object.host,
         src_volume_object.path
     )
     dst_db.update_volume(volume_id, provider_location=provider_location,
                          size=original_size)
     return dst_cinder.get_volume_by_id(volume_id)