I installed ubuntu 13.10 with vagrant and tested it on it.
sudo apt-get install libsqlite3-dev
sudo apt-get install sqlite3 # for the command-line client
sudo apt-get install bzip2 libbz2-dev
wget http://python.org/ftp/python/3.3.3/Python-3.3.3.tar.bz2
tar jxf Python-3.3.3.tar.bz2
./configure --prefix=/opt/python3.3
make
sudo make install
sudo ln -s /opt/python3.3/bin/python3.3 /usr/bin/python
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
sudo python3.3 ez_setup.py
sudo easy_install pip
sudo apt-get -y install lxc
sudo apt-get -y install lxctl
sudo python3
import lxc
c=lxc.Container("C")
c.create("ubuntu")
#If successful, you will get a message like this at the end.
#If you make a mistake while installing the module, you can start over from create and it will succeed.
Processing triggers for ureadahead ...
Can not write log, openpty() failed (/dev/pts not mounted?)
Setting up libdrm2:i386 (2.4.46-1ubuntu1) ...
Setting up libprocps0:i386 (1:3.3.3-2ubuntu9) ...
Setting up libudev1:i386 (204-0ubuntu19) ...
Setting up udev (204-0ubuntu19) ...
invoke-rc.d: policy-rc.d denied execution of restart.
Removing 'diversion of /bin/udevadm to /bin/udevadm.upgrade by fake-udev'
update-initramfs: deferring update (trigger activated)
Setting up initramfs-tools-bin (0.103ubuntu1.1) ...
Setting up initramfs-tools (0.103ubuntu1.1) ...
update-initramfs: deferring update (trigger activated)
Setting up procps (1:3.3.3-2ubuntu9) ...
invoke-rc.d: policy-rc.d denied execution of start.
Setting up openssh-client (1:6.2p2-6ubuntu0.1) ...
Setting up openssh-server (1:6.2p2-6ubuntu0.1) ...
invoke-rc.d: policy-rc.d denied execution of restart.
Setting up ssh (1:6.2p2-6ubuntu0.1) ...
Processing triggers for libc-bin ...
Processing triggers for initramfs-tools ...
Download complete
Copy /var/cache/lxc/saucy/rootfs-i386 to /usr/lib/i386-linux-gnu/lxc ...
Copying rootfs to /usr/lib/i386-linux-gnu/lxc ...
Generating locales...
en_US.UTF-8... up-to-date
Generation complete.
Creating SSH2 RSA key; this may take some time ...
Creating SSH2 DSA key; this may take some time ...
Creating SSH2 ECDSA key; this may take some time ...
invoke-rc.d: policy-rc.d denied execution of start.
##
# The default user is 'ubuntu' with password 'ubuntu'!
# Use the 'sudo' command to run tasks as root in the container.
##
#Start the container
c.start()
#Location of configuration files
c.config_file_name
'/var/lib/lxc/C/config'
#List of containers
lxc.list_containers()
['C']
#Write settings
c.append_config_item("lxc.network.ipv4", "192.168.1.10/24")
c.append_config_item("lxc.network.ipv4.gateway", "192.168.1.1")
c.save_config()
#IP address confirmation
c.get_ips()
#Attach to the console.
c.console()
A login shell like this will be launched.
Ubuntu 13.10 C tty1
C login:
Password:
The username and password is ubuntu. Ctrl-a q returns to the python interpreter.
Below is the continuation of the interpreter.
#Create a clone.
clone = lxc.Container("CLONE_NAME")
clone.clone(c)
clone.start()
clone.stop()
clone.destroy()
#Discard and exit
c.destroy()
A little more detailed sample can be found here, so please refer to it. https://github.com/lxc/lxc/blob/master/src/python-lxc/examples/api_test.py
Recommended Posts