diff options
| author | Pádraig Brady <pbrady@redhat.com> | 2013-01-29 11:07:42 +0000 |
|---|---|---|
| committer | Pádraig Brady <pbrady@redhat.com> | 2013-02-04 12:35:56 +0000 |
| commit | ca7143cf2d81d7bdca55838d893dc33dbc953089 (patch) | |
| tree | 1cdeb05fdf7920ef7e34059999e84f6d9233e2e7 | |
| parent | 7d585b2cdc5f593b293c9e3b150ebf68e547b094 (diff) | |
| download | nova-ca7143cf2d81d7bdca55838d893dc33dbc953089.tar.gz nova-ca7143cf2d81d7bdca55838d893dc33dbc953089.tar.xz nova-ca7143cf2d81d7bdca55838d893dc33dbc953089.zip | |
separate libvirt injection and configdrive config variables
This is mostly a refactoring so that if config drive is required,
variable lookup only needed for the injection case, is avoided.
There is a functional change here to make 'admin_pass' consistent
with the other variables in that the libvirt_inject_password flag
now does _not_ control whether the admin password is placed
in the config drive.
Change-Id: Ib79971aa050e56e5aa72fdd69aadd7539b2bd315
| -rw-r--r-- | nova/virt/libvirt/driver.py | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index bd2f51e69..0607e2df9 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -1491,28 +1491,6 @@ class LibvirtDriver(driver.ComputeDriver): size=size, swap_mb=swap_mb) - # target partition for file injection - target_partition = None - if not instance['kernel_id']: - target_partition = CONF.libvirt_inject_partition - if target_partition == 0: - target_partition = None - if CONF.libvirt_type == 'lxc': - target_partition = None - - if CONF.libvirt_inject_key and instance['key_data']: - key = str(instance['key_data']) - else: - key = None - - # File injection - metadata = instance.get('metadata') - - if not CONF.libvirt_inject_password: - admin_pass = None - - net = netutils.get_injected_network_template(network_info) - # Config drive if configdrive.required_by(instance): LOG.info(_('Using config drive'), instance=instance) @@ -1534,26 +1512,48 @@ class LibvirtDriver(driver.ComputeDriver): e, instance=instance) raise - elif any((key, net, metadata, admin_pass, files)): - # If we're not using config_drive, inject into root fs - injection_path = image('disk').path - img_id = instance['image_ref'] + # File injection + else: + target_partition = None + if not instance['kernel_id']: + target_partition = CONF.libvirt_inject_partition + if target_partition == 0: + target_partition = None + if CONF.libvirt_type == 'lxc': + target_partition = None + + if CONF.libvirt_inject_key and instance['key_data']: + key = str(instance['key_data']) + else: + key = None - for inject in ('key', 'net', 'metadata', 'admin_pass', 'files'): - if locals()[inject]: - LOG.info(_('Injecting %(inject)s into image' - ' %(img_id)s'), locals(), instance=instance) - try: - disk.inject_data(injection_path, - key, net, metadata, admin_pass, files, - partition=target_partition, - use_cow=CONF.use_cow_images, - mandatory=('files',)) - except Exception as e: - LOG.error(_('Error injecting data into image ' - '%(img_id)s (%(e)s)') % locals(), - instance=instance) - raise + net = netutils.get_injected_network_template(network_info) + + metadata = instance.get('metadata') + + if not CONF.libvirt_inject_password: + admin_pass = None + + if any((key, net, metadata, admin_pass, files)): + # If we're not using config_drive, inject into root fs + injection_path = image('disk').path + img_id = instance['image_ref'] + + for inj in ('key', 'net', 'metadata', 'admin_pass', 'files'): + if locals()[inj]: + LOG.info(_('Injecting %(inj)s into image ' + '%(img_id)s'), locals(), instance=instance) + try: + disk.inject_data(injection_path, + key, net, metadata, admin_pass, files, + partition=target_partition, + use_cow=CONF.use_cow_images, + mandatory=('files',)) + except Exception as e: + LOG.error(_('Error injecting data into image ' + '%(img_id)s (%(e)s)') % locals(), + instance=instance) + raise if CONF.libvirt_type == 'uml': libvirt_utils.chown(image('disk').path, 'root') |
