Exemple #1
0
    def test_returns_correct_ip_if_available(self, get_ips_mock):
        ext_cidr = ["10.0.0.0/24"]
        init_host = "controller"
        compute_host = "compute"
        user = "******"
        expected = "10.0.0.100"

        get_ips_mock.return_value = [expected, "1.2.3.4", "5.6.7.8"]

        ip = node_ip.get_ext_ip(ext_cidr, init_host, compute_host, user)

        self.assertEqual(expected, ip)
Exemple #2
0
    def test_falls_back_to_node_ip(self, get_ips_mock, socket_mock):
        ext_cidr = ["10.0.0.0/24"]
        init_host = "controller"
        compute_host = "compute"
        user = "******"
        expected = "192.168.1.3"

        get_ips_mock.return_value = []
        socket_mock.gethostbyname.return_value = expected

        ip = node_ip.get_ext_ip(ext_cidr, init_host, compute_host, user)

        self.assertEqual(expected, ip)
Exemple #3
0
    def convert_instance(self, instance, cfg, cloud):
        identity_res = cloud.resources[utils.IDENTITY_RESOURCE]
        compute_res = cloud.resources[utils.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))]

        ssh_user = cfg.cloud.ssh_user

        ext_cidr = cfg.cloud.ext_cidr
        host = node_ip.get_ext_ip(ext_cidr, cfg.cloud.ssh_host, instance_node,
                                  ssh_user)

        if not utils.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 = utils.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'] = utils.get_disk_path(
                instance, instance_block_info, disk=DISK + LOCAL)

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

        if instance.image:
            diff['path_src'] = utils.get_disk_path(instance,
                                                   instance_block_info)
        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 = utils.get_disk_path(instance,
                                           instance_block_info,
                                           disk=utils.DISK_CONFIG)
        inst = {
            'instance': {
                'name':
                instance.name,
                'instance_name':
                instance_name,
                'id':
                instance.id,
                'tenant_id':
                instance.tenant_id,
                'tenant_name':
                self.tenant_name_map.map(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': (utils.BOOT_FROM_IMAGE
                              if instance.image else utils.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
Exemple #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

        ssh_user = cfg.cloud.ssh_user

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

        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