2025-05-13 17:41:42 +03:00
|
|
|
import requests
|
2025-05-16 17:53:57 +03:00
|
|
|
import os
|
|
|
|
from rich.prompt import Prompt
|
2025-05-21 14:12:37 +03:00
|
|
|
from rich.console import Console
|
|
|
|
from rich.panel import Panel
|
|
|
|
from rich.align import Align
|
2025-05-13 17:41:42 +03:00
|
|
|
|
2025-05-28 12:45:07 +03:00
|
|
|
def show_data_pools(base_url, api_key): # output data pool info
|
2025-05-21 14:12:37 +03:00
|
|
|
url = f"http://{base_url}//api/data-pools/"
|
|
|
|
response = requests.get(url, headers={'Authorization': api_key})
|
|
|
|
console = Console()
|
2025-05-13 17:41:42 +03:00
|
|
|
if response.status_code == 200:
|
|
|
|
data_pools = response.json()
|
|
|
|
results_data_pools_info = data_pools['results']
|
2025-05-26 10:28:01 +03:00
|
|
|
#os.system('cls' if os.name == 'nt' else 'clear')
|
2025-05-21 14:12:37 +03:00
|
|
|
console.rule("[bold cyan]Data Pools Overview")
|
|
|
|
console.print(f"[bold]Data pools total:[/] {data_pools['count']}\n")
|
|
|
|
panels = []
|
2025-05-13 17:41:42 +03:00
|
|
|
for x in results_data_pools_info:
|
2025-05-21 14:12:37 +03:00
|
|
|
panel_content = (
|
|
|
|
f"[bold]Type:[/] {x['type']}\n"
|
|
|
|
f"[bold]Used:[/] {round((x['free_space']/1024), 1)} Gb / {round((x['size'] / 1024), 1)} Gb\n"
|
|
|
|
f"[bold]UUID:[/] [italic]{x['id']}"
|
|
|
|
)
|
|
|
|
panel = Panel(
|
|
|
|
Align.left(panel_content),
|
|
|
|
title=f"[bold gold3]{x['verbose_name']}[/] [red]({x['status']})[/]",
|
|
|
|
border_style="magenta",
|
|
|
|
expand=False
|
|
|
|
)
|
|
|
|
panels.append(panel)
|
|
|
|
console.print(*panels, sep="\n")
|
2025-05-13 17:41:42 +03:00
|
|
|
else:
|
2025-05-21 14:12:37 +03:00
|
|
|
console.print(f"[red]Failed to retrieve data {response.status_code}[/]")
|
2025-05-26 17:52:12 +03:00
|
|
|
Prompt.ask("[green_yellow bold]ENTER - to proceed.. :right_arrow_curving_down:")
|
|
|
|
|
|
|
|
#translates data pool uuid to verbose_name
|
|
|
|
def get_data_pool_name(base_url, api_key, data_pool_uuid):
|
|
|
|
url = f"http://{base_url}//api/data-pools/{data_pool_uuid}/"
|
|
|
|
response = requests.get(url, headers={'Authorization': api_key})
|
|
|
|
if response.status_code == 200:
|
|
|
|
data_pool_name = response.json()
|
|
|
|
return (f"{data_pool_name['verbose_name']}")
|