diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-10-24 20:45:06 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-10-24 20:45:06 +0000 |
| commit | 89ac7e332752acf13fccd8d557cabc2560d4e241 (patch) | |
| tree | fa76b10d8fbbbff8b10df4a8de4610d9d326f3e0 | |
| parent | 6581a6cdc92e540b1f5cb5bc52bb0b65138220cf (diff) | |
| parent | ccb9e3f00f2df34273b8e7698b663fd719391ae9 (diff) | |
| download | nova-89ac7e332752acf13fccd8d557cabc2560d4e241.tar.gz nova-89ac7e332752acf13fccd8d557cabc2560d4e241.tar.xz nova-89ac7e332752acf13fccd8d557cabc2560d4e241.zip | |
Merge "Refactor: config drive related functions"
| -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" |
