vantage6 5.0.0a34__py3-none-any.whl → 5.0.0a35__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.

@@ -1,8 +1,14 @@
1
1
  import click
2
+ import questionary as q
2
3
 
3
- from vantage6.common.globals import InstanceType
4
+ from vantage6.common.globals import (
5
+ DEFAULT_API_PATH,
6
+ InstanceType,
7
+ Ports,
8
+ )
4
9
 
5
10
  from vantage6.cli.common.new import new
11
+ from vantage6.cli.configuration_wizard import add_common_server_config
6
12
  from vantage6.cli.globals import DEFAULT_SERVER_SYSTEM_FOLDERS
7
13
 
8
14
 
@@ -36,4 +42,79 @@ def cli_algo_store_new(
36
42
  Create a new server configuration.
37
43
  """
38
44
 
39
- new(name, system_folders, namespace, context, InstanceType.ALGORITHM_STORE)
45
+ new(
46
+ questionnaire_function=algo_store_configuration_questionaire,
47
+ name=name,
48
+ system_folders=system_folders,
49
+ namespace=namespace,
50
+ context=context,
51
+ type_=InstanceType.ALGORITHM_STORE,
52
+ )
53
+
54
+
55
+ def algo_store_configuration_questionaire(instance_name: str) -> dict:
56
+ """
57
+ Questionary to generate a config file for the algorithm store server
58
+ instance.
59
+
60
+ Parameters
61
+ ----------
62
+ instance_name : str
63
+ Name of the server instance.
64
+
65
+ Returns
66
+ -------
67
+ dict
68
+ Dictionary with the new server configuration
69
+ """
70
+ config = {"store": {}, "database": {}}
71
+
72
+ config, is_production = add_common_server_config(
73
+ config, InstanceType.ALGORITHM_STORE, instance_name
74
+ )
75
+ if not is_production:
76
+ config["store"]["dev"] = {
77
+ "host_uri": "host.docker.internal",
78
+ "disable_review": True,
79
+ "review_own_algorithm": True,
80
+ }
81
+
82
+ default_v6_server_uri = f"http://localhost:{Ports.DEV_SERVER}{DEFAULT_API_PATH}"
83
+ default_root_username = "admin"
84
+
85
+ v6_server_uri = q.text(
86
+ "What is the Vantage6 server linked to the algorithm store? "
87
+ "Provide the link to the server endpoint.",
88
+ default=default_v6_server_uri,
89
+ ).unsafe_ask()
90
+
91
+ root_username = q.text(
92
+ "What is the username of the root user?",
93
+ default=default_root_username,
94
+ ).unsafe_ask()
95
+
96
+ config["root_user"] = {
97
+ "v6_server_uri": v6_server_uri,
98
+ "username": root_username,
99
+ }
100
+
101
+ # ask about openness of the algorithm store
102
+ config["policies"] = {}
103
+ is_open = q.confirm(
104
+ "Do you want to open the algorithm store to the public? This will allow anyone "
105
+ "to view the algorithms, but they cannot modify them.",
106
+ default=False,
107
+ ).unsafe_ask()
108
+ if is_open:
109
+ open_algos_policy = "public"
110
+ else:
111
+ is_open_to_whitelist = q.confirm(
112
+ "Do you want to allow all authenticated users to access "
113
+ "the algorithms in the store? If not allowing this, you will have to assign"
114
+ " the appropriate permissions to each user individually.",
115
+ default=True,
116
+ ).unsafe_ask()
117
+ open_algos_policy = "authenticated" if is_open_to_whitelist else "private"
118
+ config["policies"]["algorithm_view"] = open_algos_policy
119
+
120
+ return config
@@ -1,21 +1,21 @@
1
- import itertools
2
- from pathlib import Path
3
- from shutil import rmtree
4
1
  import click
5
- import questionary as q
6
2
 
7
- from vantage6.common import info
8
- from vantage6.common.docker.addons import check_docker_running
3
+ from vantage6.common.globals import InstanceType
4
+
9
5
  from vantage6.cli.common.decorator import click_insert_context
6
+ from vantage6.cli.common.remove import execute_remove
10
7
  from vantage6.cli.context import AlgorithmStoreContext
11
- from vantage6.cli.utils import remove_file
12
- from vantage6.common.globals import InstanceType
8
+ from vantage6.cli.globals import InfraComponentName
13
9
 
14
10
 
15
11
  @click.command()
16
- @click_insert_context(type_=InstanceType.ALGORITHM_STORE)
12
+ @click_insert_context(
13
+ type_=InstanceType.ALGORITHM_STORE, include_name=True, include_system_folders=True
14
+ )
17
15
  @click.option("-f", "--force", "force", flag_value=True)
18
- def cli_algo_store_remove(ctx: AlgorithmStoreContext, force: bool) -> None:
16
+ def cli_algo_store_remove(
17
+ ctx: AlgorithmStoreContext, name: str, system_folders: bool, force: bool
18
+ ) -> None:
19
19
  """
20
20
  Function to remove an algorithm store.
21
21
 
@@ -26,27 +26,11 @@ def cli_algo_store_remove(ctx: AlgorithmStoreContext, force: bool) -> None:
26
26
  force : bool
27
27
  Whether to ask for confirmation before removing or not
28
28
  """
29
- check_docker_running()
30
-
31
- if not force:
32
- if not q.confirm(
33
- "This algorithm store will be deleted permanently including its "
34
- "configuration. Are you sure?",
35
- default=False,
36
- ).ask():
37
- info("Algorithm store will not be deleted")
38
- exit(0)
39
-
40
- # now remove the folders...
41
- remove_file(ctx.config_file, "configuration")
42
-
43
- # ensure log files are closed before removing
44
- log_dir = Path(ctx.log_file.parent)
45
- info(f"Removing log directory: {log_dir}")
46
- for handler in itertools.chain(ctx.log.handlers, ctx.log.root.handlers):
47
- handler.close()
48
- # remove the whole folder with all the log files (if it exists)
49
- try:
50
- rmtree(log_dir)
51
- except FileNotFoundError:
52
- pass
29
+ execute_remove(
30
+ ctx,
31
+ InstanceType.ALGORITHM_STORE,
32
+ InfraComponentName.ALGORITHM_STORE,
33
+ name,
34
+ system_folders,
35
+ force,
36
+ )
@@ -9,12 +9,12 @@ from vantage6.common.globals import (
9
9
  from vantage6.cli.common.decorator import click_insert_context
10
10
  from vantage6.cli.common.start import (
11
11
  helm_install,
12
+ prestart_checks,
12
13
  start_port_forward,
13
14
  )
14
15
  from vantage6.cli.common.utils import (
15
16
  attach_logs,
16
17
  create_directory_if_not_exists,
17
- select_context_and_namespace,
18
18
  )
19
19
  from vantage6.cli.context.algorithm_store import AlgorithmStoreContext
20
20
  from vantage6.cli.globals import ChartName
@@ -30,9 +30,13 @@ from vantage6.cli.globals import ChartName
30
30
  default=False,
31
31
  help="Print server logs to the console after start",
32
32
  )
33
- @click_insert_context(InstanceType.ALGORITHM_STORE)
33
+ @click_insert_context(
34
+ InstanceType.ALGORITHM_STORE, include_name=True, include_system_folders=True
35
+ )
34
36
  def cli_algo_store_start(
35
37
  ctx: AlgorithmStoreContext,
38
+ name: str,
39
+ system_folders: bool,
36
40
  context: str,
37
41
  namespace: str,
38
42
  ip: str,
@@ -43,9 +47,9 @@ def cli_algo_store_start(
43
47
  Start the algorithm store.
44
48
  """
45
49
  info("Starting algorithm store...")
46
- context, namespace = select_context_and_namespace(
47
- context=context,
48
- namespace=namespace,
50
+
51
+ prestart_checks(
52
+ ctx, InstanceType.ALGORITHM_STORE, name, system_folders, context, namespace
49
53
  )
50
54
 
51
55
  create_directory_if_not_exists(ctx.log_dir)
@@ -58,10 +62,9 @@ def cli_algo_store_start(
58
62
  namespace=namespace,
59
63
  )
60
64
 
61
- # port forward for server
62
65
  info("Port forwarding for algorithm store")
63
66
  start_port_forward(
64
- service_name=f"{ctx.helm_release_name}-vantage6-algorithm-store-service",
67
+ service_name=f"{ctx.helm_release_name}-store-service",
65
68
  service_port=ctx.config["store"].get("port", Ports.DEV_ALGO_STORE.value),
66
69
  port=port or ctx.config["store"].get("port", Ports.DEV_ALGO_STORE.value),
67
70
  ip=ip,
@@ -1,17 +1,10 @@
1
1
  import click
2
- from colorama import Fore, Style
3
2
 
4
- from vantage6.common import error, info
3
+ from vantage6.common import info
5
4
  from vantage6.common.globals import InstanceType
6
5
 
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
6
+ from vantage6.cli.common.stop import execute_stop, helm_uninstall, stop_port_forward
7
+ from vantage6.cli.globals import DEFAULT_SERVER_SYSTEM_FOLDERS, InfraComponentName
15
8
 
16
9
 
17
10
  @click.command()
@@ -43,54 +36,23 @@ def cli_algo_store_stop(
43
36
  """
44
37
  Stop one or all running algorithm store(s).
45
38
  """
46
- context, namespace = select_context_and_namespace(
47
- context=context,
48
- namespace=namespace,
49
- )
50
-
51
- running_stores = find_running_service_names(
39
+ execute_stop(
40
+ stop_function=_stop_store,
52
41
  instance_type=InstanceType.ALGORITHM_STORE,
53
- only_system_folders=system_folders,
54
- only_user_folders=not system_folders,
55
- context=context,
42
+ infra_component=InfraComponentName.ALGORITHM_STORE,
43
+ stop_all=all_stores,
44
+ to_stop=name,
56
45
  namespace=namespace,
46
+ context=context,
47
+ system_folders=system_folders,
57
48
  )
58
49
 
59
- if not running_stores:
60
- error("No running algorithm stores found.")
61
- return
62
-
63
- if all_stores:
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
74
-
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?!")
80
-
81
50
 
82
51
  def _stop_store(store_name: str, namespace: str, context: str) -> None:
83
52
  info(f"Stopping store {store_name}...")
84
53
 
85
- # uninstall the helm release
86
- helm_uninstall(
87
- release_name=store_name,
88
- context=context,
89
- namespace=namespace,
90
- )
54
+ helm_uninstall(release_name=store_name, context=context, namespace=namespace)
91
55
 
92
- stop_port_forward(
93
- service_name=f"{store_name}-vantage6-algorithm-store-service",
94
- )
56
+ stop_port_forward(service_name=f"{store_name}-store-service")
95
57
 
96
58
  info(f"Store {store_name} stopped successfully.")
vantage6/cli/cli.py CHANGED
@@ -1,17 +1,19 @@
1
1
  import click
2
2
 
3
- from vantage6.cli.server.attach import cli_server_attach
4
- from vantage6.cli.server.files import cli_server_files
5
- from vantage6.cli.server.import_ import cli_server_import
6
- from vantage6.cli.server.list import cli_server_configuration_list
7
- from vantage6.cli.server.new import cli_server_new
8
- from vantage6.cli.server.remove import cli_server_remove
9
- from vantage6.cli.server.shell import cli_server_shell
10
- from vantage6.cli.server.start import cli_server_start
11
- from vantage6.cli.server.stop import cli_server_stop
12
- from vantage6.cli.server.version import cli_server_version
3
+ from vantage6.cli.algorithm.create import cli_algorithm_create
4
+ from vantage6.cli.algorithm.generate_algorithm_json import (
5
+ cli_algorithm_generate_algorithm_json,
6
+ )
7
+ from vantage6.cli.algorithm.update import cli_algorithm_update
8
+ from vantage6.cli.algostore.attach import cli_algo_store_attach
9
+ from vantage6.cli.algostore.files import cli_algo_store_files
10
+ from vantage6.cli.algostore.list import cli_algo_store_configuration_list
11
+ from vantage6.cli.algostore.new import cli_algo_store_new
12
+ from vantage6.cli.algostore.remove import cli_algo_store_remove
13
+ from vantage6.cli.algostore.start import cli_algo_store_start
14
+ from vantage6.cli.algostore.stop import cli_algo_store_stop
15
+ from vantage6.cli.globals import CLICommandName
13
16
  from vantage6.cli.node.attach import cli_node_attach
14
- from vantage6.cli.node.clean import cli_node_clean
15
17
  from vantage6.cli.node.create_private_key import cli_node_create_private_key
16
18
  from vantage6.cli.node.files import cli_node_files
17
19
  from vantage6.cli.node.list import cli_node_list
@@ -22,29 +24,26 @@ from vantage6.cli.node.set_api_key import cli_node_set_api_key
22
24
  from vantage6.cli.node.start import cli_node_start
23
25
  from vantage6.cli.node.stop import cli_node_stop
24
26
  from vantage6.cli.node.version import cli_node_version
25
- from vantage6.cli.algorithm.create import cli_algorithm_create
26
- from vantage6.cli.algorithm.update import cli_algorithm_update
27
- from vantage6.cli.algorithm.generate_algorithm_json import (
28
- cli_algorithm_generate_algorithm_json,
29
- )
27
+ from vantage6.cli.server.attach import cli_server_attach
28
+ from vantage6.cli.server.files import cli_server_files
29
+ from vantage6.cli.server.import_ import cli_server_import
30
+ from vantage6.cli.server.list import cli_server_configuration_list
31
+ from vantage6.cli.server.new import cli_server_new
32
+ from vantage6.cli.server.remove import cli_server_remove
33
+ from vantage6.cli.server.shell import cli_server_shell
34
+ from vantage6.cli.server.start import cli_server_start
35
+ from vantage6.cli.server.stop import cli_server_stop
36
+ from vantage6.cli.server.version import cli_server_version
30
37
 
31
38
  # from vantage6.cli.test.client_script import cli_test_client_script
32
- from vantage6.cli.test.feature_tester import cli_test_features
33
-
34
39
  # from vantage6.cli.test.integration_test import cli_test_integration
35
- from vantage6.cli.algostore.attach import cli_algo_store_attach
36
- from vantage6.cli.algostore.new import cli_algo_store_new
37
- from vantage6.cli.algostore.start import cli_algo_store_start
38
- from vantage6.cli.algostore.stop import cli_algo_store_stop
39
- from vantage6.cli.algostore.files import cli_algo_store_files
40
- from vantage6.cli.algostore.list import cli_algo_store_configuration_list
41
- from vantage6.cli.algostore.remove import cli_algo_store_remove
40
+ from vantage6.cli.test.feature_tester import cli_test_features
42
41
  from vantage6.cli.use.context import cli_use_context
43
42
  from vantage6.cli.use.namespace import cli_use_namespace
44
43
 
45
44
 
46
45
  # Define the server group
47
- @click.group(name="server")
46
+ @click.group(name=CLICommandName.SERVER.value)
48
47
  def cli_server() -> None:
49
48
  """
50
49
  Manage your vantage6 server instances.
@@ -65,7 +64,7 @@ cli_server.add_command(cli_server_version, name="version")
65
64
 
66
65
 
67
66
  # Define the node group
68
- @click.group(name="node")
67
+ @click.group(name=CLICommandName.NODE.value)
69
68
  def cli_node() -> None:
70
69
  """
71
70
  Manage your vantage6 node instances.
@@ -74,7 +73,6 @@ def cli_node() -> None:
74
73
 
75
74
  # Define the commands for the node group
76
75
  cli_node.add_command(cli_node_attach, name="attach")
77
- cli_node.add_command(cli_node_clean, name="clean")
78
76
  cli_node.add_command(cli_node_create_private_key, name="create-private-key")
79
77
  cli_node.add_command(cli_node_files, name="files")
80
78
  cli_node.add_command(cli_node_list, name="list")
@@ -88,7 +86,7 @@ cli_node.add_command(cli_node_version, name="version")
88
86
 
89
87
 
90
88
  # Define the dev group
91
- @click.group(name="dev")
89
+ @click.group(name=CLICommandName.DEV.value)
92
90
  def cli_dev() -> None:
93
91
  """
94
92
  Quickly manage a test network with a server and several nodes.
@@ -101,7 +99,7 @@ def cli_dev() -> None:
101
99
 
102
100
 
103
101
  # Define the algorithm group
104
- @click.group(name="algorithm")
102
+ @click.group(name=CLICommandName.ALGORITHM.value)
105
103
  def cli_algorithm() -> None:
106
104
  """
107
105
  Manage your vantage6 algorithms.
@@ -117,7 +115,7 @@ cli_algorithm.add_command(
117
115
 
118
116
 
119
117
  # Define the test group
120
- @click.group(name="test")
118
+ @click.group(name=CLICommandName.TEST.value)
121
119
  def cli_test() -> None:
122
120
  """
123
121
  Execute tests on your vantage6 infrastructure.
@@ -131,7 +129,7 @@ cli_test.add_command(cli_test_features, name="feature-test")
131
129
 
132
130
 
133
131
  # Define the algorithm-store group
134
- @click.group(name="algorithm-store")
132
+ @click.group(name=CLICommandName.ALGORITHM_STORE.value)
135
133
  def cli_algo_store() -> None:
136
134
  """
137
135
  Manage your vantage6 algorithm store server instances.
@@ -149,7 +147,7 @@ cli_algo_store.add_command(cli_algo_store_remove, name="remove")
149
147
 
150
148
 
151
149
  # Add the use group
152
- @click.group(name="use")
150
+ @click.group(name=CLICommandName.USE.value)
153
151
  def cli_use() -> None:
154
152
  """
155
153
  Manage Kubernetes context and namespace.
@@ -11,8 +11,31 @@ from vantage6.cli.utils import check_config_name_allowed, prompt_config_name
11
11
 
12
12
 
13
13
  def new(
14
- name: str, system_folders: bool, namespace: str, context: str, type_: InstanceType
15
- ):
14
+ questionnaire_function: callable,
15
+ name: str,
16
+ system_folders: bool,
17
+ namespace: str,
18
+ context: str,
19
+ type_: InstanceType,
20
+ ) -> None:
21
+ """
22
+ Create a new configuration.
23
+
24
+ Parameters
25
+ ----------
26
+ questionnaire_function : callable
27
+ Function to generate the configuration
28
+ name : str
29
+ Name of the configuration
30
+ system_folders : bool
31
+ Whether to store the configuration in the system folders
32
+ namespace : str
33
+ Namespace to use
34
+ context : str
35
+ Context to use
36
+ type_ : InstanceType
37
+ Type of the configuration (node, server, algorithm store, etc)
38
+ """
16
39
  cli_config = CliConfig()
17
40
  context, namespace = cli_config.compare_changes_config(
18
41
  context=context,
@@ -47,7 +70,9 @@ def new(
47
70
 
48
71
  # create config in ctx location
49
72
  try:
50
- cfg_file = configuration_wizard(type_, name, system_folders)
73
+ cfg_file = configuration_wizard(
74
+ questionnaire_function, type_, name, system_folders
75
+ )
51
76
  except KeyboardInterrupt:
52
77
  error("Configuration creation aborted.")
53
78
  exit(1)
@@ -0,0 +1,54 @@
1
+ import itertools
2
+ from pathlib import Path
3
+ from shutil import rmtree
4
+
5
+ import questionary as q
6
+
7
+ from vantage6.common import (
8
+ error,
9
+ info,
10
+ )
11
+ from vantage6.common.context import AppContext
12
+ from vantage6.common.globals import InstanceType
13
+
14
+ from vantage6.cli.common.utils import check_running
15
+ from vantage6.cli.globals import InfraComponentName
16
+ from vantage6.cli.utils import remove_file
17
+
18
+
19
+ def execute_remove(
20
+ ctx: AppContext,
21
+ instance_type: InstanceType,
22
+ infra_component: InfraComponentName,
23
+ name: str,
24
+ system_folders: bool,
25
+ force: bool,
26
+ ) -> None:
27
+ if check_running(ctx.helm_release_name, instance_type, name, system_folders):
28
+ error(
29
+ f"The {infra_component.value} {name} is still running! Please stop the "
30
+ f"{infra_component.value} before deleting it."
31
+ )
32
+ exit(1)
33
+
34
+ if not force:
35
+ if not q.confirm(
36
+ f"This {infra_component.value} will be deleted permanently including its "
37
+ "configuration. Are you sure?",
38
+ default=False,
39
+ ).ask():
40
+ info(f"The {infra_component.value} {name} will not be deleted")
41
+ exit(0)
42
+
43
+ # remove the config file
44
+ remove_file(ctx.config_file, "configuration")
45
+
46
+ # ensure log files are closed before removing
47
+ log_dir = Path(ctx.log_file.parent)
48
+ if log_dir.exists():
49
+ info(f"Removing log directory: {log_dir}")
50
+ for handler in itertools.chain(ctx.log.handlers, ctx.log.root.handlers):
51
+ handler.close()
52
+ # remove the whole folder with all the log files. This may also still contain
53
+ # other files like (for the server) RabbitMQ configuration etc
54
+ rmtree(log_dir)
@@ -10,6 +10,7 @@ import docker
10
10
  from docker.client import DockerClient
11
11
 
12
12
  from vantage6.common import error, info, warning
13
+ from vantage6.common.context import AppContext
13
14
  from vantage6.common.docker.addons import pull_image
14
15
  from vantage6.common.globals import (
15
16
  DEFAULT_ALGO_STORE_IMAGE,
@@ -21,8 +22,36 @@ from vantage6.common.globals import (
21
22
  InstanceType,
22
23
  )
23
24
 
25
+ from vantage6.cli.common.utils import (
26
+ check_running,
27
+ select_context_and_namespace,
28
+ )
24
29
  from vantage6.cli.globals import ChartName
25
- from vantage6.cli.utils import validate_input_cmd_args
30
+ from vantage6.cli.utils import check_config_name_allowed, validate_input_cmd_args
31
+
32
+
33
+ def prestart_checks(
34
+ ctx: AppContext,
35
+ instance_type: InstanceType,
36
+ name: str,
37
+ system_folders: bool,
38
+ context: str,
39
+ namespace: str,
40
+ ) -> None:
41
+ """
42
+ Run pre-start checks for an instance.
43
+ """
44
+
45
+ check_config_name_allowed(ctx.name)
46
+
47
+ if check_running(ctx.helm_release_name, instance_type, name, system_folders):
48
+ error(f"Instance '{name}' is already running.")
49
+ exit(1)
50
+
51
+ context, namespace = select_context_and_namespace(
52
+ context=context,
53
+ namespace=namespace,
54
+ )
26
55
 
27
56
 
28
57
  def pull_infra_image(
@@ -2,11 +2,89 @@ from __future__ import annotations
2
2
 
3
3
  import subprocess
4
4
 
5
- from vantage6.common import error, info, warning
5
+ from colorama import Fore, Style
6
6
 
7
+ from vantage6.common import error, info, warning
8
+ from vantage6.common.globals import InstanceType
9
+
10
+ from vantage6.cli.common.utils import (
11
+ find_running_service_names,
12
+ select_context_and_namespace,
13
+ select_running_service,
14
+ )
15
+ from vantage6.cli.context import get_context
16
+ from vantage6.cli.globals import InfraComponentName
7
17
  from vantage6.cli.utils import validate_input_cmd_args
8
18
 
9
19
 
20
+ def execute_stop(
21
+ stop_function: callable,
22
+ instance_type: InstanceType,
23
+ infra_component: InfraComponentName,
24
+ stop_all: bool,
25
+ to_stop: str | None,
26
+ namespace: str,
27
+ context: str,
28
+ system_folders: bool,
29
+ ):
30
+ """
31
+ Execute the stop function for a given instance type and infra component.
32
+
33
+ Parameters
34
+ ----------
35
+ stop_function : callable
36
+ The function to stop the service.
37
+ instance_type : InstanceType
38
+ The instance type of the service.
39
+ infra_component : InfraComponentName
40
+ The infra component of the service.
41
+ stop_all : bool
42
+ Whether to stop all services.
43
+ to_stop : str | None
44
+ The name of the service to stop.
45
+ namespace : str
46
+ The namespace of the service.
47
+ context : str
48
+ The context of the service.
49
+ system_folders : bool
50
+ Whether to use system folders.
51
+ """
52
+ context, namespace = select_context_and_namespace(
53
+ context=context,
54
+ namespace=namespace,
55
+ )
56
+
57
+ running_services = find_running_service_names(
58
+ instance_type=instance_type,
59
+ only_system_folders=system_folders,
60
+ only_user_folders=not system_folders,
61
+ context=context,
62
+ namespace=namespace,
63
+ )
64
+
65
+ if not running_services:
66
+ error(f"No running {infra_component.value}s found.")
67
+ return
68
+
69
+ if stop_all:
70
+ for service in running_services:
71
+ stop_function(service, namespace, context)
72
+ else:
73
+ if not to_stop:
74
+ helm_name = select_running_service(running_services, instance_type)
75
+ else:
76
+ ctx = get_context(instance_type, to_stop, system_folders)
77
+ helm_name = ctx.helm_release_name
78
+
79
+ if helm_name in running_services:
80
+ stop_function(helm_name, namespace, context)
81
+ info(
82
+ f"Stopped the {Fore.GREEN}{helm_name}{Style.RESET_ALL} {infra_component.value}."
83
+ )
84
+ else:
85
+ error(f"{Fore.RED}{to_stop}{Style.RESET_ALL} is not running?!")
86
+
87
+
10
88
  def stop_port_forward(service_name: str) -> None:
11
89
  """
12
90
  Stop the port forwarding process for a given service name.