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
@@ -5,11 +5,12 @@ import click
5
5
  from jinja2 import Environment, FileSystemLoader
6
6
  from colorama import Fore, Style
7
7
 
8
- from vantage6.common.globals import APPNAME
8
+ from vantage6.common.globals import APPNAME, InstanceType
9
9
  from vantage6.common import info, error, generate_apikey
10
10
 
11
11
  from vantage6.cli.globals import PACKAGE_FOLDER
12
- from vantage6.cli.context import ServerContext, NodeContext
12
+ from vantage6.cli.context.server import ServerContext
13
+ from vantage6.cli.context.node import NodeContext
13
14
  from vantage6.cli.server.common import get_server_context
14
15
  from vantage6.cli.server.import_ import cli_server_import
15
16
  from vantage6.cli.utils import prompt_config_name
@@ -30,14 +31,14 @@ def create_dummy_data(node_name: str, dev_folder: Path) -> Path:
30
31
  Path
31
32
  Directory the data is saved in.
32
33
  """
33
- header = ['name', 'mask', 'weapon', 'age']
34
+ header = ["name", "mask", "weapon", "age"]
34
35
  data = [
35
- ['Raphael', 'red', 'sai', 44],
36
- ['Donatello', 'purple', 'bo staff', 60],
36
+ ["Raphael", "red", "sai", 44],
37
+ ["Donatello", "purple", "bo staff", 60],
37
38
  ]
38
39
 
39
40
  data_file = dev_folder / f"df_{node_name}.csv"
40
- with open(data_file, 'w', encoding='UTF8', newline='') as f:
41
+ with open(data_file, "w", encoding="UTF8", newline="") as f:
41
42
  writer = csv.writer(f)
42
43
 
43
44
  # write the header
@@ -49,13 +50,16 @@ def create_dummy_data(node_name: str, dev_folder: Path) -> Path:
49
50
 
50
51
  f.close()
51
52
 
52
- info(f"Spawned dataset for {Fore.GREEN}{node_name}{Style.RESET_ALL}, "
53
- f"writing to {Fore.GREEN}{data_file}{Style.RESET_ALL}")
53
+ info(
54
+ f"Spawned dataset for {Fore.GREEN}{node_name}{Style.RESET_ALL}, "
55
+ f"writing to {Fore.GREEN}{data_file}{Style.RESET_ALL}"
56
+ )
54
57
  return data_file
55
58
 
56
59
 
57
- def create_node_config_file(server_url: str, port: int, config: dict,
58
- server_name: str) -> None:
60
+ def create_node_config_file(
61
+ server_url: str, port: int, config: dict, server_name: str
62
+ ) -> None:
59
63
  """Create a node configuration file (YAML).
60
64
 
61
65
  Creates a node configuration for a simulated organization. Organization ID
@@ -76,47 +80,50 @@ def create_node_config_file(server_url: str, port: int, config: dict,
76
80
  """
77
81
  environment = Environment(
78
82
  loader=FileSystemLoader(PACKAGE_FOLDER / APPNAME / "cli" / "template"),
79
- trim_blocks=True, lstrip_blocks=True, autoescape=True)
83
+ trim_blocks=True,
84
+ lstrip_blocks=True,
85
+ autoescape=True,
86
+ )
80
87
  template = environment.get_template("node_config.j2")
81
88
 
82
89
  # TODO: make this name specific to the server it connects
83
- node_name = config['node_name']
84
- folders = NodeContext.instance_folders('node', node_name, False)
85
- path_to_dev_dir = Path(folders['dev'] / server_name)
90
+ node_name = config["node_name"]
91
+ folders = NodeContext.instance_folders("node", node_name, False)
92
+ path_to_dev_dir = Path(folders["dev"] / server_name)
86
93
  path_to_dev_dir.mkdir(parents=True, exist_ok=True)
87
94
  dummy_datafile = create_dummy_data(node_name, path_to_dev_dir)
88
95
 
89
- path_to_data_dir = Path(folders['data'])
96
+ path_to_data_dir = Path(folders["data"])
90
97
  path_to_data_dir.mkdir(parents=True, exist_ok=True)
91
- full_path = Path(folders['config'] / f'{node_name}.yaml')
98
+ full_path = Path(folders["config"] / f"{node_name}.yaml")
92
99
 
93
100
  if full_path.exists():
94
101
  error(f"Node configuration file already exists: {full_path}")
95
102
  exit(1)
96
103
 
97
- node_config = template.render({
98
- "api_key": config['api_key'],
99
- "databases": {
100
- "default": dummy_datafile
101
- },
102
- "logging": {
103
- "file": f'{node_name}.log'
104
- },
105
- "port": port,
106
- "server_url": server_url,
107
- "task_dir": str(path_to_data_dir),
108
- "user_provided_config": config['user_defined_config']
109
- })
104
+ node_config = template.render(
105
+ {
106
+ "api_key": config["api_key"],
107
+ "databases": {"default": dummy_datafile},
108
+ "logging": {"file": f"{node_name}.log"},
109
+ "port": port,
110
+ "server_url": server_url,
111
+ "task_dir": str(path_to_data_dir),
112
+ "user_provided_config": config["user_defined_config"],
113
+ }
114
+ )
110
115
 
111
116
  try:
112
- with open(full_path, 'x') as f:
117
+ with open(full_path, "x") as f:
113
118
  f.write(node_config)
114
119
  except Exception as e:
115
120
  error(f"Could not write node configuration file: {e}")
116
121
  exit(1)
117
122
 
118
- info(f"Spawned node for organization {Fore.GREEN}{config['org_id']}"
119
- f"{Style.RESET_ALL}")
123
+ info(
124
+ f"Spawned node for organization {Fore.GREEN}{config['org_id']}"
125
+ f"{Style.RESET_ALL}"
126
+ )
120
127
 
121
128
 
122
129
  def _read_extra_config_file(extra_config_file: Path | None) -> str:
@@ -135,14 +142,17 @@ def _read_extra_config_file(extra_config_file: Path | None) -> str:
135
142
  if extra_config_file:
136
143
  # read the YAML file as string, so it can be appended to the
137
144
  # configuration easily
138
- with open(extra_config_file, 'r', encoding='utf-8') as f:
145
+ with open(extra_config_file, "r", encoding="utf-8") as f:
139
146
  return f.read()
140
- return ''
147
+ return ""
141
148
 
142
149
 
143
150
  def generate_node_configs(
144
- num_nodes: int, server_url: str, port: int, server_name: str,
145
- extra_node_config: Path | None
151
+ num_nodes: int,
152
+ server_url: str,
153
+ port: int,
154
+ server_name: str,
155
+ extra_node_config: Path | None,
146
156
  ) -> list[dict]:
147
157
  """Generates ``num_nodes`` node configuration files.
148
158
 
@@ -168,10 +178,10 @@ def generate_node_configs(
168
178
  extra_config = _read_extra_config_file(extra_node_config)
169
179
  for i in range(num_nodes):
170
180
  config = {
171
- 'org_id': i + 1,
172
- 'api_key': generate_apikey(),
173
- 'node_name': f"{server_name}_node_{i + 1}",
174
- "user_defined_config": extra_config
181
+ "org_id": i + 1,
182
+ "api_key": generate_apikey(),
183
+ "node_name": f"{server_name}_node_{i + 1}",
184
+ "user_defined_config": extra_config,
175
185
  }
176
186
  create_node_config_file(server_url, port, config, server_name)
177
187
  configs.append(config)
@@ -179,8 +189,7 @@ def generate_node_configs(
179
189
  return configs
180
190
 
181
191
 
182
- def create_vserver_import_config(node_configs: list[dict], server_name: str) \
183
- -> Path:
192
+ def create_vserver_import_config(node_configs: list[dict], server_name: str) -> Path:
184
193
  """Create server configuration import file (YAML).
185
194
 
186
195
  Utilized by the ``v6 server import`` command.
@@ -200,38 +209,47 @@ def create_vserver_import_config(node_configs: list[dict], server_name: str) \
200
209
  """
201
210
  environment = Environment(
202
211
  loader=FileSystemLoader(PACKAGE_FOLDER / APPNAME / "cli" / "template"),
203
- trim_blocks=True, lstrip_blocks=True, autoescape=True)
212
+ trim_blocks=True,
213
+ lstrip_blocks=True,
214
+ autoescape=True,
215
+ )
204
216
  template = environment.get_template("server_import_config.j2")
205
217
 
206
218
  organizations = []
207
- collaboration = {'name': 'demo', 'participants': []}
219
+ collaboration = {"name": "demo", "participants": []}
208
220
  for config in node_configs:
209
- org_id = config['org_id']
210
- org_data = {'name': f"org_{org_id}"}
221
+ org_id = config["org_id"]
222
+ org_data = {"name": f"org_{org_id}"}
211
223
 
212
224
  organizations.append(org_data)
213
- collaboration['participants'].append({'name': f"org_{org_id}",
214
- 'api_key': config['api_key']})
215
- organizations[0]['make_admin'] = True
216
- info(f"Organization {Fore.GREEN}{node_configs[0]['org_id']}"
217
- f"{Style.RESET_ALL} is the admin")
225
+ collaboration["participants"].append(
226
+ {"name": f"org_{org_id}", "api_key": config["api_key"]}
227
+ )
228
+ organizations[0]["make_admin"] = True
229
+ info(
230
+ f"Organization {Fore.GREEN}{node_configs[0]['org_id']}"
231
+ f"{Style.RESET_ALL} is the admin"
232
+ )
218
233
 
219
- server_import_config = template.render(organizations=organizations,
220
- collaboration=collaboration)
221
- folders = ServerContext.instance_folders("server", server_name, False)
234
+ server_import_config = template.render(
235
+ organizations=organizations, collaboration=collaboration
236
+ )
237
+ folders = ServerContext.instance_folders(InstanceType.SERVER, server_name, False)
222
238
 
223
- demo_dir = Path(folders['dev'])
239
+ demo_dir = Path(folders["dev"])
224
240
  demo_dir.mkdir(parents=True, exist_ok=True)
225
- full_path = demo_dir / f'{server_name}.yaml'
241
+ full_path = demo_dir / f"{server_name}.yaml"
226
242
  if full_path.exists():
227
243
  error(f"Server configuration file already exists: {full_path}")
228
244
  exit(1)
229
245
 
230
246
  try:
231
- with open(full_path, 'x') as f:
247
+ with open(full_path, "x") as f:
232
248
  f.write(server_import_config)
233
- info("Server import configuration ready, writing to "
234
- f"{Fore.GREEN}{full_path}{Style.RESET_ALL}")
249
+ info(
250
+ "Server import configuration ready, writing to "
251
+ f"{Fore.GREEN}{full_path}{Style.RESET_ALL}"
252
+ )
235
253
  except Exception as e:
236
254
  error(f"Could not write server import configuration file: {e}")
237
255
  exit(1)
@@ -239,9 +257,7 @@ def create_vserver_import_config(node_configs: list[dict], server_name: str) \
239
257
  return full_path
240
258
 
241
259
 
242
- def create_vserver_config(
243
- server_name: str, port: int, extra_config_file: Path
244
- ) -> Path:
260
+ def create_vserver_config(server_name: str, port: int, extra_config_file: Path) -> Path:
245
261
  """Creates server configuration file (YAML).
246
262
 
247
263
  Parameters
@@ -260,32 +276,35 @@ def create_vserver_config(
260
276
  """
261
277
  environment = Environment(
262
278
  loader=FileSystemLoader(PACKAGE_FOLDER / APPNAME / "cli" / "template"),
263
- trim_blocks=True, lstrip_blocks=True, autoescape=True)
279
+ trim_blocks=True,
280
+ lstrip_blocks=True,
281
+ autoescape=True,
282
+ )
264
283
 
265
284
  extra_config = _read_extra_config_file(extra_config_file)
266
285
 
267
286
  template = environment.get_template("server_config.j2")
268
287
  server_config = template.render(
269
- port=port,
270
- jwt_secret_key=generate_apikey(),
271
- user_provided_config=extra_config
288
+ port=port, jwt_secret_key=generate_apikey(), user_provided_config=extra_config
272
289
  )
273
290
  folders = ServerContext.instance_folders(
274
- instance_type='server', instance_name=server_name,
275
- system_folders=True)
291
+ instance_type="server", instance_name=server_name, system_folders=True
292
+ )
276
293
 
277
- config_dir = Path(folders['config'] / server_name)
294
+ config_dir = Path(folders["config"] / server_name)
278
295
  config_dir.mkdir(parents=True, exist_ok=True)
279
- full_path = folders["config"] / f'{server_name}.yaml'
296
+ full_path = folders["config"] / f"{server_name}.yaml"
280
297
  if full_path.exists():
281
298
  error(f"Server configuration file already exists: {full_path}")
282
299
  exit(1)
283
300
 
284
301
  try:
285
- with open(full_path, 'x') as f:
302
+ with open(full_path, "x") as f:
286
303
  f.write(server_config)
287
- info("Server configuration read, writing to "
288
- f"{Fore.GREEN}{full_path}{Style.RESET_ALL}")
304
+ info(
305
+ "Server configuration read, writing to "
306
+ f"{Fore.GREEN}{full_path}{Style.RESET_ALL}"
307
+ )
289
308
  except Exception as e:
290
309
  error(f"Could not write server configuration file: {e}")
291
310
  exit(1)
@@ -294,8 +313,12 @@ def create_vserver_config(
294
313
 
295
314
 
296
315
  def demo_network(
297
- num_nodes: int, server_url: str, server_port: int, server_name: str,
298
- extra_server_config: Path, extra_node_config: Path
316
+ num_nodes: int,
317
+ server_url: str,
318
+ server_port: int,
319
+ server_name: str,
320
+ extra_server_config: Path,
321
+ extra_node_config: Path,
299
322
  ) -> tuple[list[dict], Path, Path]:
300
323
  """Generates the demo network.
301
324
 
@@ -319,40 +342,71 @@ def demo_network(
319
342
  tuple[list[dict], Path, Path]
320
343
  Tuple containing node, server import and server configurations.
321
344
  """
322
- node_configs = generate_node_configs(num_nodes, server_url, server_port,
323
- server_name, extra_node_config)
324
- server_import_config = create_vserver_import_config(node_configs,
325
- server_name)
326
- server_config = create_vserver_config(server_name, server_port,
327
- extra_server_config)
345
+ node_configs = generate_node_configs(
346
+ num_nodes, server_url, server_port, server_name, extra_node_config
347
+ )
348
+ server_import_config = create_vserver_import_config(node_configs, server_name)
349
+ server_config = create_vserver_config(server_name, server_port, extra_server_config)
328
350
  return (node_configs, server_import_config, server_config)
329
351
 
330
352
 
331
353
  @click.command()
332
- @click.option('-n', '--name', default=None, type=str,
333
- help="Name for your development setup")
334
- @click.option('--num-nodes', type=int, default=3,
335
- help='Generate this number of nodes in the development network')
336
- @click.option('--server-url', type=str, default='http://host.docker.internal',
337
- help='Server URL to point to. If you are using Docker Desktop, '
338
- 'the default http://host.docker.internal should not be changed.')
339
- @click.option('-p', '--server-port', type=int, default=5000,
340
- help='Port to run the server on. Default is 5000.')
341
- @click.option('-i', '--image', type=str, default=None,
342
- help='Server docker image to use when setting up resources for '
343
- 'the development server')
344
- @click.option('--extra-server-config', type=click.Path(exists=True),
345
- default=None, help='YAML File with additional server '
346
- 'configuration. This will be appended to the server '
347
- 'configuration file')
348
- @click.option('--extra-node-config', type=click.Path('rb'), default=None,
349
- help='YAML File with additional node configuration. This will be'
350
- ' appended to each of the node configuration files')
354
+ @click.option(
355
+ "-n", "--name", default=None, type=str, help="Name for your development setup"
356
+ )
357
+ @click.option(
358
+ "--num-nodes",
359
+ type=int,
360
+ default=3,
361
+ help="Generate this number of nodes in the development network",
362
+ )
363
+ @click.option(
364
+ "--server-url",
365
+ type=str,
366
+ default="http://host.docker.internal",
367
+ help="Server URL to point to. If you are using Docker Desktop, "
368
+ "the default http://host.docker.internal should not be changed.",
369
+ )
370
+ @click.option(
371
+ "-p",
372
+ "--server-port",
373
+ type=int,
374
+ default=5000,
375
+ help="Port to run the server on. Default is 5000.",
376
+ )
377
+ @click.option(
378
+ "-i",
379
+ "--image",
380
+ type=str,
381
+ default=None,
382
+ help="Server docker image to use when setting up resources for "
383
+ "the development server",
384
+ )
385
+ @click.option(
386
+ "--extra-server-config",
387
+ type=click.Path(exists=True),
388
+ default=None,
389
+ help="YAML File with additional server "
390
+ "configuration. This will be appended to the server "
391
+ "configuration file",
392
+ )
393
+ @click.option(
394
+ "--extra-node-config",
395
+ type=click.Path("rb"),
396
+ default=None,
397
+ help="YAML File with additional node configuration. This will be"
398
+ " appended to each of the node configuration files",
399
+ )
351
400
  @click.pass_context
352
401
  def create_demo_network(
353
- click_ctx: click.Context, name: str, num_nodes: int, server_url: str,
354
- server_port: int, image: str = None, extra_server_config: Path = None,
355
- extra_node_config: Path = None
402
+ click_ctx: click.Context,
403
+ name: str,
404
+ num_nodes: int,
405
+ server_url: str,
406
+ server_port: int,
407
+ image: str = None,
408
+ extra_server_config: Path = None,
409
+ extra_node_config: Path = None,
356
410
  ) -> dict:
357
411
  """Creates a demo network.
358
412
 
@@ -364,24 +418,37 @@ def create_demo_network(
364
418
  server_name = prompt_config_name(name)
365
419
  if not ServerContext.config_exists(server_name):
366
420
  demo = demo_network(
367
- num_nodes, server_url, server_port, server_name,
368
- extra_server_config, extra_node_config
421
+ num_nodes,
422
+ server_url,
423
+ server_port,
424
+ server_name,
425
+ extra_server_config,
426
+ extra_node_config,
427
+ )
428
+ info(
429
+ f"Created {Fore.GREEN}{len(demo[0])}{Style.RESET_ALL} node "
430
+ f"configuration(s), attaching them to {Fore.GREEN}{server_name}"
431
+ f"{Style.RESET_ALL}."
369
432
  )
370
- info(f"Created {Fore.GREEN}{len(demo[0])}{Style.RESET_ALL} node "
371
- f"configuration(s), attaching them to {Fore.GREEN}{server_name}"
372
- f"{Style.RESET_ALL}.")
373
433
  else:
374
- error(f"Configuration {Fore.RED}{server_name}{Style.RESET_ALL} "
375
- "already exists!")
434
+ error(
435
+ f"Configuration {Fore.RED}{server_name}{Style.RESET_ALL} " "already exists!"
436
+ )
376
437
  exit(1)
377
438
  (node_config, server_import_config, server_config) = demo
378
439
  ctx = get_server_context(server_name, True)
379
440
  click_ctx.invoke(
380
- cli_server_import, ctx=ctx, file=server_import_config, drop_all=False,
381
- image=image, mount_src='', keep=False, wait=True
441
+ cli_server_import,
442
+ ctx=ctx,
443
+ file=server_import_config,
444
+ drop_all=False,
445
+ image=image,
446
+ mount_src="",
447
+ keep=False,
448
+ wait=True,
382
449
  )
383
450
  return {
384
451
  "node_configs": node_config,
385
452
  "server_import_config": server_import_config,
386
- "server_config": server_config
453
+ "server_config": server_config,
387
454
  }
@@ -6,19 +6,19 @@ from pathlib import Path
6
6
  import click
7
7
 
8
8
  from vantage6.common import info
9
- from vantage6.cli.context import ServerContext, NodeContext
9
+ from vantage6.cli.context.server import ServerContext
10
+ from vantage6.cli.context.node import NodeContext
10
11
  from vantage6.cli.server.common import click_insert_context
11
12
  from vantage6.cli.server.remove import cli_server_remove
12
13
  from vantage6.cli.utils import remove_file
14
+ from vantage6.common.globals import InstanceType
13
15
 
14
16
 
15
17
  @click.command()
16
18
  @click_insert_context
17
19
  @click.pass_context
18
- def remove_demo_network(
19
- click_ctx: click.Context, ctx: ServerContext
20
- ) -> None:
21
- """ Remove all related demo network files and folders.
20
+ def remove_demo_network(click_ctx: click.Context, ctx: ServerContext) -> None:
21
+ """Remove all related demo network files and folders.
22
22
 
23
23
  Select a server configuration to remove that server and the nodes attached
24
24
  to it.
@@ -31,32 +31,33 @@ def remove_demo_network(
31
31
 
32
32
  # removing the server import config
33
33
  info("Deleting demo import config file")
34
- server_configs = ServerContext.instance_folders("server", ctx.name,
35
- system_folders=False)
36
- import_config_to_del = Path(server_configs['dev']) / f"{ctx.name}.yaml"
37
- remove_file(import_config_to_del, 'import_configuration')
34
+ server_configs = ServerContext.instance_folders(
35
+ InstanceType.SERVER, ctx.name, system_folders=False
36
+ )
37
+ import_config_to_del = Path(server_configs["dev"]) / f"{ctx.name}.yaml"
38
+ remove_file(import_config_to_del, "import_configuration")
38
39
 
39
40
  # also remove the server folder
40
- server_configs = ServerContext.instance_folders("server", ctx.name,
41
- system_folders=True)
42
- server_folder = server_configs['data']
41
+ server_configs = ServerContext.instance_folders(
42
+ InstanceType.SERVER, ctx.name, system_folders=True
43
+ )
44
+ server_folder = server_configs["data"]
43
45
  if server_folder.is_dir():
44
46
  rmtree(server_folder)
45
47
 
46
48
  # remove the nodes
47
49
  configs, _ = NodeContext.available_configurations(system_folders=False)
48
50
  node_names = [
49
- config.name for config in configs if f'{ctx.name}_node_' in config.name
51
+ config.name for config in configs if f"{ctx.name}_node_" in config.name
50
52
  ]
51
53
  for name in node_names:
52
54
  node_ctx = NodeContext(name, False)
53
- for handler in itertools.chain(node_ctx.log.handlers,
54
- node_ctx.log.root.handlers):
55
+ for handler in itertools.chain(
56
+ node_ctx.log.handlers, node_ctx.log.root.handlers
57
+ ):
55
58
  handler.close()
56
- subprocess.run(
57
- ["v6", "node", "remove", "-n", name, "--user", "--force"]
58
- )
59
+ subprocess.run(["v6", "node", "remove", "-n", name, "--user", "--force"])
59
60
 
60
61
  # remove data files attached to the network
61
- data_dirs_nodes = NodeContext.instance_folders('node', '', False)['dev']
62
+ data_dirs_nodes = NodeContext.instance_folders("node", "", False)["dev"]
62
63
  rmtree(Path(data_dirs_nodes / ctx.name))
vantage6/cli/dev/start.py CHANGED
@@ -1,21 +1,21 @@
1
1
  import subprocess
2
2
  import click
3
3
 
4
- from vantage6.cli.context import ServerContext, NodeContext
4
+ from vantage6.cli.context.server import ServerContext
5
+ from vantage6.cli.context.node import NodeContext
5
6
  from vantage6.cli.server.common import click_insert_context
6
7
  from vantage6.cli.server.start import cli_server_start
7
8
 
8
9
 
9
10
  @click.command()
10
11
  @click_insert_context
11
- @click.option('--server-image', type=str, default=None,
12
- help='Server Docker image to use')
13
- @click.option('--node-image', type=str, default=None,
14
- help='Node Docker image to use')
12
+ @click.option(
13
+ "--server-image", type=str, default=None, help="Server Docker image to use"
14
+ )
15
+ @click.option("--node-image", type=str, default=None, help="Node Docker image to use")
15
16
  @click.pass_context
16
17
  def start_demo_network(
17
- click_ctx: click.Context, ctx: ServerContext, server_image: str,
18
- node_image: str
18
+ click_ctx: click.Context, ctx: ServerContext, server_image: str, node_image: str
19
19
  ) -> None:
20
20
  """Starts running a demo-network.
21
21
 
@@ -36,14 +36,14 @@ def start_demo_network(
36
36
  start_rabbitmq=False,
37
37
  rabbitmq_image=None,
38
38
  keep=True,
39
- mount_src='',
40
- attach=False
39
+ mount_src="",
40
+ attach=False,
41
41
  )
42
42
 
43
43
  # run all nodes that belong to this server
44
44
  configs, _ = NodeContext.available_configurations(system_folders=False)
45
45
  node_names = [
46
- config.name for config in configs if f'{ctx.name}_node_' in config.name
46
+ config.name for config in configs if f"{ctx.name}_node_" in config.name
47
47
  ]
48
48
  for name in node_names:
49
49
  cmd = ["v6", "node", "start", "--name", name]
vantage6/cli/dev/stop.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import click
2
2
 
3
- from vantage6.cli.context import ServerContext, NodeContext
3
+ from vantage6.cli.context.server import ServerContext
4
+ from vantage6.cli.context.node import NodeContext
4
5
  from vantage6.cli.server.common import click_insert_context
5
6
  from vantage6.cli.server.stop import cli_server_stop
6
7
  from vantage6.cli.node.stop import cli_node_stop
@@ -10,7 +11,7 @@ from vantage6.cli.node.stop import cli_node_stop
10
11
  @click_insert_context
11
12
  @click.pass_context
12
13
  def stop_demo_network(click_ctx: click.Context, ctx: ServerContext) -> None:
13
- """ Stops a demo network's server and nodes.
14
+ """Stops a demo network's server and nodes.
14
15
 
15
16
  Select a server configuration to stop that server and the nodes attached
16
17
  to it.
@@ -23,8 +24,9 @@ def stop_demo_network(click_ctx: click.Context, ctx: ServerContext) -> None:
23
24
  # stop the nodes
24
25
  configs, _ = NodeContext.available_configurations(False)
25
26
  node_names = [
26
- config.name for config in configs if f'{ctx.name}_node_' in config.name
27
+ config.name for config in configs if f"{ctx.name}_node_" in config.name
27
28
  ]
28
29
  for name in node_names:
29
- click_ctx.invoke(cli_node_stop, name=name, system_folders=False,
30
- all_nodes=False, force=False)
30
+ click_ctx.invoke(
31
+ cli_node_stop, name=name, system_folders=False, all_nodes=False, force=False
32
+ )
vantage6/cli/globals.py CHANGED
@@ -1,6 +1,7 @@
1
1
  """
2
2
  This module contains global variables that are used throughout the CLI.
3
3
  """
4
+ from enum import Enum
4
5
  from pathlib import Path
5
6
  from vantage6.common.globals import APPNAME
6
7
 
@@ -39,3 +40,26 @@ ALGORITHM_TEMPLATE_REPO = "gh:vantage6/v6-algorithm-template.git"
39
40
 
40
41
  # image to use for diagnostics in `v6 test` commands
41
42
  DIAGNOSTICS_IMAGE = "harbor2.vantage6.ai/algorithms/diagnostic"
43
+
44
+
45
+ class ServerType(str, Enum):
46
+ """Enum containing server types"""
47
+
48
+ V6SERVER = "server"
49
+ ALGORITHM_STORE = "algorithm-store"
50
+
51
+
52
+ class ServerGlobals(str, Enum):
53
+ """Enum containing server environment variables"""
54
+
55
+ DB_URI_ENV_VAR = "VANTAGE6_DB_URI"
56
+ CONFIG_NAME_ENV_VAR = "VANTAGE6_CONFIG_NAME"
57
+ PORT = "5000"
58
+
59
+
60
+ class AlgoStoreGlobals(str, Enum):
61
+ """Enum containing algorithm store environment variables"""
62
+
63
+ DB_URI_ENV_VAR = "VANTAGE6_ALGO_STORE_DB_URI"
64
+ CONFIG_NAME_ENV_VAR = "VANTAGE6_ALGO_STORE_CONFIG_NAME"
65
+ PORT = "5002" # 5001 is the default UI port