vantage6 4.2.2__py3-none-any.whl → 4.3.0b3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of vantage6 might be problematic. Click here for more details.

Files changed (49) hide show
  1. tests_cli/test_node_cli.py +1 -1
  2. tests_cli/test_server_cli.py +5 -5
  3. tests_cli/test_wizard.py +8 -9
  4. vantage6/cli/__build__ +1 -1
  5. vantage6/cli/_version.py +1 -1
  6. vantage6/cli/algostore/attach.py +32 -0
  7. vantage6/cli/algostore/new.py +55 -0
  8. vantage6/cli/algostore/start.py +102 -0
  9. vantage6/cli/algostore/stop.py +60 -0
  10. vantage6/cli/cli.py +20 -0
  11. vantage6/cli/common/decorator.py +92 -0
  12. vantage6/cli/common/start.py +232 -0
  13. vantage6/cli/configuration_manager.py +13 -23
  14. vantage6/cli/configuration_wizard.py +134 -60
  15. vantage6/cli/context/__init__.py +86 -0
  16. vantage6/cli/context/algorithm_store.py +130 -0
  17. vantage6/cli/context/base_server.py +89 -0
  18. vantage6/cli/{context.py → context/node.py} +12 -174
  19. vantage6/cli/context/server.py +127 -0
  20. vantage6/cli/dev/create.py +4 -3
  21. vantage6/cli/dev/remove.py +5 -3
  22. vantage6/cli/dev/start.py +2 -1
  23. vantage6/cli/dev/stop.py +2 -1
  24. vantage6/cli/globals.py +24 -0
  25. vantage6/cli/node/common/__init__.py +10 -4
  26. vantage6/cli/node/create_private_key.py +1 -1
  27. vantage6/cli/node/files.py +1 -1
  28. vantage6/cli/node/list.py +1 -1
  29. vantage6/cli/node/new.py +3 -2
  30. vantage6/cli/node/remove.py +1 -1
  31. vantage6/cli/node/set_api_key.py +1 -1
  32. vantage6/cli/node/start.py +7 -6
  33. vantage6/cli/rabbitmq/queue_manager.py +1 -1
  34. vantage6/cli/server/attach.py +3 -3
  35. vantage6/cli/server/common/__init__.py +5 -3
  36. vantage6/cli/server/files.py +1 -1
  37. vantage6/cli/server/import_.py +7 -3
  38. vantage6/cli/server/list.py +9 -5
  39. vantage6/cli/server/new.py +3 -2
  40. vantage6/cli/server/shell.py +3 -3
  41. vantage6/cli/server/start.py +26 -110
  42. vantage6/cli/server/stop.py +3 -4
  43. vantage6/cli/server/version.py +2 -2
  44. {vantage6-4.2.2.dist-info → vantage6-4.3.0b3.dist-info}/METADATA +3 -3
  45. vantage6-4.3.0b3.dist-info/RECORD +68 -0
  46. vantage6-4.2.2.dist-info/RECORD +0 -58
  47. {vantage6-4.2.2.dist-info → vantage6-4.3.0b3.dist-info}/WHEEL +0 -0
  48. {vantage6-4.2.2.dist-info → vantage6-4.3.0b3.dist-info}/entry_points.txt +0 -0
  49. {vantage6-4.2.2.dist-info → vantage6-4.3.0b3.dist-info}/top_level.txt +0 -0
@@ -8,10 +8,10 @@ import docker
8
8
  from colorama import Fore, Style
9
9
 
10
10
  from vantage6.common import error, info, debug
11
- from vantage6.common.globals import STRING_ENCODING, APPNAME
11
+ from vantage6.common.globals import STRING_ENCODING, APPNAME, InstanceType
12
12
  from vantage6.client import UserClient
13
13
 
14
- from vantage6.cli.context import NodeContext
14
+ from vantage6.cli.context.node import NodeContext
15
15
  from vantage6.cli.configuration_wizard import select_configuration_questionaire
16
16
 
17
17
 
@@ -92,7 +92,11 @@ def select_node(name: str, system_folders: bool) -> tuple[str, str]:
92
92
  str
93
93
  Name of the configuration file
94
94
  """
95
- name = name if name else select_configuration_questionaire("node", system_folders)
95
+ name = (
96
+ name
97
+ if name
98
+ else select_configuration_questionaire(InstanceType.NODE, system_folders)
99
+ )
96
100
 
97
101
  # raise error if config could not be found
98
102
  if not NodeContext.config_exists(name, system_folders):
@@ -118,5 +122,7 @@ def find_running_node_names(client: docker.DockerClient) -> list[str]:
118
122
  list[str]
119
123
  List of names of running nodes
120
124
  """
121
- running_nodes = client.containers.list(filters={"label": f"{APPNAME}-type=node"})
125
+ running_nodes = client.containers.list(
126
+ filters={"label": f"{APPNAME}-type={InstanceType.NODE}"}
127
+ )
122
128
  return [node.name for node in running_nodes]
@@ -11,7 +11,7 @@ from vantage6.common import (
11
11
  )
12
12
 
13
13
  from vantage6.common.encryption import RSACryptor
14
- from vantage6.cli.context import NodeContext
14
+ from vantage6.cli.context.node import NodeContext
15
15
  from vantage6.cli.globals import DEFAULT_NODE_SYSTEM_FOLDERS as N_FOL
16
16
  from vantage6.cli.node.common import select_node, create_client_and_authenticate
17
17
 
@@ -1,7 +1,7 @@
1
1
  import click
2
2
 
3
3
  from vantage6.common import info
4
- from vantage6.cli.context import NodeContext
4
+ from vantage6.cli.context.node import NodeContext
5
5
  from vantage6.cli.globals import DEFAULT_NODE_SYSTEM_FOLDERS as N_FOL
6
6
  from vantage6.cli.node.common import select_node
7
7
 
vantage6/cli/node/list.py CHANGED
@@ -5,7 +5,7 @@ from colorama import Fore, Style
5
5
  from vantage6.common import warning
6
6
  from vantage6.common.globals import APPNAME
7
7
  from vantage6.common.docker.addons import check_docker_running
8
- from vantage6.cli.context import NodeContext
8
+ from vantage6.cli.context.node import NodeContext
9
9
  from vantage6.cli.node.common import find_running_node_names
10
10
 
11
11
 
vantage6/cli/node/new.py CHANGED
@@ -2,10 +2,11 @@ import click
2
2
  from colorama import Fore, Style
3
3
 
4
4
  from vantage6.common import error, info, check_config_writeable
5
- from vantage6.cli.context import NodeContext
5
+ from vantage6.cli.context.node import NodeContext
6
6
  from vantage6.cli.globals import DEFAULT_NODE_SYSTEM_FOLDERS as N_FOL
7
7
  from vantage6.cli.configuration_wizard import configuration_wizard
8
8
  from vantage6.cli.utils import check_config_name_allowed, prompt_config_name
9
+ from vantage6.common.globals import InstanceType
9
10
 
10
11
 
11
12
  @click.command()
@@ -46,7 +47,7 @@ def cli_node_new_configuration(name: str, system_folders: bool) -> None:
46
47
 
47
48
  # create config in ctx location
48
49
  flag = "--system" if system_folders else ""
49
- cfg_file = configuration_wizard("node", name, system_folders)
50
+ cfg_file = configuration_wizard(InstanceType.NODE, name, system_folders)
50
51
  info(f"New configuration created: {Fore.GREEN}{cfg_file}{Style.RESET_ALL}")
51
52
  info(
52
53
  f"You can start the node by running "
@@ -17,7 +17,7 @@ from vantage6.common.globals import APPNAME
17
17
  from vantage6.common.globals import VPN_CONFIG_FILE
18
18
 
19
19
 
20
- from vantage6.cli.context import NodeContext
20
+ from vantage6.cli.context.node import NodeContext
21
21
  from vantage6.cli.globals import DEFAULT_NODE_SYSTEM_FOLDERS as N_FOL
22
22
  from vantage6.cli.utils import check_if_docker_daemon_is_running, remove_file
23
23
  from vantage6.cli.node.common import select_node, find_running_node_names
@@ -2,7 +2,7 @@ import click
2
2
  import questionary as q
3
3
 
4
4
  from vantage6.common import error, info, check_config_writeable
5
- from vantage6.cli.context import NodeContext
5
+ from vantage6.cli.context.node import NodeContext
6
6
  from vantage6.cli.globals import DEFAULT_NODE_SYSTEM_FOLDERS as N_FOL
7
7
  from vantage6.cli.configuration_wizard import NodeConfigurationManager
8
8
  from vantage6.cli.node.common import select_node
@@ -16,6 +16,7 @@ from vantage6.common.globals import (
16
16
  DEFAULT_DOCKER_REGISTRY,
17
17
  DEFAULT_NODE_IMAGE,
18
18
  DEFAULT_NODE_IMAGE_WO_TAG,
19
+ InstanceType,
19
20
  )
20
21
  from vantage6.common.docker.addons import (
21
22
  pull_if_newer,
@@ -23,7 +24,7 @@ from vantage6.common.docker.addons import (
23
24
  check_docker_running,
24
25
  )
25
26
 
26
- from vantage6.cli.context import NodeContext
27
+ from vantage6.cli.context.node import NodeContext
27
28
  from vantage6.cli.globals import DEFAULT_NODE_SYSTEM_FOLDERS as N_FOL
28
29
  from vantage6.cli.configuration_wizard import (
29
30
  configuration_wizard,
@@ -99,14 +100,14 @@ def cli_node_start(
99
100
  else:
100
101
  # in case no name is supplied, ask the user to select one
101
102
  if not name:
102
- name = select_configuration_questionaire("node", system_folders)
103
+ name = select_configuration_questionaire(InstanceType.NODE, system_folders)
103
104
 
104
105
  # check that config exists, if not a questionaire will be invoked
105
106
  if not NodeContext.config_exists(name, system_folders):
106
107
  warning(f"Configuration {Fore.RED}{name}{Style.RESET_ALL} does not exist.")
107
108
 
108
109
  if q.confirm("Create this configuration now?").ask():
109
- configuration_wizard("node", name, system_folders)
110
+ configuration_wizard(InstanceType.NODE, name, system_folders)
110
111
 
111
112
  else:
112
113
  error("Config file couldn't be loaded")
@@ -119,7 +120,7 @@ def cli_node_start(
119
120
 
120
121
  # check that this node is not already running
121
122
  running_nodes = docker_client.containers.list(
122
- filters={"label": f"{APPNAME}-type=node"}
123
+ filters={"label": f"{APPNAME}-type={InstanceType.NODE}"}
123
124
  )
124
125
 
125
126
  suffix = "system" if system_folders else "user"
@@ -197,7 +198,7 @@ def cli_node_start(
197
198
  # FIXME: should obtain mount points from DockerNodeContext
198
199
  mounts = [
199
200
  # (target, source)
200
- ("/mnt/log", str(ctx.log_dir)),
201
+ (f"/mnt/log/{name}", str(ctx.log_dir)),
201
202
  ("/mnt/data", data_volume.name),
202
203
  ("/mnt/vpn", vpn_volume.name),
203
204
  ("/mnt/ssh", ssh_volume.name),
@@ -346,7 +347,7 @@ def cli_node_start(
346
347
  volumes=volumes,
347
348
  detach=True,
348
349
  labels={
349
- f"{APPNAME}-type": "node",
350
+ f"{APPNAME}-type": InstanceType.NODE,
350
351
  "system": str(system_folders),
351
352
  "name": ctx.config_file_name,
352
353
  },
@@ -12,7 +12,7 @@ from vantage6.common.globals import APPNAME
12
12
  from vantage6.common import debug, info, error
13
13
  from vantage6.common.docker.addons import get_container
14
14
  from vantage6.common.docker.network_manager import NetworkManager
15
- from vantage6.cli.context import ServerContext
15
+ from vantage6.cli.context.server import ServerContext
16
16
  from vantage6.cli.rabbitmq.definitions import RABBITMQ_DEFINITIONS
17
17
  from vantage6.cli.globals import RABBIT_TIMEOUT
18
18
  from vantage6.cli.rabbitmq import split_rabbitmq_uri
@@ -9,7 +9,7 @@ from colorama import Fore, Style
9
9
 
10
10
  from vantage6.common import info, error
11
11
  from vantage6.common.docker.addons import check_docker_running
12
- from vantage6.common.globals import APPNAME
12
+ from vantage6.common.globals import APPNAME, InstanceType
13
13
 
14
14
  from vantage6.cli.globals import DEFAULT_SERVER_SYSTEM_FOLDERS
15
15
  from vantage6.cli.server.common import print_log_worker
@@ -29,7 +29,7 @@ def cli_server_attach(name: str, system_folders: bool) -> None:
29
29
  client = docker.from_env()
30
30
 
31
31
  running_servers = client.containers.list(
32
- filters={"label": f"{APPNAME}-type=server"}
32
+ filters={"label": f"{APPNAME}-type={InstanceType.SERVER}"}
33
33
  )
34
34
  running_server_names = [node.name for node in running_servers]
35
35
 
@@ -39,7 +39,7 @@ def cli_server_attach(name: str, system_folders: bool) -> None:
39
39
  ).ask()
40
40
  else:
41
41
  post_fix = "system" if system_folders else "user"
42
- name = f"{APPNAME}-{name}-{post_fix}-server"
42
+ name = f"{APPNAME}-{name}-{post_fix}-{InstanceType.SERVER}"
43
43
 
44
44
  if name in running_server_names:
45
45
  container = client.containers.get(name)
@@ -6,11 +6,11 @@ import click
6
6
  from colorama import Fore, Style
7
7
 
8
8
  from vantage6.common import error, info
9
- from vantage6.common.globals import STRING_ENCODING, APPNAME
9
+ from vantage6.common.globals import STRING_ENCODING, APPNAME, InstanceType
10
10
  from vantage6.common.docker.addons import remove_container, get_container
11
11
 
12
12
  from vantage6.cli.globals import DEFAULT_SERVER_SYSTEM_FOLDERS
13
- from vantage6.cli.context import ServerContext
13
+ from vantage6.cli.context.server import ServerContext
14
14
  from vantage6.cli.configuration_wizard import select_configuration_questionaire
15
15
 
16
16
 
@@ -77,7 +77,9 @@ def click_insert_context(func: callable) -> callable:
77
77
  if not name:
78
78
  try:
79
79
  # select configuration if none supplied
80
- name = select_configuration_questionaire("server", system_folders)
80
+ name = select_configuration_questionaire(
81
+ InstanceType.SERVER, system_folders
82
+ )
81
83
  except Exception:
82
84
  error("No configurations could be found!")
83
85
  exit(1)
@@ -1,7 +1,7 @@
1
1
  import click
2
2
 
3
3
  from vantage6.common import info
4
- from vantage6.cli.context import ServerContext
4
+ from vantage6.cli.context.server import ServerContext
5
5
  from vantage6.cli.server.common import click_insert_context
6
6
 
7
7
 
@@ -4,6 +4,7 @@ from threading import Thread
4
4
  import click
5
5
  import docker
6
6
  from sqlalchemy.engine.url import make_url
7
+ from vantage6.cli.globals import ServerGlobals
7
8
 
8
9
  from vantage6.common import info, warning
9
10
  from vantage6.common.docker.addons import check_docker_running
@@ -11,8 +12,9 @@ from vantage6.common.globals import (
11
12
  APPNAME,
12
13
  DEFAULT_DOCKER_REGISTRY,
13
14
  DEFAULT_SERVER_IMAGE,
15
+ InstanceType,
14
16
  )
15
- from vantage6.cli.context import ServerContext
17
+ from vantage6.cli.context.server import ServerContext
16
18
  from vantage6.cli.utils import check_config_name_allowed
17
19
  from vantage6.cli.server.common import click_insert_context, print_log_worker
18
20
 
@@ -113,7 +115,9 @@ def cli_server_import(
113
115
  # we're mounting the entire folder that contains the database
114
116
  mounts.append(docker.types.Mount("/mnt/database/", dirname, type="bind"))
115
117
 
116
- environment_vars = {"VANTAGE6_DB_URI": f"sqlite:////mnt/database/{basename}"}
118
+ environment_vars = {
119
+ ServerGlobals.DB_URI_ENV_VAR: f"sqlite:////mnt/database/{basename}"
120
+ }
117
121
 
118
122
  else:
119
123
  warning(
@@ -133,7 +137,7 @@ def cli_server_import(
133
137
  command=cmd,
134
138
  mounts=mounts,
135
139
  detach=True,
136
- labels={f"{APPNAME}-type": "server", "name": ctx.config_file_name},
140
+ labels={f"{APPNAME}-type": InstanceType.SERVER, "name": ctx.config_file_name},
137
141
  environment=environment_vars,
138
142
  auto_remove=not keep,
139
143
  tty=True,
@@ -5,8 +5,8 @@ from colorama import Fore, Style
5
5
 
6
6
  from vantage6.common import warning
7
7
  from vantage6.common.docker.addons import check_docker_running
8
- from vantage6.common.globals import APPNAME
9
- from vantage6.cli.context import ServerContext
8
+ from vantage6.common.globals import APPNAME, InstanceType
9
+ from vantage6.cli.context.server import ServerContext
10
10
 
11
11
 
12
12
  @click.command()
@@ -17,7 +17,9 @@ def cli_server_configuration_list() -> None:
17
17
  check_docker_running()
18
18
  client = docker.from_env()
19
19
 
20
- running_server = client.containers.list(filters={"label": f"{APPNAME}-type=server"})
20
+ running_server = client.containers.list(
21
+ filters={"label": f"{APPNAME}-type={InstanceType.SERVER}"}
22
+ )
21
23
  running_node_names = []
22
24
  for node in running_server:
23
25
  running_node_names.append(node.name)
@@ -35,7 +37,8 @@ def cli_server_configuration_list() -> None:
35
37
  for config in configs:
36
38
  status = (
37
39
  running
38
- if f"{APPNAME}-{config.name}-system-server" in running_node_names
40
+ if f"{APPNAME}-{config.name}-system-{InstanceType.SERVER}"
41
+ in running_node_names
39
42
  else stopped
40
43
  )
41
44
  click.echo(f"{config.name:25}" f"{status:25} System ")
@@ -45,7 +48,8 @@ def cli_server_configuration_list() -> None:
45
48
  for config in configs:
46
49
  status = (
47
50
  running
48
- if f"{APPNAME}-{config.name}-user-server" in running_node_names
51
+ if f"{APPNAME}-{config.name}-user-{InstanceType.SERVER}"
52
+ in running_node_names
49
53
  else stopped
50
54
  )
51
55
  click.echo(f"{config.name:25}" f"{status:25} User ")
@@ -3,9 +3,10 @@ from colorama import Fore, Style
3
3
 
4
4
  from vantage6.common import info, error, check_config_writeable
5
5
  from vantage6.cli.globals import DEFAULT_SERVER_SYSTEM_FOLDERS
6
- from vantage6.cli.context import ServerContext
6
+ from vantage6.cli.context.server import ServerContext
7
7
  from vantage6.cli.configuration_wizard import configuration_wizard
8
8
  from vantage6.cli.utils import check_config_name_allowed, prompt_config_name
9
+ from vantage6.common.globals import InstanceType
9
10
 
10
11
 
11
12
  @click.command()
@@ -44,7 +45,7 @@ def cli_server_new(name: str, system_folders: bool) -> None:
44
45
  exit(1)
45
46
 
46
47
  # create config in ctx location
47
- cfg_file = configuration_wizard("server", name, system_folders)
48
+ cfg_file = configuration_wizard(InstanceType.SERVER, name, system_folders)
48
49
  info(f"New configuration created: {Fore.GREEN}{cfg_file}{Style.RESET_ALL}")
49
50
 
50
51
  # info(f"root user created.")
@@ -6,8 +6,8 @@ from colorama import Fore, Style
6
6
 
7
7
  from vantage6.common import info, error, debug as debug_msg
8
8
  from vantage6.common.docker.addons import check_docker_running
9
- from vantage6.common.globals import APPNAME
10
- from vantage6.cli.context import ServerContext
9
+ from vantage6.common.globals import APPNAME, InstanceType
10
+ from vantage6.cli.context.server import ServerContext
11
11
  from vantage6.cli.server.common import click_insert_context
12
12
 
13
13
 
@@ -28,7 +28,7 @@ def cli_server_shell(ctx: ServerContext) -> None:
28
28
  docker_client = docker.from_env()
29
29
 
30
30
  running_servers = docker_client.containers.list(
31
- filters={"label": f"{APPNAME}-type=server"}
31
+ filters={"label": f"{APPNAME}-type={InstanceType.SERVER}"}
32
32
  )
33
33
 
34
34
  if ctx.docker_container_name not in [s.name for s in running_servers]:
@@ -1,28 +1,28 @@
1
- import os
2
- from threading import Thread
3
- import time
4
-
5
1
  import click
6
2
  import docker
7
- from colorama import Fore, Style
8
- from sqlalchemy.engine.url import make_url
9
3
  from docker.client import DockerClient
10
4
 
11
5
  from vantage6.common import info, warning, error
12
- from vantage6.common.docker.addons import pull_if_newer, check_docker_running
13
6
  from vantage6.common.docker.network_manager import NetworkManager
14
7
  from vantage6.common.globals import (
15
8
  APPNAME,
16
- DEFAULT_DOCKER_REGISTRY,
17
9
  DEFAULT_SERVER_IMAGE,
18
10
  DEFAULT_UI_IMAGE,
11
+ InstanceType,
19
12
  )
20
13
 
21
- from vantage6.cli.globals import DEFAULT_UI_PORT
22
- from vantage6.cli.context import ServerContext
23
- from vantage6.cli.utils import check_config_name_allowed
14
+ from vantage6.cli.globals import DEFAULT_UI_PORT, ServerGlobals
15
+ from vantage6.cli.context.server import ServerContext
24
16
  from vantage6.cli.rabbitmq.queue_manager import RabbitMQManager
25
- from vantage6.cli.server.common import click_insert_context, print_log_worker, stop_ui
17
+ from vantage6.cli.server.common import click_insert_context, stop_ui
18
+ from vantage6.cli.common.start import (
19
+ attach_logs,
20
+ check_for_start,
21
+ get_image,
22
+ mount_database,
23
+ mount_source,
24
+ pull_image,
25
+ )
26
26
 
27
27
 
28
28
  @click.command()
@@ -81,47 +81,15 @@ def cli_server_start(
81
81
  """
82
82
  Start the server.
83
83
  """
84
- # will print an error if not
85
- check_docker_running()
86
-
87
84
  info("Starting server...")
88
- info("Finding Docker daemon.")
89
- docker_client = docker.from_env()
90
-
91
- # check if name is allowed for docker volume, else exit
92
- check_config_name_allowed(ctx.name)
85
+ docker_client = check_for_start(ctx, InstanceType.SERVER)
93
86
 
94
- # check that this server is not already running
95
- running_servers = docker_client.containers.list(
96
- filters={"label": f"{APPNAME}-type=server"}
97
- )
98
- for server in running_servers:
99
- if server.name == f"{APPNAME}-{ctx.name}-{ctx.scope}-server":
100
- error(f"Server {Fore.RED}{ctx.name}{Style.RESET_ALL} " "is already running")
101
- exit(1)
87
+ image = get_image(image, ctx, "server", DEFAULT_SERVER_IMAGE)
102
88
 
103
89
  # check that log directory exists - or create it
104
90
  ctx.log_dir.mkdir(parents=True, exist_ok=True)
105
91
 
106
- # Determine image-name. First we check if the option --image has been used.
107
- # Then we check if the image has been specified in the config file, and
108
- # finally we use the default settings from the package.
109
- if image is None:
110
- custom_images: dict = ctx.config.get("images")
111
- if custom_images:
112
- image = custom_images.get("server")
113
- if not image:
114
- image = f"{DEFAULT_DOCKER_REGISTRY}/{DEFAULT_SERVER_IMAGE}"
115
-
116
- info(f"Pulling latest server image '{image}'.")
117
- try:
118
- pull_if_newer(docker.from_env(), image)
119
- # docker_client.images.pull(image)
120
- except Exception as e:
121
- warning(" ... Getting latest server image failed:")
122
- warning(f" {e}")
123
- else:
124
- info(" ... success!")
92
+ pull_image(docker_client, image)
125
93
 
126
94
  info("Creating mounts")
127
95
  config_file = "/mnt/config.yaml"
@@ -130,41 +98,13 @@ def cli_server_start(
130
98
  docker.types.Mount("/mnt/log/", str(ctx.log_dir), type="bind"),
131
99
  ]
132
100
 
133
- if mount_src:
134
- mount_src = os.path.abspath(mount_src)
135
- mounts.append(docker.types.Mount("/vantage6", mount_src, type="bind"))
136
- # FIXME: code duplication with cli_server_import()
137
- # try to mount database
138
- uri = ctx.config["uri"]
139
- url = make_url(uri)
140
- environment_vars = None
141
-
142
- # If host is None, we're dealing with a file-based DB, like SQLite
143
- if url.host is None:
144
- db_path = url.database
101
+ src_mount = mount_source(mount_src)
102
+ if src_mount:
103
+ mounts.append(src_mount)
145
104
 
146
- if not os.path.isabs(db_path):
147
- # We're dealing with a relative path here -> make it absolute
148
- db_path = ctx.data_dir / url.database
149
-
150
- basename = os.path.basename(db_path)
151
- dirname = os.path.dirname(db_path)
152
- os.makedirs(dirname, exist_ok=True)
153
-
154
- # we're mounting the entire folder that contains the database
155
- mounts.append(docker.types.Mount("/mnt/database/", dirname, type="bind"))
156
-
157
- environment_vars = {
158
- "VANTAGE6_DB_URI": f"sqlite:////mnt/database/{basename}",
159
- "VANTAGE6_CONFIG_NAME": ctx.config_file_name,
160
- }
161
-
162
- else:
163
- warning(
164
- f"Database could not be transferred, make sure {url.host} "
165
- "is reachable from the Docker container"
166
- )
167
- info("Consider using the docker-compose method to start a server")
105
+ mount, environment_vars = mount_database(ctx, InstanceType.SERVER)
106
+ if mount:
107
+ mounts.append(mount)
168
108
 
169
109
  # Create a docker network for the server and other services like RabbitMQ
170
110
  # to reside in
@@ -209,13 +149,13 @@ def cli_server_start(
209
149
  info(cmd)
210
150
 
211
151
  info("Run Docker container")
212
- port_ = str(port or ctx.config["port"] or 5000)
152
+ port_ = str(port or ctx.config["port"] or ServerGlobals.PORT)
213
153
  container = docker_client.containers.run(
214
154
  image,
215
155
  command=cmd,
216
156
  mounts=mounts,
217
157
  detach=True,
218
- labels={f"{APPNAME}-type": "server", "name": ctx.config_file_name},
158
+ labels={f"{APPNAME}-type": InstanceType.SERVER, "name": ctx.config_file_name},
219
159
  environment=environment_vars,
220
160
  ports={f"{internal_port}/tcp": (ip, port_)},
221
161
  name=ctx.docker_container_name,
@@ -227,18 +167,7 @@ def cli_server_start(
227
167
  info(f"Success! container id = {container.id}")
228
168
 
229
169
  if attach:
230
- logs = container.attach(stream=True, logs=True, stdout=True)
231
- Thread(target=print_log_worker, args=(logs,), daemon=True).start()
232
- while True:
233
- try:
234
- time.sleep(1)
235
- except KeyboardInterrupt:
236
- info("Closing log file. Keyboard Interrupt.")
237
- info(
238
- "Note that your server is still running! Shut it down "
239
- f"with {Fore.RED}v6 server stop{Style.RESET_ALL}"
240
- )
241
- exit(0)
170
+ attach_logs(container, InstanceType.SERVER)
242
171
 
243
172
 
244
173
  def _start_rabbitmq(
@@ -296,22 +225,9 @@ def _start_ui(client: DockerClient, ctx: ServerContext, ui_port: int) -> None:
296
225
  ui_port = DEFAULT_UI_PORT
297
226
 
298
227
  # find image to use
299
- custom_images: dict = ctx.config.get("images")
300
- image = None
301
- if custom_images:
302
- image = custom_images.get("ui")
303
- if not image:
304
- image = f"{DEFAULT_DOCKER_REGISTRY}/{DEFAULT_UI_IMAGE}"
228
+ image = get_image(None, ctx, "ui", DEFAULT_UI_IMAGE)
305
229
 
306
- info(f"Pulling latest UI image '{image}'.")
307
- try:
308
- pull_if_newer(docker.from_env(), image)
309
- # docker_client.images.pull(image)
310
- except Exception as e:
311
- warning(" ... Getting latest node image failed:")
312
- warning(f" {e}")
313
- else:
314
- info(" ... success!")
230
+ pull_image(client, image)
315
231
 
316
232
  # set environment variables
317
233
  env_vars = {
@@ -15,7 +15,7 @@ from vantage6.common.docker.addons import (
15
15
  delete_network,
16
16
  remove_container_if_exists,
17
17
  )
18
- from vantage6.common.globals import APPNAME
18
+ from vantage6.common.globals import APPNAME, InstanceType
19
19
  from vantage6.cli.rabbitmq import split_rabbitmq_uri
20
20
 
21
21
  from vantage6.cli.globals import DEFAULT_SERVER_SYSTEM_FOLDERS
@@ -37,7 +37,7 @@ def cli_server_stop(name: str, system_folders: bool, all_servers: bool):
37
37
  client = docker.from_env()
38
38
 
39
39
  running_servers = client.containers.list(
40
- filters={"label": f"{APPNAME}-type=server"}
40
+ filters={"label": f"{APPNAME}-type={InstanceType.SERVER}"}
41
41
  )
42
42
 
43
43
  if not running_servers:
@@ -58,7 +58,7 @@ def cli_server_stop(name: str, system_folders: bool, all_servers: bool):
58
58
  ).ask()
59
59
  else:
60
60
  post_fix = "system" if system_folders else "user"
61
- container_name = f"{APPNAME}-{name}-{post_fix}-server"
61
+ container_name = f"{APPNAME}-{name}-{post_fix}-{InstanceType.SERVER}"
62
62
 
63
63
  if container_name not in running_server_names:
64
64
  error(f"{Fore.RED}{name}{Style.RESET_ALL} is not running!")
@@ -88,7 +88,6 @@ def _stop_server_containers(
88
88
  info(f"Stopped the {Fore.GREEN}{container_name}{Style.RESET_ALL} server.")
89
89
 
90
90
  # find the configuration name from the docker container name
91
- # server name is formatted as f"{APPNAME}-{self.name}-{self.scope}-server"
92
91
  scope = "system" if system_folders else "user"
93
92
  config_name = get_server_config_name(container_name, scope)
94
93
 
@@ -4,7 +4,7 @@ import docker
4
4
 
5
5
  from vantage6.common import error
6
6
  from vantage6.common.docker.addons import check_docker_running
7
- from vantage6.common.globals import APPNAME
7
+ from vantage6.common.globals import APPNAME, InstanceType
8
8
  from vantage6.cli.globals import DEFAULT_SERVER_SYSTEM_FOLDERS
9
9
  from vantage6.cli import __version__
10
10
 
@@ -23,7 +23,7 @@ def cli_server_version(name: str, system_folders: bool) -> None:
23
23
  client = docker.from_env()
24
24
 
25
25
  running_servers = client.containers.list(
26
- filters={"label": f"{APPNAME}-type=server"}
26
+ filters={"label": f"{APPNAME}-type={InstanceType.SERVER}"}
27
27
  )
28
28
  running_server_names = [server.name for server in running_servers]
29
29
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vantage6
3
- Version: 4.2.2
3
+ Version: 4.3.0b3
4
4
  Summary: vantage6 command line interface
5
5
  Home-page: https://github.com/vantage6/vantage6
6
6
  Requires-Python: >=3.10
@@ -15,8 +15,8 @@ Requires-Dist: questionary ==1.10.0
15
15
  Requires-Dist: rich ==13.5.2
16
16
  Requires-Dist: schema ==0.7.5
17
17
  Requires-Dist: SQLAlchemy ==1.4.46
18
- Requires-Dist: vantage6-common ==4.2.2
19
- Requires-Dist: vantage6-client ==4.2.2
18
+ Requires-Dist: vantage6-common ==4.3.0b3
19
+ Requires-Dist: vantage6-client ==4.3.0b3
20
20
  Provides-Extra: dev
21
21
  Requires-Dist: coverage ==6.4.4 ; extra == 'dev'
22
22
  Requires-Dist: black ; extra == 'dev'