From ccb9e3f00f2df34273b8e7698b663fd719391ae9 Mon Sep 17 00:00:00 2001 From: Mate Lakat Date: Wed, 24 Oct 2012 18:55:49 +0100 Subject: Refactor: config drive related functions Related to blueprint xenapi-config-drive Move the configdrive related functions to the nova.virt.configdrive module, so that it could be used by other drivers as well. Also move the configdrive related configuration options to the same module. Change-Id: Ib97ab907ac820e616017f770c2f3a8366af57a0f --- nova/virt/configdrive.py | 14 ++++++++++++++ nova/virt/libvirt/driver.py | 20 +++----------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/nova/virt/configdrive.py b/nova/virt/configdrive.py index 7ae97f2ec..86ef13ed0 100644 --- a/nova/virt/configdrive.py +++ b/nova/virt/configdrive.py @@ -38,6 +38,12 @@ configdrive_opts = [ default=tempfile.tempdir, help=('Where to put temporary files associated with ' 'config drive creation')), + # force_config_drive is a string option, to allow for future behaviors + # (e.g. use config_drive based on image properties) + cfg.StrOpt('force_config_drive', + default=None, + help='Set to force injection to take place on a config drive ' + '(if set, valid options are: always)'), ] FLAGS = flags.FLAGS @@ -142,3 +148,11 @@ class ConfigDriveBuilder(object): shutil.rmtree(self.tempdir) except OSError, e: LOG.error(_('Could not remove tmpdir: %s'), str(e)) + + +def required_by(instance): + return instance.get('config_drive') or FLAGS.force_config_drive + + +def enabled_for(instance): + return required_by(instance) or instance.get('config_drive_id') diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 049203539..fd241c38d 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -165,12 +165,6 @@ libvirt_opts = [ default=True, help='Use a separated OS thread pool to realize non-blocking' ' libvirt calls'), - # force_config_drive is a string option, to allow for future behaviors - # (e.g. use config_drive based on image properties) - cfg.StrOpt('force_config_drive', - default=None, - help='Set to force injection to take place on a config drive ' - '(if set, valid options are: always)'), cfg.StrOpt('libvirt_cpu_mode', default=None, help='Set to "host-model" to clone the host CPU feature flags; ' @@ -1250,13 +1244,6 @@ class LibvirtDriver(driver.ComputeDriver): if not suffix: suffix = '' - # Are we using a config drive? - using_config_drive = False - if (instance.get('config_drive') or - FLAGS.force_config_drive): - LOG.info(_('Using config drive'), instance=instance) - using_config_drive = True - # syntactic nicety def basepath(fname='', suffix=suffix): return os.path.join(FLAGS.instances_path, @@ -1398,7 +1385,8 @@ class LibvirtDriver(driver.ComputeDriver): net = netutils.get_injected_network_template(network_info) # Config drive - if using_config_drive: + if configdrive.required_by(instance): + LOG.info(_('Using config drive'), instance=instance) extra_md = {} if admin_pass: extra_md['admin_pass'] = admin_pass @@ -1657,9 +1645,7 @@ class LibvirtDriver(driver.ComputeDriver): mount_device) devices.append(cfg) - if (instance.get('config_drive') or - instance.get('config_drive_id') or - FLAGS.force_config_drive): + if configdrive.enabled_for(instance): diskconfig = config.LibvirtConfigGuestDisk() diskconfig.source_type = "file" diskconfig.driver_format = "raw" -- cgit