mirror of
https://github.com/OVERLORD7F/SVMU.git
synced 2025-10-01 21:52:47 +03:00
@@ -34,4 +34,16 @@ def cluster_info(base_url, api_key): # output short clusters overview
|
||||
else:
|
||||
console.print(f"[red]Failed to retrieve data {response.status_code}[/]")
|
||||
Prompt.ask("[green_yellow bold]ENTER - return to Main Menu.. :right_arrow_curving_down:")
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
|
||||
def check_api_key(base_url, api_key): # test api key and show spaceVM version
|
||||
url = f"http://{base_url}/api/controllers/base-version/"
|
||||
response = requests.get(url, headers={'Authorization': api_key})
|
||||
console = Console()
|
||||
if response.status_code == 200:
|
||||
cluster_info = response.json()
|
||||
version = cluster_info['version']
|
||||
console.print(f"[bold green]Successfully conected to SpaceVM version {version}")
|
||||
else:
|
||||
console.print(f"[bold red]{response.status_code}[/]")
|
||||
return response.status_code
|
@@ -1,5 +1,8 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from cluster_api import *
|
||||
from data_pools_api import *
|
||||
from rich import print
|
||||
from rich.panel import Panel
|
||||
from rich.console import Console , Align
|
||||
@@ -55,7 +58,12 @@ def config_edit(config_relative_path):
|
||||
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:
|
||||
@@ -74,4 +82,16 @@ def config_edit(config_relative_path):
|
||||
cls()
|
||||
|
||||
def cls():
|
||||
os.system('cls' if os.name=='nt' else 'clear')
|
||||
os.system('cls' if os.name=='nt' else 'clear')
|
||||
|
||||
def ping(base_url):
|
||||
DNULL = open(os.devnull, 'w')
|
||||
if os.name == 'nt':
|
||||
status = subprocess.call(["ping","-n","1",base_url],stdout = DNULL)
|
||||
else:
|
||||
status = subprocess.call(["ping","-c","1",base_url],stdout = DNULL)
|
||||
|
||||
if status == 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
@@ -12,7 +12,7 @@ def data_pools(base_url, api_key): # output data pool info
|
||||
if response.status_code == 200:
|
||||
data_pools = response.json()
|
||||
results_data_pools_info = data_pools['results']
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
#os.system('cls' if os.name == 'nt' else 'clear')
|
||||
console.rule("[bold cyan]Data Pools Overview")
|
||||
console.print(f"[bold]Data pools total:[/] {data_pools['count']}\n")
|
||||
panels = []
|
||||
@@ -32,5 +32,4 @@ def data_pools(base_url, api_key): # output data pool info
|
||||
console.print(*panels, sep="\n")
|
||||
else:
|
||||
console.print(f"[red]Failed to retrieve data {response.status_code}[/]")
|
||||
Prompt.ask("[green_yellow bold]ENTER - return to Main Menu.. :right_arrow_curving_down:")
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
Prompt.ask("[green_yellow bold]ENTER - return to Main Menu.. :right_arrow_curving_down:")
|
4
main.py
4
main.py
@@ -51,5 +51,7 @@ title="[bold magenta]SpaceVM Utility - Main Menu" , subtitle = menu_subtitle, su
|
||||
data_pools(base_url , api_key)
|
||||
if menu_choice == "6":
|
||||
vm_info_short(base_url , api_key)
|
||||
if menu_choice == "7":
|
||||
check_api_key(base_url, api_key)
|
||||
os.system('cls' if os.name=='nt' else 'clear') #clears screen before looping back to main menu
|
||||
console.print("[red bold]Exiting Utility ")
|
||||
console.print("[red bold]Exiting Utility ")
|
||||
|
Reference in New Issue
Block a user