def convert_volume(vol, cfg, cloud):
     compute = cloud.resources[utl.COMPUTE_RESOURCE]
     volume = {
         'id':
         vol.id,
         'size':
         vol.size,
         'display_name':
         vol.display_name,
         'display_description':
         vol.display_description,
         'volume_type':
         (None if vol.volume_type == u'None' else vol.volume_type),
         'availability_zone':
         vol.availability_zone,
         'device':
         vol.attachments[0]['device'] if vol.attachments else None,
         'bootable':
         False,
         'volume_image_metadata': {},
         'host':
         None,
         'path':
         None
     }
     if 'bootable' in vol.__dict__:
         volume['bootable'] = True if vol.bootable.lower(
         ) == 'true' else False
     if 'volume_image_metadata' in vol.__dict__:
         volume['volume_image_metadata'] = {
             'image_id': vol.volume_image_metadata['image_id'],
             'checksum': vol.volume_image_metadata['checksum']
         }
     if cfg.storage.backend == utl.CEPH:
         volume['path'] = "%s/%s%s" % (
             cfg.storage.rbd_pool, cfg.storage.volume_name_template, vol.id)
         volume['host'] = (cfg.storage.host
                           if cfg.storage.host else cfg.cloud.host)
     elif vol.attachments and (cfg.storage.backend == utl.ISCSI):
         instance = compute.read_info(
             search_opts={'id': vol.attachments[0]['server_id']})
         instance = instance[utl.INSTANCES_TYPE]
         instance_info = instance.values()[0][utl.INSTANCE_BODY]
         volume['host'] = instance_info['host']
         list_disk = utl.get_libvirt_block_info(
             instance_info['instance_name'], cloud.getIpSsh(),
             instance_info['host'], cfg.cloud.ssh_user,
             cfg.cloud.ssh_sudo_password)
         volume['path'] = utl.find_element_by_in(list_disk, vol.id)
     return volume
Beispiel #2
0
 def convert_volume(vol, cfg, cloud):
     compute = cloud.resources[utils.COMPUTE_RESOURCE]
     volume = {
         'id': vol.id,
         'size': vol.size,
         'display_name': vol.display_name,
         'display_description': vol.display_description,
         'volume_type': (
             None if vol.volume_type == u'None' else vol.volume_type),
         'availability_zone': vol.availability_zone,
         'device': vol.attachments[0][
             'device'] if vol.attachments else None,
         'bootable': vol.bootable.lower() == 'true',
         'volume_image_metadata': {},
         'host': None,
         'path': None,
         'project_id': getattr(vol, 'os-vol-tenant-attr:tenant_id'),
         'metadata': vol.metadata
     }
     if 'volume_image_metadata' in vol.__dict__:
         volume['volume_image_metadata'] = {
             'image_id': vol.volume_image_metadata['image_id'],
             'checksum': vol.volume_image_metadata['checksum'],
             'image_name': vol.volume_image_metadata.get('image_name'),
             'size': int(vol.volume_image_metadata.get('size', 0))
         }
     if cfg.storage.backend == utils.CEPH:
         volume['path'] = "%s/%s%s" % (
             cfg.storage.rbd_pool, cfg.storage.volume_name_template, vol.id)
         volume['host'] = (cfg.storage.host
                           if cfg.storage.host
                           else cfg.cloud.ssh_host)
     elif vol.attachments and (cfg.storage.backend == utils.ISCSI):
         instance = compute.read_info(
             search_opts={'id': vol.attachments[0]['server_id']})
         instance = instance[utils.INSTANCES_TYPE]
         instance_info = instance.values()[0][utils.INSTANCE_BODY]
         volume['host'] = instance_info['host']
         list_disk = utils.get_libvirt_block_info(
             instance_info['instance_name'],
             cfg.cloud.ssh_host,
             instance_info['host'],
             cfg.cloud.ssh_user,
             cfg.cloud.ssh_sudo_password)
         volume['path'] = utils.find_element_by_in(list_disk, vol.id)
     return volume
Beispiel #3
0
    def convert_instance(instance, cfg, cloud):
        identity_res = cloud.resources[utl.IDENTITY_RESOURCE]
        compute_res = cloud.resources[utl.COMPUTE_RESOURCE]
        sg_res = server_groups.ServerGroupsHandler(cloud)

        instance_name = instance_libvirt_name(instance)
        instance_node = instance_host(instance)

        get_tenant_name = identity_res.get_tenants_func()

        security_groups = []
        for security_group in getattr(instance, 'security_groups', []):
            security_groups.append(security_group['name'])

        interfaces = compute_res.get_networks(instance)

        volumes = [{'id': v.id,
                    'num_device': i,
                    'device': v.device} for i, v in enumerate(
                        compute_res.nova_client.volumes.get_server_volumes(
                            instance.id))]

        is_ceph = cfg.compute.backend.lower() == utl.CEPH
        direct_transfer = cfg.migrate.direct_compute_transfer

        ssh_user = cfg.cloud.ssh_user

        if direct_transfer:
            ext_cidr = cfg.cloud.ext_cidr
            host = node_ip.get_ext_ip(ext_cidr,
                                      cfg.cloud.ssh_host,
                                      instance_node,
                                      ssh_user)
        elif is_ceph:
            host = cfg.compute.host_eph_drv
        else:
            host = instance_node

        if not utl.libvirt_instance_exists(instance_name,
                                           cfg.cloud.ssh_host,
                                           instance_node,
                                           ssh_user,
                                           cfg.cloud.ssh_sudo_password):
            LOG.warning('Instance %s (%s) not found on %s, skipping migration',
                        instance_name, instance.id, instance_node)
            return None

        instance_block_info = utl.get_libvirt_block_info(
            instance_name,
            cfg.cloud.ssh_host,
            instance_node,
            ssh_user,
            cfg.cloud.ssh_sudo_password)

        ephemeral_path = {
            'path_src': None,
            'path_dst': None,
            'host_src': host,
            'host_dst': None
        }

        flav_details = instances.get_flav_details(compute_res.mysql_connector,
                                                  instance.id)
        is_ephemeral = flav_details['ephemeral_gb'] > 0
        if is_ephemeral:
            ephemeral_path['path_src'] = utl.get_disk_path(
                instance,
                instance_block_info,
                is_ceph_ephemeral=is_ceph,
                disk=DISK + LOCAL)

        diff = {
            'path_src': None,
            'path_dst': None,
            'host_src': host,
            'host_dst': None
        }

        if instance.image:
            diff['path_src'] = utl.get_disk_path(
                instance,
                instance_block_info,
                is_ceph_ephemeral=is_ceph)
        flav_name = compute_res.get_flavor_from_id(instance.flavor['id'],
                                                   include_deleted=True).name
        flav_details.update({'name': flav_name})

        tenant_name = get_tenant_name(instance.tenant_id)

        if cfg.migrate.keep_affinity_settings:
            server_group = sg_res.get_server_group_id_by_vm(instance.id,
                                                            tenant_name)
        else:
            server_group = None

        config_drive = utl.get_disk_path(instance, instance_block_info,
                                         disk=utl.DISK_CONFIG)
        inst = {'instance': {'name': instance.name,
                             'instance_name': instance_name,
                             'id': instance.id,
                             'tenant_id': instance.tenant_id,
                             'tenant_name': tenant_name,
                             'status': instance.status,
                             'flavor_id': instance.flavor['id'],
                             'flav_details': flav_details,
                             'image_id': instance.image[
                                 'id'] if instance.image else None,
                             'boot_mode': (utl.BOOT_FROM_IMAGE
                                           if instance.image
                                           else utl.BOOT_FROM_VOLUME),
                             'key_name': instance.key_name,
                             'availability_zone': getattr(
                                 instance,
                                 'OS-EXT-AZ:availability_zone'),
                             'security_groups': security_groups,
                             'boot_volume': copy.deepcopy(
                                 volumes[0]) if volumes else None,
                             'interfaces': interfaces,
                             'host': instance_node,
                             'is_ephemeral': is_ephemeral,
                             'volumes': volumes,
                             'user_id': instance.user_id,
                             'server_group': server_group,
                             'config_drive': config_drive is not None,
                             },
                'ephemeral': ephemeral_path,
                'diff': diff,
                'meta': {'old_id': instance.id},
                }

        return inst
Beispiel #4
0
    def convert_instance(instance, cfg, cloud):
        identity_res = cloud.resources[utl.IDENTITY_RESOURCE]
        compute_res = cloud.resources[utl.COMPUTE_RESOURCE]

        instance_name = getattr(instance, "OS-EXT-SRV-ATTR:instance_name")
        instance_host = getattr(instance, INSTANCE_HOST_ATTRIBUTE)

        get_tenant_name = identity_res.get_tenants_func()

        security_groups = []
        for security_group in getattr(instance, 'security_groups', []):
            security_groups.append(security_group['name'])

        interfaces = compute_res.get_networks(instance)

        volumes = [{'id': v.id,
                    'num_device': i,
                    'device': v.device} for i, v in enumerate(
                        compute_res.nova_client.volumes.get_server_volumes(
                            instance.id))]

        is_ephemeral = compute_res.get_flavor_from_id(
            instance.flavor['id']).ephemeral > 0

        is_ceph = cfg.compute.backend.lower() == utl.CEPH
        direct_transfer = cfg.migrate.direct_compute_transfer

        ssh_user = cfg.cloud.ssh_user

        if direct_transfer:
            ext_cidr = cfg.cloud.ext_cidr
            host = utl.get_ext_ip(ext_cidr,
                                  cloud.getIpSsh(),
                                  instance_host,
                                  ssh_user)
        elif is_ceph:
            host = cfg.compute.host_eph_drv
        else:
            host = instance_host

        instance_block_info = utl.get_libvirt_block_info(
            instance_name,
            cloud.getIpSsh(),
            instance_host,
            ssh_user,
            cfg.cloud.ssh_sudo_password)

        ephemeral_path = {
            'path_src': None,
            'path_dst': None,
            'host_src': host,
            'host_dst': None
        }

        if is_ephemeral:
            ephemeral_path['path_src'] = utl.get_disk_path(
                instance,
                instance_block_info,
                is_ceph_ephemeral=is_ceph,
                disk=DISK+LOCAL)

        diff = {
            'path_src': None,
            'path_dst': None,
            'host_src': host,
            'host_dst': None
        }

        if instance.image:
            diff['path_src'] = utl.get_disk_path(
                instance,
                instance_block_info,
                is_ceph_ephemeral=is_ceph)
        flav_details = instances.get_flav_details(compute_res.mysql_connector,
                                                  instance.id)
        flav_name = compute_res.get_flavor_from_id(instance.flavor['id']).name
        flav_details.update({'name': flav_name})

        inst = {'instance': {'name': instance.name,
                             'instance_name': instance_name,
                             'id': instance.id,
                             'tenant_id': instance.tenant_id,
                             'tenant_name': get_tenant_name(
                                 instance.tenant_id),
                             'status': instance.status,
                             'flavor_id': instance.flavor['id'],
                             'flav_details': flav_details,
                             'image_id': instance.image[
                                 'id'] if instance.image else None,
                             'boot_mode': (utl.BOOT_FROM_IMAGE
                                           if instance.image
                                           else utl.BOOT_FROM_VOLUME),
                             'key_name': instance.key_name,
                             'availability_zone': getattr(
                                 instance,
                                 'OS-EXT-AZ:availability_zone'),
                             'security_groups': security_groups,
                             'boot_volume': copy.deepcopy(
                                 volumes[0]) if volumes else None,
                             'interfaces': interfaces,
                             'host': instance_host,
                             'is_ephemeral': is_ephemeral,
                             'volumes': volumes,
                             'user_id': instance.user_id
                             },
                'ephemeral': ephemeral_path,
                'diff': diff,
                'meta': {},
                }

        return inst
Beispiel #5
0
    def convert_instance(instance, cfg, cloud):
        identity_res = cloud.resources[utl.IDENTITY_RESOURCE]
        compute_res = cloud.resources[utl.COMPUTE_RESOURCE]

        instance_name = getattr(instance, "OS-EXT-SRV-ATTR:instance_name")
        instance_host = getattr(instance, 'OS-EXT-SRV-ATTR:host')

        get_tenant_name = identity_res.get_tenants_func()

        security_groups = []
        for security_group in instance.security_groups:
            security_groups.append(security_group['name'])

        interfaces = compute_res.get_networks(instance)

        volumes = [{'id': v.id,
                    'num_device': i,
                    'device': v.device} for i, v in enumerate(
                        compute_res.nova_client.volumes.get_server_volumes(
                            instance.id))]

        is_ephemeral = compute_res.get_flavor_from_id(
            instance.flavor['id']).ephemeral > 0

        is_ceph = cfg.compute.backend.lower() == utl.CEPH
        direct_transfer = cfg.migrate.direct_compute_transfer

        if direct_transfer:
            ext_cidr = cfg.cloud.ext_cidr
            host = utl.get_ext_ip(ext_cidr,
                                  cloud.getIpSsh(),
                                  instance_host)
        elif is_ceph:
            host = cfg.compute.host_eph_drv
        else:
            host = instance_host

        instance_block_info = utl.get_libvirt_block_info(
            instance_name,
            cloud.getIpSsh(),
            instance_host)

        ephemeral_path = {
            'path_src': None,
            'path_dst': None,
            'host_src': host,
            'host_dst': None
        }

        if is_ephemeral:
            ephemeral_path['path_src'] = utl.get_disk_path(
                instance,
                instance_block_info,
                is_ceph_ephemeral=is_ceph,
                disk=DISK+LOCAL)

        diff = {
            'path_src': None,
            'path_dst': None,
            'host_src': host,
            'host_dst': None
        }

        if instance.image:
            diff['path_src'] = utl.get_disk_path(
                instance,
                instance_block_info,
                is_ceph_ephemeral=is_ceph)

        inst = {'instance': {'name': instance.name,
                             'instance_name': instance_name,
                             'id': instance.id,
                             'tenant_id': instance.tenant_id,
                             'tenant_name': get_tenant_name(
                                 instance.tenant_id),
                             'status': instance.status,
                             'flavor_id': instance.flavor['id'],
                             'image_id': instance.image[
                                 'id'] if instance.image else None,
                             'boot_mode': (utl.BOOT_FROM_IMAGE
                                           if instance.image
                                           else utl.BOOT_FROM_VOLUME),
                             'key_name': instance.key_name,
                             'availability_zone': getattr(
                                 instance,
                                 'OS-EXT-AZ:availability_zone'),
                             'security_groups': security_groups,
                             'boot_volume': copy.deepcopy(
                                 volumes[0]) if volumes else None,
                             'interfaces': interfaces,
                             'host': instance_host,
                             'is_ephemeral': is_ephemeral,
                             'volumes': volumes
                             },
                'ephemeral': ephemeral_path,
                'diff': diff,
                'meta': {},
                }

        return inst
Beispiel #6
0
    def convert_instance(instance, cfg, cloud):
        identity_res = cloud.resources[utl.IDENTITY_RESOURCE]
        compute_res = cloud.resources[utl.COMPUTE_RESOURCE]
        sg_res = server_groups.ServerGroupsHandler(cloud)

        instance_name = instance_libvirt_name(instance)
        instance_node = instance_host(instance)

        get_tenant_name = identity_res.get_tenants_func()

        security_groups = []
        for security_group in getattr(instance, 'security_groups', []):
            security_groups.append(security_group['name'])

        interfaces = compute_res.get_networks(instance)

        volumes = [{
            'id': v.id,
            'num_device': i,
            'device': v.device
        } for i, v in enumerate(
            compute_res.nova_client.volumes.get_server_volumes(instance.id))]

        is_ceph = cfg.compute.backend.lower() == utl.CEPH
        direct_transfer = cfg.migrate.direct_compute_transfer

        ssh_user = cfg.cloud.ssh_user

        if direct_transfer:
            ext_cidr = cfg.cloud.ext_cidr
            host = node_ip.get_ext_ip(ext_cidr, cfg.cloud.ssh_host,
                                      instance_node, ssh_user)
        elif is_ceph:
            host = cfg.compute.host_eph_drv
        else:
            host = instance_node

        if not utl.libvirt_instance_exists(instance_name, cfg.cloud.ssh_host,
                                           instance_node, ssh_user,
                                           cfg.cloud.ssh_sudo_password):
            LOG.warning('Instance %s (%s) not found on %s, skipping migration',
                        instance_name, instance.id, instance_node)
            return None

        instance_block_info = utl.get_libvirt_block_info(
            instance_name, cfg.cloud.ssh_host, instance_node, ssh_user,
            cfg.cloud.ssh_sudo_password)

        ephemeral_path = {
            'path_src': None,
            'path_dst': None,
            'host_src': host,
            'host_dst': None
        }

        flav_details = instances.get_flav_details(compute_res.mysql_connector,
                                                  instance.id)
        is_ephemeral = flav_details['ephemeral_gb'] > 0
        if is_ephemeral:
            ephemeral_path['path_src'] = utl.get_disk_path(
                instance,
                instance_block_info,
                is_ceph_ephemeral=is_ceph,
                disk=DISK + LOCAL)

        diff = {
            'path_src': None,
            'path_dst': None,
            'host_src': host,
            'host_dst': None
        }

        if instance.image:
            diff['path_src'] = utl.get_disk_path(instance,
                                                 instance_block_info,
                                                 is_ceph_ephemeral=is_ceph)
        flav_name = compute_res.get_flavor_from_id(instance.flavor['id'],
                                                   include_deleted=True).name
        flav_details.update({'name': flav_name})

        tenant_name = get_tenant_name(instance.tenant_id)

        if cfg.migrate.keep_affinity_settings:
            server_group = sg_res.get_server_group_id_by_vm(
                instance.id, tenant_name)
        else:
            server_group = None

        config_drive = utl.get_disk_path(instance,
                                         instance_block_info,
                                         disk=utl.DISK_CONFIG)
        inst = {
            'instance': {
                'name':
                instance.name,
                'instance_name':
                instance_name,
                'id':
                instance.id,
                'tenant_id':
                instance.tenant_id,
                'tenant_name':
                tenant_name,
                'status':
                instance.status,
                'flavor_id':
                instance.flavor['id'],
                'flav_details':
                flav_details,
                'image_id':
                instance.image['id'] if instance.image else None,
                'boot_mode': (utl.BOOT_FROM_IMAGE
                              if instance.image else utl.BOOT_FROM_VOLUME),
                'key_name':
                instance.key_name,
                'availability_zone':
                getattr(instance, 'OS-EXT-AZ:availability_zone'),
                'security_groups':
                security_groups,
                'boot_volume':
                copy.deepcopy(volumes[0]) if volumes else None,
                'interfaces':
                interfaces,
                'host':
                instance_node,
                'is_ephemeral':
                is_ephemeral,
                'volumes':
                volumes,
                'user_id':
                instance.user_id,
                'server_group':
                server_group,
                'config_drive':
                config_drive is not None,
            },
            'ephemeral': ephemeral_path,
            'diff': diff,
            'meta': {
                'old_id': instance.id
            },
        }

        return inst