OpenVZ containers

This module provides high-level tools for managing OpenVZ templates and containers.
Warning
The remote host needs a patched kernel with OpenVZ support.
See also
fabtools.require.openvz

Manage templates

fabtools.openvz.downloadtemplate(_name=None, url=None)[source]
Download an OpenVZ template.
Example:
from fabtools.openvz import downloadtemplate # Use custom OS template download_template(url=’http://example.com/templates/mybox.tar.gz‘)
If no _url
is provided, the OS template will be downloaded from the download.openvz.org repository:
from fabtools.openvz import download_template # Use OS template from http://download.openvz.org/template/precreated/ download_template(‘debian-6.0-x86_64’)

Manage containers

fabtools.openvz.exists(ctid_or_name)[source]
Check if the container exists.
fabtools.openvz.create(ctid, ostemplate=None, config=None, private=None, root=None, ipadd=None, hostname=None, _kwargs)[source]
Create an OpenVZ container.
fabtools.openvz.set(_ctid_or_name
, save=True, **kwargs)[source]
Set container parameters.
fabtools.openvz.status(ctid_or_name)[source]
Get the status of the container.
fabtools.openvz.start(ctid_or_name, wait=False, force=False, **kwargs)[source]
Start the container.
If wait is
True, wait until the container is up and running.
Warning
wait=True is broken with vzctl 3.0.24 on Debian 6.0 (squeeze)
fabtools.openvz.stop(ctid_or_name, fast=False, **kwargs)[source]
Stop the container.
fabtools.openvz.restart(ctid_or_name, wait=True, force=False, fast=False, **kwargs)[source]
Restart the container.
fabtools.openvz.destroy(ctid_or_name)**[source]
Destroy the container.

Run commands inside a container

fabtools.openvz.exec2(ctid_or_name, command)[source]
Run a command inside the container.
import fabtools res = fabtools.openvz.exec2(‘foo’, ‘hostname’)
Warning
the command will be run as root.
fabtools.openvz.guest(*args, _kwds_)[source]
Context manager to run commands inside a guest container.
Supported basic operations are: run, sudo and put.
Warning
commands executed with
run() will be run as root inside the container. Use sudo(command, user=’foo’)** to run them as an unpriviledged user.
Example:
from fabtools.openvz import guest with guest(‘foo’): run(‘hostname’) sudo(‘whoami’, user=’alice’) put(‘files/hello.txt’)

Container class

class_fabtools.openvz.container.Container(_ctid)[source]
Object-oriented interface to OpenVZ containers.
create(_kwargs)[source]
Create the container.
Extra args are passed to fabtools.openvz.create().
destroy()[source]
Destroy the container.
set(
kwargs_)[source]
Set container parameters.
Extra args are passed to fabtools.openvz.set().
start(_kwargs)[source]
Start the container.
Extra args are passed to fabtools.openvz.start().
stop(
kwargs_)[source]
Stop the container.
Extra args are passed to fabtools.openvz.stop().
restart(_kwargs)[source]
Restart the container.
Extra args are passed to fabtools.openvz.restart().
status()[source]
Get the container’s status.
running()[source]
Check if the container is running.
exists()[source]
Check if the container exists.
exec2(_command
)[source]
Run a command inside the container.
from fabtools.require.openvz import container with container(‘foo’) as ct: res = ct.exec2(‘hostname’)
Warning
the command will be run as
root**.