Merge "Refactor: config drive related functions"

This commit is contained in:
Jenkins
2012-10-24 20:45:06 +00:00
committed by Gerrit Code Review
2 changed files with 17 additions and 17 deletions
+14
View File
@@ -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')
+3 -17
View File
@@ -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"