update
This commit is contained in:
parent
8ec8bd1f29
commit
906b39fe07
1 changed files with 20 additions and 8 deletions
|
@ -31,7 +31,7 @@ class _LXCMonitor(threading.Thread):
|
|||
|
||||
def run(self):
|
||||
master, slave = pty.openpty()
|
||||
cmd = ['lxc-monitor', '-n', '.*']
|
||||
cmd = ['/usr/bin/lxc-monitor', '-n', '.*']
|
||||
self._process = subprocess.Popen(cmd, stdout=slave, bufsize=1)
|
||||
stdout = os.fdopen(master)
|
||||
while self._process.poll() is None:
|
||||
|
@ -134,7 +134,7 @@ class lxc():
|
|||
# todo: add condition
|
||||
self.stop(name)
|
||||
|
||||
cmd = ['lxc-destroy', '-f', '-n', name]
|
||||
cmd = ['/usr/bin/lxc-destroy', '-f', '-n', name]
|
||||
|
||||
return subprocess.check_call(cmd)
|
||||
|
||||
|
@ -142,39 +142,51 @@ class lxc():
|
|||
"""
|
||||
returns info dict about the specified container
|
||||
"""
|
||||
#
|
||||
if not self.exists(name):
|
||||
raise ContainerNotExists("The container (%s) does not exist!" % name)
|
||||
|
||||
#
|
||||
cmd = ['/usr/bin/lxc-info', '-n', name, "-H"]
|
||||
out = subprocess.check_output(cmd).splitlines()
|
||||
clean = []
|
||||
info = {}
|
||||
|
||||
#
|
||||
for line in out:
|
||||
# print line
|
||||
if line not in clean:
|
||||
clean.append(line)
|
||||
|
||||
#
|
||||
for line in clean:
|
||||
key, value = line.split(":")
|
||||
|
||||
# strip
|
||||
key = key.lstrip()
|
||||
value = value.lstrip()
|
||||
|
||||
#
|
||||
key = key.replace(" ", "_")
|
||||
|
||||
info[key.lower()] = value
|
||||
|
||||
# get container size
|
||||
info['container_size'] = self.__get_container_size(name)
|
||||
return info
|
||||
|
||||
def __get_container_size(self, name):
|
||||
cmd = ['/usr/bin/du', '--total', '-s', '/var/lib/lxc/%s' % name]
|
||||
out = subprocess.check_output(cmd).splitlines()
|
||||
size = 0
|
||||
for l in out:
|
||||
key, value = l.split('\t')
|
||||
if value == 'total':
|
||||
size = key
|
||||
return int(key)
|
||||
|
||||
def freeze(self, name):
|
||||
"""
|
||||
freezes the container
|
||||
"""
|
||||
if not self.exists(name):
|
||||
raise ContainerNotExists("The container (%s) does not exist!" % name)
|
||||
cmd = ['lxc-freeze', '-n', name]
|
||||
cmd = ['/usr/bin/lxc-freeze', '-n', name]
|
||||
subprocess.check_call(cmd)
|
||||
|
||||
def unfreeze(self, name):
|
||||
|
|
Loading…
Add table
Reference in a new issue