Exemplo n.º 1
0
    def test_get_swap(self):
        swap = [self.swap_driver_bdm]
        legacy_swap = [self.swap_legacy_driver_bdm]
        no_swap = [self.volume_driver_bdm]

        self.assertEqual(swap[0], driver_block_device.get_swap(swap))
        self.assertEqual(legacy_swap[0], driver_block_device.get_swap(legacy_swap))
        self.assertIsNone(driver_block_device.get_swap(no_swap))
        self.assertIsNone(driver_block_device.get_swap([]))
Exemplo n.º 2
0
    def test_get_swap(self):
        swap = [self.swap_driver_bdm]
        legacy_swap = [self.swap_legacy_driver_bdm]
        no_swap = [self.volume_driver_bdm]

        self.assertEqual(swap[0], driver_block_device.get_swap(swap))
        self.assertEqual(legacy_swap[0],
                         driver_block_device.get_swap(legacy_swap))
        self.assertIsNone(driver_block_device.get_swap(no_swap))
        self.assertIsNone(driver_block_device.get_swap([]))
Exemplo n.º 3
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)
Exemplo n.º 4
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()
Exemplo n.º 5
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(context)
Exemplo n.º 6
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)
Exemplo n.º 7
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)