container_delete
This commit is contained in:
parent
87d71f6634
commit
e68a947a6b
1 changed files with 14 additions and 11 deletions
|
@ -20,7 +20,7 @@ class ContainerNotExists(Exception):
|
|||
|
||||
|
||||
_logger = logging.getLogger("pylxc")
|
||||
_monitor = None
|
||||
_monitor = None
|
||||
|
||||
|
||||
class _LXCMonitor(threading.Thread):
|
||||
|
@ -28,7 +28,7 @@ class _LXCMonitor(threading.Thread):
|
|||
threading.Thread.__init__(self)
|
||||
self._process = None
|
||||
self._monitors = {}
|
||||
|
||||
|
||||
def run(self):
|
||||
master, slave = pty.openpty()
|
||||
cmd = ['lxc-monitor', '-n', '.*']
|
||||
|
@ -46,23 +46,23 @@ class _LXCMonitor(threading.Thread):
|
|||
logging.debug("State of container '%s' changed to '%s'", container, state)
|
||||
self._monitors[container](state)
|
||||
_logger.info("LXC Monitor stopped!")
|
||||
|
||||
|
||||
def add_monitor(self, name, callback):
|
||||
self._monitors[name] = callback
|
||||
|
||||
|
||||
def rm_monitor(self, name):
|
||||
self._monitors.pop(name)
|
||||
|
||||
|
||||
def is_monitored(self, name):
|
||||
return name in self._monitors
|
||||
|
||||
|
||||
def kill(self):
|
||||
try:
|
||||
self._process.terminate()
|
||||
self._process.wait()
|
||||
except:
|
||||
pass
|
||||
self.join()
|
||||
self.join()
|
||||
|
||||
|
||||
class lxc():
|
||||
|
@ -114,9 +114,13 @@ class lxc():
|
|||
if not self.exists(name):
|
||||
raise ContainerNotExists("The container (%s) does not exist!" % name)
|
||||
|
||||
cmd = ['lxc-stop', '-n', name]
|
||||
cmd = ['/usr/bin/lxc-stop', '-n', name]
|
||||
|
||||
return subprocess.check_call(cmd)
|
||||
try:
|
||||
result = subprocess.check_call(cmd)
|
||||
return True
|
||||
exception Exception as e:
|
||||
return False
|
||||
|
||||
def destroy(self, name):
|
||||
"""
|
||||
|
@ -317,7 +321,7 @@ class lxc():
|
|||
# i = i.replace(' (auto)', '')
|
||||
# containers_list.append(i)
|
||||
# return containers_list
|
||||
|
||||
|
||||
|
||||
# def kill(name, signal):
|
||||
# '''
|
||||
|
@ -387,4 +391,3 @@ class lxc():
|
|||
# _monitor = None
|
||||
# signal.signal(signal.SIGTERM, signal.SIG_DFL)
|
||||
# signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue