-
-
Save aweimeow/12d08db27ac3547704052997b6224c33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python3 | |
import os | |
import sys | |
from subprocess import Popen, PIPE | |
def command(cmd): | |
p = Popen(cmd.split(), stdout=PIPE, stderr=PIPE) | |
stdout, stderr = p.communicate() | |
return stdout if stdout else stderr | |
if __name__ == '__main__': | |
print('Image Generator, Empty for default value') | |
name = input('Input VM name: ') | |
base = input('Input base Image(trusty/xenial): ') | |
size = input('Input VM image size(10, GB for unit): ') | |
if not name: | |
raise Exception('Name should not be empty') | |
if not base: | |
base = 'trusty' | |
if not size: | |
size = 10 | |
else: | |
size = int(size) | |
variant = 'ubuntu14.04' if base == 'trusty' else 'ubuntu16.04' | |
create_img_cmd = 'qemu-img create -f qcow2 {name}.qcow2 {size}G' | |
virt_install_cmd = 'virt-install --virt-type kvm --name {name} --ram 1024 '\ | |
'--cdrom=base/{base}.iso '\ | |
'--disk={name}.qcow2,format=qcow2 '\ | |
'--network network=default '\ | |
'--graphics vnc,listen=0.0.0.0 --noautoconsole '\ | |
'--os-type=linux --os-variant={variant}' | |
os.system(create_img_cmd.format(name=name, size=size)) | |
os.system(virt_install_cmd.format(name=name, base=base, variant=variant)) | |
#print(command(create_img_cmd.format(name=name, size=size))) | |
#print(command(virt_install_cmd.format(name=name, base=base, variant))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment