vantage6 5.0.0a7__py3-none-any.whl → 5.0.0a14__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 (37) hide show
  1. tests_cli/test_node_cli.py +4 -21
  2. tests_cli/test_server_cli.py +33 -12
  3. vantage6/cli/__build__ +1 -1
  4. vantage6/cli/algostore/attach.py +6 -42
  5. vantage6/cli/algostore/list.py +1 -1
  6. vantage6/cli/algostore/start.py +2 -2
  7. vantage6/cli/algostore/stop.py +1 -1
  8. vantage6/cli/cli.py +4 -11
  9. vantage6/cli/common/utils.py +25 -3
  10. vantage6/cli/configuration_manager.py +1 -0
  11. vantage6/cli/context/algorithm_store.py +1 -1
  12. vantage6/cli/context/node.py +1 -1
  13. vantage6/cli/node/attach.py +5 -66
  14. vantage6/cli/node/common/__init__.py +1 -1
  15. vantage6/cli/node/start.py +2 -2
  16. vantage6/cli/server/attach.py +5 -55
  17. vantage6/cli/server/import_.py +4 -1
  18. vantage6/cli/server/list.py +2 -1
  19. vantage6/cli/server/shell.py +1 -1
  20. vantage6/cli/server/start.py +5 -2
  21. vantage6/cli/server/stop.py +2 -2
  22. vantage6/cli/server/version.py +2 -2
  23. vantage6/cli/template/algo_store_config.j2 +1 -1
  24. vantage6/cli/template/node_config.j2 +1 -0
  25. vantage6/cli/template/server_config.j2 +1 -1
  26. vantage6/cli/test/common/diagnostic_runner.py +2 -4
  27. vantage6/cli/test/integration_test.py +113 -113
  28. {vantage6-5.0.0a7.dist-info → vantage6-5.0.0a14.dist-info}/METADATA +4 -4
  29. {vantage6-5.0.0a7.dist-info → vantage6-5.0.0a14.dist-info}/RECORD +32 -37
  30. vantage6/cli/dev/create.py +0 -633
  31. vantage6/cli/dev/remove.py +0 -94
  32. vantage6/cli/dev/start.py +0 -123
  33. vantage6/cli/dev/stop.py +0 -47
  34. vantage6/cli/dev/utils.py +0 -24
  35. {vantage6-5.0.0a7.dist-info → vantage6-5.0.0a14.dist-info}/WHEEL +0 -0
  36. {vantage6-5.0.0a7.dist-info → vantage6-5.0.0a14.dist-info}/entry_points.txt +0 -0
  37. {vantage6-5.0.0a7.dist-info → vantage6-5.0.0a14.dist-info}/top_level.txt +0 -0
@@ -1,633 +0,0 @@
1
- from pathlib import Path
2
- from importlib import resources as impresources
3
- import yaml
4
- import click
5
- import pandas as pd
6
-
7
- from jinja2 import Environment, FileSystemLoader
8
- from colorama import Fore, Style
9
-
10
- from vantage6.common.globals import APPNAME, InstanceType, Ports
11
- from vantage6.common import info, error, generate_apikey
12
-
13
- import vantage6.cli.dev.data as data_dir
14
- from vantage6.cli.context.algorithm_store import AlgorithmStoreContext
15
- from vantage6.cli.globals import PACKAGE_FOLDER
16
- from vantage6.cli.context.server import ServerContext
17
- from vantage6.cli.context.node import NodeContext
18
- from vantage6.cli.server.common import get_server_context
19
- from vantage6.cli.server.import_ import cli_server_import
20
- from vantage6.cli.utils import prompt_config_name
21
-
22
-
23
- def create_node_data_files(num_nodes: int, server_name: str) -> list[Path]:
24
- """Create data files for nodes.
25
-
26
- Parameters
27
- ----------
28
- num_nodes : int
29
- Number of nodes to create data files for.
30
- server_name : str
31
- Name of the server.
32
-
33
- Returns
34
- -------
35
- list[Path]
36
- List of paths to the created data files.
37
- """
38
- info(f"Creating data files for {num_nodes} nodes.")
39
- data_files = []
40
- full_df = pd.read_csv(impresources.files(data_dir) / "olympic_athletes_2016.csv")
41
- length_df = len(full_df)
42
- for i in range(num_nodes):
43
- node_name = f"{server_name}_node_{i + 1}"
44
- dev_folder = NodeContext.instance_folders("node", node_name, False)["dev"]
45
- data_folder = Path(dev_folder / server_name)
46
- data_folder.mkdir(parents=True, exist_ok=True)
47
-
48
- # Split the data over the nodes
49
- start = i * length_df // num_nodes
50
- end = (i + 1) * length_df // num_nodes
51
- data = full_df[start:end]
52
- data_file = data_folder / f"{node_name}.csv"
53
-
54
- # write data to file
55
- data.to_csv(data_file, index=False)
56
- data_files.append(data_file)
57
- return data_files
58
-
59
-
60
- def create_node_config_file(
61
- server_url: str, port: int, config: dict, server_name: str, datafile: Path
62
- ) -> None:
63
- """Create a node configuration file (YAML).
64
-
65
- Creates a node configuration for a simulated organization. Organization ID
66
- is used for generating both the organization name and node_name as each
67
- organization only houses one node.
68
-
69
- Parameters
70
- ----------
71
- server_url : str
72
- Url of the dummy server.
73
- port : int
74
- Port of the dummy server.
75
- config : dict
76
- Configuration dictionary containing org_id, api_key, node name and
77
- additional user_defined_config.
78
- server_name : str
79
- Configuration name of the dummy server.
80
- datafile : Path
81
- Path to the data file for the node to use.
82
- """
83
- environment = Environment(
84
- loader=FileSystemLoader(PACKAGE_FOLDER / APPNAME / "cli" / "template"),
85
- trim_blocks=True,
86
- lstrip_blocks=True,
87
- autoescape=True,
88
- )
89
- template = environment.get_template("node_config.j2")
90
-
91
- # TODO: make this name specific to the server it connects
92
- node_name = config["node_name"]
93
- folders = NodeContext.instance_folders("node", node_name, False)
94
- path_to_dev_dir = Path(folders["dev"] / server_name)
95
- path_to_dev_dir.mkdir(parents=True, exist_ok=True)
96
-
97
- path_to_data_dir = Path(folders["data"])
98
- path_to_data_dir.mkdir(parents=True, exist_ok=True)
99
- full_path = Path(folders["config"] / f"{node_name}.yaml")
100
-
101
- if full_path.exists():
102
- error(f"Node configuration file already exists: {full_path}")
103
- exit(1)
104
-
105
- node_config = template.render(
106
- {
107
- "api_key": config["api_key"],
108
- "databases": {"default": datafile},
109
- "logging": {"file": f"{node_name}.log"},
110
- "port": port,
111
- "server_url": server_url,
112
- "task_dir": str(path_to_data_dir),
113
- "user_provided_config": config["user_defined_config"],
114
- }
115
- )
116
-
117
- try:
118
- with open(full_path, "x") as f:
119
- f.write(node_config)
120
- except Exception as e:
121
- error(f"Could not write node configuration file: {e}")
122
- exit(1)
123
-
124
- info(
125
- f"Spawned node for organization {Fore.GREEN}{config['org_id']}"
126
- f"{Style.RESET_ALL}"
127
- )
128
-
129
-
130
- def _read_extra_config_file(extra_config_file: Path | None) -> str:
131
- """Reads extra configuration file.
132
-
133
- Parameters
134
- ----------
135
- extra_config_file : Path | None
136
- Path to file with additional configuration.
137
-
138
- Returns
139
- -------
140
- str
141
- Extra configuration file content
142
- """
143
- if extra_config_file:
144
- # read the YAML file as string, so it can be appended to the
145
- # configuration easily
146
- with open(extra_config_file, "r", encoding="utf-8") as f:
147
- return f.read()
148
- return ""
149
-
150
-
151
- def generate_node_configs(
152
- num_nodes: int,
153
- server_url: str,
154
- port: int,
155
- server_name: str,
156
- extra_node_config: Path | None,
157
- ) -> list[dict]:
158
- """Generates ``num_nodes`` node configuration files.
159
-
160
- Parameters
161
- ----------
162
- num_nodes : int
163
- Integer to determine how many configurations to create.
164
- server_url : str
165
- Url of the dummy server.
166
- port : int
167
- Port of the dummy server.
168
- server_name : str
169
- Configuration name of the dummy server.
170
- extra_node_config : Path | None
171
- Path to file with additional node configuration.
172
-
173
- Returns
174
- -------
175
- list[dict]
176
- List of dictionaries containing node configurations.
177
- """
178
- configs = []
179
- extra_config = _read_extra_config_file(extra_node_config)
180
- node_data_files = create_node_data_files(num_nodes, server_name)
181
- for i in range(num_nodes):
182
- config = {
183
- "org_id": i + 1,
184
- "api_key": generate_apikey(),
185
- "node_name": f"{server_name}_node_{i + 1}",
186
- "user_defined_config": extra_config,
187
- }
188
- create_node_config_file(
189
- server_url, port, config, server_name, node_data_files[i]
190
- )
191
- configs.append(config)
192
-
193
- return configs
194
-
195
-
196
- def create_vserver_import_config(node_configs: list[dict], server_name: str) -> Path:
197
- """Create server configuration import file (YAML).
198
-
199
- Utilized by the ``v6 server import`` command.
200
-
201
- Parameters
202
- ----------
203
- node_configs : list[dict]
204
- List of dictionaries containing the node configurations, returned from
205
- ``generate_node_configs()``.
206
- server_name : str
207
- Server name.
208
-
209
- Returns
210
- -------
211
- Path
212
- Path object where the server import configuration is stored.
213
- """
214
- environment = Environment(
215
- loader=FileSystemLoader(PACKAGE_FOLDER / APPNAME / "cli" / "template"),
216
- trim_blocks=True,
217
- lstrip_blocks=True,
218
- autoescape=True,
219
- )
220
- template = environment.get_template("server_import_config.j2")
221
-
222
- organizations = []
223
- collaboration = {"name": "demo", "participants": []}
224
- for config in node_configs:
225
- org_id = config["org_id"]
226
- org_data = {"name": f"org_{org_id}"}
227
-
228
- organizations.append(org_data)
229
- collaboration["participants"].append(
230
- {"name": f"org_{org_id}", "api_key": config["api_key"]}
231
- )
232
- organizations[0]["make_admin"] = True
233
- info(
234
- f"Organization {Fore.GREEN}{node_configs[0]['org_id']}"
235
- f"{Style.RESET_ALL} is the admin"
236
- )
237
-
238
- server_import_config = template.render(
239
- organizations=organizations, collaboration=collaboration
240
- )
241
- folders = ServerContext.instance_folders(InstanceType.SERVER, server_name, False)
242
-
243
- demo_dir = Path(folders["dev"])
244
- demo_dir.mkdir(parents=True, exist_ok=True)
245
- full_path = demo_dir / f"{server_name}.yaml"
246
- if full_path.exists():
247
- error(f"Server configuration file already exists: {full_path}")
248
- exit(1)
249
-
250
- try:
251
- with open(full_path, "x") as f:
252
- f.write(server_import_config)
253
- info(
254
- "Server import configuration ready, writing to "
255
- f"{Fore.GREEN}{full_path}{Style.RESET_ALL}"
256
- )
257
- except Exception as e:
258
- error(f"Could not write server import configuration file: {e}")
259
- exit(1)
260
-
261
- return full_path
262
-
263
-
264
- def create_vserver_config(
265
- server_name: str,
266
- port: int,
267
- server_url: str,
268
- extra_config_file: Path,
269
- ui_image: str | None,
270
- ui_port: int,
271
- store_port: int,
272
- ) -> Path:
273
- """Creates server configuration file (YAML).
274
-
275
- Parameters
276
- ----------
277
- server_name : str
278
- Server name.
279
- port : int
280
- Server port.
281
- server_url : str
282
- Url of the server this
283
- extra_config_file : Path
284
- Path to file with additional server configuration.
285
- ui_image : str | None
286
- UI docker image to specify in configuration files. Will be used on startup of
287
- the network.
288
- ui_port : int
289
- Port to run the UI on.
290
- store_port : int
291
- Port to run the algorithm store on.
292
-
293
- Returns
294
- -------
295
- Path
296
- Path object where server configuration is stored.
297
- """
298
- environment = Environment(
299
- loader=FileSystemLoader(PACKAGE_FOLDER / APPNAME / "cli" / "template"),
300
- trim_blocks=True,
301
- lstrip_blocks=True,
302
- autoescape=True,
303
- )
304
-
305
- extra_config = _read_extra_config_file(extra_config_file)
306
- if ui_image is not None:
307
- if extra_config:
308
- extra_config += "\n"
309
- extra_config += f"images:\n ui: {ui_image}"
310
-
311
- template = environment.get_template("server_config.j2")
312
- server_config = template.render(
313
- port=port,
314
- host_uri=server_url,
315
- jwt_secret_key=generate_apikey(),
316
- user_provided_config=extra_config,
317
- ui_port=ui_port,
318
- store_port=store_port,
319
- )
320
- folders = ServerContext.instance_folders(
321
- instance_type=InstanceType.SERVER,
322
- instance_name=server_name,
323
- system_folders=False,
324
- )
325
-
326
- config_dir = Path(folders["config"] / server_name)
327
- config_dir.mkdir(parents=True, exist_ok=True)
328
- full_path = folders["config"] / f"{server_name}.yaml"
329
- if full_path.exists():
330
- error(f"Server configuration file already exists: {full_path}")
331
- exit(1)
332
-
333
- try:
334
- with open(full_path, "x") as f:
335
- f.write(server_config)
336
- info(
337
- "Server configuration read, writing to "
338
- f"{Fore.GREEN}{full_path}{Style.RESET_ALL}"
339
- )
340
- except Exception as e:
341
- error(f"Could not write server configuration file: {e}")
342
- exit(1)
343
-
344
- return full_path
345
-
346
-
347
- def create_algo_store_config(
348
- server_name: str,
349
- server_url: str,
350
- server_port: int,
351
- store_port: int,
352
- extra_config_file: Path,
353
- ) -> Path:
354
- """Create algorithm store configuration file (YAML).
355
-
356
- Parameters
357
- ----------
358
- server_name : str
359
- Server name.
360
- server_url : str
361
- Url of the server this store connects to.
362
- server_port : int
363
- Port of the server this store connects to.
364
- port : int
365
- Port of the algorithm store.
366
- extra_config_file : Path
367
- Path to file with additional algorithm store configuration.
368
- """
369
- environment = Environment(
370
- loader=FileSystemLoader(PACKAGE_FOLDER / APPNAME / "cli" / "template"),
371
- trim_blocks=True,
372
- lstrip_blocks=True,
373
- autoescape=True,
374
- )
375
-
376
- extra_config = _read_extra_config_file(extra_config_file)
377
-
378
- template = environment.get_template("algo_store_config.j2")
379
- store_config = template.render(
380
- port=store_port,
381
- server_port=server_port,
382
- host_uri=server_url,
383
- user_provided_config=extra_config,
384
- )
385
- folders = AlgorithmStoreContext.instance_folders(
386
- instance_type=InstanceType.ALGORITHM_STORE,
387
- instance_name="{server_name}_store",
388
- system_folders=False,
389
- )
390
-
391
- config_dir = Path(folders["config"] / f"{server_name}_store")
392
- config_dir.mkdir(parents=True, exist_ok=True)
393
- full_path = folders["config"] / f"{server_name}_store.yaml"
394
- if full_path.exists():
395
- error(f"Algorithm store configuration file already exists: {full_path}")
396
- exit(1)
397
-
398
- try:
399
- with open(full_path, "x") as f:
400
- f.write(store_config)
401
- info(
402
- "Algorithm store configuration ready, writing to "
403
- f"{Fore.GREEN}{full_path}{Style.RESET_ALL}"
404
- )
405
- except Exception as e:
406
- error(f"Could not write algorithm store configuration file: {e}")
407
- exit(1)
408
-
409
- return full_path
410
-
411
-
412
- def demo_network(
413
- num_nodes: int,
414
- server_url: str,
415
- server_port: int,
416
- server_name: str,
417
- extra_server_config: Path,
418
- extra_node_config: Path,
419
- extra_store_config: Path,
420
- ui_image: str,
421
- ui_port: int,
422
- algorithm_store_port: int,
423
- ) -> tuple[list[dict], Path, Path]:
424
- """Generates the demo network.
425
-
426
- Parameters
427
- ----------
428
- num_nodes : int
429
- Integer to determine how many configurations to create.
430
- server_url : str
431
- Url of the dummy server.
432
- server_port : int
433
- Port of the dummy server.
434
- server_name : str
435
- Server name.
436
- extra_server_config : Path
437
- Path to file with additional server configuration.
438
- extra_node_config : Path
439
- Path to file with additional node configuration.
440
- extra_store_config : Path
441
- Path to file with additional algorithm store configuration.
442
- ui_image : str | None
443
- UI docker image to specify in configuration files. Will be used on startup of
444
- the network.
445
- ui_port : int
446
- Port to run the UI on.
447
- algorithm_store_port : int
448
- Port to run the algorithm store on.
449
-
450
- Returns
451
- -------
452
- tuple[list[dict], Path, Path]
453
- Tuple containing node, server import and server configurations.
454
- """
455
- node_configs = generate_node_configs(
456
- num_nodes, server_url, server_port, server_name, extra_node_config
457
- )
458
- server_import_config = create_vserver_import_config(node_configs, server_name)
459
- server_config = create_vserver_config(
460
- server_name,
461
- server_port,
462
- server_url,
463
- extra_server_config,
464
- ui_image,
465
- ui_port,
466
- algorithm_store_port,
467
- )
468
- store_config = create_algo_store_config(
469
- server_name, server_url, server_port, algorithm_store_port, extra_store_config
470
- )
471
- return (node_configs, server_import_config, server_config, store_config)
472
-
473
-
474
- @click.command()
475
- @click.option(
476
- "-n", "--name", default=None, type=str, help="Name for your development setup"
477
- )
478
- @click.option(
479
- "--num-nodes",
480
- type=int,
481
- default=3,
482
- help="Generate this number of nodes in the development network",
483
- )
484
- @click.option(
485
- "--server-url",
486
- type=str,
487
- default="http://host.docker.internal",
488
- help="Server URL to point to. If you are using Docker Desktop, the default "
489
- "http://host.docker.internal should not be changed. If you are using Linux without"
490
- " Docker Desktop, you should set this to http://172.17.0.1",
491
- )
492
- @click.option(
493
- "-p",
494
- "--server-port",
495
- type=int,
496
- default=Ports.DEV_SERVER.value,
497
- help=f"Port to run the server on. Default is {Ports.DEV_SERVER.value}.",
498
- )
499
- @click.option(
500
- "--ui-port",
501
- type=int,
502
- default=Ports.DEV_UI.value,
503
- help=f"Port to run the UI on. Default is {Ports.DEV_UI.value}.",
504
- )
505
- @click.option(
506
- "--algorithm-store-port",
507
- type=int,
508
- default=Ports.DEV_ALGO_STORE.value,
509
- help=(
510
- f"Port to run the algorithm store on. Default is {Ports.DEV_ALGO_STORE.value}."
511
- ),
512
- )
513
- @click.option(
514
- "-i",
515
- "--image",
516
- type=str,
517
- default=None,
518
- help="Server docker image to use when setting up resources for "
519
- "the development server",
520
- )
521
- @click.option(
522
- "--ui-image",
523
- type=str,
524
- default=None,
525
- help="UI docker image to specify in configuration files. Will be used on startup of"
526
- " the network",
527
- )
528
- @click.option(
529
- "--extra-server-config",
530
- type=click.Path(exists=True),
531
- default=None,
532
- help="YAML File with additional server "
533
- "configuration. This will be appended to the server "
534
- "configuration file",
535
- )
536
- @click.option(
537
- "--extra-node-config",
538
- type=click.Path("rb"),
539
- default=None,
540
- help="YAML File with additional node configuration. This will be"
541
- " appended to each of the node configuration files",
542
- )
543
- @click.option(
544
- "--extra-store-config",
545
- type=click.Path("rb"),
546
- default=None,
547
- help="YAML File with additional algorithm store configuration. This will be"
548
- " appended to the algorithm store configuration file",
549
- )
550
- @click.pass_context
551
- def create_demo_network(
552
- click_ctx: click.Context,
553
- name: str,
554
- num_nodes: int,
555
- server_url: str,
556
- server_port: int,
557
- ui_port: int,
558
- algorithm_store_port: int,
559
- image: str = None,
560
- ui_image: str = None,
561
- extra_server_config: Path = None,
562
- extra_node_config: Path = None,
563
- extra_store_config: Path = None,
564
- ) -> dict:
565
- """Creates a demo network.
566
-
567
- Creates server instance as well as its import configuration file. Server
568
- name is set to 'dev_default_server'. Generates `n` node configurations, but
569
- by default this is set to 3. Then runs a Batch import of
570
- organizations/collaborations/users and tasks.
571
- """
572
- server_name = prompt_config_name(name)
573
- if not ServerContext.config_exists(server_name, False):
574
- demo = demo_network(
575
- num_nodes,
576
- server_url,
577
- server_port,
578
- server_name,
579
- extra_server_config,
580
- extra_node_config,
581
- extra_store_config,
582
- ui_image,
583
- ui_port,
584
- algorithm_store_port,
585
- )
586
- info(
587
- f"Created {Fore.GREEN}{len(demo[0])}{Style.RESET_ALL} node "
588
- f"configuration(s), attaching them to {Fore.GREEN}{server_name}"
589
- f"{Style.RESET_ALL}."
590
- )
591
- else:
592
- error(f"Configuration {Fore.RED}{server_name}{Style.RESET_ALL} already exists!")
593
- exit(1)
594
- (node_config, server_import_config, server_config, store_config) = demo
595
- ctx = get_server_context(server_name, False, ServerContext)
596
- click_ctx.invoke(
597
- cli_server_import,
598
- ctx=ctx,
599
- file=server_import_config,
600
- drop_all=False,
601
- image=image,
602
- mount_src="",
603
- keep=False,
604
- wait=True,
605
- )
606
- info(
607
- "Development network was set up successfully! You can now start the "
608
- f"server and nodes with {Fore.GREEN}v6 dev start-demo-network"
609
- f"{Style.RESET_ALL}"
610
- )
611
- # find user credentials to print. Read from server import file
612
- with open(server_import_config, "r") as f:
613
- server_import_config = yaml.safe_load(f)
614
-
615
- try:
616
- user = server_import_config["organizations"][0]["users"][0]
617
- username = user["username"]
618
- password = user["password"]
619
- info(
620
- "You can login with the following credentials:\n"
621
- f"Username: {username}\n"
622
- f"Password: {password}\n"
623
- )
624
- except KeyError:
625
- # No user found, skip printing credentials
626
- pass
627
-
628
- return {
629
- "node_configs": node_config,
630
- "server_import_config": server_import_config,
631
- "server_config": server_config,
632
- "store_config": store_config,
633
- }