forked from armadaplatform/armada
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_ssh.py
29 lines (21 loc) · 1004 Bytes
/
api_ssh.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import socket
from armada_backend import api_base
from armada_backend.hermes_init import HERMES_DIRECTORY
from armada_backend.utils import get_container_ssh_address
class SshAddress(api_base.ApiCommand):
def on_get(self, req, resp):
container_id, error = self.get_get_parameter(req, 'container_id')
if error:
return self.status_error(resp, error)
try:
ssh_address = get_container_ssh_address(container_id)
except Exception as e:
return self.status_exception(resp, "Cannot inspect requested container.", e)
return self.status_ok(resp, {'ssh': ssh_address})
class HermesAddress(api_base.ApiCommand):
def on_get(self, req, resp):
try:
ssh_address = get_container_ssh_address(socket.gethostname())
except Exception as e:
return self.status_exception(resp, "Cannot inspect own container.", e)
return self.status_ok(resp, {'ssh': ssh_address, 'path': HERMES_DIRECTORY})