api_test.py revision 4e31246a25d29db0c554ae2f6b34fc19b8fcdefd
#
# api_test.py: Test/demo of the python3-lxc API
#
# (C) Copyright Canonical Ltd. 2012
#
# Authors:
# Stéphane Graber <stgraber@ubuntu.com>
#
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
# USA
#
import lxc
import uuid
import os
import subprocess
import sys
import time
# Let's pick a random name, avoiding clashes
## Instantiate the container instance
print("Getting instance for '%s'" % CONTAINER_NAME)
# A few basic checks of the current state
# Try to get the host architecture for dpkg systems
arch = "i386"
try:
except:
pass
## Create a rootfs
print("Creating rootfs using 'download', arch=%s" % arch)
{"dist": "ubuntu",
"release": "trusty",
"arch": arch})
## Test the config
print("Testing the configuration")
# A few basic checks of the current state
## Test the networking
print("Testing the networking")
# A few basic checks of the current state
## Starting the container
print("Starting the container")
# A few basic checks of the current state
## Checking IP address
print("Getting the interface names")
## Checking IP address
print("Getting the IP addresses")
count = 0
ips = []
count += 1
+ lxc.CLONE_NEWUTS))
else:
# A few basic checks of the current state
## Test running config
## Testing cgroups a bit
print("Testing cgroup API")
## Freezing the container
print("Freezing the container")
# A few basic checks of the current state
## Unfreezing the container
print("Unfreezing the container")
# A few basic checks of the current state
## Attaching to tty1
print("Attaching to tty1")
## Shutting down the container
print("Shutting down the container")
print("Stopping the container")
# A few basic checks of the current state
## Snapshotting the container
print("Snapshotting the container")
assert(not container.snapshot_list())
## Cloning the container
print("Cloning the container as '%s'" % CLONE_NAME)
print ("Renaming the clone to '%s'" % RENAME_NAME)
## Destroy the container
print("Destroying the container")