-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Chuck Short <[email protected]>
- Loading branch information
Chuck Short
committed
May 26, 2015
1 parent
8e6d9fc
commit 3d86295
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/python | ||
# | ||
# api_test.py: Test/demo of the python3-lxc API | ||
# | ||
# (C) Copyright Canonical Ltd. 2015 | ||
# | ||
# Authors: | ||
# Chuck Short <[email protected]> | ||
# | ||
# This library is free software; you can redistribute it and/or | ||
# 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 uuid | ||
import sys | ||
import subprocess | ||
import time | ||
|
||
# Let's pick a random name, avoiding clashes | ||
CONTAINER_NAME = str(uuid.uuid1()) | ||
|
||
from pylxd import api | ||
|
||
lxd = api.API() | ||
try: | ||
lxd.container_defined(CONTAINER_NAME) | ||
except Exception as e: | ||
print "Container doesnt exist: %s" % e | ||
|
||
config = {'name': CONTAINER_NAME, | ||
'source': {'type': 'none'}} | ||
lxd.container_init(config) | ||
if lxd.container_defined(CONTAINER_NAME): | ||
print "Container is running" | ||
else: | ||
print "Whoops!" | ||
containers = lxd.container_list() | ||
for x in containers: | ||
lxd.container_destroy(x) |