From fb10bde9f190d465532c43e613b45fc80971c125 Mon Sep 17 00:00:00 2001 From: Kushal Das Date: Aug 06 2015 12:21:15 +0000 Subject: setup_instance function will setup a new instance. --- diff --git a/computer/virt.py b/computer/virt.py index 996d9a6..a963c37 100644 --- a/computer/virt.py +++ b/computer/virt.py @@ -1,4 +1,5 @@ import os +import time import subprocess def system(cmd): @@ -54,3 +55,25 @@ def setup_instance_storage(image_name, instance_name, path='/var/lib/libvirt/ima return True, file_path +def setup_instance(instance_name, storage_path, ram=1024, vcpus=1): + """ + Sets up an instance, and boot it. + + :param instance_name: Name of the instance. + :param storage_path: Path of the storage. + :param ram: RAM for the instance, default is 1024MB + :param vcpus: Default is one. + :return: + """ + + cmd = '/usr/bin/virt-install --connect qemu:///system --import -n {0} --nographics -r {1} --os-type=linux --disk {2},device=disk,bus=virtio,format=qcow2 --vcpus={3}'.format(instance_name, ram, storage_path, vcpus) + out, err, ret_code = system(cmd) + #TODO: + # Find out how to handle serial console in a better way. + if ret_code: # Installation failed. + return False + + # When we are here, means the system booted properly. + return True + +