Advertisement
noteirak

VirtualBox API - List Machines sample

Feb 21st, 2015
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement