vantage6 5.0.0a29__py3-none-any.whl → 5.0.0a34__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 (45) hide show
  1. vantage6/cli/__init__.py +5 -1
  2. vantage6/cli/algorithm/generate_algorithm_json.py +3 -11
  3. vantage6/cli/algostore/new.py +24 -46
  4. vantage6/cli/algostore/start.py +33 -67
  5. vantage6/cli/algostore/stop.py +75 -40
  6. vantage6/cli/common/new.py +60 -0
  7. vantage6/cli/common/start.py +17 -223
  8. vantage6/cli/common/stop.py +1 -1
  9. vantage6/cli/common/utils.py +212 -16
  10. vantage6/cli/configuration_manager.py +65 -0
  11. vantage6/cli/configuration_wizard.py +95 -76
  12. vantage6/cli/context/algorithm_store.py +8 -7
  13. vantage6/cli/context/base_server.py +22 -30
  14. vantage6/cli/context/node.py +11 -2
  15. vantage6/cli/context/server.py +17 -8
  16. vantage6/cli/globals.py +12 -11
  17. vantage6/cli/node/common/__init__.py +1 -1
  18. vantage6/cli/node/create_private_key.py +9 -6
  19. vantage6/cli/node/set_api_key.py +7 -4
  20. vantage6/cli/node/start.py +1 -1
  21. vantage6/cli/node/stop.py +7 -7
  22. vantage6/cli/server/import_.py +1 -2
  23. vantage6/cli/server/list.py +0 -3
  24. vantage6/cli/server/new.py +13 -51
  25. vantage6/cli/server/shell.py +1 -1
  26. vantage6/cli/server/start.py +17 -17
  27. vantage6/cli/server/stop.py +64 -15
  28. vantage6/cli/template/algo_store_config.j2 +195 -22
  29. vantage6/cli/template/server_config.j2 +255 -33
  30. vantage6-5.0.0a34.dist-info/METADATA +54 -0
  31. {vantage6-5.0.0a29.dist-info → vantage6-5.0.0a34.dist-info}/RECORD +33 -42
  32. {vantage6-5.0.0a29.dist-info → vantage6-5.0.0a34.dist-info}/WHEEL +1 -2
  33. vantage6-5.0.0a34.dist-info/entry_points.txt +2 -0
  34. tests_cli/__init__.py +0 -0
  35. tests_cli/test_client_script.py +0 -23
  36. tests_cli/test_example.py +0 -7
  37. tests_cli/test_node_cli.py +0 -452
  38. tests_cli/test_server_cli.py +0 -180
  39. tests_cli/test_wizard.py +0 -141
  40. vantage6/cli/__build__ +0 -1
  41. vantage6/cli/_version.py +0 -23
  42. vantage6/cli/template/server_import_config.j2 +0 -31
  43. vantage6-5.0.0a29.dist-info/METADATA +0 -238
  44. vantage6-5.0.0a29.dist-info/entry_points.txt +0 -5
  45. vantage6-5.0.0a29.dist-info/top_level.txt +0 -2
vantage6/cli/__init__.py CHANGED
@@ -1,3 +1,7 @@
1
1
  """Command line interface for the vantage6 infrastructure."""
2
2
 
3
- from ._version import version_info, __version__ # noqa: F401
3
+ import importlib.metadata
4
+
5
+ # note that here we cannot use __package__ because __package__ resolves to vantage6.cli
6
+ # whereas the PyPi package is called vantage6
7
+ __version__ = importlib.metadata.version("vantage6")
@@ -19,8 +19,6 @@ from vantage6.common.algorithm_function import (
19
19
  )
20
20
  from vantage6.common.enum import AlgorithmArgumentType, AlgorithmStepType, StrEnumBase
21
21
 
22
- from vantage6.algorithm.tools import DecoratorStepType
23
-
24
22
  from vantage6.algorithm.client import AlgorithmClient
25
23
  from vantage6.algorithm.preprocessing.algorithm_json_data import (
26
24
  PREPROCESSING_FUNCTIONS_JSON_DATA,
@@ -120,7 +118,7 @@ class Function:
120
118
  # infrastructure-defined function
121
119
  if (
122
120
  not self.func.__module__.startswith("vantage6.algorithm.")
123
- or not self.json["name"] in PREPROCESSING_FUNCTIONS_JSON_DATA
121
+ or self.json["name"] not in PREPROCESSING_FUNCTIONS_JSON_DATA
124
122
  ):
125
123
  return
126
124
 
@@ -327,14 +325,8 @@ class Function:
327
325
  def _get_step_type(self) -> AlgorithmStepType | None:
328
326
  """Get the step type of the function"""
329
327
  decorator_type = get_vantage6_decorator_type(self.func)
330
- if decorator_type == DecoratorStepType.FEDERATED:
331
- return AlgorithmStepType.FEDERATED_COMPUTE
332
- elif decorator_type == DecoratorStepType.CENTRAL:
333
- return AlgorithmStepType.CENTRAL_COMPUTE
334
- elif decorator_type == DecoratorStepType.PREPROCESSING:
335
- return AlgorithmStepType.PREPROCESSING
336
- elif decorator_type == DecoratorStepType.DATA_EXTRACTION:
337
- return AlgorithmStepType.DATA_EXTRACTION
328
+ if decorator_type in AlgorithmStepType.list():
329
+ return decorator_type
338
330
  else:
339
331
  warning(
340
332
  f"Unsupported decorator type: {decorator_type} for function {self.name}"
@@ -1,61 +1,39 @@
1
1
  import click
2
- from colorama import Fore, Style
3
2
 
4
- from vantage6.common import info, error, ensure_config_dir_writable
5
3
  from vantage6.common.globals import InstanceType
4
+
5
+ from vantage6.cli.common.new import new
6
6
  from vantage6.cli.globals import DEFAULT_SERVER_SYSTEM_FOLDERS
7
- from vantage6.cli.context.algorithm_store import AlgorithmStoreContext
8
- from vantage6.cli.configuration_wizard import configuration_wizard
9
- from vantage6.cli.utils import check_config_name_allowed, prompt_config_name
10
7
 
11
8
 
12
9
  @click.command()
13
10
  @click.option(
14
- "-n", "--name", default=None, help="name of the configuration you want to use."
11
+ "-n", "--name", default=None, help="Name of the configuration you want to use."
12
+ )
13
+ @click.option(
14
+ "--system",
15
+ "system_folders",
16
+ flag_value=True,
17
+ help="Use system folders instead of user folders. This is the default",
18
+ )
19
+ @click.option(
20
+ "--user",
21
+ "system_folders",
22
+ flag_value=False,
23
+ default=DEFAULT_SERVER_SYSTEM_FOLDERS,
24
+ help="Use user folders instead of system folders",
15
25
  )
16
- @click.option("--system", "system_folders", flag_value=True)
26
+ @click.option("--context", default=None, help="Kubernetes context to use")
17
27
  @click.option(
18
- "--user", "system_folders", flag_value=False, default=DEFAULT_SERVER_SYSTEM_FOLDERS
28
+ "--namespace",
29
+ default=None,
30
+ help="Kubernetes namespace to use",
19
31
  )
20
- def cli_algo_store_new(name: str, system_folders: bool) -> None:
32
+ def cli_algo_store_new(
33
+ name: str, system_folders: bool, namespace: str, context: str
34
+ ) -> None:
21
35
  """
22
36
  Create a new server configuration.
23
37
  """
24
- name = prompt_config_name(name)
25
-
26
- # check if name is allowed for docker volume, else exit
27
- check_config_name_allowed(name)
28
-
29
- # check that this config does not exist
30
- try:
31
- if AlgorithmStoreContext.config_exists(name, system_folders):
32
- error(f"Configuration {Fore.RED}{name}{Style.RESET_ALL} already " "exists!")
33
- exit(1)
34
- except Exception as e:
35
- error(e)
36
- exit(1)
37
-
38
- # Check that we can write in this folder
39
- if not ensure_config_dir_writable(system_folders):
40
- error("Your user does not have write access to all folders. Exiting")
41
- info(
42
- f"Create a new server using '{Fore.GREEN}v6 algorithm-store new "
43
- f"--user{Style.RESET_ALL}' instead!"
44
- )
45
- exit(1)
46
-
47
- # create config in ctx location
48
- try:
49
- cfg_file = configuration_wizard(
50
- InstanceType.ALGORITHM_STORE, name, system_folders
51
- )
52
- except KeyboardInterrupt:
53
- error("Configuration creation aborted.")
54
- exit(1)
55
- info(f"New configuration created: {Fore.GREEN}{cfg_file}{Style.RESET_ALL}")
56
38
 
57
- flag = "" if system_folders else "--user"
58
- info(
59
- f"You can start the algorithm store by running {Fore.GREEN}v6 "
60
- f"algorithm-store start {flag}{Style.RESET_ALL}"
61
- )
39
+ new(name, system_folders, namespace, context, InstanceType.ALGORITHM_STORE)
@@ -2,39 +2,29 @@ import click
2
2
 
3
3
  from vantage6.common import info
4
4
  from vantage6.common.globals import (
5
- APPNAME,
6
- DEFAULT_ALGO_STORE_IMAGE,
7
5
  InstanceType,
8
6
  Ports,
9
7
  )
10
8
 
11
9
  from vantage6.cli.common.decorator import click_insert_context
12
10
  from vantage6.cli.common.start import (
11
+ helm_install,
12
+ start_port_forward,
13
+ )
14
+ from vantage6.cli.common.utils import (
13
15
  attach_logs,
14
- check_for_start,
15
- get_image,
16
- mount_config_file,
17
- mount_database,
18
- mount_source,
19
- pull_infra_image,
16
+ create_directory_if_not_exists,
17
+ select_context_and_namespace,
20
18
  )
21
19
  from vantage6.cli.context.algorithm_store import AlgorithmStoreContext
20
+ from vantage6.cli.globals import ChartName
22
21
 
23
22
 
24
23
  @click.command()
24
+ @click.option("--context", default=None, help="Kubernetes context to use")
25
+ @click.option("--namespace", default=None, help="Kubernetes namespace to use")
25
26
  @click.option("--ip", default=None, help="IP address to listen on")
26
27
  @click.option("-p", "--port", default=None, type=int, help="Port to listen on")
27
- @click.option("-i", "--image", default=None, help="Algorithm store Docker image to use")
28
- @click.option(
29
- "--keep/--auto-remove",
30
- default=False,
31
- help="Keep image after algorithm store has been stopped. Useful for debugging",
32
- )
33
- @click.option(
34
- "--mount-src",
35
- default="",
36
- help="Override vantage6 source code in container with the source code in this path",
37
- )
38
28
  @click.option(
39
29
  "--attach/--detach",
40
30
  default=False,
@@ -43,65 +33,41 @@ from vantage6.cli.context.algorithm_store import AlgorithmStoreContext
43
33
  @click_insert_context(InstanceType.ALGORITHM_STORE)
44
34
  def cli_algo_store_start(
45
35
  ctx: AlgorithmStoreContext,
36
+ context: str,
37
+ namespace: str,
46
38
  ip: str,
47
39
  port: int,
48
- image: str,
49
- keep: bool,
50
- mount_src: str,
51
40
  attach: bool,
52
41
  ) -> None:
53
42
  """
54
- Start the algorithm store server.
43
+ Start the algorithm store.
55
44
  """
56
45
  info("Starting algorithm store...")
57
- docker_client = check_for_start(ctx, InstanceType.ALGORITHM_STORE)
58
-
59
- image = get_image(image, ctx, "algorithm-store", DEFAULT_ALGO_STORE_IMAGE)
60
-
61
- info("Pulling algorithm store image...")
62
- pull_infra_image(docker_client, image, InstanceType.ALGORITHM_STORE)
63
-
64
- config_file = "/mnt/config.yaml"
65
- mounts = mount_config_file(ctx, config_file)
66
-
67
- src_mount = mount_source(mount_src)
68
- if src_mount:
69
- mounts.append(src_mount)
46
+ context, namespace = select_context_and_namespace(
47
+ context=context,
48
+ namespace=namespace,
49
+ )
70
50
 
71
- mount, environment_vars = mount_database(ctx, InstanceType.ALGORITHM_STORE)
72
- if mount:
73
- mounts.append(mount)
51
+ create_directory_if_not_exists(ctx.log_dir)
74
52
 
75
- # The `ip` and `port` refer here to the ip and port within the container.
76
- # So we do not really care that is it listening on all interfaces.
77
- internal_port = 5000
78
- cmd = (
79
- f"uwsgi --http :{internal_port} --gevent 1000 --http-websockets "
80
- "--master --callable app --disable-logging "
81
- "--wsgi-file /vantage6/vantage6-algorithm-store/vantage6/algorithm"
82
- f"/store/wsgi.py --pyargv {config_file}"
53
+ helm_install(
54
+ release_name=ctx.helm_release_name,
55
+ chart_name=ChartName.ALGORITHM_STORE,
56
+ values_file=ctx.config_file,
57
+ context=context,
58
+ namespace=namespace,
83
59
  )
84
- info(cmd)
85
60
 
86
- info("Run Docker container")
87
- port_ = str(port or ctx.config["port"] or Ports.DEV_ALGO_STORE)
88
- container = docker_client.containers.run(
89
- image,
90
- command=cmd,
91
- mounts=mounts,
92
- detach=True,
93
- labels={
94
- f"{APPNAME}-type": InstanceType.ALGORITHM_STORE.value,
95
- "name": ctx.config_file_name,
96
- },
97
- environment=environment_vars,
98
- ports={f"{internal_port}/tcp": (ip, port_)},
99
- name=ctx.docker_container_name,
100
- auto_remove=not keep,
101
- tty=True,
61
+ # port forward for server
62
+ info("Port forwarding for algorithm store")
63
+ start_port_forward(
64
+ service_name=f"{ctx.helm_release_name}-vantage6-algorithm-store-service",
65
+ service_port=ctx.config["store"].get("port", Ports.DEV_ALGO_STORE.value),
66
+ port=port or ctx.config["store"].get("port", Ports.DEV_ALGO_STORE.value),
67
+ ip=ip,
68
+ context=context,
69
+ namespace=namespace,
102
70
  )
103
71
 
104
- info(f"Success! container id = {container.id}")
105
-
106
72
  if attach:
107
- attach_logs(container, InstanceType.ALGORITHM_STORE)
73
+ attach_logs("app=store", "component=store-server")
@@ -1,61 +1,96 @@
1
1
  import click
2
- import docker
3
2
  from colorama import Fore, Style
4
3
 
5
- from vantage6.common import error, info, warning
6
- from vantage6.common.docker.addons import (
7
- check_docker_running,
8
- remove_container_if_exists,
9
- )
10
- from vantage6.common.globals import APPNAME, InstanceType
4
+ from vantage6.common import error, info
5
+ from vantage6.common.globals import InstanceType
11
6
 
12
- from vantage6.cli.common.decorator import click_insert_context
13
- from vantage6.cli.context.algorithm_store import AlgorithmStoreContext
7
+ from vantage6.cli.common.stop import helm_uninstall, stop_port_forward
8
+ from vantage6.cli.common.utils import (
9
+ find_running_service_names,
10
+ select_context_and_namespace,
11
+ select_running_service,
12
+ )
13
+ from vantage6.cli.context import get_context
14
+ from vantage6.cli.globals import DEFAULT_SERVER_SYSTEM_FOLDERS
14
15
 
15
16
 
16
17
  @click.command()
17
- @click_insert_context(InstanceType.ALGORITHM_STORE)
18
+ @click.option("-n", "--name", default=None, help="Configuration name")
19
+ @click.option("--context", default=None, help="Kubernetes context to use")
20
+ @click.option("--namespace", default=None, help="Kubernetes namespace to use")
21
+ @click.option(
22
+ "--system",
23
+ "system_folders",
24
+ flag_value=True,
25
+ default=DEFAULT_SERVER_SYSTEM_FOLDERS,
26
+ help="Search for configuration in system folders instead of user folders. "
27
+ "This is the default.",
28
+ )
29
+ @click.option(
30
+ "--user",
31
+ "system_folders",
32
+ flag_value=False,
33
+ help="Search for configuration in the user folders instead of system folders.",
34
+ )
18
35
  @click.option("--all", "all_stores", flag_value=True, help="Stop all algorithm stores")
19
- def cli_algo_store_stop(ctx: AlgorithmStoreContext, all_stores: bool):
36
+ def cli_algo_store_stop(
37
+ name: str,
38
+ context: str,
39
+ namespace: str,
40
+ system_folders: bool,
41
+ all_stores: bool,
42
+ ):
20
43
  """
21
- Stop one or all running server(s).
44
+ Stop one or all running algorithm store(s).
22
45
  """
23
- check_docker_running()
24
- client = docker.from_env()
46
+ context, namespace = select_context_and_namespace(
47
+ context=context,
48
+ namespace=namespace,
49
+ )
25
50
 
26
- running_stores = client.containers.list(
27
- filters={"label": f"{APPNAME}-type={InstanceType.ALGORITHM_STORE}"}
51
+ running_stores = find_running_service_names(
52
+ instance_type=InstanceType.ALGORITHM_STORE,
53
+ only_system_folders=system_folders,
54
+ only_user_folders=not system_folders,
55
+ context=context,
56
+ namespace=namespace,
28
57
  )
29
58
 
30
59
  if not running_stores:
31
- warning("No algorithm stores are currently running.")
60
+ error("No running algorithm stores found.")
32
61
  return
33
62
 
34
- running_store_names = [server.name for server in running_stores]
35
-
36
63
  if all_stores:
37
- for container_name in running_store_names:
38
- _stop_algorithm_store(client, container_name)
39
- return
64
+ for store in running_stores:
65
+ _stop_store(store["name"], namespace, context)
66
+ else:
67
+ if not name:
68
+ store_name = select_running_service(
69
+ running_stores, InstanceType.ALGORITHM_STORE
70
+ )
71
+ else:
72
+ ctx = get_context(InstanceType.ALGORITHM_STORE, name, system_folders)
73
+ store_name = ctx.helm_release_name
40
74
 
41
- container_name = ctx.docker_container_name
42
- if container_name not in running_store_names:
43
- error(f"{Fore.RED}{ctx.name}{Style.RESET_ALL} is not running!")
44
- return
75
+ if store_name in running_stores:
76
+ _stop_store(store_name, namespace, context)
77
+ info(f"Stopped the {Fore.GREEN}{store_name}{Style.RESET_ALL} store.")
78
+ else:
79
+ error(f"{Fore.RED}{name}{Style.RESET_ALL} is not running?!")
45
80
 
46
- _stop_algorithm_store(client, container_name)
47
81
 
82
+ def _stop_store(store_name: str, namespace: str, context: str) -> None:
83
+ info(f"Stopping store {store_name}...")
48
84
 
49
- def _stop_algorithm_store(client, container_name) -> None:
50
- """
51
- Stop the algorithm store server.
52
-
53
- Parameters
54
- ----------
55
- client : DockerClient
56
- The docker client
57
- container_name : str
58
- The name of the container to stop
59
- """
60
- remove_container_if_exists(client, name=container_name)
61
- info(f"Stopped the {Fore.GREEN}{container_name}{Style.RESET_ALL} server.")
85
+ # uninstall the helm release
86
+ helm_uninstall(
87
+ release_name=store_name,
88
+ context=context,
89
+ namespace=namespace,
90
+ )
91
+
92
+ stop_port_forward(
93
+ service_name=f"{store_name}-vantage6-algorithm-store-service",
94
+ )
95
+
96
+ info(f"Store {store_name} stopped successfully.")
@@ -0,0 +1,60 @@
1
+ from colorama import Fore, Style
2
+
3
+ from vantage6.common import ensure_config_dir_writable, error, info
4
+ from vantage6.common.globals import InstanceType
5
+
6
+ from vantage6.cli.common.utils import get_main_cli_command_name
7
+ from vantage6.cli.config import CliConfig
8
+ from vantage6.cli.configuration_wizard import configuration_wizard
9
+ from vantage6.cli.context import select_context_class
10
+ from vantage6.cli.utils import check_config_name_allowed, prompt_config_name
11
+
12
+
13
+ def new(
14
+ name: str, system_folders: bool, namespace: str, context: str, type_: InstanceType
15
+ ):
16
+ cli_config = CliConfig()
17
+ context, namespace = cli_config.compare_changes_config(
18
+ context=context,
19
+ namespace=namespace,
20
+ )
21
+
22
+ name = prompt_config_name(name)
23
+
24
+ # check if name is valid
25
+ check_config_name_allowed(name)
26
+
27
+ # check that this config does not exist
28
+ ctx_class = select_context_class(type_)
29
+ try:
30
+ if ctx_class.config_exists(name, system_folders):
31
+ error(f"Configuration {Fore.RED}{name}{Style.RESET_ALL} already exists!")
32
+ exit(1)
33
+ except Exception as e:
34
+ error(e)
35
+ exit(1)
36
+
37
+ command_name = get_main_cli_command_name(type_)
38
+
39
+ # Check that we can write in this folder
40
+ if not ensure_config_dir_writable(system_folders):
41
+ error("Your user does not have write access to all folders. Exiting")
42
+ info(
43
+ f"Create a new {command_name} using '{Fore.GREEN}v6 {command_name} new "
44
+ f"--user{Style.RESET_ALL}' instead!"
45
+ )
46
+ exit(1)
47
+
48
+ # create config in ctx location
49
+ try:
50
+ cfg_file = configuration_wizard(type_, name, system_folders)
51
+ except KeyboardInterrupt:
52
+ error("Configuration creation aborted.")
53
+ exit(1)
54
+ info(f"New configuration created: {Fore.GREEN}{cfg_file}{Style.RESET_ALL}")
55
+
56
+ flag = "" if system_folders else "--user"
57
+ info(
58
+ f"You can start the {command_name} by running {Fore.GREEN}v6 {command_name} "
59
+ f"start {flag}{Style.RESET_ALL}"
60
+ )