Control Linux Containers via Salt
depends: | lxc package for distribution |
---|
lxc >= 1.0 (even beta alpha) is required
Return True if the named container can be attached to via the lxc-attach command
CLI Example:
salt 'minion' lxc.attachable ubuntu
Install and configure salt in a container.
salt 'minion' lxc.bootstrap name [config=config_data] \
[approve_key=(True|False)] [install=(True|False)]
CLI Example:
salt '*' lxc.bootstrap ubuntu
Create a new container.
CLI Example:
salt 'minion' lxc.clone name orig [snapshot=(True|False)] \
[size=filesystem_size] [vgname=volume_group] \
[profile=profile_name]
CLI Example:
salt '*' lxc.clone myclone ubuntu "snapshot=True"
Thin wrapper to lxc.init to be used from the saltcloud lxc driver
CLI Example:
salt '*' lxc.cloud_init foo
Interface between salt.cloud.lxc driver and lxc.init vm_ is a mapping of vm opts in the salt.cloud format as documented for the lxc driver.
This can be used either:
CLI Example:
salt '*' lxc.cloud_init_interface foo
additionnal ips which will be wired on the main bridge (br0) which is connected to internet. Be aware that you may use manual virtual mac addresses providen by you provider (online, ovh, etc). This is a list of mappings {ip: '', mac: '',netmask:''} Set gateway to None and an interface with a gateway to escape from another interface that eth0. eg:
- {'mac': '00:16:3e:01:29:40',
'gateway': None, (default)
'link': 'br0', (default)
'netmask': '', (default)
'ip': '22.1.4.25'}
Copy a file or directory from the host into a container
CLI Example:
salt 'minion' lxc.cp /tmp/foo /root/foo
Create a new container.
CLI Example:
salt 'minion' lxc.create name [config=config_file] \
[profile=profile] [template=template_name] \
[backing=backing_store] [vgname=volume_group] \
[size=filesystem_size] [options=template_options]
Destroy the named container. WARNING: Destroys all data associated with the container.
CLI Example:
salt '*' lxc.destroy name [stop=(True|False)]
Edit an LXC configuration file. If a setting is already present inside the file, its value will be replaced. If it does not exist, it will be appended to the end of the file. Comments and blank lines will be kept in-tact if they already exist in the file.
After the file is edited, its contents will be returned. By default, it will be returned in simple format, meaning an unordered dict (which may not represent the actual file order). Passing in an out_format of commented will return a data structure which accurately represents the order and content of the file.
CLI Examples:
salt 'minion' lxc.edit_conf /etc/lxc/mycontainer.conf out_format=commented lxc.network.type=veth
Returns whether the named container exists.
CLI Example:
salt '*' lxc.exists name
Freeze the named container.
CLI Example:
salt '*' lxc.freeze name
If the needed base does not exist, then create it, if it does exist create nothing and return the name of the base lxc container so it can be cloned.
CLI Example:
salt 'minion' lxc.init name [cpuset=cgroups_cpuset] \
[nic=nic_profile] [profile=lxc_profile] \
[nic_opts=nic_opts] [image=network image path]\
[seed=(True|False)] [install=(True|False)] \
[config=minion_config]
Returns the value of a cgroup parameter for a container.
CLI Example:
salt '*' lxc.get_parameter name parameter
Returns information about a container.
CLI Example:
salt '*' lxc.info name
Initialize a new container.
This is a partial idempotent function as if it is already provisioned, we will reset a bit the lxc configuration file but much of the hard work will be escaped as markers will prevent re-execution of harmful tasks.
CLI Example:
salt 'minion' lxc.init name [cpuset=cgroups_cpuset] \
[cpushare=cgroups_cpushare] [memory=cgroups_memory] \
[nic=nic_profile] [profile=lxc_profile] \
[nic_opts=nic_opts] [start=(True|False)] \
[seed=(True|False)] [install=(True|False)] \
[config=minion_config] [approve_key=(True|False) \
[clone=original] [autostart=True] \
[priv_key=/path_or_content] [pub_key=/path_or_content] \
[bridge=lxcbr0] [gateway=10.0.3.1] \
[dnsservers[dns1,dns2]] \
[users=[foo]] password='secret'
Extra options for network interfaces. E.g:
{"eth0": {"mac": "aa:bb:cc:dd:ee:ff", "ipv4": "10.1.1.1", "ipv6": "2001:db8::ff00:42:8329"}}
or
{"eth0": {"mac": "aa:bb:cc:dd:ee:ff", "ipv4": "10.1.1.1/24", "ipv6": "2001:db8::ff00:42:8329"}}
List defined containers classified by status. Status can be running, stopped, and frozen.
- extra
Also get per container specific info at once. Warning: it will not return a collection of list but a collection of mappings by status and then per container name:
{'running': ['foo']} # normal mode {'running': {'foo': {'info1': 'bar'}} # extra mode
CLI Example:
salt '*' lxc.list
salt '*' lxc.list extra=True
Return just a list of the containers available
CLI Example:
salt '*' lxc.ls
Read in an LXC configuration file. By default returns a simple, unsorted dict, but can also return a more detailed structure including blank lines and comments.
CLI Examples:
salt 'minion' lxc.read_conf /etc/lxc/mycontainer.conf
salt 'minion' lxc.read_conf /etc/lxc/mycontainer.conf out_format=commented
Run a command inside the container.
CLI Example:
salt 'minion' name command [no_start=(True|False)] \
[preserve_state=(True|False)] [stdout=(True|False)] \
[stderr=(True|False)]
Note
If stderr and stdout are both False, the return code is returned. If stderr and stdout are both True, the pid and return code are also returned.
Update container DNS configuration and possibly also resolv.conf one.
CLI Example:
salt-call -lall lxc.set_dns ubuntu ['8.8.8.8', '4.4.4.4']
Set the value of a cgroup parameter for a container.
CLI Example:
salt '*' lxc.set_parameter name parameter value
Set the password of one or more system users inside containers
CLI Example:
salt '*' lxc.set_pass container-name root foo
Start the named container.
CLI Example:
salt '*' lxc.start name
Returns the state of a container.
CLI Example:
salt '*' lxc.state name
Stop the named container.
CLI Example:
salt '*' lxc.stop name
Returns a list of existing templates
CLI Example:
salt '*' lxc.templates
Unfreeze the named container.
CLI Example:
salt '*' lxc.unfreeze name
Edit LXC configuration options
CLI Example:
salt-call -lall lxc.update_lxc_conf ubuntu lxc_conf="[{'network.ipv4.ip':'10.0.3.5'}]" lxc_conf_unset="['lxc.utsname']"
Write out an LXC configuration file
This is normally only used internally. The format of the data structure must match that which is returned from lxc.read_conf(), with out_format set to commented.
An example might look like:
[
{'lxc.utsname': '$CONTAINER_NAME'},
'# This is a commented line\n',
'\n',
{'lxc.mount': '$CONTAINER_FSTAB'},
{'lxc.rootfs': {'comment': 'This is another test',
'value': 'This is another test'}},
'\n',
{'lxc.network.type': 'veth'},
{'lxc.network.flags': 'up'},
{'lxc.network.link': 'br0'},
{'lxc.network.hwaddr': '$CONTAINER_MACADDR'},
{'lxc.network.ipv4': '$CONTAINER_IPADDR'},
{'lxc.network.name': '$CONTAINER_DEVICENAME'},
]
CLI Examples:
salt 'minion' lxc.write_conf /etc/lxc/mycontainer.conf \
out_format=commented
Docs for previous releases are available on salt.rtfd.org.
Latest Salt release: 2014.7.2
22.16.104. salt.modules.mac_group
Upcoming SaltStack events, webinars and local meet ups and user groups.