noteirak

VirtualBox API - List Machines sample

Feb 21st, 2015
488
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×