mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-07 05:41:40 +00:00
python: PEP8 compatibility
The new version of the pep8 command is detecting more indentation mistakes than it used to, this fixes them. Signed-off-by: Stéphane Graber <stgraber@ubuntu.com> Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
parent
f79d43bbe7
commit
bde1853954
@ -52,10 +52,11 @@ def randomMAC():
|
|||||||
return ':'.join(map(lambda x: "%02x" % x, mac))
|
return ':'.join(map(lambda x: "%02x" % x, mac))
|
||||||
|
|
||||||
# Begin parsing the command line
|
# Begin parsing the command line
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(description=_(
|
||||||
description=_("LXC: Start an ephemeral container"),
|
"LXC: Start an ephemeral container"),
|
||||||
formatter_class=argparse.RawTextHelpFormatter, epilog=_(
|
formatter_class=argparse.RawTextHelpFormatter,
|
||||||
"""If a COMMAND is given, then the container will run only as long
|
epilog=_("If a COMMAND is given, then the "
|
||||||
|
"""container will run only as long
|
||||||
as the command runs.
|
as the command runs.
|
||||||
If no COMMAND is given, this command will attach to tty1 and stop the
|
If no COMMAND is given, this command will attach to tty1 and stop the
|
||||||
container when exiting (with ctrl-a-q).
|
container when exiting (with ctrl-a-q).
|
||||||
@ -80,13 +81,15 @@ parser.add_argument("--daemon", "-d", action="store_true",
|
|||||||
|
|
||||||
parser.add_argument("--union-type", "-U", type=str, default="overlayfs",
|
parser.add_argument("--union-type", "-U", type=str, default="overlayfs",
|
||||||
choices=("overlayfs", "aufs"),
|
choices=("overlayfs", "aufs"),
|
||||||
help=_("type of union (overlayfs or aufs), defaults to overlayfs."))
|
help=_("type of union (overlayfs or aufs), "
|
||||||
|
"defaults to overlayfs."))
|
||||||
|
|
||||||
parser.add_argument("--keep-data", "-k", action="store_true",
|
parser.add_argument("--keep-data", "-k", action="store_true",
|
||||||
help=_("Use a persistent backend instead of tmpfs."))
|
help=_("Use a persistent backend instead of tmpfs."))
|
||||||
|
|
||||||
parser.add_argument("command", metavar='CMD', type=str, nargs="*",
|
parser.add_argument("command", metavar='CMD', type=str, nargs="*",
|
||||||
help=_("Run specific command in container (command as argument)"))
|
help=_("Run specific command in container "
|
||||||
|
"(command as argument)"))
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@ -152,8 +155,8 @@ if orig.get_config_item("lxc.mount"):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if "%s/rootfs/" % dest_path not in dest_mount:
|
if "%s/rootfs/" % dest_path not in dest_mount:
|
||||||
print(_(
|
print(_("Skipping mount entry '%s' as it's outside "
|
||||||
"Skipping mount entry '%s' as it's outside of the container rootfs.") % line)
|
"of the container rootfs.") % line)
|
||||||
|
|
||||||
overlay_dirs += [(fields[0], dest_mount)]
|
overlay_dirs += [(fields[0], dest_mount)]
|
||||||
|
|
||||||
@ -248,11 +251,9 @@ if args.daemon:
|
|||||||
|
|
||||||
You can enter it from the command line with: lxc-console -n %s
|
You can enter it from the command line with: lxc-console -n %s
|
||||||
The following IP addresses have be found in the container:
|
The following IP addresses have be found in the container:
|
||||||
%s""") % (
|
%s""") % (dest.name,
|
||||||
dest.name,
|
|
||||||
"\n".join([" - %s" % entry for entry in ips]
|
"\n".join([" - %s" % entry for entry in ips]
|
||||||
or [" - %s" % _("No address could be found")])
|
or [" - %s" % _("No address could be found")])))
|
||||||
))
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# Now deal with the case where we want to run a command in the container
|
# Now deal with the case where we want to run a command in the container
|
||||||
|
@ -44,17 +44,17 @@ container = lxc.Container(CONTAINER_NAME)
|
|||||||
# A few basic checks of the current state
|
# A few basic checks of the current state
|
||||||
assert(container.config_file_name == "%s/%s/config" %
|
assert(container.config_file_name == "%s/%s/config" %
|
||||||
(LXC_PATH_LIB, CONTAINER_NAME))
|
(LXC_PATH_LIB, CONTAINER_NAME))
|
||||||
assert(container.defined == False)
|
assert(not container.defined)
|
||||||
assert(container.init_pid == -1)
|
assert(container.init_pid == -1)
|
||||||
assert(container.name == CONTAINER_NAME)
|
assert(container.name == CONTAINER_NAME)
|
||||||
assert(container.running == False)
|
assert(not container.running)
|
||||||
assert(container.state == "STOPPED")
|
assert(container.state == "STOPPED")
|
||||||
|
|
||||||
## Create a rootfs
|
## Create a rootfs
|
||||||
print("Creating rootfs using '%s'" % LXC_TEMPLATE)
|
print("Creating rootfs using '%s'" % LXC_TEMPLATE)
|
||||||
container.create(LXC_TEMPLATE)
|
container.create(LXC_TEMPLATE)
|
||||||
|
|
||||||
assert(container.defined == True)
|
assert(container.defined)
|
||||||
assert(container.name == CONTAINER_NAME
|
assert(container.name == CONTAINER_NAME
|
||||||
== container.get_config_item("lxc.utsname"))
|
== container.get_config_item("lxc.utsname"))
|
||||||
assert(container.name in lxc.list_containers())
|
assert(container.name in lxc.list_containers())
|
||||||
@ -86,7 +86,7 @@ container.wait("RUNNING", 3)
|
|||||||
|
|
||||||
# A few basic checks of the current state
|
# A few basic checks of the current state
|
||||||
assert(container.init_pid > 1)
|
assert(container.init_pid > 1)
|
||||||
assert(container.running == True)
|
assert(container.running)
|
||||||
assert(container.state == "RUNNING")
|
assert(container.state == "RUNNING")
|
||||||
|
|
||||||
## Checking IP address
|
## Checking IP address
|
||||||
@ -104,7 +104,7 @@ container.wait("FROZEN", 3)
|
|||||||
|
|
||||||
# A few basic checks of the current state
|
# A few basic checks of the current state
|
||||||
assert(container.init_pid > 1)
|
assert(container.init_pid > 1)
|
||||||
assert(container.running == True)
|
assert(container.running)
|
||||||
assert(container.state == "FROZEN")
|
assert(container.state == "FROZEN")
|
||||||
|
|
||||||
## Unfreezing the container
|
## Unfreezing the container
|
||||||
@ -114,7 +114,7 @@ container.wait("RUNNING", 3)
|
|||||||
|
|
||||||
# A few basic checks of the current state
|
# A few basic checks of the current state
|
||||||
assert(container.init_pid > 1)
|
assert(container.init_pid > 1)
|
||||||
assert(container.running == True)
|
assert(container.running)
|
||||||
assert(container.state == "RUNNING")
|
assert(container.state == "RUNNING")
|
||||||
|
|
||||||
if len(sys.argv) > 1 and sys.argv[1] == "--with-console":
|
if len(sys.argv) > 1 and sys.argv[1] == "--with-console":
|
||||||
@ -133,7 +133,7 @@ if container.running:
|
|||||||
|
|
||||||
# A few basic checks of the current state
|
# A few basic checks of the current state
|
||||||
assert(container.init_pid == -1)
|
assert(container.init_pid == -1)
|
||||||
assert(container.running == False)
|
assert(not container.running)
|
||||||
assert(container.state == "STOPPED")
|
assert(container.state == "STOPPED")
|
||||||
|
|
||||||
## Cloning the container
|
## Cloning the container
|
||||||
@ -148,4 +148,4 @@ clone.destroy()
|
|||||||
print("Destroying the container")
|
print("Destroying the container")
|
||||||
container.destroy()
|
container.destroy()
|
||||||
|
|
||||||
assert(container.defined == False)
|
assert(not container.defined)
|
||||||
|
@ -272,8 +272,7 @@ class Container(_lxc.Container):
|
|||||||
if not source.defined:
|
if not source.defined:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if subprocess.call(
|
if subprocess.call(["lxc-clone", "-o", source.name, "-n", self.name],
|
||||||
["lxc-clone", "-o", source.name, "-n", self.name],
|
|
||||||
universal_newlines=True) != 0:
|
universal_newlines=True) != 0:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -288,8 +287,7 @@ class Container(_lxc.Container):
|
|||||||
if not self.running:
|
if not self.running:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if subprocess.call(
|
if subprocess.call(["lxc-console", "-n", self.name, "-t", "%s" % tty],
|
||||||
["lxc-console", "-n", self.name, "-t", "%s" % tty],
|
|
||||||
universal_newlines=True) != 0:
|
universal_newlines=True) != 0:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@ -339,7 +337,8 @@ class Container(_lxc.Container):
|
|||||||
ip6_cmd = base_cmd + ["-6", "addr", "show", "scope", "global"]
|
ip6_cmd = base_cmd + ["-6", "addr", "show", "scope", "global"]
|
||||||
if interface:
|
if interface:
|
||||||
ip = subprocess.Popen(ip6_cmd + ["dev", interface],
|
ip = subprocess.Popen(ip6_cmd + ["dev", interface],
|
||||||
stdout=subprocess.PIPE, universal_newlines=True)
|
stdout=subprocess.PIPE,
|
||||||
|
universal_newlines=True)
|
||||||
else:
|
else:
|
||||||
ip = subprocess.Popen(ip6_cmd, stdout=subprocess.PIPE,
|
ip = subprocess.Popen(ip6_cmd, stdout=subprocess.PIPE,
|
||||||
universal_newlines=True)
|
universal_newlines=True)
|
||||||
@ -355,7 +354,8 @@ class Container(_lxc.Container):
|
|||||||
ip4_cmd = base_cmd + ["-4", "addr", "show", "scope", "global"]
|
ip4_cmd = base_cmd + ["-4", "addr", "show", "scope", "global"]
|
||||||
if interface:
|
if interface:
|
||||||
ip = subprocess.Popen(ip4_cmd + ["dev", interface],
|
ip = subprocess.Popen(ip4_cmd + ["dev", interface],
|
||||||
stdout=subprocess.PIPE, universal_newlines=True)
|
stdout=subprocess.PIPE,
|
||||||
|
universal_newlines=True)
|
||||||
else:
|
else:
|
||||||
ip = subprocess.Popen(ip4_cmd, stdout=subprocess.PIPE,
|
ip = subprocess.Popen(ip4_cmd, stdout=subprocess.PIPE,
|
||||||
universal_newlines=True)
|
universal_newlines=True)
|
||||||
@ -407,14 +407,14 @@ class Container(_lxc.Container):
|
|||||||
set_key(key, value)
|
set_key(key, value)
|
||||||
new_value = self.get_config_item(key)
|
new_value = self.get_config_item(key)
|
||||||
|
|
||||||
if isinstance(value, str) and isinstance(new_value, str) and \
|
if (isinstance(value, str) and isinstance(new_value, str) and
|
||||||
value == new_value:
|
value == new_value):
|
||||||
return True
|
return True
|
||||||
elif isinstance(value, list) and isinstance(new_value, list) and \
|
elif (isinstance(value, list) and isinstance(new_value, list) and
|
||||||
set(value) == set(new_value):
|
set(value) == set(new_value)):
|
||||||
return True
|
return True
|
||||||
elif isinstance(value, str) and isinstance(new_value, list) and \
|
elif (isinstance(value, str) and isinstance(new_value, list) and
|
||||||
set([value]) == set(new_value):
|
set([value]) == set(new_value)):
|
||||||
return True
|
return True
|
||||||
elif old_value:
|
elif old_value:
|
||||||
set_key(key, old_value)
|
set_key(key, old_value)
|
||||||
@ -423,7 +423,7 @@ class Container(_lxc.Container):
|
|||||||
self.clear_config_item(key)
|
self.clear_config_item(key)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def wait(self, state, timeout = -1):
|
def wait(self, state, timeout=-1):
|
||||||
"""
|
"""
|
||||||
Wait for the container to reach a given state or timeout.
|
Wait for the container to reach a given state or timeout.
|
||||||
"""
|
"""
|
||||||
@ -433,6 +433,7 @@ class Container(_lxc.Container):
|
|||||||
|
|
||||||
return _lxc.Container.wait(self, state, timeout)
|
return _lxc.Container.wait(self, state, timeout)
|
||||||
|
|
||||||
|
|
||||||
def list_containers(as_object=False):
|
def list_containers(as_object=False):
|
||||||
"""
|
"""
|
||||||
List the containers on the system.
|
List the containers on the system.
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
from distutils.core import setup, Extension
|
from distutils.core import setup, Extension
|
||||||
|
|
||||||
module = Extension('_lxc', sources = ['lxc.c'], libraries = ['lxc'])
|
module = Extension('_lxc', sources=['lxc.c'], libraries=['lxc'])
|
||||||
|
|
||||||
setup (name = '_lxc',
|
setup(name='_lxc',
|
||||||
version = '0.1',
|
version='0.1',
|
||||||
description = 'LXC',
|
description='LXC',
|
||||||
packages = ['lxc'],
|
packages=['lxc'],
|
||||||
package_dir = {'lxc':'lxc'},
|
package_dir={'lxc': 'lxc'},
|
||||||
ext_modules = [module])
|
ext_modules=[module])
|
||||||
|
Loading…
Reference in New Issue
Block a user