vantage6 5.0.0a33__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.

Files changed (45) hide show
  1. vantage6/cli/algostore/new.py +106 -47
  2. vantage6/cli/algostore/remove.py +18 -34
  3. vantage6/cli/algostore/start.py +36 -67
  4. vantage6/cli/algostore/stop.py +43 -46
  5. vantage6/cli/cli.py +31 -33
  6. vantage6/cli/common/new.py +85 -0
  7. vantage6/cli/common/remove.py +54 -0
  8. vantage6/cli/common/start.py +36 -213
  9. vantage6/cli/common/stop.py +78 -0
  10. vantage6/cli/common/utils.py +253 -16
  11. vantage6/cli/configuration_manager.py +90 -12
  12. vantage6/cli/configuration_wizard.py +49 -414
  13. vantage6/cli/context/algorithm_store.py +7 -6
  14. vantage6/cli/context/base_server.py +22 -30
  15. vantage6/cli/context/node.py +14 -17
  16. vantage6/cli/context/server.py +16 -7
  17. vantage6/cli/globals.py +29 -8
  18. vantage6/cli/node/attach.py +1 -0
  19. vantage6/cli/node/common/__init__.py +1 -1
  20. vantage6/cli/node/create_private_key.py +9 -6
  21. vantage6/cli/node/files.py +12 -25
  22. vantage6/cli/node/new.py +348 -28
  23. vantage6/cli/node/remove.py +14 -90
  24. vantage6/cli/node/restart.py +30 -51
  25. vantage6/cli/node/set_api_key.py +7 -4
  26. vantage6/cli/node/start.py +81 -304
  27. vantage6/cli/node/stop.py +36 -96
  28. vantage6/cli/server/import_.py +1 -2
  29. vantage6/cli/server/list.py +0 -3
  30. vantage6/cli/server/new.py +72 -42
  31. vantage6/cli/server/remove.py +12 -33
  32. vantage6/cli/server/shell.py +1 -1
  33. vantage6/cli/server/start.py +22 -20
  34. vantage6/cli/server/stop.py +37 -17
  35. vantage6/cli/template/algo_store_config.j2 +195 -22
  36. vantage6/cli/template/node_config.j2 +336 -33
  37. vantage6/cli/template/server_config.j2 +255 -33
  38. vantage6/cli/utils.py +0 -2
  39. {vantage6-5.0.0a33.dist-info → vantage6-5.0.0a35.dist-info}/METADATA +4 -4
  40. vantage6-5.0.0a35.dist-info/RECORD +75 -0
  41. vantage6/cli/node/clean.py +0 -46
  42. vantage6/cli/template/server_import_config.j2 +0 -31
  43. vantage6-5.0.0a33.dist-info/RECORD +0 -75
  44. {vantage6-5.0.0a33.dist-info → vantage6-5.0.0a35.dist-info}/WHEEL +0 -0
  45. {vantage6-5.0.0a33.dist-info → vantage6-5.0.0a35.dist-info}/entry_points.txt +0 -0
@@ -5,6 +5,7 @@ import os.path
5
5
  from sqlalchemy.engine.url import make_url
6
6
 
7
7
  from vantage6.common.context import AppContext
8
+
8
9
  from vantage6.cli.globals import (
9
10
  DEFAULT_SERVER_SYSTEM_FOLDERS as S_FOL,
10
11
  ServerType,
@@ -19,35 +20,29 @@ class BaseServerContext(AppContext):
19
20
  in common.
20
21
  """
21
22
 
22
- def get_database_uri(self, db_env_var: str) -> str:
23
+ def get_database_uri(self) -> str:
23
24
  """
24
25
  Obtain the database uri from the environment or the configuration.
25
26
 
26
- Parameters
27
- ----------
28
- db_env_var : str
29
- Name of the environment variable that contains the database uri
30
-
31
27
  Returns
32
28
  -------
33
29
  str
34
30
  string representation of the database uri
35
31
  """
36
- uri = os.environ.get(db_env_var) or self.config["uri"]
37
- url = make_url(uri)
38
-
39
- if url.host is None and not os.path.isabs(url.database):
40
- # We're dealing with a relative path here of a local database, when
41
- # we're running the server outside of docker. Therefore we need to
42
- # prepend the data directory to the database name, but after the
43
- # driver name (e.g. sqlite:////db.sqlite ->
44
- # sqlite:////data_dir>/db.sqlite)
45
-
46
- # find index of database name
47
- idx_db_name = str(url).find(url.database)
48
-
49
- # add the datadir to the right location in the database uri
50
- return str(url)[:idx_db_name] + str(self.data_dir / url.database)
32
+ # within container, the uri is set in the config file
33
+ if self.in_container:
34
+ return self.config.get("uri")
35
+
36
+ # outside container, the uri is set in the values.yaml in a different location
37
+ is_db_external = self.config.get("database", {}).get("external", False)
38
+ if is_db_external:
39
+ uri = self.config["database"]["uri"]
40
+ else:
41
+ db_conf = self.config["database"]
42
+ uri = (
43
+ f"postgresql://{db_conf['username']}:{db_conf['password']}@"
44
+ f"{self.helm_release_name}-postgres-service:5432/{db_conf['name']}"
45
+ )
51
46
 
52
47
  return uri
53
48
 
@@ -56,8 +51,8 @@ class BaseServerContext(AppContext):
56
51
  cls,
57
52
  path: str,
58
53
  server_type: ServerType,
59
- config_name_env_var: str,
60
54
  system_folders: bool = S_FOL,
55
+ in_container: bool = False,
61
56
  ) -> BaseServerContext:
62
57
  """
63
58
  Create a server context from an external configuration file. External
@@ -70,20 +65,17 @@ class BaseServerContext(AppContext):
70
65
  Path of the configuration file
71
66
  server_type : ServerType
72
67
  Type of server, either 'server' or 'algorithm-store'
73
- config_name_env_var : str
74
- Name of the environment variable that contains the name of the
75
- configuration
76
68
  system_folders : bool, optional
77
69
  System wide or user configuration, by default S_FOL
70
+ in_container : bool, optional
71
+ Whether the application is running inside a container, by default False
78
72
 
79
73
  Returns
80
74
  -------
81
75
  ServerContext
82
76
  Server context object
83
77
  """
84
- cls = super().from_external_config_file(path, server_type, system_folders)
85
- # if we are running a server in a docker container, the name is taken
86
- # from the name of the config file (which is usually a default). Get
87
- # the config name from environment if it is given.
88
- cls.name = os.environ.get(config_name_env_var) or cls.name
78
+ cls = super().from_external_config_file(
79
+ path, server_type, system_folders, in_container
80
+ )
89
81
  return cls
@@ -25,6 +25,8 @@ class NodeContext(AppContext):
25
25
  _description_, by default N_FOL
26
26
  config_file : str, optional
27
27
  _description_, by default None
28
+ in_container : bool, optional
29
+ Whether the application is running inside a container, by default False
28
30
  """
29
31
 
30
32
  # The server configuration manager is aware of the structure of the server
@@ -38,6 +40,7 @@ class NodeContext(AppContext):
38
40
  config_file: str = None,
39
41
  print_log_header: bool = True,
40
42
  logger_prefix: str = "",
43
+ in_container: bool = False,
41
44
  ):
42
45
  super().__init__(
43
46
  InstanceType.NODE,
@@ -46,6 +49,7 @@ class NodeContext(AppContext):
46
49
  config_file=config_file,
47
50
  print_log_header=print_log_header,
48
51
  logger_prefix=logger_prefix,
52
+ in_container=in_container,
49
53
  )
50
54
  if print_log_header:
51
55
  self.log.info("vantage6 version '%s'", __version__)
@@ -146,7 +150,10 @@ class NodeContext(AppContext):
146
150
  dictionary with database names as keys and their corresponding
147
151
  paths as values.
148
152
  """
149
- return self.config["databases"]
153
+ if self.in_container:
154
+ return self.config["databases"]
155
+ else:
156
+ return self.config["node"]["databases"]
150
157
 
151
158
  @property
152
159
  def docker_container_name(self) -> str:
@@ -226,19 +233,6 @@ class NodeContext(AppContext):
226
233
  self.data_dir = dirs.get("data")
227
234
  self.config_dir = dirs.get("config")
228
235
 
229
- @staticmethod
230
- def instance_folders(*_args, **_kwargs) -> dict:
231
- """Log, data and config folders are always mounted. The node manager
232
- should take care of this.
233
- """
234
- mnt = Path("/mnt")
235
-
236
- return {
237
- "log": mnt / "log",
238
- "data": mnt / "data",
239
- "config": mnt / "config",
240
- }
241
-
242
236
  def __create_node_identifier(self) -> str:
243
237
  """
244
238
  Create a unique identifier for the node.
@@ -248,6 +242,9 @@ class NodeContext(AppContext):
248
242
  str
249
243
  Unique identifier for the node
250
244
  """
251
- return hashlib.sha256(
252
- os.environ.get("V6_API_KEY").encode(STRING_ENCODING)
253
- ).hexdigest()[:16]
245
+ if self.in_container:
246
+ api_key = os.environ.get("V6_API_KEY")
247
+ else:
248
+ api_key = self.config["node"]["apiKey"]
249
+
250
+ return hashlib.sha256(api_key.encode(STRING_ENCODING)).hexdigest()[:16]
@@ -10,7 +10,6 @@ from vantage6.cli.context.base_server import BaseServerContext
10
10
  from vantage6.cli.globals import (
11
11
  DEFAULT_SERVER_SYSTEM_FOLDERS as S_FOL,
12
12
  PROMETHEUS_DIR,
13
- ServerGlobals,
14
13
  ServerType,
15
14
  )
16
15
 
@@ -32,9 +31,17 @@ class ServerContext(BaseServerContext):
32
31
  # configuration file and makes sure only valid configuration can be loaded.
33
32
  INST_CONFIG_MANAGER = ServerConfigurationManager
34
33
 
35
- def __init__(self, instance_name: str, system_folders: bool = S_FOL):
34
+ def __init__(
35
+ self,
36
+ instance_name: str,
37
+ system_folders: bool = S_FOL,
38
+ in_container: bool = False,
39
+ ):
36
40
  super().__init__(
37
- InstanceType.SERVER, instance_name, system_folders=system_folders
41
+ InstanceType.SERVER,
42
+ instance_name,
43
+ system_folders=system_folders,
44
+ in_container=in_container,
38
45
  )
39
46
  self.log.info("vantage6 version '%s'", __version__)
40
47
 
@@ -47,7 +54,7 @@ class ServerContext(BaseServerContext):
47
54
  str
48
55
  string representation of the database uri
49
56
  """
50
- return super().get_database_uri(ServerGlobals.DB_URI_ENV_VAR.value)
57
+ return super().get_database_uri()
51
58
 
52
59
  @property
53
60
  def docker_container_name(self) -> str:
@@ -59,7 +66,7 @@ class ServerContext(BaseServerContext):
59
66
  str
60
67
  Server's docker container name
61
68
  """
62
- return f"{APPNAME}-{self.name}-{self.scope}-{ServerType.V6SERVER}"
69
+ return f"{APPNAME}-{self.name}-{self.scope}-{ServerType.V6SERVER.value}"
63
70
 
64
71
  @property
65
72
  def prometheus_container_name(self) -> str:
@@ -87,7 +94,7 @@ class ServerContext(BaseServerContext):
87
94
 
88
95
  @classmethod
89
96
  def from_external_config_file(
90
- cls, path: str, system_folders: bool = S_FOL
97
+ cls, path: str, system_folders: bool = S_FOL, in_container: bool = False
91
98
  ) -> ServerContext:
92
99
  """
93
100
  Create a server context from an external configuration file. External
@@ -100,6 +107,8 @@ class ServerContext(BaseServerContext):
100
107
  Path of the configuration file
101
108
  system_folders : bool, optional
102
109
  System wide or user configuration, by default S_FOL
110
+ in_container : bool, optional
111
+ Whether the application is running inside a container, by default False
103
112
 
104
113
  Returns
105
114
  -------
@@ -109,8 +118,8 @@ class ServerContext(BaseServerContext):
109
118
  return super().from_external_config_file(
110
119
  path,
111
120
  ServerType.V6SERVER,
112
- ServerGlobals.CONFIG_NAME_ENV_VAR.value,
113
121
  system_folders,
122
+ in_container,
114
123
  )
115
124
 
116
125
  @classmethod
vantage6/cli/globals.py CHANGED
@@ -56,6 +56,12 @@ DEFAULT_PROMETHEUS_IMAGE = "prom/prometheus"
56
56
  PROMETHEUS_CONFIG = "prometheus.yml"
57
57
  PROMETHEUS_DIR = "prometheus"
58
58
 
59
+ # template folder
60
+ TEMPLATE_FOLDER = PACKAGE_FOLDER / APPNAME / "cli" / "template"
61
+ SERVER_TEMPLATE_FILE = "server_config.j2"
62
+ NODE_TEMPLATE_FILE = "node_config.j2"
63
+ ALGO_STORE_TEMPLATE_FILE = "algo_store_config.j2"
64
+
59
65
 
60
66
  # datasets included in the nodes of the dev network
61
67
  class DefaultDatasets(StrEnumBase):
@@ -72,15 +78,30 @@ class ServerType(StrEnumBase):
72
78
  ALGORITHM_STORE = "algorithm-store"
73
79
 
74
80
 
75
- class ServerGlobals(StrEnumBase):
76
- """Enum containing server environment variables"""
81
+ class ChartName(StrEnumBase):
82
+ """Enum containing chart names"""
83
+
84
+ SERVER = "server"
85
+ ALGORITHM_STORE = "store"
86
+ NODE = "node"
87
+ AUTH = "auth"
88
+
77
89
 
78
- DB_URI_ENV_VAR = "VANTAGE6_DB_URI"
79
- CONFIG_NAME_ENV_VAR = "VANTAGE6_CONFIG_NAME"
90
+ class CLICommandName(StrEnumBase):
91
+ """Enum containing CLI command names"""
92
+
93
+ SERVER = "server"
94
+ ALGORITHM_STORE = "algorithm-store"
95
+ NODE = "node"
96
+ ALGORITHM = "algorithm"
97
+ TEST = "test"
98
+ DEV = "dev"
99
+ USE = "use"
80
100
 
81
101
 
82
- class AlgoStoreGlobals(StrEnumBase):
83
- """Enum containing algorithm store environment variables"""
102
+ class InfraComponentName(StrEnumBase):
103
+ """Enum containing infrastructure components"""
84
104
 
85
- DB_URI_ENV_VAR = "VANTAGE6_ALGO_STORE_DB_URI"
86
- CONFIG_NAME_ENV_VAR = "VANTAGE6_ALGO_STORE_CONFIG_NAME"
105
+ SERVER = "server"
106
+ ALGORITHM_STORE = "store"
107
+ NODE = "node"
@@ -1,6 +1,7 @@
1
1
  import click
2
2
 
3
3
  from vantage6.common import info
4
+
4
5
  from vantage6.cli.common.utils import attach_logs
5
6
 
6
7
 
@@ -109,6 +109,6 @@ def find_running_node_names(client: docker.DockerClient) -> list[str]:
109
109
  List of names of running nodes
110
110
  """
111
111
  running_nodes = client.containers.list(
112
- filters={"label": f"{APPNAME}-type={InstanceType.NODE}"}
112
+ filters={"label": f"{APPNAME}-type={InstanceType.NODE.value}"}
113
113
  )
114
114
  return [node.name for node in running_nodes]
@@ -1,19 +1,20 @@
1
1
  from pathlib import Path
2
+
2
3
  import click
3
4
  from colorama import Fore, Style
4
5
 
5
6
  from vantage6.common import (
6
- warning,
7
+ bytes_to_base64s,
8
+ debug,
7
9
  error,
8
10
  info,
9
- debug,
10
- bytes_to_base64s,
11
+ warning,
11
12
  )
12
-
13
13
  from vantage6.common.encryption import RSACryptor
14
+
14
15
  from vantage6.cli.context.node import NodeContext
15
16
  from vantage6.cli.globals import DEFAULT_NODE_SYSTEM_FOLDERS as N_FOL
16
- from vantage6.cli.node.common import select_node, create_client_and_authenticate
17
+ from vantage6.cli.node.common import create_client_and_authenticate, select_node
17
18
 
18
19
 
19
20
  @click.command()
@@ -28,7 +29,7 @@ from vantage6.cli.node.common import select_node, create_client_and_authenticate
28
29
  "--system",
29
30
  "system_folders",
30
31
  flag_value=True,
31
- help="Search for configuration in system folders rather than " "user folders",
32
+ help="Search for configuration in system folders rather than user folders",
32
33
  )
33
34
  @click.option(
34
35
  "--user",
@@ -137,6 +138,8 @@ def cli_node_create_private_key(
137
138
 
138
139
  # update config file
139
140
  info("Updating configuration")
141
+ # TODO v5+ this probably messes up the current config as the template is used...
142
+ # Fix when reimplementing this in v5
140
143
  ctx.config["encryption"]["private_key"] = str(file_)
141
144
  ctx.config_manager.put(ctx.config)
142
145
  ctx.config_manager.save(ctx.config_file)
@@ -1,42 +1,29 @@
1
1
  import click
2
2
 
3
3
  from vantage6.common import info
4
+ from vantage6.common.globals import InstanceType
5
+
6
+ from vantage6.cli.common.decorator import click_insert_context
4
7
  from vantage6.cli.context.node import NodeContext
5
- from vantage6.cli.globals import DEFAULT_NODE_SYSTEM_FOLDERS as N_FOL
6
- from vantage6.cli.node.common import select_node
7
8
 
8
9
 
9
10
  @click.command()
10
- @click.option("-n", "--name", default=None, help="Configuration name")
11
- @click.option(
12
- "--system",
13
- "system_folders",
14
- flag_value=True,
15
- help="Search for the configuration in the system folders",
16
- )
17
- @click.option(
18
- "--user",
19
- "system_folders",
20
- flag_value=False,
21
- default=N_FOL,
22
- help="Search for the configuration in the user folders. This is " "the default",
23
- )
24
- def cli_node_files(name: str, system_folders: bool) -> None:
11
+ @click_insert_context(type_=InstanceType.NODE)
12
+ def cli_node_files(ctx: NodeContext) -> None:
25
13
  """
26
14
  Prints the location of important node files.
27
15
 
28
16
  If the specified configuration cannot be found, it exits. Otherwise
29
17
  it returns the absolute path to the output.
30
18
  """
31
- name = select_node(name, system_folders)
32
-
33
- # create node context
34
- ctx = NodeContext(name, system_folders=system_folders)
35
-
36
- # return path of the configuration
37
19
  info(f"Configuration file = {ctx.config_file}")
38
20
  info(f"Log file = {ctx.log_file}")
39
21
  info(f"data folders = {ctx.data_dir}")
40
22
  info("Database labels and files")
41
- for db in ctx.databases:
42
- info(f" - {db['label']:15} = {db['uri']} (type: {db['type']})")
23
+ for db in ctx.databases["fileBased"] or []:
24
+ info(
25
+ f" - {db['name']:15} = {db['volumePath']}/{db['originalName']} "
26
+ f"(type: {db['type']})"
27
+ )
28
+ for db in ctx.databases["serviceBased"] or []:
29
+ info(f" - {db['name']:15} = {db['uri']} (type: {db['type']})")