Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
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