Ich habe Ubuntu 13.10 mit Vagrant installiert und darauf getestet.
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")
#Bei Erfolg erhalten Sie am Ende eine solche Nachricht.
#Wenn die Modulinstallation in der Mitte fehlschlägt, können Sie erfolgreich sein, indem Sie von vorne beginnen.
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.
##
#Starten Sie den Container
c.start()
#Speicherort der Konfigurationsdatei
c.config_file_name
'/var/lib/lxc/C/config'
#Liste der Container
lxc.list_containers()
['C']
#Einstellungen schreiben
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()
#Bestätigung der IP-Adresse
c.get_ips()
#An die Konsole anschließen.
c.console()
Eine solche Login-Shell wird gestartet.
Ubuntu 13.10 C tty1
C login:
Password:
Der Benutzername und das Passwort sind Ubuntu. Strg-a q kehrt zum Python-Interpreter zurück.
Unten ist die Fortsetzung des Dolmetschers.
#Erstellen Sie einen Klon.
clone = lxc.Container("CLONE_NAME")
clone.clone(c)
clone.start()
clone.stop()
clone.destroy()
#Verwerfen und beenden
c.destroy()
Ein etwas detaillierteres Beispiel finden Sie hier. Bitte beziehen Sie sich darauf. https://github.com/lxc/lxc/blob/master/src/python-lxc/examples/api_test.py
Recommended Posts