|
2 | 2 |
|
3 | 3 | from pathlib import Path |
4 | 4 |
|
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 | +) |
8 | 10 |
|
9 | 11 | def node_configuration_questionaire(dirs, instance_name): |
10 | 12 | """Questionary to generate a config file for the node instance.""" |
@@ -94,37 +96,99 @@ def node_configuration_questionaire(dirs, instance_name): |
94 | 96 |
|
95 | 97 | return config |
96 | 98 |
|
| 99 | +def server_configuration_questionaire(dirs, instance_name): |
| 100 | + """Questionary to generate a config file for the node instance.""" |
97 | 101 |
|
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): |
99 | 157 |
|
100 | 158 | # 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) |
102 | 160 |
|
103 | 161 | # 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) |
105 | 168 |
|
106 | 169 | # in the case of an environment we need to add it to the current |
107 | 170 | # configuration. In the case of application we can simply overwrite this |
108 | 171 | # key (although there might be environments present) |
109 | 172 | config_file = Path(dirs.get("config")) / (instance_name + ".yaml") |
110 | 173 |
|
111 | 174 | if Path(config_file).exists(): |
112 | | - config_manager = NodeConfigurationManager.from_file(config_file) |
| 175 | + config_manager = conf_manager.from_file(config_file) |
113 | 176 | else: |
114 | | - config_manager = NodeConfigurationManager(instance_name) |
| 177 | + config_manager = conf_manager(instance_name) |
115 | 178 |
|
116 | 179 | config_manager.put(environment, config) |
117 | 180 | config_manager.save(config_file) |
118 | 181 |
|
119 | 182 | return config_file |
120 | 183 |
|
121 | 184 |
|
122 | | -def select_configuration_questionaire(system_folders): |
| 185 | +def select_configuration_questionaire(type_, system_folders): |
123 | 186 | """Ask which configuration the user wants to use |
124 | 187 |
|
125 | 188 | It shows only configurations that are in the default folder. |
126 | 189 | """ |
127 | | - configs, f = NodeContext.available_configurations(system_folders) |
| 190 | + context = NodeContext if type_ == "node" else ServerContext |
| 191 | + configs, f = context.available_configurations(system_folders) |
128 | 192 |
|
129 | 193 | # each collection (file) can contain multiple configs. (e.g. test, |
130 | 194 | # dev) |
|
0 commit comments