changes in importing config

This commit is contained in:
OVERLORD7F
2025-05-15 11:46:28 +03:00
parent 22f3d3fe64
commit 28e9bb8ea4
2 changed files with 34 additions and 13 deletions

20
config_data_import.py Normal file
View File

@@ -0,0 +1,20 @@
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 import_threelines(config_relative_path):
threelines = []
with open(config_relative_path, "r") as f:
all_lines = f.readlines()
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

27
main.py
View File

@@ -1,5 +1,8 @@
import sys
import os
from config_data_import import *
from cluster_api import *
from domain_api import *
@@ -38,22 +41,24 @@ else:
config_edit()
#importing API-KEY / IP / DATA POOL UUID from config
threelines = import_threelines(config_relative_path)
print(f"3 lines: {threelines}")
base_url=threelines[0]
api_key=threelines[1]
data_pool_uuid=threelines[2]
'''
with open(config_relative_path, "r") as f:
all_lines = f.readlines()
base_url = all_lines[0].strip('\n')
api_key = "jwt " + all_lines[1].strip('\n') #actual format for api_key. That was realy obvious DACOM >:C
data_pool_uuid = all_lines[2].strip('\n')
'''
#importing VM-UUIDs
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)
vm_uuids = import_vm_uuid(config_relative_path)
print(f"vm uuids: {vm_uuids}")
#so-called INT MAIN
menu_choice=0
@@ -84,8 +89,6 @@ while(menu_choice != ""): #main menu loop
if menu_choice == 2:
print(vm_uuids)
select_uuids=int(input("Select VM to delete disks from. \n Type VM uuid index number (from list above) to select: ")) - 1
print(f"actual selected uuid = {select_uuids}")
print(vm_uuids[select_uuids])
domain_all_content = get_domain_all_content(base_url , api_key , vm_uuids[select_uuids])
disk_uuids = get_disk_uuids(base_url , api_key , domain_all_content)
for x in disk_uuids:
@@ -95,8 +98,6 @@ while(menu_choice != ""): #main menu loop
vdisk_size=str(input("Enter disk size (GB): "))
print(vm_uuids)
select_uuids=int(input("Select VM to attach new disk. \n Type VM uuid index number (from list above) to select: ")) - 1
print(f"actual selected uuid = {select_uuids}")
print(vm_uuids[select_uuids])
create_and_attach_disk(vm_uuids[select_uuids] , data_pool_uuid, vdisk_size, "falloc")
if menu_choice == 4:
print("#" * 5 , "Preparing VMs for Courses" , "#" * 5)