Skip to content

Commit 50de767

Browse files
author
Simca
committed
First alpha
1 parent 7459e9d commit 50de767

File tree

7 files changed

+52
-19
lines changed

7 files changed

+52
-19
lines changed

src/openstack_cli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
# limitations under the License.
1515

1616
__app_name__ = "openstack-cli"
17-
__app_version__ = "1.0.dev0"
17+
__app_version__ = "1.0"

src/openstack_cli/commands/list.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def print_cluster(servers: Dict[str, List[OpenStackVMInfo]]):
6565

6666

6767
def __init__(conf: Configuration, search_pattern: str):
68+
ostack = OpenStack(conf)
6869
clusters = ostack.get_server_by_cluster(search_pattern=search_pattern, sort=True)
6970

7071
if search_pattern and len(clusters) == 0:

src/openstack_cli/commands/up.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __work_unit(x: OpenStackVMInfo) -> bool:
6565
img_flavor = fl
6666
break
6767

68-
_default_key = ostack.get_keypairs()[0]
68+
_default_key = ostack.get_keypairs()[0] if ostack.get_keypairs() else None
6969
_key = _default_key if not key else ostack.get_keypair(name, _default_key)
7070
_pass = conf.default_vm_password if not password else password
7171

@@ -125,6 +125,6 @@ def __work_unit_waiter(x: OpenStackVMInfo) -> bool:
125125
users = line.split("@users@:")[1].strip().split(" ")
126126
to.print_row("User accounts", ",".join(users))
127127

128-
to.print_row("Used key", _key.name)
128+
to.print_row("Used key", _key.name if _key else "Not used")
129129
to.print_row("Used password", _pass)
130130

src/openstack_cli/core/__init__.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,22 @@ def main_entry():
2424
is_debug: bool = "debug" in commands.discovery.kwargs_name
2525
if is_debug:
2626
os.putenv("API_DEBUG", "True")
27-
28-
# currently hack to avoid key generating on reset command
29-
if commands.discovery.command_name == "conf" and commands.discovery.command_arguments[:1] == "reset":
30-
pass
31-
else:
32-
conf.initialize()
33-
34-
commands.discovery.start_application(kwargs={
35-
"conf": conf,
36-
"debug": is_debug
37-
})
27+
try:
28+
# currently hack to avoid key generating on reset command
29+
if commands.discovery.command_name == "conf" and commands.discovery.command_arguments[:1] == "reset":
30+
pass
31+
else:
32+
conf.initialize()
33+
34+
commands.discovery.start_application(kwargs={
35+
"conf": conf,
36+
"debug": is_debug
37+
})
38+
except Exception as e:
39+
if is_debug:
40+
raise e
41+
else:
42+
print(f"Error: {str(e)}")
3843

3944

4045
if __name__ == "__main__":

src/openstack_cli/modules/config/__init__.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,19 +279,44 @@ def __initial_configuration(self):
279279

280280
from openstack_cli.modules.openstack import OpenStack
281281

282-
self.os_address = self.__ask_text_question("OpenStack address: ")
283-
self.os_login = self.__ask_text_question("OpenStack login: ")
284-
self.os_password = self.__ask_text_question("OpenStack password", encrypted=True)
282+
self.os_address = self.__ask_text_question("OpenStack identity api address: ")
283+
self.os_login = self.__ask_text_question("OpenStack username: ")
284+
self.os_password = self.__ask_text_question("OpenStack password: ", encrypted=True)
285285

286+
print("Trying connect to the API...")
286287
osvm = OpenStack(self)
288+
if osvm.has_errors:
289+
from openstack_cli.core.output import StatusOutput
290+
so = StatusOutput()
291+
so.check_issues(osvm.last_errors)
292+
self.reset()
293+
raise RuntimeError("Unable to continue")
287294

288295
self.__test_encrypted_property = "test"
289296

290-
_p = getpass("Default VM password: ")
297+
from openstack_cli.commands.networks import print_networks
298+
299+
print("Please select default network for the VM (could be changed via 'conf network' command):")
300+
_net = print_networks(ostack=osvm, select=True)
301+
if not _net:
302+
raise RuntimeError("Network is not selected")
303+
self.default_network = _net
304+
305+
_p = self.__ask_text_question("Default VM password: ", encrypted=True)
291306
if not _p: # ToDo: add more strict check
292307
_p = "qwerty"
293308
self.default_vm_password = _p
294309

310+
from openstack_cli.commands.conf import _keys_create
311+
_default_keypair_name = "default"
312+
_existing_key = osvm.get_keypair(_default_keypair_name)
313+
if _existing_key:
314+
print(f"Keypair with name '{_default_keypair_name}' already exist, need to be removed")
315+
osvm.delete_keypair(_default_keypair_name)
316+
317+
_keys_create(self, osvm, _default_keypair_name)
318+
print(f"Key '{_default_keypair_name}' could be exported using command 'conf keys export {_default_keypair_name}'")
319+
295320
self.is_conf_initialized = True
296321
print("Tool configuration is done, thanks!")
297322

src/openstack_cli/modules/config/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self):
4242
self.__system: str = sys.platform
4343

4444
from openstack_cli import __app_name__ as app_name, __app_version__ as app_version
45-
self.__config_dir: str = self.__user_data_dir(appname=app_name, version=app_version)
45+
self.__config_dir: str = self.__user_data_dir(appname=app_name, version=None)
4646

4747
if self.__config_dir and not os.path.exists(self.__config_dir):
4848
os.makedirs(self.__config_dir, exist_ok=True)

src/openstack_cli/modules/config/storage.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ def reset(self):
123123
if os.path.exists(self.configuration_file_path):
124124
os.remove(self.configuration_file_path)
125125

126+
self._db_connection = sqlite3.connect(self.configuration_file_path, check_same_thread=False)
127+
126128
def create_key(self, persist: bool, master_password: str):
127129
if persist and master_password is None:
128130
print("Notice: With no password set would be generated default PC-depended encryption key")

0 commit comments

Comments
 (0)