This is my python code. I am not sure about "# Switch to mutable
machine" and "# Add a storage controler"


#!/usr/bin/python

import traceback
import time
from datetime import date
from vboxapi import VirtualBoxManager

style = None
myMachineName = "___MY_TEST_MACHINE___"
myMachineType = "WindowsXP"
g_virtualBoxManager = VirtualBoxManager(style, None)
globalConstant = g_virtualBoxManager
vb = g_virtualBoxManager.vbox
mgr = g_virtualBoxManager.mgr
HardDiskVariant_Fixed = 0x10000
myMachinesFolder = "/home/.VirtualBox/Machines"
myHardDisksFolder = "/home/.VirtualBox/HardDisks/"
now = date.today()

def createVirtualMachine():
        
        # Create a new VirtualMachine
        try:
                mach = vb.createMachine(myMachineName, myMachineType, 
myMachinesFolder, "")
                mach.saveSettings()
                vb.registerMachine(mach)
        except:
                print now, " - Cannot create VirtualMachine..."
                traceback.print_exc()

        # Create a new HardDisk 
        try:
                hardDisk = vb.createHardDisk("VDI", myHardDisksFolder)
        except:
                print now, " - Cannot create HardDisk..."
                traceback.print_exc()

        # Create the new BaseStorage
        try:            
                progress = hardDisk.createBaseStorage(18874368,
globalConstant.constants.HardDiskVariant_Fixed)
        except:
                print now, " - Cannot create BaseStorage..."
                traceback.print_exc()

        # Switch to  mutable machine
        try:
                myOpenedSession = 
g_virtualBoxManager.openMachineSession(mach.id)
                mach = session.Machine
        except:
                print now, " - Switch to mutable machine..."
                traceback.print_exc()

        # Add a storage controler
        try:
                StorageControler = addStorageController("myStorageControler",
globalConstant.constants.StorageBus_SATA)
                
StorageControler.controllerType(globalConstant.constants.StorageBus_SATA)
        except:
                print now, " - Cannot add a storage controler..."
                traceback.print_exc()

        # Attach the new VirtualMachine to the new HardDisk
        #try:
        #res = mach.attachHardDisk(hardDisk.id, StorageControler, 0, 0)
        #except:
        #print "Cannot attach the machine ", mach.id, " to the hard disk ", 
hardDisk.id

        try:
                g_virtualBoxManager.closeMachineSession(myOpenedSession)
        except:
                print now, " - Cannot close machine session..."
                traceback.print_exc()

createVirtualMachine()

_______________________________________________
vbox-dev mailing list
[email protected]
http://vbox.innotek.de/mailman/listinfo/vbox-dev

Reply via email to