Merge pull request #28610 from pass-by-value/lxc_config_additions

Lxc config additions
This commit is contained in:
Mike Place 2015-11-05 11:43:05 -07:00
commit 35dbca24e7
4 changed files with 75 additions and 5 deletions

View file

@ -191,3 +191,53 @@ Driver Support
- Container creation
- Image listing (LXC templates)
- Running container information (IP addresses, etc.)
Systemd Check
-------------
.. versionadded:: 2015.8.2
Some container templates might not have systemd installed resulting in errors during
container creation time. To prevent this please set the ``uses_systemd`` option to ``False``.
Option `uses_systemd` defaults to `True`.
.. code-block:: yaml
ubuntu-lxc:
provider: dev-lxc
lxc_profile:
template: download
options:
release: trusty
arch: amd64
image: ubuntu
script_args: -P
uses_systemd: False
network_profile: ubuntu
minion:
master: localhost
Bootstrap Delay
---------------
.. versionchanged:: 2015.8.0
The ``bootstrap_delay`` config option lets you specify the time to wait (in seconds) between container creation
and salt bootstrap execution. It is useful to ensure that all essential services have started before the
bootstrap script is executed. By default there's no wait time between container creation and bootstrap.
.. code-block:: yaml
ubuntu-lxc:
provider: dev-lxc
lxc_profile:
template: download
options:
release: trusty
arch: amd64
image: ubuntu
script_args: -P
bootstrap_delay: 62
network_profile: ubuntu
minion:
master: localhost

View file

@ -750,6 +750,12 @@ VALID_OPTS = {
# HTTP request max file content size.
'http_max_body': int,
# Delay in seconds before executing bootstrap (salt cloud)
'bootstrap_delay': int,
# Does this lxc template have systemd installed?
'uses_systemd': bool,
}
# default configurations
@ -1220,6 +1226,8 @@ CLOUD_CONFIG_DEFAULTS = {
'log_fmt_console': _DFLT_LOG_FMT_CONSOLE,
'log_fmt_logfile': _DFLT_LOG_FMT_LOGFILE,
'log_granular_levels': {},
'bootstrap_delay': None,
'uses_systemd': True,
}
DEFAULT_API_OPTS = {

View file

@ -1142,6 +1142,7 @@ def init(name,
bootstrap_args=None,
bootstrap_shell=None,
bootstrap_url=None,
uses_systemd=True,
**kwargs):
'''
Initialize a new container.
@ -1295,6 +1296,9 @@ def init(name,
unconditional_install
Run the script even if the container seems seeded
uses_systemd
Set to true if the lxc template has systemd installed
CLI Example:
.. code-block:: bash
@ -1615,7 +1619,8 @@ def init(name,
bootstrap_delay=bootstrap_delay,
bootstrap_url=bootstrap_url,
bootstrap_shell=bootstrap_shell,
bootstrap_args=bootstrap_args)
bootstrap_args=bootstrap_args,
uses_systemd=uses_systemd)
except (SaltInvocationError, CommandExecutionError) as exc:
ret['comment'] = 'Bootstrap failed: ' + exc.strerror
ret['result'] = False
@ -3319,7 +3324,7 @@ def test_bare_started_state(name, path=None):
return ret
def wait_started(name, path=None, timeout=300):
def wait_started(name, path=None, timeout=300, uses_systemd=True):
'''
Check that the system has fully inited
@ -3347,7 +3352,7 @@ def wait_started(name, path=None, timeout=300):
raise CommandExecutionError(
'Container {0} is not running'.format(name))
ret = False
if running_systemd(name, path=path):
if uses_systemd and running_systemd(name, path=path):
test_started = test_sd_started_state
logger = log.error
else:
@ -3403,7 +3408,8 @@ def bootstrap(name,
path=None,
bootstrap_delay=None,
bootstrap_args=None,
bootstrap_shell=None):
bootstrap_shell=None,
uses_systemd=True):
'''
Install and configure salt in a container.
@ -3464,7 +3470,7 @@ def bootstrap(name,
[approve_key=(True|False)] [install=(True|False)]
'''
wait_started(name, path=path)
wait_started(name, path=path, uses_systemd=uses_systemd)
if bootstrap_delay is not None:
try:
time.sleep(bootstrap_delay)

View file

@ -312,6 +312,11 @@ def init(names, host=None, saltcloud_mode=False, quiet=False, **kwargs):
if saltcloud_mode:
kw = copy.deepcopy(kw)
kw['name'] = name
saved_kwargs = {}
if 'bootstrap_delay' in kw:
saved_kwargs['bootstrap_delay'] = kw['bootstrap_delay']
if 'uses_systemd' in kw:
saved_kwargs['uses_systemd'] = kw['uses_systemd']
kw = client.cmd(
host, 'lxc.cloud_init_interface', args + [kw],
expr_form='list', timeout=600).get(host, {})
@ -320,6 +325,7 @@ def init(names, host=None, saltcloud_mode=False, quiet=False, **kwargs):
kw['seed'] = seeds.get(name, seed_arg)
if not kw['seed']:
kw.pop('seed_cmd', '')
kw.update(saved_kwargs)
cmds.append(
(host,
name,