mirror of
https://github.com/OVERLORD7F/SVMU.git
synced 2025-10-01 21:52:47 +03:00
Added option to write selected VMs by tag (#10) to сonfig
This commit is contained in:
@@ -119,14 +119,13 @@ def config_import(config_relative_path):
|
|||||||
vm_names.append(get_vm_name(base_url, api_key, x))
|
vm_names.append(get_vm_name(base_url, api_key, x))
|
||||||
return base_url, api_key, data_pool_uuid, data_pool_name, vm_list, vm_names, disk1_size, disk2_size, disk3_size
|
return base_url, api_key, data_pool_uuid, data_pool_name, vm_list, vm_names, disk1_size, disk2_size, disk3_size
|
||||||
|
|
||||||
def change_data_pool(base_url, api_key, config_relative_path):
|
def change_data_pool(base_url, api_key, config_relative_path): #change selected data pool in config
|
||||||
cls()
|
cls()
|
||||||
show_data_pools(base_url, api_key)
|
show_data_pools(base_url, api_key)
|
||||||
new_data_pool_uuid = input("Type NEW Data Pool UUID: ")
|
new_data_pool_uuid = input("Type NEW Data Pool UUID: ")
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(config_relative_path)
|
config.read(config_relative_path)
|
||||||
if config.has_section('Data_Pool'):
|
if config.has_section('Data_Pool'):
|
||||||
# update data_pool_uuid
|
|
||||||
config.set('Data_Pool', 'data_pool_uuid', new_data_pool_uuid)
|
config.set('Data_Pool', 'data_pool_uuid', new_data_pool_uuid)
|
||||||
with open(config_relative_path, 'w') as config_file:
|
with open(config_relative_path, 'w') as config_file:
|
||||||
config.write(config_file)
|
config.write(config_file)
|
||||||
@@ -135,7 +134,7 @@ def change_data_pool(base_url, api_key, config_relative_path):
|
|||||||
config_show(config_relative_path)
|
config_show(config_relative_path)
|
||||||
|
|
||||||
|
|
||||||
def change_vm_uuids(config_relative_path):
|
def change_vm_uuids(config_relative_path): #change selected VM uuids in config
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(config_relative_path)
|
config.read(config_relative_path)
|
||||||
# Remove old VM_List section if it exists, then add a fresh one
|
# Remove old VM_List section if it exists, then add a fresh one
|
||||||
|
@@ -2,11 +2,12 @@
|
|||||||
import requests
|
import requests
|
||||||
import secrets #for generating unique names
|
import secrets #for generating unique names
|
||||||
import os
|
import os
|
||||||
|
import configparser
|
||||||
from config_data_import import *
|
from config_data_import import *
|
||||||
from rich.console import Console , Align
|
from rich.console import Console , Align
|
||||||
from rich.columns import Columns
|
from rich.columns import Columns
|
||||||
from rich.panel import Panel
|
from rich.panel import Panel
|
||||||
from rich.prompt import Prompt
|
from rich.prompt import Prompt, Confirm
|
||||||
from rich.progress import Progress, SpinnerColumn, TextColumn
|
from rich.progress import Progress, SpinnerColumn, TextColumn
|
||||||
|
|
||||||
console = Console() #necessary for pretty menus & output
|
console = Console() #necessary for pretty menus & output
|
||||||
@@ -195,11 +196,11 @@ def vm_check_power(base_url , api_key , vm_uuids):
|
|||||||
if domain_info['user_power_state'] == 1:
|
if domain_info['user_power_state'] == 1:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def vm_tags(base_url, api_key):
|
def select_vm_by_tags(base_url, api_key, config_relative_path):
|
||||||
url = f"http://{base_url}/api/domains/"
|
url = f"http://{base_url}/api/domains/"
|
||||||
response = requests.get(url, headers={'Authorization': api_key})
|
response = requests.get(url, headers={'Authorization': api_key})
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
verbose_name_input = input("Write tag:")
|
verbose_name_input = input("Specify tag: ")
|
||||||
output_renderables = []
|
output_renderables = []
|
||||||
vm_info_short = response.json()
|
vm_info_short = response.json()
|
||||||
y= vm_info_short
|
y= vm_info_short
|
||||||
@@ -215,15 +216,31 @@ def vm_tags(base_url, api_key):
|
|||||||
else:
|
else:
|
||||||
print(f"Failed to retrieve data {response.status_code}")
|
print(f"Failed to retrieve data {response.status_code}")
|
||||||
console.rule(style="grey53")
|
console.rule(style="grey53")
|
||||||
|
|
||||||
|
if vm_id_list: # promt to write found VM UUIDs to config
|
||||||
|
write_to_config = Confirm.ask("[bold yellow]Write these VM UUIDs to config file?")
|
||||||
|
if write_to_config:
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read(config_relative_path)
|
||||||
|
# Remove old VM_List section if it exists, then add a fresh one
|
||||||
|
if config.has_section('VM_List'):
|
||||||
|
config.remove_section('VM_List')
|
||||||
|
config.add_section('VM_List')
|
||||||
|
for idx, vm_id in enumerate(vm_id_list, 1):
|
||||||
|
config.set('VM_List', f'uuid_{idx}', vm_id)
|
||||||
|
with open(config_relative_path, 'w') as configfile:
|
||||||
|
config.write(configfile)
|
||||||
|
console.print(f"[green bold]VM UUIDs have been written in config :pencil:")
|
||||||
|
|
||||||
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')
|
||||||
return(vm_id_list)
|
return(vm_id_list)
|
||||||
|
|
||||||
def vm_menu(base_url, api_key, vm_uuids):
|
def vm_menu(base_url, api_key, vm_uuids, config_relative_path):
|
||||||
os.system('cls' if os.name=='nt' else 'clear')
|
os.system('cls' if os.name=='nt' else 'clear')
|
||||||
config_menu_options="[gold bold][1] [grey53 italic]Show VM info \n (for selected VMs in config)[/grey53 italic]\n \
|
config_menu_options="[gold bold][1] [grey53 italic]Show VM info \n (for selected VMs in config)[/grey53 italic]\n \
|
||||||
\n[gold bold][2] [grey53 italic]Show VMs Name / UUID[/grey53 italic]\n \
|
\n[gold bold][2] [grey53 italic]Show VMs Name / UUID[/grey53 italic]\n \
|
||||||
\n[gold bold][3] [grey53 italic]Show VMs by tags / UUID[/grey53 italic]\n \
|
\n[gold bold][3] [grey53 italic]Select VMs by tag / UUID[/grey53 italic]\n \
|
||||||
\n\n[green_yellow bold]ENTER - return to Main Menu[/]"
|
\n\n[green_yellow bold]ENTER - return to Main Menu[/]"
|
||||||
config_menu_options=Align.center(config_menu_options, vertical="middle")
|
config_menu_options=Align.center(config_menu_options, vertical="middle")
|
||||||
console = Console()
|
console = Console()
|
||||||
@@ -239,4 +256,4 @@ def vm_menu(base_url, api_key, vm_uuids):
|
|||||||
vm_info_short(base_url , api_key)
|
vm_info_short(base_url , api_key)
|
||||||
if sub_choice == "3":
|
if sub_choice == "3":
|
||||||
os.system('cls' if os.name=='nt' else 'clear')
|
os.system('cls' if os.name=='nt' else 'clear')
|
||||||
vm_tags(base_url , api_key)
|
select_vm_by_tags(base_url , api_key, config_relative_path)
|
4
main.py
4
main.py
@@ -22,7 +22,7 @@ while(menu_choice != ""): #main menu loop
|
|||||||
menu_options=f"[gold bold][1] [grey53 italic]Manage utility config\n[/grey53 italic] \
|
menu_options=f"[gold bold][1] [grey53 italic]Manage utility config\n[/grey53 italic] \
|
||||||
\n[gold bold][2] [grey53 italic]Enter disk edit mode[/grey53 italic]\n \
|
\n[gold bold][2] [grey53 italic]Enter disk edit mode[/grey53 italic]\n \
|
||||||
\n[gold bold][3] [grey53 italic]Show breif cluster overview[/grey53 italic]\n \
|
\n[gold bold][3] [grey53 italic]Show breif cluster overview[/grey53 italic]\n \
|
||||||
\n[gold bold][4] [grey53 italic]Show VM info[/grey53 italic]\n \
|
\n[gold bold][4] [grey53 italic]Enter VM menu[/grey53 italic]\n \
|
||||||
\n[gold bold][5] [grey53 italic]Show data pools[/grey53 italic]\n \
|
\n[gold bold][5] [grey53 italic]Show data pools[/grey53 italic]\n \
|
||||||
\n\n[green_yellow bold]ENTER - exit Utility[/]\n\n \
|
\n\n[green_yellow bold]ENTER - exit Utility[/]\n\n \
|
||||||
[underline bold grey53]Currently imported config:[/]\n \
|
[underline bold grey53]Currently imported config:[/]\n \
|
||||||
@@ -38,7 +38,7 @@ while(menu_choice != ""): #main menu loop
|
|||||||
if menu_choice == "3":
|
if menu_choice == "3":
|
||||||
cluster_info(base_url , api_key)
|
cluster_info(base_url , api_key)
|
||||||
if menu_choice == "4":
|
if menu_choice == "4":
|
||||||
vm_menu(base_url , api_key, vm_uuids)
|
vm_menu(base_url , api_key, vm_uuids, config_relative_path)
|
||||||
if menu_choice == "5":
|
if menu_choice == "5":
|
||||||
show_data_pools(base_url , api_key)
|
show_data_pools(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
|
||||||
|
Reference in New Issue
Block a user