Example #1
0
def create_vm(name, ram, disk_size, image, vcpu):
    config = data.get_config()
    create.make_config(name, "", ram, vcpu, image)
    message = "Created new configuration for vm%s at %s/vm%s.xml" % (str(name), str(config['config_directory']), str(name))
   
    create_log(message, 1)

    create.make_image(name, disk_size)
    message2 = "Created new disk image %s/vm%s.img of size %sGB." % (str(name), str(config['disk_directory']), str(disk_size))
    
    create_log(message2, 1)

    conn = connect()
    xmlpath = "%s/vm%s.xml" % (str(config['config_directory']), str(name))
    
    xml = ""

    with open(xmlpath, "r") as file:
        xml = file.read()

    conn.defineXML(xml)

    message3 = "Defined new domain vm%s." % str(name)
    create_log(message3, 1)

    newdom = conn.lookupByName("vm%s" % str(name))
    newdom.create()

    message4 = "Sent startup to vm%s." % str(name)
    create_log(message4, 1)
Example #2
0
def update_config(vm):
    config = data.get_config()
    path = "%s/vm%s.xml" % (str(config['config_directory']), str(vm[0]['_id']))
    try:
        os.remove(path)
    except:
        message2 = "Tried to delete config at %s but it wasn't there." % path
        create_log(message2, 2)
        pass
    
    message1 = "Deleted config for vm%s at %s/vm%s.xml" % (str(vm), str(config['config_directory']), str(vm[0]['_id']))
    create_log(message1, 1)

    create.make_config(vm[0]['_id'], "", str(vm[0]['ram']), str(vm[0]['vcpu']), vm[0]['disk_image'])

    message = "Created new configuration for vm%s at %s/vm%s.xml" % (str(vm[0]['_id']), str(config['config_directory']), str(vm[0]['_id']))
    create_log(message, 1)