Esempio n. 1
0
def default_device_names(virt_type, instance, root_device_name,
                         update_func, ephemerals, swap, block_device_mapping):

    block_device_info = {
        'root_device_name': root_device_name,
        'swap': driver_block_device.get_swap(
            driver_block_device.convert_swap(swap)),
        'ephemerals': driver_block_device.convert_ephemerals(ephemerals),
        'block_device_mapping': (
            driver_block_device.convert_volumes(
                block_device_mapping) +
            driver_block_device.convert_snapshots(
                block_device_mapping))
    }

    devices = dict((bdm.get('id'), bdm) for bdm in
        itertools.chain(ephemerals, swap, block_device_mapping))

    get_disk_info(virt_type, instance, block_device_info)

    for driver_bdm in itertools.chain(block_device_info['ephemerals'],
                               [block_device_info['swap']] if
                               block_device_info['swap'] else [],
                               block_device_info['block_device_mapping']):
        if driver_bdm.id in devices:
            bdm = devices[driver_bdm.id]
            # NOTE (ndipanov): We may have chosen different values
            # for bus and type so update those along with device name
            bdm['device_name'] = get_device_name(driver_bdm)
            bdm['disk_bus'] = driver_bdm['disk_bus']
            # Swap does not have device type in driver format
            bdm['device_type'] = driver_bdm.get('device_type', 'disk')
            if update_func:
                update_func(bdm)
Esempio n. 2
0
def default_device_names(virt_type, context, instance, root_device_name,
                         ephemerals, swap, block_device_mapping,
                         image_meta):

    block_device_info = {
        'root_device_name': root_device_name,
        'swap': driver_block_device.get_swap(
            driver_block_device.convert_swap(swap)),
        'ephemerals': driver_block_device.convert_ephemerals(ephemerals),
        'block_device_mapping': (
            driver_block_device.convert_volumes(
                block_device_mapping) +
            driver_block_device.convert_snapshots(
                block_device_mapping) +
            driver_block_device.convert_blanks(
                block_device_mapping))
    }

    get_disk_info(virt_type, instance, image_meta, block_device_info)

    for driver_bdm in itertools.chain(block_device_info['ephemerals'],
                               [block_device_info['swap']] if
                               block_device_info['swap'] else [],
                               block_device_info['block_device_mapping']):
        driver_bdm.save()
Esempio n. 3
0
def default_device_names(virt_type, context, instance, root_device_name, ephemerals, swap, block_device_mapping):

    block_device_info = {
        "root_device_name": root_device_name,
        "swap": driver_block_device.get_swap(driver_block_device.convert_swap(swap)),
        "ephemerals": driver_block_device.convert_ephemerals(ephemerals),
        "block_device_mapping": (
            driver_block_device.convert_volumes(block_device_mapping)
            + driver_block_device.convert_snapshots(block_device_mapping)
        ),
    }

    get_disk_info(virt_type, instance, block_device_info)

    for driver_bdm in itertools.chain(
        block_device_info["ephemerals"],
        [block_device_info["swap"]] if block_device_info["swap"] else [],
        block_device_info["block_device_mapping"],
    ):
        driver_bdm.save(context)
Esempio n. 4
0
def default_device_names(virt_type, context, instance, root_device_name,
                         ephemerals, swap, block_device_mapping):

    block_device_info = {
        'root_device_name':
        root_device_name,
        'swap':
        driver_block_device.get_swap(driver_block_device.convert_swap(swap)),
        'ephemerals':
        driver_block_device.convert_ephemerals(ephemerals),
        'block_device_mapping':
        (driver_block_device.convert_volumes(block_device_mapping) +
         driver_block_device.convert_snapshots(block_device_mapping) +
         driver_block_device.convert_blanks(block_device_mapping))
    }

    get_disk_info(virt_type, instance, block_device_info)

    for driver_bdm in itertools.chain(
            block_device_info['ephemerals'],
        [block_device_info['swap']] if block_device_info['swap'] else [],
            block_device_info['block_device_mapping']):
        driver_bdm.save(context)
Esempio n. 5
0
    def _list_running_instances(self, context, all_instances):
        """List running instances (on all compute nodes).

        This method returns a dictionary with the following keys:
            - used_images
            - instance_names
            - used_swap_images
            - used_ephemeral_images
        """
        used_images = {}
        instance_names = set()
        used_swap_images = set()
        used_ephemeral_images = set()
        instance_bdms = objects.BlockDeviceMappingList.bdms_by_instance_uuid(
            context, [instance.uuid for instance in all_instances])

        for instance in all_instances:
            # NOTE(mikal): "instance name" here means "the name of a directory
            # which might contain an instance" and therefore needs to include
            # historical permutations as well as the current one.
            instance_names.add(instance.name)
            instance_names.add(instance.uuid)
            if (instance.task_state in self.resize_states
                    or instance.vm_state == vm_states.RESIZED):
                instance_names.add(instance.name + '_resize')
                instance_names.add(instance.uuid + '_resize')

            for image_key in ['image_ref', 'kernel_id', 'ramdisk_id']:
                image_ref_str = getattr(instance, image_key)
                if image_ref_str is None:
                    continue
                local, remote, insts = used_images.get(image_ref_str,
                                                       (0, 0, []))
                if instance.host == CONF.host:
                    local += 1
                else:
                    remote += 1
                insts.append(instance.name)
                used_images[image_ref_str] = (local, remote, insts)

            bdms = instance_bdms.get(instance.uuid)
            if bdms:
                swap = driver_block_device.convert_swap(bdms)
                if swap:
                    swap_image = 'swap_' + str(swap[0]['swap_size'])
                    used_swap_images.add(swap_image)
                ephemeral = driver_block_device.convert_ephemerals(bdms)
                if ephemeral:
                    os_type = nova.privsep.fs.get_fs_type_for_os_type(
                        instance.os_type)
                    file_name = nova.privsep.fs.get_file_extension_for_os_type(
                        os_type, CONF.default_ephemeral_format)
                    ephemeral_gb = str(ephemeral[0]['size'])
                    ephemeral_image = "ephemeral_%s_%s" % (ephemeral_gb,
                                                           file_name)
                    used_ephemeral_images.add(ephemeral_image)

        return {
            'used_images': used_images,
            'instance_names': instance_names,
            'used_swap_images': used_swap_images,
            'used_ephemeral_images': used_ephemeral_images
        }