mirror of
https://github.com/OVERLORD7F/SVMU.git
synced 2025-10-01 21:52:47 +03:00
@@ -35,3 +35,15 @@ def cluster_info(base_url, api_key): # output short clusters overview
|
|||||||
console.print(f"[red]Failed to retrieve data {response.status_code}[/]")
|
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:")
|
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 os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from cluster_api import *
|
||||||
|
from data_pools_api import *
|
||||||
from rich import print
|
from rich import print
|
||||||
from rich.panel import Panel
|
from rich.panel import Panel
|
||||||
from rich.console import Console , Align
|
from rich.console import Console , Align
|
||||||
@@ -55,7 +58,12 @@ def config_edit(config_relative_path):
|
|||||||
menu_choice=str(read_input)
|
menu_choice=str(read_input)
|
||||||
if menu_choice == "Y" or menu_choice == "y":
|
if menu_choice == "Y" or menu_choice == "y":
|
||||||
base_url = input("Type SpaceVM Controller IP: ")
|
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: ")
|
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: ")
|
data_pool_uuid = input("Type Data Pool UUID you wish to use: ")
|
||||||
lines = [base_url, api_key, data_pool_uuid]
|
lines = [base_url, api_key, data_pool_uuid]
|
||||||
with open(config_relative_path, "w+") as file:
|
with open(config_relative_path, "w+") as file:
|
||||||
@@ -75,3 +83,15 @@ def config_edit(config_relative_path):
|
|||||||
|
|
||||||
def 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:
|
if response.status_code == 200:
|
||||||
data_pools = response.json()
|
data_pools = response.json()
|
||||||
results_data_pools_info = data_pools['results']
|
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.rule("[bold cyan]Data Pools Overview")
|
||||||
console.print(f"[bold]Data pools total:[/] {data_pools['count']}\n")
|
console.print(f"[bold]Data pools total:[/] {data_pools['count']}\n")
|
||||||
panels = []
|
panels = []
|
||||||
@@ -33,4 +33,3 @@ def data_pools(base_url, api_key): # output data pool info
|
|||||||
else:
|
else:
|
||||||
console.print(f"[red]Failed to retrieve data {response.status_code}[/]")
|
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:")
|
Prompt.ask("[green_yellow bold]ENTER - return to Main Menu.. :right_arrow_curving_down:")
|
||||||
os.system('cls' if os.name == 'nt' else 'clear')
|
|
2
main.py
2
main.py
@@ -51,5 +51,7 @@ title="[bold magenta]SpaceVM Utility - Main Menu" , subtitle = menu_subtitle, su
|
|||||||
data_pools(base_url , api_key)
|
data_pools(base_url , api_key)
|
||||||
if menu_choice == "6":
|
if menu_choice == "6":
|
||||||
vm_info_short(base_url , api_key)
|
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
|
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