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
vantage6/cli/node/stop.py CHANGED
@@ -14,18 +14,30 @@ from vantage6.cli.node.common import find_running_node_names
14
14
 
15
15
  @click.command()
16
16
  @click.option("-n", "--name", default=None, help="Configuration name")
17
- @click.option('--system', 'system_folders', flag_value=True,
18
- help="Search for configuration in system folders instead of "
19
- "user folders")
20
- @click.option('--user', 'system_folders', flag_value=False, default=N_FOL,
21
- help="Search for configuration in the user folders instead of "
22
- "system folders. This is the default.")
23
- @click.option('--all', 'all_nodes', flag_value=True,
24
- help="Stop all running nodes")
25
- @click.option('--force', 'force', flag_value=True,
26
- help="Kill nodes instantly; don't wait for them to shut down")
27
- def cli_node_stop(name: str, system_folders: bool, all_nodes: bool,
28
- force: bool) -> None:
17
+ @click.option(
18
+ "--system",
19
+ "system_folders",
20
+ flag_value=True,
21
+ help="Search for configuration in system folders instead of " "user folders",
22
+ )
23
+ @click.option(
24
+ "--user",
25
+ "system_folders",
26
+ flag_value=False,
27
+ default=N_FOL,
28
+ help="Search for configuration in the user folders instead of "
29
+ "system folders. This is the default.",
30
+ )
31
+ @click.option("--all", "all_nodes", flag_value=True, help="Stop all running nodes")
32
+ @click.option(
33
+ "--force",
34
+ "force",
35
+ flag_value=True,
36
+ help="Kill nodes instantly; don't wait for them to shut down",
37
+ )
38
+ def cli_node_stop(
39
+ name: str, system_folders: bool, all_nodes: bool, force: bool
40
+ ) -> None:
29
41
  """
30
42
  Stop one or all running nodes.
31
43
  """
@@ -39,9 +51,11 @@ def cli_node_stop(name: str, system_folders: bool, all_nodes: bool,
39
51
  return
40
52
 
41
53
  if force:
42
- warning('Forcing the node to stop will not terminate helper '
43
- 'containers, neither will it remove routing rules made on the '
44
- 'host!')
54
+ warning(
55
+ "Forcing the node to stop will not terminate helper "
56
+ "containers, neither will it remove routing rules made on the "
57
+ "host!"
58
+ )
45
59
 
46
60
  if all_nodes:
47
61
  for name in running_node_names:
@@ -53,10 +67,10 @@ def cli_node_stop(name: str, system_folders: bool, all_nodes: bool,
53
67
  info(f"Stopped the {Fore.GREEN}{name}{Style.RESET_ALL} Node.")
54
68
  else:
55
69
  if not name:
56
- name = q.select("Select the node you wish to stop:",
57
- choices=running_node_names).ask()
70
+ name = q.select(
71
+ "Select the node you wish to stop:", choices=running_node_names
72
+ ).ask()
58
73
  else:
59
-
60
74
  post_fix = "system" if system_folders else "user"
61
75
  name = f"{APPNAME}-{name}-{post_fix}"
62
76
 
@@ -12,12 +12,20 @@ from vantage6.cli.node.common import find_running_node_names
12
12
 
13
13
  @click.command()
14
14
  @click.option("-n", "--name", default=None, help="Configuration name")
15
- @click.option('--system', 'system_folders', flag_value=True,
16
- help="Search for configuration in system folders rather than "
17
- "user folders")
18
- @click.option('--user', 'system_folders', flag_value=False, default=N_FOL,
19
- help="Search for configuration in user folders rather than "
20
- "system folders. This is the default")
15
+ @click.option(
16
+ "--system",
17
+ "system_folders",
18
+ flag_value=True,
19
+ help="Search for configuration in system folders rather than " "user folders",
20
+ )
21
+ @click.option(
22
+ "--user",
23
+ "system_folders",
24
+ flag_value=False,
25
+ default=N_FOL,
26
+ help="Search for configuration in user folders rather than "
27
+ "system folders. This is the default",
28
+ )
21
29
  def cli_node_version(name: str, system_folders: bool) -> None:
22
30
  """
23
31
  Returns current version of a vantage6 node.
@@ -29,19 +37,21 @@ def cli_node_version(name: str, system_folders: bool) -> None:
29
37
 
30
38
  if not name:
31
39
  if not running_node_names:
32
- error("No nodes are running! You can only check the version for "
33
- "nodes that are running")
40
+ error(
41
+ "No nodes are running! You can only check the version for "
42
+ "nodes that are running"
43
+ )
34
44
  exit(1)
35
- name = q.select("Select the node you wish to inspect:",
36
- choices=running_node_names).ask()
45
+ name = q.select(
46
+ "Select the node you wish to inspect:", choices=running_node_names
47
+ ).ask()
37
48
  else:
38
49
  post_fix = "system" if system_folders else "user"
39
50
  name = f"{APPNAME}-{name}-{post_fix}"
40
51
 
41
52
  if name in running_node_names:
42
53
  container = client.containers.get(name)
43
- version = container.exec_run(cmd='vnode-local version', stdout=True)
44
- click.echo(
45
- {"node": version.output.decode('utf-8'), "cli": __version__})
54
+ version = container.exec_run(cmd="vnode-local version", stdout=True)
55
+ click.echo({"node": version.output.decode("utf-8"), "cli": __version__})
46
56
  else:
47
57
  error(f"Node {name} is not running! Cannot provide version...")
@@ -15,14 +15,14 @@ def split_rabbitmq_uri(rabbit_uri: str) -> dict:
15
15
  dict[str]
16
16
  The vhost defined in the RabbitMQ URI
17
17
  """
18
- (user_details, location_details) = rabbit_uri.split('@', 1)
19
- (user, password) = user_details.split('/')[-1].split(':', 1)
20
- (host, remainder) = location_details.split(':', 1)
21
- port, vhost = remainder.split('/', 1)
18
+ (user_details, location_details) = rabbit_uri.split("@", 1)
19
+ (user, password) = user_details.split("/")[-1].split(":", 1)
20
+ (host, remainder) = location_details.split(":", 1)
21
+ port, vhost = remainder.split("/", 1)
22
22
  return {
23
- 'user': user,
24
- 'password': password,
25
- 'host': host,
26
- 'port': port,
27
- 'vhost': vhost,
23
+ "user": user,
24
+ "password": password,
25
+ "host": host,
26
+ "port": port,
27
+ "vhost": vhost,
28
28
  }
@@ -1,30 +1,26 @@
1
1
  RABBITMQ_DEFINITIONS = {
2
- "rabbit_version": "3.6.6",
3
- "users": [
4
- {
5
- "name": "{{username}}",
6
- "password_hash": "{{password}}",
7
- "hashing_algorithm": "rabbit_password_hashing_sha256",
8
- "tags": "administrator"
9
- }
10
- ],
11
- "vhosts": [
12
- {
13
- "name": "{{vhost_name}}"
14
- }
15
- ],
16
- "permissions": [
17
- {
18
- "user": "{{username}}",
19
- "vhost": "{{vhost_name}}",
20
- "configure": ".*",
21
- "write": ".*",
22
- "read": ".*"
23
- }
24
- ],
25
- "parameters": [],
26
- "policies": [],
27
- "queues": [],
28
- "exchanges": [],
29
- "bindings": []
2
+ "rabbit_version": "3.6.6",
3
+ "users": [
4
+ {
5
+ "name": "{{username}}",
6
+ "password_hash": "{{password}}",
7
+ "hashing_algorithm": "rabbit_password_hashing_sha256",
8
+ "tags": "administrator",
9
+ }
10
+ ],
11
+ "vhosts": [{"name": "{{vhost_name}}"}],
12
+ "permissions": [
13
+ {
14
+ "user": "{{username}}",
15
+ "vhost": "{{vhost_name}}",
16
+ "configure": ".*",
17
+ "write": ".*",
18
+ "read": ".*",
19
+ }
20
+ ],
21
+ "parameters": [],
22
+ "policies": [],
23
+ "queues": [],
24
+ "exchanges": [],
25
+ "bindings": [],
30
26
  }
@@ -12,14 +12,14 @@ from vantage6.common.globals import APPNAME
12
12
  from vantage6.common import debug, info, error
13
13
  from vantage6.common.docker.addons import get_container
14
14
  from vantage6.common.docker.network_manager import NetworkManager
15
- from vantage6.cli.context import ServerContext
15
+ from vantage6.cli.context.server import ServerContext
16
16
  from vantage6.cli.rabbitmq.definitions import RABBITMQ_DEFINITIONS
17
17
  from vantage6.cli.globals import RABBIT_TIMEOUT
18
18
  from vantage6.cli.rabbitmq import split_rabbitmq_uri
19
19
 
20
- DEFAULT_RABBIT_IMAGE = 'harbor2.vantage6.ai/infrastructure/rabbitmq'
21
- RABBIT_CONFIG = 'rabbitmq.config'
22
- RABBIT_DIR = 'rabbitmq'
20
+ DEFAULT_RABBIT_IMAGE = "harbor2.vantage6.ai/infrastructure/rabbitmq"
21
+ RABBIT_CONFIG = "rabbitmq.config"
22
+ RABBIT_DIR = "rabbitmq"
23
23
 
24
24
 
25
25
  class RabbitMQManager:
@@ -36,17 +36,19 @@ class RabbitMQManager:
36
36
  Docker image to use for RabbitMQ container. By default, the image
37
37
  harbor2.vantage6.ai/infrastructure/rabbitmq is used.
38
38
  """
39
- def __init__(self, ctx: ServerContext, network_mgr: NetworkManager,
40
- image: str = None) -> None:
39
+
40
+ def __init__(
41
+ self, ctx: ServerContext, network_mgr: NetworkManager, image: str = None
42
+ ) -> None:
41
43
  self.ctx = ctx
42
- self.queue_uri = self.ctx.config['rabbitmq'].get('uri')
44
+ self.queue_uri = self.ctx.config["rabbitmq"].get("uri")
43
45
  rabbit_splitted = split_rabbitmq_uri(self.queue_uri)
44
- self.rabbit_user = rabbit_splitted['user']
45
- self.rabbit_pass = rabbit_splitted['password']
46
- self.vhost = rabbit_splitted['vhost']
47
- self.port = rabbit_splitted['port']
48
- self.host = rabbit_splitted['host']
49
- self.definitions_file = Path(self.ctx.data_dir / 'definitions.json')
46
+ self.rabbit_user = rabbit_splitted["user"]
47
+ self.rabbit_pass = rabbit_splitted["password"]
48
+ self.vhost = rabbit_splitted["vhost"]
49
+ self.port = rabbit_splitted["port"]
50
+ self.host = rabbit_splitted["host"]
51
+ self.definitions_file = Path(self.ctx.data_dir / "definitions.json")
50
52
  self.network_mgr = network_mgr
51
53
 
52
54
  self.docker = docker.from_env()
@@ -64,19 +66,16 @@ class RabbitMQManager:
64
66
  # same for 15672 in container to 8080 on host
65
67
  # TODO check if these ports are not already used on the host
66
68
  ports = {
67
- f'{self.port}/tcp': self.port,
69
+ f"{self.port}/tcp": self.port,
68
70
  # TODO this is for the management tool, do we keep this? Not used
69
71
  # at the moment..
70
- '15672/tcp': 8080
72
+ "15672/tcp": 8080,
71
73
  }
72
74
 
73
75
  # check if a RabbitMQ container is already running
74
- self.rabbit_container = get_container(
75
- docker_client=self.docker, name=self.host
76
- )
76
+ self.rabbit_container = get_container(docker_client=self.docker, name=self.host)
77
77
  if self.rabbit_container:
78
- info("RabbitMQ is already running! Linking the server to that "
79
- "queue")
78
+ info("RabbitMQ is already running! Linking the server to that " "queue")
80
79
  if not self.network_mgr.contains(self.rabbit_container):
81
80
  self.network_mgr.connect(self.rabbit_container)
82
81
  return
@@ -93,14 +92,14 @@ class RabbitMQManager:
93
92
  labels={
94
93
  f"{APPNAME}-type": "rabbitmq",
95
94
  },
96
- network=self.network_mgr.network_name
95
+ network=self.network_mgr.network_name,
97
96
  )
98
97
 
99
98
  # Wait until RabbitMQ is up before continuing with other stuff
100
99
  self._wait_for_startup()
101
100
 
102
101
  def _wait_for_startup(self) -> None:
103
- """ Wait until RabbitMQ has been initialized """
102
+ """Wait until RabbitMQ has been initialized"""
104
103
  interval = 10
105
104
  attempts = int((RABBIT_TIMEOUT + interval) / interval)
106
105
  is_running = False
@@ -144,12 +143,11 @@ class RabbitMQManager:
144
143
  rabbit_definitions = self._get_rabbitmq_definitions()
145
144
 
146
145
  # write the RabbitMQ definition to file(s)
147
- with open(self.definitions_file, 'w') as f:
146
+ with open(self.definitions_file, "w") as f:
148
147
  json.dump(rabbit_definitions, f, indent=2)
149
148
 
150
149
  # write RabbitMQ config to file
151
- rabbit_conf = \
152
- Path(__file__).parent.resolve() / RABBIT_CONFIG
150
+ rabbit_conf = Path(__file__).parent.resolve() / RABBIT_CONFIG
153
151
  shutil.copyfile(rabbit_conf, self.ctx.data_dir / RABBIT_CONFIG)
154
152
 
155
153
  # check if a directory for persistent RabbitMQ storage exists,
@@ -160,14 +158,12 @@ class RabbitMQManager:
160
158
 
161
159
  return {
162
160
  self.definitions_file: {
163
- 'bind': '/etc/rabbitmq/definitions.json', 'mode': 'ro'
161
+ "bind": "/etc/rabbitmq/definitions.json",
162
+ "mode": "ro",
164
163
  },
165
- self.ctx.data_dir / RABBIT_CONFIG: {
166
- 'bind': '/etc/rabbitmq/rabbitmq.config', 'mode': 'ro'
167
- },
168
- rabbit_data_dir: {
169
- 'bind': '/var/lib/rabbitmq', 'mode': 'rw'
170
- }
164
+ self.ctx.data_dir
165
+ / RABBIT_CONFIG: {"bind": "/etc/rabbitmq/rabbitmq.config", "mode": "ro"},
166
+ rabbit_data_dir: {"bind": "/var/lib/rabbitmq", "mode": "rw"},
171
167
  }
172
168
 
173
169
  def _get_rabbitmq_definitions(self) -> dict:
@@ -181,12 +177,13 @@ class RabbitMQManager:
181
177
  startup of RabbitMQ
182
178
  """
183
179
  rabbit_definitions = RABBITMQ_DEFINITIONS
184
- rabbit_definitions['users'][0]['name'] = self.rabbit_user
185
- rabbit_definitions['permissions'][0]['user'] = self.rabbit_user
186
- rabbit_definitions['users'][0]['password_hash'] = \
187
- self._get_hashed_pw(self.rabbit_pass)
188
- rabbit_definitions['vhosts'][0]['name'] = self.vhost
189
- rabbit_definitions['permissions'][0]['vhost'] = self.vhost
180
+ rabbit_definitions["users"][0]["name"] = self.rabbit_user
181
+ rabbit_definitions["permissions"][0]["user"] = self.rabbit_user
182
+ rabbit_definitions["users"][0]["password_hash"] = self._get_hashed_pw(
183
+ self.rabbit_pass
184
+ )
185
+ rabbit_definitions["vhosts"][0]["name"] = self.vhost
186
+ rabbit_definitions["permissions"][0]["vhost"] = self.vhost
190
187
  return rabbit_definitions
191
188
 
192
189
  def _get_hashed_pw(self, pw: str) -> str:
@@ -208,7 +205,7 @@ class RabbitMQManager:
208
205
  salt = os.urandom(4)
209
206
 
210
207
  # Concatenate that with the UTF-8 representation of the password
211
- tmp0 = salt + pw.encode('utf-8')
208
+ tmp0 = salt + pw.encode("utf-8")
212
209
 
213
210
  # Take the SHA256 hash and get the bytes back
214
211
  tmp1 = hashlib.sha256(tmp0).digest()
@@ -218,4 +215,4 @@ class RabbitMQManager:
218
215
 
219
216
  # convert to base64 encoding:
220
217
  pass_hash = base64.b64encode(salted_hash)
221
- return pass_hash.decode('utf-8')
218
+ return pass_hash.decode("utf-8")
@@ -5,11 +5,11 @@ import click
5
5
  import questionary as q
6
6
  import docker
7
7
 
8
- from colorama import (Fore, Style)
8
+ from colorama import Fore, Style
9
9
 
10
10
  from vantage6.common import info, error
11
11
  from vantage6.common.docker.addons import check_docker_running
12
- from vantage6.common.globals import APPNAME
12
+ from vantage6.common.globals import APPNAME, InstanceType
13
13
 
14
14
  from vantage6.cli.globals import DEFAULT_SERVER_SYSTEM_FOLDERS
15
15
  from vantage6.cli.server.common import print_log_worker
@@ -17,9 +17,10 @@ from vantage6.cli.server.common import print_log_worker
17
17
 
18
18
  @click.command()
19
19
  @click.option("-n", "--name", default=None, help="configuration name")
20
- @click.option('--system', 'system_folders', flag_value=True)
21
- @click.option('--user', 'system_folders', flag_value=False,
22
- default=DEFAULT_SERVER_SYSTEM_FOLDERS)
20
+ @click.option("--system", "system_folders", flag_value=True)
21
+ @click.option(
22
+ "--user", "system_folders", flag_value=False, default=DEFAULT_SERVER_SYSTEM_FOLDERS
23
+ )
23
24
  def cli_server_attach(name: str, system_folders: bool) -> None:
24
25
  """
25
26
  Show the server logs in the current console.
@@ -28,15 +29,17 @@ def cli_server_attach(name: str, system_folders: bool) -> None:
28
29
  client = docker.from_env()
29
30
 
30
31
  running_servers = client.containers.list(
31
- filters={"label": f"{APPNAME}-type=server"})
32
+ filters={"label": f"{APPNAME}-type={InstanceType.SERVER}"}
33
+ )
32
34
  running_server_names = [node.name for node in running_servers]
33
35
 
34
36
  if not name:
35
- name = q.select("Select the server you wish to inspect:",
36
- choices=running_server_names).ask()
37
+ name = q.select(
38
+ "Select the server you wish to inspect:", choices=running_server_names
39
+ ).ask()
37
40
  else:
38
41
  post_fix = "system" if system_folders else "user"
39
- name = f"{APPNAME}-{name}-{post_fix}-server"
42
+ name = f"{APPNAME}-{name}-{post_fix}-{InstanceType.SERVER}"
40
43
 
41
44
  if name in running_server_names:
42
45
  container = client.containers.get(name)
@@ -47,8 +50,10 @@ def cli_server_attach(name: str, system_folders: bool) -> None:
47
50
  time.sleep(1)
48
51
  except KeyboardInterrupt:
49
52
  info("Closing log file. Keyboard Interrupt.")
50
- info("Note that your server is still running! Shut it down "
51
- f"with {Fore.RED}v6 server stop{Style.RESET_ALL}")
53
+ info(
54
+ "Note that your server is still running! Shut it down "
55
+ f"with {Fore.RED}v6 server stop{Style.RESET_ALL}"
56
+ )
52
57
  exit(0)
53
58
  else:
54
59
  error(f"{Fore.RED}{name}{Style.RESET_ALL} was not running!?")
@@ -6,11 +6,11 @@ import click
6
6
  from colorama import Fore, Style
7
7
 
8
8
  from vantage6.common import error, info
9
- from vantage6.common.globals import STRING_ENCODING, APPNAME
9
+ from vantage6.common.globals import STRING_ENCODING, APPNAME, InstanceType
10
10
  from vantage6.common.docker.addons import remove_container, get_container
11
11
 
12
12
  from vantage6.cli.globals import DEFAULT_SERVER_SYSTEM_FOLDERS
13
- from vantage6.cli.context import ServerContext
13
+ from vantage6.cli.context.server import ServerContext
14
14
  from vantage6.cli.configuration_wizard import select_configuration_questionaire
15
15
 
16
16
 
@@ -29,19 +29,33 @@ def click_insert_context(func: callable) -> callable:
29
29
  Callable
30
30
  Click function with context
31
31
  """
32
- @click.option('-n', '--name', default=None,
33
- help="Name of the configuration you want to use.")
34
- @click.option('-c', '--config', default=None,
35
- help='Absolute path to configuration-file; overrides NAME')
36
- @click.option('--system', 'system_folders', flag_value=True,
37
- help='Use system folders instead of user folders. This is '
38
- 'the default')
39
- @click.option('--user', 'system_folders', flag_value=False,
40
- default=DEFAULT_SERVER_SYSTEM_FOLDERS,
41
- help='Use user folders instead of system folders')
32
+
33
+ @click.option(
34
+ "-n", "--name", default=None, help="Name of the configuration you want to use."
35
+ )
36
+ @click.option(
37
+ "-c",
38
+ "--config",
39
+ default=None,
40
+ help="Absolute path to configuration-file; overrides NAME",
41
+ )
42
+ @click.option(
43
+ "--system",
44
+ "system_folders",
45
+ flag_value=True,
46
+ help="Use system folders instead of user folders. This is " "the default",
47
+ )
48
+ @click.option(
49
+ "--user",
50
+ "system_folders",
51
+ flag_value=False,
52
+ default=DEFAULT_SERVER_SYSTEM_FOLDERS,
53
+ help="Use user folders instead of system folders",
54
+ )
42
55
  @wraps(func)
43
- def func_with_context(name: str, config: str, system_folders: bool, *args,
44
- **kwargs) -> callable:
56
+ def func_with_context(
57
+ name: str, config: str, system_folders: bool, *args, **kwargs
58
+ ) -> callable:
45
59
  """
46
60
  Decorator function that adds the context to the function.
47
61
 
@@ -52,14 +66,11 @@ def click_insert_context(func: callable) -> callable:
52
66
  """
53
67
  # path to configuration file always overrides name
54
68
  if config:
55
- ctx = ServerContext.from_external_config_file(
56
- config,
57
- system_folders
58
- )
59
- elif 'ctx' in kwargs:
69
+ ctx = ServerContext.from_external_config_file(config, system_folders)
70
+ elif "ctx" in kwargs:
60
71
  # if ctx is already in kwargs (typically when one click command
61
72
  # calls another internally), use that existing ctx
62
- ctx = kwargs.pop('ctx')
73
+ ctx = kwargs.pop("ctx")
63
74
  else:
64
75
  # in case no name, ctx or config file is supplied, ask the user to
65
76
  # select an existing config by name
@@ -67,7 +78,7 @@ def click_insert_context(func: callable) -> callable:
67
78
  try:
68
79
  # select configuration if none supplied
69
80
  name = select_configuration_questionaire(
70
- "server", system_folders
81
+ InstanceType.SERVER, system_folders
71
82
  )
72
83
  except Exception:
73
84
  error("No configurations could be found!")
@@ -79,8 +90,7 @@ def click_insert_context(func: callable) -> callable:
79
90
  return func_with_context
80
91
 
81
92
 
82
- def get_server_context(name: str, system_folders: bool) \
83
- -> ServerContext:
93
+ def get_server_context(name: str, system_folders: bool) -> ServerContext:
84
94
  """
85
95
  Load the server context from the configuration file.
86
96
 
@@ -142,5 +152,7 @@ def stop_ui(client: DockerClient, ctx: ServerContext) -> None:
142
152
  ui_container = get_container(client, name=ui_container_name)
143
153
  if ui_container:
144
154
  remove_container(ui_container, kill=True)
145
- info(f"Stopped the {Fore.GREEN}{ui_container_name}"
146
- f"{Style.RESET_ALL} User Interface container.")
155
+ info(
156
+ f"Stopped the {Fore.GREEN}{ui_container_name}"
157
+ f"{Style.RESET_ALL} User Interface container."
158
+ )
@@ -1,7 +1,7 @@
1
1
  import click
2
2
 
3
3
  from vantage6.common import info
4
- from vantage6.cli.context import ServerContext
4
+ from vantage6.cli.context.server import ServerContext
5
5
  from vantage6.cli.server.common import click_insert_context
6
6
 
7
7