SHARE
TWEET

VirtualBox API - List Machines sample

noteirak Feb 21st, 2015 (edited) 434 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
  3.  * Version 2, December 2004
  4.  *
  5.  * Everyone is permitted to copy and distribute verbatim or modified
  6.  * copies of this license document, and changing it is allowed as long
  7.  * as the name is changed.
  8.  *
  9.  * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
  10.  * TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  11.  *
  12.  * 0. You just DO WHAT THE FUCK YOU WANT TO.
  13.  */
  14.  
  15. public class ListRunningVms {
  16.    
  17.    public static void main(String[] args) {
  18.      
  19.       VirtualBoxManager vboxManager = VirtualBoxManager.createInstance(null);
  20.       try {
  21.          vboxManager.connect("http://localhost:18083", "user", "password"); // only if you are using WebServices Bindings
  22.          IVirtualBox vbox = vboxManager.getVBox();
  23.          for (IMachine vm : vbox.getMachines()) {
  24.             if (MachineState.Running.equals(vm.getState())) {
  25.                System.out.println(vm.getName()+ " "+vm.getId());
  26.             }
  27.          }
  28.       } finally {
  29.          vboxManager.disconnect(); // only if you are using WebServices Bindings
  30.          vboxManager.cleanup();
  31.       }
  32.    }
  33.    
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top