mirror of
https://github.com/OVERLORD7F/SVMU.git
synced 2025-10-01 21:52:47 +03:00
- Finally, proper config file is here!
- Small changes in menus
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
import configparser
|
||||
from cluster_api import *
|
||||
from data_pools_api import *
|
||||
from rich import print
|
||||
@@ -20,6 +20,7 @@ def config_menu(config_relative_path):
|
||||
sub_choice=str(input("\n>>> "))
|
||||
if sub_choice == "1":
|
||||
config_show(config_relative_path)
|
||||
config_menu(config_relative_path)
|
||||
if sub_choice == "2":
|
||||
config_edit(config_relative_path)
|
||||
|
||||
@@ -29,57 +30,63 @@ def config_show(config_relative_path):
|
||||
with open(config_relative_path, "r") as f:
|
||||
print(f.read())
|
||||
console.rule(style="yellow")
|
||||
Prompt.ask("[green_yellow bold]ENTER - return to Main Menu.. :right_arrow_curving_down:")
|
||||
Prompt.ask("[green_yellow bold]ENTER - return to Utility Configuration.. :right_arrow_curving_down:")
|
||||
|
||||
def import_vm_uuid(config_relative_path):
|
||||
vm_uuids = []
|
||||
with open(config_relative_path, "r") as f:
|
||||
for i in range(3): # ignoring 2 first lines (IP, API-KEY)
|
||||
next(f)
|
||||
for line in f:
|
||||
line = line.strip('\n')
|
||||
if line: # checks if line is empty (EOF). ESSENTIAL, DO NOT REMOVE
|
||||
vm_uuids.append(line)
|
||||
return vm_uuids
|
||||
def config_import(config_relative_path):
|
||||
config = configparser.ConfigParser()
|
||||
config.read(config_relative_path)
|
||||
|
||||
def import_threelines(config_relative_path):
|
||||
threelines = [None] * 3
|
||||
with open(config_relative_path, "r") as f:
|
||||
all_lines = f.readlines()
|
||||
if len(all_lines) < 3:
|
||||
raise ValueError("Check config. Receiving less than 3 lines!")
|
||||
threelines[0] = all_lines[0].strip('\n')
|
||||
threelines[1] = "jwt " + all_lines[1].strip('\n') #actual format for api_key. That was realy obvious DACOM >:C
|
||||
threelines[2] = all_lines[2].strip('\n')
|
||||
return threelines
|
||||
base_url = config.get('General', 'controller_ip')
|
||||
api_key = config.get('General', 'api_key')
|
||||
data_pool_uuid = config.get('Data_Pool', 'data_pool_uuid')
|
||||
|
||||
vm_list = []
|
||||
if 'VM_List' in config:
|
||||
for key, value in config['VM_List'].items():
|
||||
vm_list.append(value)
|
||||
|
||||
config_values = {
|
||||
'base_url': base_url,
|
||||
'api_key': "jwt " + api_key,
|
||||
'data_pool_uuid': data_pool_uuid,
|
||||
'vm_list': vm_list
|
||||
}
|
||||
|
||||
return config_values
|
||||
|
||||
def config_edit(config_relative_path):
|
||||
read_input=input("Create new config file? (Y / N): ")
|
||||
menu_choice=str(read_input)
|
||||
read_input = input("Create new config file? (Y / N): ")
|
||||
menu_choice = str(read_input)
|
||||
if menu_choice == "Y" or menu_choice == "y":
|
||||
base_url = input("Type SpaceVM Controller IP: ")
|
||||
while ping(base_url) != True:
|
||||
base_url = console.input("[bold red]No response.\nCheck and type SpaceVM Controller IP again: [/]")
|
||||
api_key = input("Type your API Key: ")
|
||||
while check_api_key(base_url, "jwt " + api_key) != 200:
|
||||
api_key = console.input("[bold red]Check and type SpaceVM Controller API Key again: [/]")
|
||||
data_pools(base_url,"jwt " + api_key)
|
||||
data_pool_uuid = input("Type Data Pool UUID you wish to use: ")
|
||||
lines = [base_url, api_key, data_pool_uuid]
|
||||
with open(config_relative_path, "w+") as file:
|
||||
for line in lines:
|
||||
file.write(line + '\n')
|
||||
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config["General"] = {
|
||||
"controller_ip": base_url,
|
||||
"api_key": api_key,
|
||||
}
|
||||
config["Data_Pool"] = {"data_pool_uuid": data_pool_uuid}
|
||||
|
||||
with open(config_relative_path, "w") as configfile:
|
||||
config.write(configfile)
|
||||
|
||||
print("Type VM UUIDs one by one (input ENTER to stop)")
|
||||
with open(config_relative_path, "a") as file: #appends new content at the end without modifying the existing data
|
||||
vm_input="test"
|
||||
while (vm_input != ""):
|
||||
with open(config_relative_path, "a") as file:
|
||||
file.write("[VM_List]\n") #manually writing section for VMs
|
||||
vm_input = []
|
||||
x = 0
|
||||
while vm_input != "":
|
||||
vm_input = input(">> ")
|
||||
file.write(vm_input + '\n')
|
||||
console.print("[green bold]VM UUIDs has been written in config :pencil:")
|
||||
console.print("[green bold]Configuration completed ! :white_check_mark:")
|
||||
Prompt.ask("[green_yellow bold]Press ENTER to proceed.. :right_arrow_curving_down:")
|
||||
cls()
|
||||
if vm_input:
|
||||
x += 1
|
||||
file.write(f"UUID_{x} = {vm_input}\n")
|
||||
|
||||
console.print("[green bold]VM UUIDs have been written in config :pencil:")
|
||||
console.print("[green bold]Configuration completed ! :white_check_mark:")
|
||||
Prompt.ask("[green_yellow bold]Press ENTER to proceed.. :right_arrow_curving_down:")
|
||||
cls()
|
||||
|
||||
def cls():
|
||||
os.system('cls' if os.name=='nt' else 'clear')
|
||||
|
Reference in New Issue
Block a user