diff options
| author | Mate Lakat <mate.lakat@citrix.com> | 2012-10-24 18:55:49 +0100 |
|---|---|---|
| committer | Mate Lakat <mate.lakat@citrix.com> | 2012-10-24 18:55:49 +0100 |
| commit | ccb9e3f00f2df34273b8e7698b663fd719391ae9 (patch) | |
| tree | 67e8c83bb3da65c84052e2ef46a5d6ee66c976de | |
| parent | a6297a1b93525a93e9f401511c9630b065005b86 (diff) | |
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
| -rw-r--r-- | nova/virt/configdrive.py | 14 | ||||
| -rw-r--r-- | 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" |
