Skip to content
This repository was archived by the owner on May 6, 2024. It is now read-only.

Commit 8c787cc

Browse files
Disentangled dependacies from server and cli
1 parent 16b2906 commit 8c787cc

File tree

6 files changed

+206
-55
lines changed

6 files changed

+206
-55
lines changed

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
packages=find_namespace_packages(),
2525
python_requires='>=3.6',
2626
install_requires=[
27+
'schema==0.7.1',
28+
'click==7.1.1',
29+
'SQLAlchemy==1.3.15',
2730
'docker==4.2.0',
2831
'colorama==0.4.3',
2932
'questionary==1.5.1',

vantage6/cli/configuration_wizard.py

Lines changed: 74 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
from pathlib import Path
44

5-
from vantage6.cli.context import NodeContext
6-
from vantage6.cli.configuration_manager import NodeConfigurationManager
7-
5+
from vantage6.cli.context import NodeContext, ServerContext
6+
from vantage6.cli.configuration_manager import (
7+
NodeConfigurationManager,
8+
ServerConfigurationManager
9+
)
810

911
def node_configuration_questionaire(dirs, instance_name):
1012
"""Questionary to generate a config file for the node instance."""
@@ -94,37 +96,99 @@ def node_configuration_questionaire(dirs, instance_name):
9496

9597
return config
9698

99+
def server_configuration_questionaire(dirs, instance_name):
100+
"""Questionary to generate a config file for the node instance."""
97101

98-
def configuration_wizard(instance_name, environment, system_folders):
102+
config = q.prompt([
103+
{
104+
"type": "text",
105+
"name": "description",
106+
"message": "Enter a human-readable description:"
107+
},
108+
{
109+
"type": "text",
110+
"name": "ip",
111+
"message": "ip:",
112+
"default": "127.0.0.1"
113+
},
114+
{
115+
"type": "text",
116+
"name": "port",
117+
"message": "Enter port to which the server listens:",
118+
"default": "5000"
119+
},
120+
{
121+
"type": "text",
122+
"name": "api_path",
123+
"message": "Path of the api:",
124+
"default": "/api"
125+
},
126+
{
127+
"type": "text",
128+
"name": "uri",
129+
"message": "Database URI:"
130+
},
131+
{
132+
"type": "select",
133+
"name": "allow_drop_all",
134+
"message": "Allowed to drop all tables: ",
135+
"choices": ["True", "False"]
136+
}
137+
])
138+
139+
res = q.select("Which level of logging would you like?",
140+
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL", "NOTSET"]
141+
).ask()
142+
143+
config["logging"] = {
144+
"level": res,
145+
"file": f"{instance_name}.log",
146+
"use_console": True,
147+
"backup_count":5,
148+
"max_size": 1024,
149+
"format": "%(asctime)s - %(name)-14s - %(levelname)-8s - %(message)s",
150+
"datefmt": "%Y-%m-%d %H:%M:%S"
151+
}
152+
153+
return config
154+
155+
156+
def configuration_wizard(type_, instance_name, environment, system_folders):
99157

100158
# for defaults and where to save the config
101-
dirs = NodeContext.instance_folders("node", instance_name, system_folders)
159+
dirs = NodeContext.instance_folders(type_, instance_name, system_folders)
102160

103161
# invoke questionaire to create configuration file
104-
config = node_configuration_questionaire(dirs, instance_name)
162+
if type_ == "node":
163+
conf_manager = NodeConfigurationManager
164+
config = node_configuration_questionaire(dirs, instance_name)
165+
else:
166+
conf_manager = ServerConfigurationManager
167+
config = server_configuration_questionaire(dirs, instance_name)
105168

106169
# in the case of an environment we need to add it to the current
107170
# configuration. In the case of application we can simply overwrite this
108171
# key (although there might be environments present)
109172
config_file = Path(dirs.get("config")) / (instance_name + ".yaml")
110173

111174
if Path(config_file).exists():
112-
config_manager = NodeConfigurationManager.from_file(config_file)
175+
config_manager = conf_manager.from_file(config_file)
113176
else:
114-
config_manager = NodeConfigurationManager(instance_name)
177+
config_manager = conf_manager(instance_name)
115178

116179
config_manager.put(environment, config)
117180
config_manager.save(config_file)
118181

119182
return config_file
120183

121184

122-
def select_configuration_questionaire(system_folders):
185+
def select_configuration_questionaire(type_, system_folders):
123186
"""Ask which configuration the user wants to use
124187
125188
It shows only configurations that are in the default folder.
126189
"""
127-
configs, f = NodeContext.available_configurations(system_folders)
190+
context = NodeContext if type_ == "node" else ServerContext
191+
configs, f = context.available_configurations(system_folders)
128192

129193
# each collection (file) can contain multiple configs. (e.g. test,
130194
# dev)

vantage6/cli/context.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
from sqlalchemy.engine.url import make_url
44

5-
from vantage6.cli.configuration_manager import (NodeConfigurationManager,
6-
ServerConfigurationManager)
75
from vantage6.common.context import AppContext
86
from vantage6.common.globals import APPNAME
9-
from vantage6.cli.globals import (
10-
DEFAULT_NODE_ENVIRONMENT as N_ENV,
11-
DEFAULT_NODE_SYSTEM_FOLDERS as N_FOL,
12-
DEFAULT_SERVER_ENVIRONMENT as S_ENV,
13-
DEFAULT_SERVER_SYSTEM_FOLDERS as S_FOL
14-
)
7+
from vantage6.cli.configuration_manager import (NodeConfigurationManager,
8+
ServerConfigurationManager)
9+
from vantage6.cli.globals import (DEFAULT_NODE_ENVIRONMENT as N_ENV,
10+
DEFAULT_NODE_SYSTEM_FOLDERS as N_FOL,
11+
DEFAULT_SERVER_ENVIRONMENT as S_ENV,
12+
DEFAULT_SERVER_SYSTEM_FOLDERS as S_FOL)
1513

1614

1715
class ServerContext(AppContext):

vantage6/cli/globals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828

2929
DATA_FOLDER = PACAKAGE_FOLDER / APPNAME / "_data"
3030

31-
with open(Path(PACAKAGE_FOLDER) / APPNAME / "VERSION") as f:
32-
VERSION = f.read()
31+
with open(Path(PACAKAGE_FOLDER) / APPNAME / "cli" / "VERSION") as f:
32+
VERSION = f.read()

vantage6/cli/node.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
from colorama import Fore, Style
2525

2626
from vantage6.common.globals import (STRING_ENCODING, APPNAME)
27+
from vantage6.common import (warning, error, info, debug)
28+
from vantage6.cli.context import NodeContext
2729
from vantage6.cli.globals import (
2830
DEFAULT_NODE_ENVIRONMENT as N_ENV,
2931
DEFAULT_NODE_SYSTEM_FOLDERS as N_FOL
3032
)
31-
from vantage6.cli.context import NodeContext
3233
from vantage6.cli.configuration_wizard import (
3334
configuration_wizard,
3435
select_configuration_questionaire
3536
)
36-
from vantage6.common import (warning, error, info, debug)
3737

3838

3939
@click.group(name="node")
@@ -131,7 +131,7 @@ def cli_node_new_configuration(name, environment, system_folders):
131131
)
132132

133133
# create config in ctx location
134-
cfg_file = configuration_wizard(name, environment, system_folders)
134+
cfg_file = configuration_wizard("node", name, environment, system_folders)
135135
info(f"New configuration created: {Fore.GREEN}{cfg_file}{Style.RESET_ALL}")
136136

137137
#
@@ -151,7 +151,7 @@ def cli_node_files(name, environment, system_folders):
151151
"""
152152
# select configuration name if none supplied
153153
name, environment = (name, environment) if name else \
154-
select_configuration_questionaire(system_folders)
154+
select_configuration_questionaire("node", system_folders)
155155

156156
# raise error if config could not be found
157157
if not NodeContext.config_exists(name, environment, system_folders):
@@ -215,7 +215,7 @@ def cli_node_start(name, config, environment, system_folders, image, keep,
215215
# in case no name is supplied, ask the user to select one
216216
if not name:
217217
name, environment = select_configuration_questionaire(
218-
system_folders)
218+
"node", system_folders)
219219

220220
# check that config exists, if not a questionaire will be invoked
221221
if not NodeContext.config_exists(name, environment, system_folders):
@@ -224,7 +224,7 @@ def cli_node_start(name, config, environment, system_folders, image, keep,
224224
question += f" create this config now?"
225225

226226
if q.confirm(question).ask():
227-
configuration_wizard(name, environment, system_folders)
227+
configuration_wizard("node", name, environment, system_folders)
228228

229229
else:
230230
error("Config file couldn't be loaded")

0 commit comments

Comments
 (0)