Skip to content

Commit

Permalink
Merge branch 'temporary'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kippiii committed Jan 8, 2023
2 parents 63b8084 + e0d64a2 commit 66c2e55
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "Container manager for the Jabberwocky project"
authors = ["Kippiii <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "jabberwocky_container_manager"}]
packages = [{include = "src"}]

[tool.poetry.dependencies]
python = "^3.8,<3.12"
Expand Down
18 changes: 18 additions & 0 deletions src/containers/container_manager_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ def run_command(self, container_name: str, cli: List[str]) -> None:
self._recv_expect(sock, 1024, b"BEGIN")
_RunCommandClient(sock)

def install(self, archive_path_str: str, container_name: str) -> None:
"""
Installs a new container from a given archive path
:param archive_path_str: The path to the archive
:param container_name: The name of the container
"""
absolute_archive_path = abspath(archive_path_str)

sock = self._make_connection()
sock.send(b"INSTALL")
self._recv_expect(sock, 1024, b"CONT")
sock.send(bytes(archive_path_str, "utf-8"))
self._recv_expect(sock, 1024, b"CONT")
sock.send(bytes(container_name, "utf-8"))
self._recv_expect(sock, 1024, b"OK")
sock.close()

def server_halt(self) -> None:
"""
Tells the server to halt
Expand Down
25 changes: 24 additions & 1 deletion src/containers/container_manager_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import threading
from typing import Dict, Optional, Tuple
from signal import SIGABRT
from pathlib import Path

from paramiko.channel import ChannelFile, ChannelStderrFile, ChannelStdinFile
from paramiko import SSHException

from src.containers.container import Container
from src.containers.port_allocation import allocate_port
from src.containers.exceptions import BootFailure, PoweroffBadExitError
from src.system.syspath import get_container_dir, get_server_info_file
from src.system.syspath import get_container_dir, get_server_info_file, install_container


class ContainerManagerServer:
Expand Down Expand Up @@ -139,6 +140,7 @@ def start_connection(self) -> None:
b"STOP": self._stop,
b"KILL": self._kill,
b"PING": self._ping,
b"INSTALL": self._install,
}[msg]()

except KeyError:
Expand Down Expand Up @@ -316,6 +318,27 @@ def _put(self) -> None:
self.manager.containers[container_name].put(local_file, remote_file)
self.client_sock.send(b"OK")

def _install(self) -> None:
"""
Installs a container on the system
"""
self.client_sock.send(b"CONT")
archive_path_str = self.client_sock.recv(1024).decode("utf-8")
self.client_sock.send(b"CONT")
container_name = self.client_sock.recv(1024).decode("utf-8")

self.manager.logger.debug(
"Installing container '%s' from '%s'", archive_path_str, container_name
)

archive_path = Path(archive_path_str)
if not archive_path.is_file():
self.client_sock.send(b"INVALID_PATH")
return
install_container(archive_path, container_name)

self.client_sock.send(b"OK")


class _RunCommandHandler:
"""
Expand Down

0 comments on commit 66c2e55

Please sign in to comment.