1 | /* $Id:$ */
|
---|
2 | /*
|
---|
3 | * Copyright (C) 2010 Oracle Corporation
|
---|
4 | *
|
---|
5 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
6 | * available from http://www.virtualbox.org. This file is free software;
|
---|
7 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
8 | * General Public License (GPL) as published by the Free Software
|
---|
9 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
10 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
11 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
12 | */
|
---|
13 |
|
---|
14 | import org.mozilla.interfaces.*;
|
---|
15 | import org.virtualbox.*;
|
---|
16 |
|
---|
17 | public class TestVBox
|
---|
18 | {
|
---|
19 | public static void main(String[] args)
|
---|
20 | {
|
---|
21 | VirtualBoxManager mgr = VirtualBoxManager.getInstance(null);
|
---|
22 |
|
---|
23 | System.out.println("\n--> initialized\n");
|
---|
24 |
|
---|
25 | try
|
---|
26 | {
|
---|
27 | IVirtualBox vbox = mgr.getVBox();
|
---|
28 | System.out.println("VirtualBox version: " + vbox.getVersion() + "\n");
|
---|
29 |
|
---|
30 | /* list all VMs and print some info for each */
|
---|
31 | IMachine[] machs = vbox.getMachines(null);
|
---|
32 | for (IMachine m : machs)
|
---|
33 | {
|
---|
34 | try
|
---|
35 | {
|
---|
36 | System.out.println("VM name: " + m.getName() + ", RAM size: " + m.getMemorySize() + "MB");
|
---|
37 | System.out.println(" HWVirt: " + m.getHWVirtExProperty(HWVirtExPropertyType.Enabled)
|
---|
38 | + ", Nested Paging: " + m.getHWVirtExProperty(HWVirtExPropertyType.NestedPaging)
|
---|
39 | + ", PAE: " + m.getCPUProperty(CPUPropertyType.PAE) );
|
---|
40 | }
|
---|
41 | catch (Throwable e)
|
---|
42 | {
|
---|
43 | e.printStackTrace();
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | /* do something silly, start the first VM in the list */
|
---|
48 | String m = machs[0].getName();
|
---|
49 | System.out.println("\nAttempting to start VM '" + m + "'");
|
---|
50 | if (mgr.startVm(m, 7000))
|
---|
51 | {
|
---|
52 | System.out.println("started, presss any key...");
|
---|
53 | int ch = System.in.read();
|
---|
54 | }
|
---|
55 | else
|
---|
56 | {
|
---|
57 | System.out.println("cannot start machine "+m);
|
---|
58 | }
|
---|
59 | }
|
---|
60 | catch (Throwable e)
|
---|
61 | {
|
---|
62 | e.printStackTrace();
|
---|
63 | }
|
---|
64 |
|
---|
65 | mgr.cleanup();
|
---|
66 |
|
---|
67 | System.out.println("\n--< done\n");
|
---|
68 | }
|
---|
69 |
|
---|
70 | }
|
---|