Controlling VirtualBox from commandline with python
Question: We are using python virtualbox API for controlling the virtualbox. For that we
are using the "pyvb" package(as given in python API documentation).

    
    
    al=pyvb.vb.VB()
    m=pyvb.vm.vbVM()
    al.startVM(m)
    

we have executed using the python interpreter. No error is shown but the
virtualbox doesnt start. Could you please tell us what could be wrong(all
necessary modules and packages have been imported)


Answer: I found that I can use the following functions to find if a VM is running,
restore a VM to a specific snapshot, and start a VM by name.

    
    
    from subprocess import Popen, PIPE
    
        def running_vms():
            """
            Return list of running vms
            """
            f = Popen(r'vboxmanage --nologo list runningvms', stdout=PIPE).stdout
            data = [ eachLine.strip() for eachLine in f ]
            return data
    
        def restore_vm(name='', snapshot=''):
            """
            Restore VM to specific snapshot uuid
    
            name = VM Name
            snapshot = uuid of snapshot  (uuid can be found in the xml file of your machines folder)
            """
            command = r'vboxmanage --nologo snapshot %s restore %s' % (name,snapshot)
            f = Popen(command, stdout=PIPE).stdout
            data = [ eachLine.strip() for eachLine in f ]
            return data
    
        def launch_vm(name=''):
            """
            Launch VM
    
            name = VM Name
            """
            command = r'vboxmanage --nologo startvm %s ' % name
            f = Popen(command, stdout=PIPE).stdout
            data = [ eachLine.strip() for eachLine in f ]
            return data
    

