mirror of
https://github.com/gnh1201/caterpillar.git
synced 2024-11-26 15:31:45 +00:00
Merge pull request #39 from gnh1201/Container
Some checks failed
Ruff / ruff (push) Has been cancelled
Some checks failed
Ruff / ruff (push) Has been cancelled
add docker container lifecycle methods
This commit is contained in:
commit
7139092c12
|
@ -21,7 +21,7 @@ class Container(Extension):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.type = "rpcmethod"
|
self.type = "rpcmethod"
|
||||||
self.method = "container_init"
|
self.method = "container_init"
|
||||||
self.exported_methods = ["container_run", "container_stop"]
|
self.exported_methods = ["container_cteate", "container_start", "container_run", "container_stop", "container_pause", "container_unpause", "container_restart", "container_kill", "container_remove"]
|
||||||
|
|
||||||
# docker
|
# docker
|
||||||
self.client = docker.from_env()
|
self.client = docker.from_env()
|
||||||
|
@ -30,6 +30,16 @@ class Container(Extension):
|
||||||
logger.info("[*] Greeting! dispatch")
|
logger.info("[*] Greeting! dispatch")
|
||||||
conn.send(b"Greeting! dispatch")
|
conn.send(b"Greeting! dispatch")
|
||||||
|
|
||||||
|
def container_cteate(self, type, id, params, conn):
|
||||||
|
# todo: -
|
||||||
|
return b"[*] Created"
|
||||||
|
|
||||||
|
def container_start(self, type, id, params, conn):
|
||||||
|
name = params['name']
|
||||||
|
|
||||||
|
container = self.client.containers.get(name)
|
||||||
|
container.start()
|
||||||
|
|
||||||
def container_run(self, type, id, params, conn):
|
def container_run(self, type, id, params, conn):
|
||||||
devices = params["devices"]
|
devices = params["devices"]
|
||||||
image = params["image"]
|
image = params["image"]
|
||||||
|
@ -47,8 +57,8 @@ class Container(Extension):
|
||||||
detach=True,
|
detach=True,
|
||||||
)
|
)
|
||||||
container.logs()
|
container.logs()
|
||||||
|
|
||||||
logger.info("[*] Running...")
|
logger.info("[*] Running...")
|
||||||
|
return b"[*] Running..."
|
||||||
|
|
||||||
def container_stop(self, type, id, params, conn):
|
def container_stop(self, type, id, params, conn):
|
||||||
name = params["name"]
|
name = params["name"]
|
||||||
|
@ -57,3 +67,36 @@ class Container(Extension):
|
||||||
container.stop()
|
container.stop()
|
||||||
|
|
||||||
logger.info("[*] Stopped")
|
logger.info("[*] Stopped")
|
||||||
|
return b"[*] Stopped"
|
||||||
|
|
||||||
|
def container_pause(self, type, id, params, conn):
|
||||||
|
name = params['name']
|
||||||
|
|
||||||
|
container = self.client.containers.get(name)
|
||||||
|
container.pause()
|
||||||
|
return b"[*] Paused"
|
||||||
|
|
||||||
|
def container_unpause(self, type, id, params, conn):
|
||||||
|
name = params['name']
|
||||||
|
|
||||||
|
container = self.client.containers.get(name)
|
||||||
|
container.unpause()
|
||||||
|
return b"[*] Unpaused"
|
||||||
|
|
||||||
|
def container_restart(self, type, id, params, conn):
|
||||||
|
name = params['name']
|
||||||
|
|
||||||
|
container = self.client.containers.get(name)
|
||||||
|
container.restart()
|
||||||
|
return b"[*] Restarted"
|
||||||
|
|
||||||
|
def container_kill(self, type, id, params, conn):
|
||||||
|
# TODO: -
|
||||||
|
return b"[*] Killed"
|
||||||
|
|
||||||
|
def container_remove(self, type, id, params, conn):
|
||||||
|
name = params['name']
|
||||||
|
|
||||||
|
container = self.client.containers.get(name)
|
||||||
|
container.remove()
|
||||||
|
return b"[*] Removed"
|
Loading…
Reference in New Issue
Block a user