fabtools.openvz

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.

Manage templates

fabtools.openvz.download_template(name=None, url=None)

Download an OpenVZ template.

Example:

from fabtools.openvz import download_template

# 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)

Check if the container exists.

fabtools.openvz.create(ctid, ostemplate=None, config=None, private=None, root=None, ipadd=None, hostname=None, **kwargs)

Create an OpenVZ container.

fabtools.openvz.set(ctid_or_name, save=True, **kwargs)

Set container parameters.

fabtools.openvz.status(ctid_or_name)

Get the status of the container.

fabtools.openvz.start(ctid_or_name, wait=False, force=False, **kwargs)

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)

Stop the container.

fabtools.openvz.restart(ctid_or_name, wait=True, force=False, fast=False, **kwargs)

Restart the container.

fabtools.openvz.destroy(ctid_or_name)

Destroy the container.

Run commands inside a container

fabtools.openvz.exec2(ctid_or_name, command)

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)

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.