-
Notifications
You must be signed in to change notification settings - Fork 1
/
engima
executable file
·136 lines (133 loc) · 6.07 KB
/
engima
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env python3
import colorama
import os
import subprocess
import time
from colorama import Fore, Style
from consolemenu import *
from consolemenu.items import *
print(Fore.RED) #Declares default color. Will add multiple colors soon!
# GUI Logic
def mainConsole():
# GUI Logic
menu = ConsoleMenu("MultipassSimplified v1.1", "A Python TUI Interface for the Multipass VM System by Ty "WarpWing" Chermsirivatana.")
# Command Logic
launchMP = FunctionItem("Create New MP Instance", launchMPI)
shellMP = FunctionItem("Shell into MP Instance",shellMPI)
stopMP = FunctionItem("Stop MP Instance",stopMPI)
deleteMP = FunctionItem("Delete MP Instance",deleteMPI)
purgeMP = FunctionItem("Purge deleted MP Instances",purgeMPI)
recoverMP = FunctionItem("Recover deleted MP Instance",recoverMPI)
# Menu Append Array
menu.append_item(launchMP)
menu.append_item(shellMP)
menu.append_item(stopMP)
menu.append_item(deleteMP)
menu.append_item(purgeMP)
menu.append_item(recoverMP)
# Menu Show Function
menu.show()
# Launch MP Logic
def launchMPI():
print("What would like to name this MP Instance?")
mpname = input("Name: ")
print("How many CPUs would you like to allocate?")
print("The minimum CPUs is 1 and the default CPU allocation is 1 if left blank")
mpcpu = input("CPUs: ")
print("How much Memory would you like to allocate?")
print("Please use the suffixes of K,M or G in declaring memory.")
print("The minimum Memory is 128M and the default is 1G if left blank")
mpmem = input("Memory: ")
print("How much disk space would you like to allocate?")
print("Please use the suffixes of K,M or G in declaring disk space.")
print("The minimum storage is 512M and the default is 5G")
mpdisk = input("Space: ")
mpc = input("Would you like to include a CloudInit file? y/n?: ")
if mpc == 'y':
mpci = input("Please provide the absolute path of the Cloudinit file: ")
else:
mpci = ''
if mpcpu == '':
mpcpu = 1
if mpmem == '':
mpmem = '128M'
if mpdisk == '':
mpdisk = '5G'
print(f"To finalize the creation of this MP Instance,please verify the following settings:")
print(f"Name: {mpname}")
print(f"CPUs: {mpcpu}")
print(f"Memory: {mpmem}")
print(f"Disk Space: {mpdisk}")
print(f"Cloud-Init File Path: {mpci}")
mpfinal = input("Is this correct? y/n?: ")
if mpfinal == "y":
print("Creating MP Instance with the following settings")
os.system(f"multipass launch -n {mpname} -c {mpcpu} -m {mpmem} -d {mpdisk} ")
print(f"Instance {mpname} created!")
time.sleep(2)
elif mpci != '' and mpfinal == "y":
print("Creating MP Instance with the following settings")
os.system(f"multipass launch -n {mpname} -c {mpcpu} -m {mpmem} -d {mpdisk} --cloud-init {mpci}")
print(f"Instance {mpname} created!")
time.sleep(2)
else:
print("Going back to the main menu!") # I'll work on a fix later that allows you to either resubmit settings or go back to the main menu.
time.sleep(2)
# Shell MP Logic
def shellMPI():
print("---------------------------------------------------------------------------")
x = subprocess.Popen("multipass list", shell=True, stdout=subprocess.PIPE)
subprocess_return = x.stdout.read()
print(subprocess_return.decode("ascii"))
print("---------------------------------------------------------------------------")
x = input(f"Please type the name of the instance you would like to shell into: ")
os.system(f"multipass shell {x}")
print(Fore.RED)
# Stop MP Instance Logic
def stopMPI():
print("---------------------------------------------------------------------------")
x = subprocess.Popen("multipass list", shell=True, stdout=subprocess.PIPE)
subprocess_return = x.stdout.read()
print(subprocess_return.decode("ascii"))
print("---------------------------------------------------------------------------")
x = input(f"Please type the name of the instance you would like to stop: ")
os.system(f"multipass stop {x}")
print(Fore.RED)
# Delete MP Instance Logic
def deleteMPI():
print("---------------------------------------------------------------------------")
x = subprocess.Popen("multipass list", shell=True, stdout=subprocess.PIPE)
subprocess_return = x.stdout.read()
print(subprocess_return.decode("ascii"))
print("---------------------------------------------------------------------------")
x = input(f"Please type the name of the instance you would like to delete: ")
os.system(f"multipass delete {x}")
print(Fore.RED)
# Purge MP Instance Logic
def purgeMPI():
print("---------------------------------------------------------------------------")
x = subprocess.Popen("multipass list", shell=True, stdout=subprocess.PIPE)
subprocess_return = x.stdout.read()
print(subprocess_return.decode("ascii"))
print("---------------------------------------------------------------------------")
x1 = input(f"This command terminates all deleted MP Instances. You cannot recover them after this process is finished. Would you like to continue? y/n?: ")
if x1 == "y":
print("Purging all deleted MP Instances!")
os.system(f"multipass purge")
print("All deleted MP Instances have been purged.")
time.sleep(2)
else:
print("Going back to the main menu!") # I'll work on a fix later that allows you to either resubmit settings or go back to the main menu.
time.sleep(2)
# Recovery MP Instance Logic
def recoverMPI():
print("---------------------------------------------------------------------------")
x = subprocess.Popen("multipass list", shell=True, stdout=subprocess.PIPE)
subprocess_return = x.stdout.read()
print(subprocess_return.decode("ascii"))
print("---------------------------------------------------------------------------")
x = input(f"Please type the name of the instance you would like to recover: ")
os.system(f"multipass recover {x}")
print(Fore.RED)
# Invoking Console
mainConsole()