vantage6 4.2.1__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 (64) hide show
  1. tests_cli/test_example.py +0 -1
  2. tests_cli/test_node_cli.py +74 -79
  3. tests_cli/test_server_cli.py +22 -22
  4. tests_cli/test_wizard.py +41 -29
  5. vantage6/cli/__build__ +1 -1
  6. vantage6/cli/_version.py +11 -8
  7. vantage6/cli/algorithm/create.py +14 -14
  8. vantage6/cli/algorithm/update.py +9 -6
  9. vantage6/cli/algostore/attach.py +32 -0
  10. vantage6/cli/algostore/new.py +55 -0
  11. vantage6/cli/algostore/start.py +102 -0
  12. vantage6/cli/algostore/stop.py +60 -0
  13. vantage6/cli/cli.py +32 -12
  14. vantage6/cli/common/decorator.py +92 -0
  15. vantage6/cli/common/start.py +232 -0
  16. vantage6/cli/configuration_manager.py +22 -32
  17. vantage6/cli/configuration_wizard.py +255 -193
  18. vantage6/cli/context/__init__.py +86 -0
  19. vantage6/cli/context/algorithm_store.py +130 -0
  20. vantage6/cli/context/base_server.py +89 -0
  21. vantage6/cli/context/node.py +254 -0
  22. vantage6/cli/context/server.py +127 -0
  23. vantage6/cli/dev/create.py +180 -113
  24. vantage6/cli/dev/remove.py +20 -19
  25. vantage6/cli/dev/start.py +10 -10
  26. vantage6/cli/dev/stop.py +7 -5
  27. vantage6/cli/globals.py +24 -0
  28. vantage6/cli/node/attach.py +21 -10
  29. vantage6/cli/node/clean.py +4 -2
  30. vantage6/cli/node/common/__init__.py +15 -11
  31. vantage6/cli/node/create_private_key.py +58 -27
  32. vantage6/cli/node/files.py +14 -6
  33. vantage6/cli/node/list.py +18 -24
  34. vantage6/cli/node/new.py +21 -12
  35. vantage6/cli/node/remove.py +31 -22
  36. vantage6/cli/node/set_api_key.py +18 -12
  37. vantage6/cli/node/start.py +38 -12
  38. vantage6/cli/node/stop.py +32 -18
  39. vantage6/cli/node/version.py +23 -13
  40. vantage6/cli/rabbitmq/__init__.py +9 -9
  41. vantage6/cli/rabbitmq/definitions.py +24 -28
  42. vantage6/cli/rabbitmq/queue_manager.py +37 -40
  43. vantage6/cli/server/attach.py +16 -11
  44. vantage6/cli/server/common/__init__.py +37 -25
  45. vantage6/cli/server/files.py +1 -1
  46. vantage6/cli/server/import_.py +45 -37
  47. vantage6/cli/server/list.py +22 -23
  48. vantage6/cli/server/new.py +20 -14
  49. vantage6/cli/server/remove.py +5 -4
  50. vantage6/cli/server/shell.py +17 -6
  51. vantage6/cli/server/start.py +118 -174
  52. vantage6/cli/server/stop.py +31 -23
  53. vantage6/cli/server/version.py +16 -13
  54. vantage6/cli/test/common/diagnostic_runner.py +30 -34
  55. vantage6/cli/test/feature_tester.py +51 -25
  56. vantage6/cli/test/integration_test.py +69 -29
  57. vantage6/cli/utils.py +6 -5
  58. {vantage6-4.2.1.dist-info → vantage6-4.3.0b3.dist-info}/METADATA +5 -3
  59. vantage6-4.3.0b3.dist-info/RECORD +68 -0
  60. vantage6/cli/context.py +0 -416
  61. vantage6-4.2.1.dist-info/RECORD +0 -58
  62. {vantage6-4.2.1.dist-info → vantage6-4.3.0b3.dist-info}/WHEEL +0 -0
  63. {vantage6-4.2.1.dist-info → vantage6-4.3.0b3.dist-info}/entry_points.txt +0 -0
  64. {vantage6-4.2.1.dist-info → vantage6-4.3.0b3.dist-info}/top_level.txt +0 -0
@@ -1,149 +1,110 @@
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 (
13
- pull_if_newer, check_docker_running
14
- )
15
6
  from vantage6.common.docker.network_manager import NetworkManager
16
7
  from vantage6.common.globals import (
17
8
  APPNAME,
18
- DEFAULT_DOCKER_REGISTRY,
19
9
  DEFAULT_SERVER_IMAGE,
20
- DEFAULT_UI_IMAGE
10
+ DEFAULT_UI_IMAGE,
11
+ InstanceType,
21
12
  )
22
13
 
23
- from vantage6.cli.globals import DEFAULT_UI_PORT
24
- from vantage6.cli.context import ServerContext
25
- 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
26
16
  from vantage6.cli.rabbitmq.queue_manager import RabbitMQManager
27
- from vantage6.cli.server.common import (
28
- 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,
29
25
  )
30
26
 
31
27
 
32
28
  @click.command()
33
- @click.option('--ip', default=None, help='IP address to listen on')
34
- @click.option('-p', '--port', default=None, type=int, help='Port to listen on')
35
- @click.option('-i', '--image', default=None, help="Server Docker image to use")
36
- @click.option('--with-ui', 'start_ui', flag_value=True, default=False,
37
- help="Start the graphical User Interface as well")
38
- @click.option('--ui-port', default=None, type=int,
39
- help="Port to listen on for the User Interface")
40
- @click.option('--with-rabbitmq', 'start_rabbitmq', flag_value=True,
41
- default=False, help="Start RabbitMQ message broker as local "
42
- "container - use in development only")
43
- @click.option('--rabbitmq-image', default=None,
44
- help="RabbitMQ docker image to use")
45
- @click.option('--keep/--auto-remove', default=False,
46
- help="Keep image after server has stopped. Useful for debugging")
47
- @click.option('--mount-src', default='',
48
- help="Override vantage6 source code in container with the source"
49
- " code in this path")
50
- @click.option('--attach/--detach', default=False,
51
- help="Print server logs to the console after start")
29
+ @click.option("--ip", default=None, help="IP address to listen on")
30
+ @click.option("-p", "--port", default=None, type=int, help="Port to listen on")
31
+ @click.option("-i", "--image", default=None, help="Server Docker image to use")
32
+ @click.option(
33
+ "--with-ui",
34
+ "start_ui",
35
+ flag_value=True,
36
+ default=False,
37
+ help="Start the graphical User Interface as well",
38
+ )
39
+ @click.option(
40
+ "--ui-port", default=None, type=int, help="Port to listen on for the User Interface"
41
+ )
42
+ @click.option(
43
+ "--with-rabbitmq",
44
+ "start_rabbitmq",
45
+ flag_value=True,
46
+ default=False,
47
+ help="Start RabbitMQ message broker as local "
48
+ "container - use in development only",
49
+ )
50
+ @click.option("--rabbitmq-image", default=None, help="RabbitMQ docker image to use")
51
+ @click.option(
52
+ "--keep/--auto-remove",
53
+ default=False,
54
+ help="Keep image after server has stopped. Useful for debugging",
55
+ )
56
+ @click.option(
57
+ "--mount-src",
58
+ default="",
59
+ help="Override vantage6 source code in container with the source"
60
+ " code in this path",
61
+ )
62
+ @click.option(
63
+ "--attach/--detach",
64
+ default=False,
65
+ help="Print server logs to the console after start",
66
+ )
52
67
  @click_insert_context
53
- def cli_server_start(ctx: ServerContext, ip: str, port: int, image: str,
54
- start_ui: bool, ui_port: int, start_rabbitmq: bool,
55
- rabbitmq_image: str, keep: bool, mount_src: str,
56
- attach: bool) -> None:
68
+ def cli_server_start(
69
+ ctx: ServerContext,
70
+ ip: str,
71
+ port: int,
72
+ image: str,
73
+ start_ui: bool,
74
+ ui_port: int,
75
+ start_rabbitmq: bool,
76
+ rabbitmq_image: str,
77
+ keep: bool,
78
+ mount_src: str,
79
+ attach: bool,
80
+ ) -> None:
57
81
  """
58
82
  Start the server.
59
83
  """
60
- # will print an error if not
61
- check_docker_running()
62
-
63
84
  info("Starting server...")
64
- info("Finding Docker daemon.")
65
- docker_client = docker.from_env()
85
+ docker_client = check_for_start(ctx, InstanceType.SERVER)
66
86
 
67
- # check if name is allowed for docker volume, else exit
68
- check_config_name_allowed(ctx.name)
69
-
70
- # check that this server is not already running
71
- running_servers = docker_client.containers.list(
72
- filters={"label": f"{APPNAME}-type=server"})
73
- for server in running_servers:
74
- if server.name == f"{APPNAME}-{ctx.name}-{ctx.scope}-server":
75
- error(f"Server {Fore.RED}{ctx.name}{Style.RESET_ALL} "
76
- "is already running")
77
- exit(1)
87
+ image = get_image(image, ctx, "server", DEFAULT_SERVER_IMAGE)
78
88
 
79
89
  # check that log directory exists - or create it
80
90
  ctx.log_dir.mkdir(parents=True, exist_ok=True)
81
91
 
82
- # Determine image-name. First we check if the option --image has been used.
83
- # Then we check if the image has been specified in the config file, and
84
- # finally we use the default settings from the package.
85
- if image is None:
86
- custom_images: dict = ctx.config.get('images')
87
- if custom_images:
88
- image = custom_images.get('server')
89
- if not image:
90
- image = f"{DEFAULT_DOCKER_REGISTRY}/{DEFAULT_SERVER_IMAGE}"
91
-
92
- info(f"Pulling latest server image '{image}'.")
93
- try:
94
- pull_if_newer(docker.from_env(), image)
95
- # docker_client.images.pull(image)
96
- except Exception as e:
97
- warning(' ... Getting latest server image failed:')
98
- warning(f" {e}")
99
- else:
100
- info(" ... success!")
92
+ pull_image(docker_client, image)
101
93
 
102
94
  info("Creating mounts")
103
95
  config_file = "/mnt/config.yaml"
104
96
  mounts = [
105
- docker.types.Mount(
106
- config_file, str(ctx.config_file), type="bind"
107
- ), docker.types.Mount(
108
- "/mnt/log/", str(ctx.log_dir), type="bind"
109
- )
97
+ docker.types.Mount(config_file, str(ctx.config_file), type="bind"),
98
+ docker.types.Mount("/mnt/log/", str(ctx.log_dir), type="bind"),
110
99
  ]
111
100
 
112
- if mount_src:
113
- mount_src = os.path.abspath(mount_src)
114
- mounts.append(docker.types.Mount("/vantage6", mount_src, type="bind"))
115
- # FIXME: code duplication with cli_server_import()
116
- # try to mount database
117
- uri = ctx.config['uri']
118
- url = make_url(uri)
119
- environment_vars = None
120
-
121
- # If host is None, we're dealing with a file-based DB, like SQLite
122
- if (url.host is None):
123
- db_path = url.database
124
-
125
- if not os.path.isabs(db_path):
126
- # We're dealing with a relative path here -> make it absolute
127
- db_path = ctx.data_dir / url.database
128
-
129
- basename = os.path.basename(db_path)
130
- dirname = os.path.dirname(db_path)
131
- os.makedirs(dirname, exist_ok=True)
132
-
133
- # we're mounting the entire folder that contains the database
134
- mounts.append(docker.types.Mount(
135
- "/mnt/database/", dirname, type="bind"
136
- ))
137
-
138
- environment_vars = {
139
- "VANTAGE6_DB_URI": f"sqlite:////mnt/database/{basename}",
140
- "VANTAGE6_CONFIG_NAME": ctx.config_file_name
141
- }
101
+ src_mount = mount_source(mount_src)
102
+ if src_mount:
103
+ mounts.append(src_mount)
142
104
 
143
- else:
144
- warning(f"Database could not be transferred, make sure {url.host} "
145
- "is reachable from the Docker container")
146
- 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)
147
108
 
148
109
  # Create a docker network for the server and other services like RabbitMQ
149
110
  # to reside in
@@ -152,70 +113,66 @@ def cli_server_start(ctx: ServerContext, ip: str, port: int, image: str,
152
113
  )
153
114
  server_network_mgr.create_network(is_internal=False)
154
115
 
155
- if start_rabbitmq or ctx.config.get('rabbitmq') and \
156
- ctx.config['rabbitmq'].get('start_with_server', False):
116
+ if (
117
+ start_rabbitmq
118
+ or ctx.config.get("rabbitmq")
119
+ and ctx.config["rabbitmq"].get("start_with_server", False)
120
+ ):
157
121
  # Note that ctx.data_dir has been created at this point, which is
158
122
  # required for putting some RabbitMQ configuration files inside
159
- info('Starting RabbitMQ container')
123
+ info("Starting RabbitMQ container")
160
124
  _start_rabbitmq(ctx, rabbitmq_image, server_network_mgr)
161
- elif ctx.config.get('rabbitmq'):
162
- info("RabbitMQ is provided in the config file as external service. "
163
- "Assuming this service is up and running.")
125
+ elif ctx.config.get("rabbitmq"):
126
+ info(
127
+ "RabbitMQ is provided in the config file as external service. "
128
+ "Assuming this service is up and running."
129
+ )
164
130
  else:
165
- warning('Message queue disabled! This means that the vantage6 server '
166
- 'cannot be scaled horizontally!')
131
+ warning(
132
+ "Message queue disabled! This means that the vantage6 server "
133
+ "cannot be scaled horizontally!"
134
+ )
167
135
 
168
136
  # start the UI if requested
169
- if start_ui or ctx.config.get('ui') and ctx.config['ui'].get('enabled'):
137
+ if start_ui or ctx.config.get("ui") and ctx.config["ui"].get("enabled"):
170
138
  _start_ui(docker_client, ctx, ui_port)
171
139
 
172
140
  # The `ip` and `port` refer here to the ip and port within the container.
173
141
  # So we do not really care that is it listening on all interfaces.
174
142
  internal_port = 5000
175
143
  cmd = (
176
- f'uwsgi --http :{internal_port} --gevent 1000 --http-websockets '
177
- '--master --callable app --disable-logging '
178
- '--wsgi-file /vantage6/vantage6-server/vantage6/server/wsgi.py '
179
- f'--pyargv {config_file}'
144
+ f"uwsgi --http :{internal_port} --gevent 1000 --http-websockets "
145
+ "--master --callable app --disable-logging "
146
+ "--wsgi-file /vantage6/vantage6-server/vantage6/server/wsgi.py "
147
+ f"--pyargv {config_file}"
180
148
  )
181
149
  info(cmd)
182
150
 
183
151
  info("Run Docker container")
184
- port_ = str(port or ctx.config["port"] or 5000)
152
+ port_ = str(port or ctx.config["port"] or ServerGlobals.PORT)
185
153
  container = docker_client.containers.run(
186
154
  image,
187
155
  command=cmd,
188
156
  mounts=mounts,
189
157
  detach=True,
190
- labels={
191
- f"{APPNAME}-type": "server",
192
- "name": ctx.config_file_name
193
- },
158
+ labels={f"{APPNAME}-type": InstanceType.SERVER, "name": ctx.config_file_name},
194
159
  environment=environment_vars,
195
160
  ports={f"{internal_port}/tcp": (ip, port_)},
196
161
  name=ctx.docker_container_name,
197
162
  auto_remove=not keep,
198
163
  tty=True,
199
- network=server_network_mgr.network_name
164
+ network=server_network_mgr.network_name,
200
165
  )
201
166
 
202
167
  info(f"Success! container id = {container.id}")
203
168
 
204
169
  if attach:
205
- logs = container.attach(stream=True, logs=True, stdout=True)
206
- Thread(target=print_log_worker, args=(logs,), daemon=True).start()
207
- while True:
208
- try:
209
- time.sleep(1)
210
- except KeyboardInterrupt:
211
- info("Closing log file. Keyboard Interrupt.")
212
- info("Note that your server is still running! Shut it down "
213
- f"with {Fore.RED}v6 server stop{Style.RESET_ALL}")
214
- exit(0)
170
+ attach_logs(container, InstanceType.SERVER)
215
171
 
216
172
 
217
- def _start_rabbitmq(ctx: ServerContext, rabbitmq_image: str,
218
- network_mgr: NetworkManager) -> None:
173
+ def _start_rabbitmq(
174
+ ctx: ServerContext, rabbitmq_image: str, network_mgr: NetworkManager
175
+ ) -> None:
219
176
  """
220
177
  Start the RabbitMQ container if it is not already running.
221
178
 
@@ -228,14 +185,15 @@ def _start_rabbitmq(ctx: ServerContext, rabbitmq_image: str,
228
185
  network_mgr : NetworkManager
229
186
  Network manager object
230
187
  """
231
- rabbit_uri = ctx.config['rabbitmq'].get('uri')
188
+ rabbit_uri = ctx.config["rabbitmq"].get("uri")
232
189
  if not rabbit_uri:
233
- error("No RabbitMQ URI found in the configuration file! Please add"
234
- "a 'uri' key to the 'rabbitmq' section of the configuration.")
190
+ error(
191
+ "No RabbitMQ URI found in the configuration file! Please add"
192
+ "a 'uri' key to the 'rabbitmq' section of the configuration."
193
+ )
235
194
  exit(1)
236
195
  # kick off RabbitMQ container
237
- rabbit_mgr = RabbitMQManager(
238
- ctx=ctx, network_mgr=network_mgr, image=rabbitmq_image)
196
+ rabbit_mgr = RabbitMQManager(ctx=ctx, network_mgr=network_mgr, image=rabbitmq_image)
239
197
  rabbit_mgr.start()
240
198
 
241
199
 
@@ -253,34 +211,23 @@ def _start_ui(client: DockerClient, ctx: ServerContext, ui_port: int) -> None:
253
211
  Port to expose the UI on
254
212
  """
255
213
  # if no port is specified, check if config contains a port
256
- ui_config = ctx.config.get('ui')
214
+ ui_config = ctx.config.get("ui")
257
215
  if ui_config and not ui_port:
258
- ui_port = ui_config.get('port')
216
+ ui_port = ui_config.get("port")
259
217
 
260
218
  # check if the port is valid
261
219
  # TODO make function to check if port is valid, and use in more places
262
220
  if not isinstance(ui_port, int) or not 0 < ui_port < 65536:
263
- warning(f"UI port '{ui_port}' is not valid! Using default port "
264
- f"{DEFAULT_UI_PORT}")
221
+ warning(
222
+ f"UI port '{ui_port}' is not valid! Using default port "
223
+ f"{DEFAULT_UI_PORT}"
224
+ )
265
225
  ui_port = DEFAULT_UI_PORT
266
226
 
267
227
  # find image to use
268
- custom_images: dict = ctx.config.get('images')
269
- image = None
270
- if custom_images:
271
- image = custom_images.get('ui')
272
- if not image:
273
- image = f"{DEFAULT_DOCKER_REGISTRY}/{DEFAULT_UI_IMAGE}"
228
+ image = get_image(None, ctx, "ui", DEFAULT_UI_IMAGE)
274
229
 
275
- info(f"Pulling latest UI image '{image}'.")
276
- try:
277
- pull_if_newer(docker.from_env(), image)
278
- # docker_client.images.pull(image)
279
- except Exception as e:
280
- warning(' ... Getting latest node image failed:')
281
- warning(f" {e}")
282
- else:
283
- info(" ... success!")
230
+ pull_image(client, image)
284
231
 
285
232
  # set environment variables
286
233
  env_vars = {
@@ -291,16 +238,13 @@ def _start_ui(client: DockerClient, ctx: ServerContext, ui_port: int) -> None:
291
238
  # stop the UI container if it is already running
292
239
  stop_ui(client, ctx)
293
240
 
294
- info(f'Starting User Interface at port {ui_port}')
241
+ info(f"Starting User Interface at port {ui_port}")
295
242
  ui_container_name = f"{APPNAME}-{ctx.name}-{ctx.scope}-ui"
296
243
  client.containers.run(
297
244
  image,
298
245
  detach=True,
299
- labels={
300
- f"{APPNAME}-type": "ui",
301
- "name": ctx.config_file_name
302
- },
303
- ports={"80/tcp": (ctx.config.get('ip'), ui_port)},
246
+ labels={f"{APPNAME}-type": "ui", "name": ctx.config_file_name},
247
+ ports={"80/tcp": (ctx.config.get("ip"), ui_port)},
304
248
  name=ui_container_name,
305
249
  environment=env_vars,
306
250
  tty=True,
@@ -1,16 +1,21 @@
1
1
  import click
2
2
  import questionary as q
3
3
  import docker
4
- from colorama import (Fore, Style)
4
+ from colorama import Fore, Style
5
5
  from docker.client import DockerClient
6
6
 
7
7
  from vantage6.common import info, warning, error
8
8
  from vantage6.common.docker.addons import (
9
- check_docker_running, remove_container,
10
- get_server_config_name, get_container, get_num_nonempty_networks,
11
- get_network, delete_network, remove_container_if_exists
9
+ check_docker_running,
10
+ remove_container,
11
+ get_server_config_name,
12
+ get_container,
13
+ get_num_nonempty_networks,
14
+ get_network,
15
+ delete_network,
16
+ remove_container_if_exists,
12
17
  )
13
- from vantage6.common.globals import APPNAME
18
+ from vantage6.common.globals import APPNAME, InstanceType
14
19
  from vantage6.cli.rabbitmq import split_rabbitmq_uri
15
20
 
16
21
  from vantage6.cli.globals import DEFAULT_SERVER_SYSTEM_FOLDERS
@@ -19,10 +24,11 @@ from vantage6.cli.server.common import get_server_context, stop_ui
19
24
 
20
25
  @click.command()
21
26
  @click.option("-n", "--name", default=None, help="Configuration name")
22
- @click.option('--system', 'system_folders', flag_value=True)
23
- @click.option('--user', 'system_folders', flag_value=False,
24
- default=DEFAULT_SERVER_SYSTEM_FOLDERS)
25
- @click.option('--all', 'all_servers', flag_value=True, help="Stop all servers")
27
+ @click.option("--system", "system_folders", flag_value=True)
28
+ @click.option(
29
+ "--user", "system_folders", flag_value=False, default=DEFAULT_SERVER_SYSTEM_FOLDERS
30
+ )
31
+ @click.option("--all", "all_servers", flag_value=True, help="Stop all servers")
26
32
  def cli_server_stop(name: str, system_folders: bool, all_servers: bool):
27
33
  """
28
34
  Stop one or all running server(s).
@@ -31,7 +37,8 @@ def cli_server_stop(name: str, system_folders: bool, all_servers: bool):
31
37
  client = docker.from_env()
32
38
 
33
39
  running_servers = client.containers.list(
34
- filters={"label": f"{APPNAME}-type=server"})
40
+ filters={"label": f"{APPNAME}-type={InstanceType.SERVER}"}
41
+ )
35
42
 
36
43
  if not running_servers:
37
44
  warning("No servers are currently running.")
@@ -46,11 +53,12 @@ def cli_server_stop(name: str, system_folders: bool, all_servers: bool):
46
53
 
47
54
  # make sure we have a configuration name to work with
48
55
  if not name:
49
- container_name = q.select("Select the server you wish to stop:",
50
- choices=running_server_names).ask()
56
+ container_name = q.select(
57
+ "Select the server you wish to stop:", choices=running_server_names
58
+ ).ask()
51
59
  else:
52
60
  post_fix = "system" if system_folders else "user"
53
- container_name = f"{APPNAME}-{name}-{post_fix}-server"
61
+ container_name = f"{APPNAME}-{name}-{post_fix}-{InstanceType.SERVER}"
54
62
 
55
63
  if container_name not in running_server_names:
56
64
  error(f"{Fore.RED}{name}{Style.RESET_ALL} is not running!")
@@ -59,8 +67,9 @@ def cli_server_stop(name: str, system_folders: bool, all_servers: bool):
59
67
  _stop_server_containers(client, container_name, system_folders)
60
68
 
61
69
 
62
- def _stop_server_containers(client: DockerClient, container_name: str,
63
- system_folders: bool) -> None:
70
+ def _stop_server_containers(
71
+ client: DockerClient, container_name: str, system_folders: bool
72
+ ) -> None:
64
73
  """
65
74
  Given a server's name, kill its docker container and related (RabbitMQ)
66
75
  containers.
@@ -79,7 +88,6 @@ def _stop_server_containers(client: DockerClient, container_name: str,
79
88
  info(f"Stopped the {Fore.GREEN}{container_name}{Style.RESET_ALL} server.")
80
89
 
81
90
  # find the configuration name from the docker container name
82
- # server name is formatted as f"{APPNAME}-{self.name}-{self.scope}-server"
83
91
  scope = "system" if system_folders else "user"
84
92
  config_name = get_server_config_name(container_name, scope)
85
93
 
@@ -95,13 +103,13 @@ def _stop_server_containers(client: DockerClient, container_name: str,
95
103
 
96
104
  # kill RabbitMQ if it exists and no other servers are using to it (i.e. it
97
105
  # is not in other docker networks with other containers)
98
- rabbit_uri = ctx.config.get('rabbitmq', {}).get('uri')
106
+ rabbit_uri = ctx.config.get("rabbitmq", {}).get("uri")
99
107
  if rabbit_uri:
100
- rabbit_container_name = split_rabbitmq_uri(
101
- rabbit_uri=rabbit_uri)['host']
108
+ rabbit_container_name = split_rabbitmq_uri(rabbit_uri=rabbit_uri)["host"]
102
109
  rabbit_container = get_container(client, name=rabbit_container_name)
103
- if rabbit_container and \
104
- get_num_nonempty_networks(rabbit_container) == 0:
110
+ if rabbit_container and get_num_nonempty_networks(rabbit_container) == 0:
105
111
  remove_container(rabbit_container, kill=True)
106
- info(f"Stopped the {Fore.GREEN}{rabbit_container_name}"
107
- f"{Style.RESET_ALL} container.")
112
+ info(
113
+ f"Stopped the {Fore.GREEN}{rabbit_container_name}"
114
+ f"{Style.RESET_ALL} container."
115
+ )
@@ -4,16 +4,17 @@ 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
 
11
11
 
12
12
  @click.command()
13
13
  @click.option("-n", "--name", default=None, help="Configuration name")
14
- @click.option('--system', 'system_folders', flag_value=True)
15
- @click.option('--user', 'system_folders', flag_value=False,
16
- default=DEFAULT_SERVER_SYSTEM_FOLDERS)
14
+ @click.option("--system", "system_folders", flag_value=True)
15
+ @click.option(
16
+ "--user", "system_folders", flag_value=False, default=DEFAULT_SERVER_SYSTEM_FOLDERS
17
+ )
17
18
  def cli_server_version(name: str, system_folders: bool) -> None:
18
19
  """
19
20
  Print the version of the vantage6 server.
@@ -22,25 +23,27 @@ def cli_server_version(name: str, system_folders: bool) -> None:
22
23
  client = docker.from_env()
23
24
 
24
25
  running_servers = client.containers.list(
25
- filters={"label": f"{APPNAME}-type=server"})
26
+ filters={"label": f"{APPNAME}-type={InstanceType.SERVER}"}
27
+ )
26
28
  running_server_names = [server.name for server in running_servers]
27
29
 
28
30
  if not name:
29
31
  if not running_server_names:
30
- error("No servers are running! You can only check the version for "
31
- "servers that are running")
32
+ error(
33
+ "No servers are running! You can only check the version for "
34
+ "servers that are running"
35
+ )
32
36
  exit(1)
33
- name = q.select("Select the server you wish to inspect:",
34
- choices=running_server_names).ask()
37
+ name = q.select(
38
+ "Select the server you wish to inspect:", choices=running_server_names
39
+ ).ask()
35
40
  else:
36
41
  post_fix = "system" if system_folders else "user"
37
42
  name = f"{APPNAME}-{name}-{post_fix}"
38
43
 
39
44
  if name in running_server_names:
40
45
  container = client.containers.get(name)
41
- version = container.exec_run(cmd='vserver-local version',
42
- stdout=True)
43
- click.echo({"server": version.output.decode('utf-8'),
44
- "cli": __version__})
46
+ version = container.exec_run(cmd="vserver-local version", stdout=True)
47
+ click.echo({"server": version.output.decode("utf-8"), "cli": __version__})
45
48
  else:
46
49
  error(f"Server {name} is not running! Cannot provide version...")