-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
executable file
·76 lines (62 loc) · 2.32 KB
/
main.py
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
#!/usr/bin/python3
#Script will ask about VM name, ram, disk size and etc
import os
class create:
def __init__(self):
self.check_packages()
self.disk_path="/var/lib/libvirt/images/"
self.bus="virtio"
self.location="http://172.22.26.203/repos/fedora25/"
self.net_adp="virbr0"
self.ksfile="http://172.22.26.203/repos/ksnew2.cfg"
def check_packages(self):
os.system("./libvirt.sh")
print("Prerequisite Check \n donex")
def get_name(self):
self.name=input("Enter name of VM: ")
return self.name
def get_ram(self):
ram=input("Enter RAM size(MiB): ")
return ram
def get_cpus(self):
cpus=input("Enter number of vcpus: ")
return cpus
def get_size(self):
size=input("Enter size you want to allocate to VM(GiB): ")
return size
def get_ksdevice(self):
ksdevice=input("Enter the network interface to be used during installation: ")
return ksdevice
def get_ipaddress(self):
ipaddress=input("Enter the ipaddress to be assigned to operating system: ")
return ipaddress
def get_netmask(self):
netmask=input("Enter the subnet mask to be assigned to operating system: ")
return netmask
def get_gateway(self):
gateway=input("Enter the gateway to be assigned to operating system: ")
return gateway
def get_dns(self):
dns=input("Enter the dns to be assigned to operating system: ")
return dns
def final(self):
#os.system('ls')
self.finalcmd=str("virt-install "
+" --name "+self.get_name()
+" --ram "+self.get_ram()
+" --vcpus "+self.get_cpus()
+" --disk path="+self.disk_path+self.name+".qcow2,bus="+self.bus+",size="+self.get_size()
+" --location "+self.location
+" --extra-args="
+"'ks="+self.ksfile
+" ksdevice=ens3"
+" ip="+self.get_ipaddress()
+" netmask="+self.get_netmask()
+" gateway="+self.get_gateway()
+" dns="+self.get_dns()
+"' --network bridge:"+self.net_adp)
print(self.finalcmd)
os.system(self.finalcmd)
if __name__ == '__main__':
vm = create()
vm.final()