From f215e02bf85f68d3a6106c2a1f4f7f063f819064 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 11 Apr 2024 10:17:27 +0200 Subject: Adding upstream version 7.0.14-dfsg. Signed-off-by: Daniel Baumann --- .../webservice/samples/java/axis/clienttest.java | 310 +++++++++++++++++++ .../Main/webservice/samples/java/jax-ws/Makefile | 83 +++++ .../webservice/samples/java/jax-ws/Makefile.glue | 72 +++++ .../webservice/samples/java/jax-ws/clienttest.java | 339 +++++++++++++++++++++ .../webservice/samples/java/jax-ws/metrictest.java | 231 ++++++++++++++ .../Main/webservice/samples/perl/clienttest.pl | 232 ++++++++++++++ .../Main/webservice/samples/php/clienttest.php | 108 +++++++ src/VBox/Main/webservice/samples/python/Makefile | 39 +++ .../Main/webservice/samples/python/Makefile.glue | 35 +++ .../Main/webservice/samples/python/clienttest.py | 132 ++++++++ 10 files changed, 1581 insertions(+) create mode 100644 src/VBox/Main/webservice/samples/java/axis/clienttest.java create mode 100644 src/VBox/Main/webservice/samples/java/jax-ws/Makefile create mode 100644 src/VBox/Main/webservice/samples/java/jax-ws/Makefile.glue create mode 100644 src/VBox/Main/webservice/samples/java/jax-ws/clienttest.java create mode 100644 src/VBox/Main/webservice/samples/java/jax-ws/metrictest.java create mode 100755 src/VBox/Main/webservice/samples/perl/clienttest.pl create mode 100644 src/VBox/Main/webservice/samples/php/clienttest.php create mode 100644 src/VBox/Main/webservice/samples/python/Makefile create mode 100644 src/VBox/Main/webservice/samples/python/Makefile.glue create mode 100755 src/VBox/Main/webservice/samples/python/clienttest.py (limited to 'src/VBox/Main/webservice/samples') diff --git a/src/VBox/Main/webservice/samples/java/axis/clienttest.java b/src/VBox/Main/webservice/samples/java/axis/clienttest.java new file mode 100644 index 00000000..9c515485 --- /dev/null +++ b/src/VBox/Main/webservice/samples/java/axis/clienttest.java @@ -0,0 +1,310 @@ +/* $Id: clienttest.java $ */ +/*!file + * Sample client for the VirtualBox web service, written in Java (raw web service variant). + * + * Run the VirtualBox web service server first; see the VirtualBox + * SDK reference for details. + * + * The following license applies to this file only: + */ + +/* + * Copyright (C) 2008-2023 Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +import org.virtualbox.www.Service.VboxService; +import org.virtualbox.www.Service.VboxServiceLocator; +import org.virtualbox.www.VboxPortType; + +public class clienttest +{ + private VboxService _service; + private VboxPortType _port; + private String _oVbox; + + public clienttest() + { + try + { + // instantiate the webservice in instance data; the classes + // VboxServiceLocator and VboxPortType have been created + // by the WSDL2Java helper that you should have run prior + // to compiling this example, as described in the User Manual. + _service = new VboxServiceLocator(); + _port = _service.getvboxServicePort(); + + // From now on, we can call any method in the webservice by + // prefixing it with "port." + + // First step is always to log on to the webservice. This + // returns a managed object reference to the webservice's + // global instance of IVirtualBox, which in turn contains + // the most important methods provided by the Main API. + _oVbox = _port.IWebsessionManager_logon("", ""); + + // Call IVirtualBox::getVersion and print out the result + String version = _port.IVirtualBox_getVersion(_oVbox); + System.out.println("Initialized connection to VirtualBox version " + version); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public void showVMs() + { + try + { + // Call IVirtualBox::getMachines, which yields an array + // of managed object references to all machines which have + // been registered: + String[] aMachines = _port.IVirtualBox_getMachines2(_oVbox); + // Walk through this array and, for each machine, call + // IMachine::getName (accessor method to the "name" attribute) + for (int i = 0; i < aMachines.length; i++) + { + String oMachine = aMachines[i]; + String machinename = _port.IMachine_getName(oMachine); + System.out.println("Machine " + i + ": " + oMachine + " - " + machinename); + + // release managed object reference + _port.IManagedObjectRef_release(oMachine); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public void listHostInfo() + { + try + { + String oHost = _port.IVirtualBox_getHost(_oVbox); + + org.apache.axis.types.UnsignedInt uProcCount = _port.IHost_getProcessorCount(oHost); + System.out.println("Processor count: " + uProcCount); + + String oCollector = _port.IVirtualBox_getPerformanceCollector(_oVbox); + + String aobj[] = {oHost}; + String astrMetrics[] = {"*"}; + String aMetrics[] = {}; + aMetrics = _port.IPerformanceCollector_getMetrics(oCollector, + astrMetrics, + aobj); + +// String astrMetricNames[] = { "*" }; +// String aObjects[]; +// String aRetNames[]; +// int aRetIndices[]; +// int aRetLengths[]; +// int aRetData[]; +// int rc = _port.ICollector_queryMetricsData(oCollector, +// aObjects, +// aRetNames, +// aRetObjects, +// aRetIndices, +// aRetLengths, +// aRetData); +// +/* + Bstr metricNames[] = { L"*" }; + com::SafeArray metrics (1); + metricNames[0].cloneTo (&metrics [0]); + com::SafeArray retNames; + com::SafeIfaceArray retObjects; + com::SafeArray retIndices; + com::SafeArray retLengths; + com::SafeArray retData; + CHECK_ERROR (collector, QueryMetricsData(ComSafeArrayAsInParam(metrics), + ComSafeArrayInArg(objects), + ComSafeArrayAsOutParam(retNames), + ComSafeArrayAsOutParam(retObjects), + ComSafeArrayAsOutParam(retIndices), + ComSafeArrayAsOutParam(retLengths), + ComSafeArrayAsOutParam(retData)) ); +*/ + + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public void startVM(String strVM) + { + String oSession = ""; + Boolean fSessionOpen = false; + + try + { + // this is pretty much what VBoxManage does to start a VM + String oMachine = ""; + Boolean fOK = false; + + oSession = _port.IWebsessionManager_getSessionObject(_oVbox); + + // first assume we were given a UUID + try + { + oMachine = _port.IVirtualBox_getMachine(_oVbox, strVM); + fOK = true; + } + catch (Exception e) + { + } + + if (!fOK) + { + try + { + // or try by name + oMachine = _port.IVirtualBox_findMachine(_oVbox, strVM); + fOK = true; + } + catch (Exception e) + { + } + } + + if (!fOK) + { + System.out.println("Error: can't find VM \"" + strVM + "\""); + } + else + { + String uuid = _port.IMachine_getId(oMachine); + String sessionType = "gui"; + String env = "DISPLAY=:0.0"; + String oProgress = _port.IVirtualBox_openRemoteSession(_oVbox, oSession, uuid, sessionType, env); + fSessionOpen = true; + + System.out.println("Session for VM " + uuid + " is opening..."); + _port.IProgress_waitForCompletion(oProgress, 10000); + + int rc = _port.IProgress_getResultCode(oProgress).intValue(); + if (rc != 0) + { + System.out.println("Session failed!"); + } + } + } + catch (Exception e) + { + e.printStackTrace(); + } + + if (fSessionOpen) + { + try + { + _port.ISession_close(oSession); + } + catch (Exception e) + { + } + } + } + + public void cleanup() + { + try + { + if (_oVbox.length() > 0) + { + // log off + _port.IWebsessionManager_logoff(_oVbox); + _oVbox = null; + System.out.println("Logged off."); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public static void printArgs() + { + System.out.println( "Usage: java clienttest ..." + + "\nwith being:" + + "\n show vms list installed virtual machines" + + "\n list hostinfo list host info" + + "\n startvm start the given virtual machine"); + } + + public static void main(String[] args) + { + if (args.length < 1) + { + System.out.println("Error: Must specify at least one argument."); + printArgs(); + } + else + { + clienttest c = new clienttest(); + if (args[0].equals("show")) + { + if (args.length == 2) + { + if (args[1].equals("vms")) + c.showVMs(); + else + System.out.println("Error: Unknown argument to \"show\": \"" + args[1] + "\"."); + } + else + System.out.println("Error: Missing argument to \"show\" command"); + } + else if (args[0].equals("list")) + { + if (args.length == 2) + { + if (args[1].equals("hostinfo")) + c.listHostInfo(); + else + System.out.println("Error: Unknown argument to \"show\": \"" + args[1] + "\"."); + } + else + System.out.println("Error: Missing argument to \"show\" command"); + } + else if (args[0].equals("startvm")) + { + if (args.length == 2) + { + c.startVM(args[1]); + } + else + System.out.println("Error: Missing argument to \"startvm\" command"); + } + else + System.out.println("Error: Unknown command: \"" + args[0] + "\"."); + + c.cleanup(); + } + } +} diff --git a/src/VBox/Main/webservice/samples/java/jax-ws/Makefile b/src/VBox/Main/webservice/samples/java/jax-ws/Makefile new file mode 100644 index 00000000..505ce926 --- /dev/null +++ b/src/VBox/Main/webservice/samples/java/jax-ws/Makefile @@ -0,0 +1,83 @@ +# $Id: Makefile $ +## @file +# Makefile for java samples. +# + + +# +# Copyright (C) 2008-2023 Oracle and/or its affiliates. +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +JAVA16=java +JAVA15=/usr/lib/jvm/java-1.5.0-sun/bin/java +JAVAC = javac +JAVAC15 = javac -target 1.5 +JAVAC16 = javac -target 1.6 +MKDIR = mkdir +RM = rm + +DEST16 = ./gen16 +DEST15 = ./gen15 + +VBOXWS15 = ../lib/vboxws_java15.jar +VBOXWS16 = ../lib/vboxws_java16.jar + +JAXWS=./jaxws-ri +JAXWSLIBS=$(JAXWS)/lib/jaxws-api.jar:$(JAXWS)/lib/jaxb-api.jar:$(JAXWS)/lib/jsr181-api.jar:$(JAXWS)/lib/jaxws-rt.jar + +all: run16 + +metric: metric16 + +$(DEST16)/clienttest.class: clienttest.java + $(MKDIR) -p $(DEST16) + $(JAVAC16) -d $(DEST16) -cp $(VBOXWS16) $< + +$(DEST15)/clienttest.class: clienttest.java + $(MKDIR) -p $(DEST15) + $(JAVAC15) -d $(DEST15) -cp $(VBOXWS15):$(JAXWSLIBS) $< + +run16: $(DEST16)/clienttest.class + $(JAVA16) -cp $(VBOXWS16):$(DEST16) clienttest show vms + +run15: $(DEST15)/clienttest.class + $(JAVA15) -cp $(VBOXWS15):$(JAXWSLIBS):$(DEST15) clienttest show vms + +$(DEST16)/metrictest.class: metrictest.java + $(MKDIR) -p $(DEST16) + $(JAVAC16) -d $(DEST16) -cp $(VBOXWS16) $< + +$(DEST15)/metrictest.class: metrictest.java + $(MKDIR) -p $(DEST15) + $(JAVAC15) -d $(DEST15) -cp $(VBOXWS15):$(JAXWSLIBS) $< + +metric16: $(DEST16)/metrictest.class + -$(JAVA16) -cp $(VBOXWS16):$(DEST16) metrictest + +metric15: $(DEST15)/metrictest.class + -$(JAVA15) -cp $(VBOXWS15):$(JAXWSLIBS):$(DEST15) metrictest + +clean: + $(RM) -rf $(DEST15) $(DEST16) + diff --git a/src/VBox/Main/webservice/samples/java/jax-ws/Makefile.glue b/src/VBox/Main/webservice/samples/java/jax-ws/Makefile.glue new file mode 100644 index 00000000..495e6a12 --- /dev/null +++ b/src/VBox/Main/webservice/samples/java/jax-ws/Makefile.glue @@ -0,0 +1,72 @@ +# $Id: Makefile.glue $ +## @file +# Makefile for java samples. +# + +# +# Copyright (C) 2008-2023 Oracle and/or its affiliates. +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +JAXWS=./jaxws-ri +JAXWSLIBS=$(JAXWS)/lib/jaxws-api.jar:$(JAXWS)/lib/jaxb-api.jar:$(JAXWS)/lib/jsr181-api.jar:$(JAXWS)/lib/jaxws-rt.jar + + +JAVA16=java +JAVA15=/usr/lib/jvm/java-1.5.0-sun/bin/java +JAVAC15 = javac -target 1.5 +JAVAC16 = javac -target 1.6 +WSIMPORT15 = $(JAVA15) -cp $(JAXWS)/lib/jaxws-tools.jar com.sun.tools.ws.WsImport +WSIMPORT16 = wsimport +JAR = jar +CP = cp +MKDIR = mkdir +RM = rm + +DEST16 = ./gen16 +DEST15 = ./gen15 + +VBOXWS15 = ../lib/vboxws_java15.jar +VBOXWS16 = ../lib/vboxws_java16.jar + +all: $(VBOXWS15) $(VBOXWS16) + +$(VBOXWS15): ../../../vboxwebService.wsdl ../../../vboxweb.wsdl *.java + $(RM) -rf $(DEST15) + $(MKDIR) -p $(DEST15) + $(WSIMPORT15) -d $(DEST15) $< + $(JAVAC15) -cp $(DEST15) *.java -d $(DEST15) + $(CP) ../../../vboxwebService.wsdl ../../../vboxweb.wsdl $(DEST15) + $(JAR) cvf $(VBOXWS15) -C $(DEST15) . > /dev/null + +$(VBOXWS16): ../../../vboxwebService.wsdl ../../../vboxweb.wsdl *.java + $(RM) -rf $(DEST16) + $(MKDIR) -p $(DEST16) + $(WSIMPORT16) -d $(DEST16) $< + $(JAVAC16) -cp $(DEST16) *.java -d $(DEST16) + $(CP) ../../../vboxwebService.wsdl ../../../vboxweb.wsdl $(DEST16) + $(JAR) cvf $(VBOXWS16) -C $(DEST16) . > /dev/null + +clean: + $(RM) -rf $(DEST) + diff --git a/src/VBox/Main/webservice/samples/java/jax-ws/clienttest.java b/src/VBox/Main/webservice/samples/java/jax-ws/clienttest.java new file mode 100644 index 00000000..08700642 --- /dev/null +++ b/src/VBox/Main/webservice/samples/java/jax-ws/clienttest.java @@ -0,0 +1,339 @@ +/* $Id: clienttest.java $ */ +/*!file + * Sample client for the VirtualBox web service, written in Java (object-oriented bindings). + * + * Run the VirtualBox web service server first; see the VirtualBox + * SDK reference for details. + * + * The following license applies to this file only: + */ + +/* + * Copyright (C) 2008-2023 Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +/* Somewhat ugly way to support versioning */ +import com.sun.xml.ws.commons.virtualbox{VBOX_API_SUFFIX}.*; + +import java.util.*; +import javax.xml.ws.Holder; + +public class clienttest +{ + IWebsessionManager mgr; + IVirtualBox vbox; + + public clienttest() + { + mgr = new IWebsessionManager("http://localhost:18083/"); + vbox = mgr.logon("test", "test"); + System.out.println("Initialized connection to VirtualBox version " + vbox.getVersion()); + } + + public void disconnect() + { + mgr.disconnect(vbox); + } + + class Desktop + { + String name; + String uuid; + + Desktop(int n) + { + name = "Mach"+n; + uuid = UUID.randomUUID().toString(); + } + String getName() + { + return name; + } + String getId() + { + return uuid; + } + } + + public void test() + { + for (int i=0; i<100; i++) + { + String baseFolder = + vbox.getSystemProperties().getDefaultMachineFolder(); + Desktop desktop = new Desktop(i); + IMachine machine = vbox.createMachine(baseFolder, + "linux", + desktop.getName(), + desktop.getId(), + true); + machine.saveSettings(); + mgr.cleanupUnused(); + } + } + + public void test2() + { + ISession session = mgr.getSessionObject(vbox); + String id = "bc8b6219-2775-42c4-f1b2-b48b3c177294"; + vbox.openSession(session, id); + IMachine mach = session.getMachine(); + IBIOSSettings bios = mach.getBIOSSettings(); + bios.setIOAPICEnabled(true); + mach.saveSettings(); + session.close(); + } + + + public void test3() + { + + IWebsessionManager mgr1 = new IWebsessionManager("http://localhost:18082/"); + IWebsessionManager mgr2 = new IWebsessionManager("http://localhost:18083/"); + IVirtualBox vbox1 = mgr1.logon("test", "test"); + IVirtualBox vbox2 = mgr2.logon("test", "test"); + + + System.out.println("connection 1 to VirtualBox version " + vbox1.getVersion()); + System.out.println("connection 2 to VirtualBox version " + vbox2.getVersion()); + mgr1.disconnect(vbox1); + mgr2.disconnect(vbox2); + + mgr1 = new IWebsessionManager("http://localhost:18082/"); + mgr2 = new IWebsessionManager("http://localhost:18083/"); + vbox1 = mgr1.logon("test", "test"); + vbox2 = mgr2.logon("test", "test"); + + System.out.println("second connection 1 to VirtualBox version " + vbox1.getVersion()); + System.out.println("second connection 2 to VirtualBox version " + vbox2.getVersion()); + + mgr1.disconnect(vbox1); + mgr2.disconnect(vbox2); + } + + public void showVMs() + { + try + { + int i = 0; + for (IMachine m : vbox.getMachines()) + { + System.out.println("Machine " + (i++) + ": " + " [" + m.getId() + "]" + " - " + m.getName()); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public void listHostInfo() + { + try + { + IHost host = vbox.getHost(); + long uProcCount = host.getProcessorCount(); + System.out.println("Processor count: " + uProcCount); + + for (long i=0; i aMetrics = + oCollector.getMetrics(Arrays.asList(new String[]{"*"}), + Arrays.asList(new IUnknown[]{host})); + + for (IPerformanceMetric m : aMetrics) + { + System.out.println("known metric = "+m.getMetricName()); + } + + Holder> names = new Holder> (); + Holder> objects = new Holder>() ; + Holder> units = new Holder>(); + Holder> scales = new Holder>(); + Holder> sequenceNumbers = new Holder>(); + Holder> indices = new Holder>(); + Holder> lengths = new Holder>(); + + List vals = + oCollector.queryMetricsData(Arrays.asList(new String[]{"*"}), + Arrays.asList(new IUnknown[]{host}), + names, objects, units, scales, + sequenceNumbers, indices, lengths); + + for (int i=0; i < names.value.size(); i++) + System.out.println("name: "+names.value.get(i)); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public void startVM(String strVM) + { + ISession oSession = null; + IMachine oMachine = null; + + try + { + oSession = mgr.getSessionObject(vbox); + + // first assume we were given a UUID + try + { + oMachine = vbox.getMachine(strVM); + } + catch (Exception e) + { + try + { + oMachine = vbox.findMachine(strVM); + } + catch (Exception e1) + { + } + } + + if (oMachine == null) + { + System.out.println("Error: can't find VM \"" + strVM + "\""); + } + else + { + String uuid = oMachine.getId(); + String sessionType = "gui"; + ArrayList env = new ArrayList(); + env.add("DISPLAY=:0.0"); + IProgress oProgress = + oMachine.launchVMProcess(oSession, + sessionType, + env); + System.out.println("Session for VM " + uuid + " is opening..."); + oProgress.waitForCompletion(10000); + + long rc = oProgress.getResultCode(); + if (rc != 0) + System.out.println("Session failed!"); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + finally + { + if (oSession != null) + { + oSession.close(); + } + } + } + + public void cleanup() + { + try + { + if (vbox != null) + { + disconnect(); + vbox = null; + System.out.println("Logged off."); + } + mgr.cleanupUnused(); + mgr = null; + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public static void printArgs() + { + System.out.println( "Usage: java clienttest ..." + + "\nwith being:" + + "\n show vms list installed virtual machines" + + "\n list hostinfo list host info" + + "\n startvm start the given virtual machine"); + } + + public static void main(String[] args) + { + if (args.length < 1) + { + System.out.println("Error: Must specify at least one argument."); + printArgs(); + } + else + { + clienttest c = new clienttest(); + if (args[0].equals("show")) + { + if (args.length == 2) + { + if (args[1].equals("vms")) + c.showVMs(); + else + System.out.println("Error: Unknown argument to \"show\": \"" + args[1] + "\"."); + } + else + System.out.println("Error: Missing argument to \"show\" command"); + } + else if (args[0].equals("list")) + { + if (args.length == 2) + { + if (args[1].equals("hostinfo")) + c.listHostInfo(); + else + System.out.println("Error: Unknown argument to \"show\": \"" + args[1] + "\"."); + } + else + System.out.println("Error: Missing argument to \"list\" command"); + } + else if (args[0].equals("startvm")) + { + if (args.length == 2) + { + c.startVM(args[1]); + } + else + System.out.println("Error: Missing argument to \"startvm\" command"); + } + else if (args[0].equals("test")) + { + c.test3(); + } + else + System.out.println("Error: Unknown command: \"" + args[0] + "\"."); + + c.cleanup(); + } + } +} diff --git a/src/VBox/Main/webservice/samples/java/jax-ws/metrictest.java b/src/VBox/Main/webservice/samples/java/jax-ws/metrictest.java new file mode 100644 index 00000000..29428fd7 --- /dev/null +++ b/src/VBox/Main/webservice/samples/java/jax-ws/metrictest.java @@ -0,0 +1,231 @@ +/* $Id: metrictest.java $ */ +/*!file + * Sample of performance API usage, written in Java. + * + * Don't forget to run VBOX webserver + * with 'vboxwebsrv -t 1000' command, to calm down watchdog thread. + * + * The following license applies to this file only: + */ + +/* + * Copyright (C) 2008-2023 Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +import com.sun.xml.ws.commons.virtualbox{VBOX_API_SUFFIX}.*; + +import java.util.*; +import javax.xml.ws.Holder; + +class PerformanceData +{ + public String name; + public IUnknown object; + public String unit; + public Long scale; + public Long sequenceNumber; + public List samples; + + public String getFormattedSamples() + { + String out = "["; + String separator = ""; + + if (scale != 1) + { + for (Long sample : samples) + { + out += separator + (sample.doubleValue() / scale) + " " + unit; + separator = ", "; + } + } + else + { + for (Long sample : samples) + { + out += separator + sample.toString() + " " + unit; + separator = ", "; + } + } + out += "]"; + return out; + } +} + +class PerformanceCollector +{ + private IVirtualBox _vbox; + private IPerformanceCollector _collector; + + public PerformanceCollector(IVirtualBox vbox) + { + _vbox = vbox; + _collector = vbox.getPerformanceCollector(); + } + + public void cleanup() + { + _collector.releaseRemote(); + } + + public List setup(List metricNames, List objects, Long period, Long samples) + { + return _collector.setupMetrics(metricNames, objects, period, samples); + } + + public List enable(List metricNames, List objects) + { + return _collector.enableMetrics(metricNames, objects); + } + + public List disable(List metricNames, List objects) + { + return _collector.disableMetrics(metricNames, objects); + } + + public List query(List filterMetrics, List filterObjects) + { + Holder> names = new Holder>(); + Holder> objects = new Holder>(); + Holder> units = new Holder>(); + Holder> scales = new Holder>(); + Holder> sequenceNumbers = new Holder>(); + Holder> indices = new Holder>(); + Holder> lengths = new Holder>(); + List values = + _collector.queryMetricsData(filterMetrics, filterObjects, + names, objects, units, scales, sequenceNumbers, indices, lengths); + List data = new ArrayList(names.value.size()); + for (int i = 0; i < names.value.size(); i++) + { + PerformanceData singleMetricData = new PerformanceData(); + singleMetricData.name = names.value.get(i); + singleMetricData.object = objects.value.get(i); + singleMetricData.unit = units.value.get(i); + singleMetricData.scale = scales.value.get(i); + singleMetricData.sequenceNumber = sequenceNumbers.value.get(i); + List samples = new ArrayList(lengths.value.get(i).intValue()); + for (int j = 0; j < lengths.value.get(i); j++) + { + samples.add(values.get(indices.value.get(i).intValue() + j).longValue()); + } + singleMetricData.samples = samples; + data.add(singleMetricData); + } + + return data; + } +} + +public class metrictest implements Runnable +{ + IVirtualBox vbox; + IWebsessionManager mgr; + PerformanceCollector perf; + + public metrictest() + { + mgr = new IWebsessionManager("http://localhost:18083/"); + vbox = mgr.logon("test", "test"); + System.out.println("Initialized connection to VirtualBox version " + vbox.getVersion()); + perf = new PerformanceCollector(vbox); + } + + private String getObjectName(IUnknown object) + { + try + { + String machineName = object.getRemoteWSPort().iMachineGetName(object.getRef()); + return machineName; + } catch (Exception e) + { + } + return new String("host"); + } + + public void setup() + { + perf.setup(Arrays.asList(new String[]{"*"}), + new ArrayList(), + new Long(1), new Long(5)); + } + + public void collect() + { + try + { + List allObjects = new ArrayList(); + List metricData = perf.query(Arrays.asList(new String[]{"*"}), + allObjects); + for (PerformanceData md : metricData) + { + System.out.println("(" + getObjectName(md.object) + ") " + + md.name + " " + md.getFormattedSamples()); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public void run() + { + // Clean up + try + { + if (perf != null) + { + perf.cleanup(); + perf = null; + } + if (vbox != null) + { + mgr.logoff(vbox); + vbox = null; + mgr = null; + System.out.println("Logged off."); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public static void main(String[] args) throws InterruptedException + { + metrictest c = new metrictest(); + // Add a shutdown handle to clean up + Runtime.getRuntime().addShutdownHook(new Thread(c)); + // Start metric collection + c.setup(); + // Obtain and print out stats continuously until ctrl-C is pressed + while (true) + { + Thread.sleep(1000); // Sleep for a second + c.collect(); + } + } +} diff --git a/src/VBox/Main/webservice/samples/perl/clienttest.pl b/src/VBox/Main/webservice/samples/perl/clienttest.pl new file mode 100755 index 00000000..4abab575 --- /dev/null +++ b/src/VBox/Main/webservice/samples/perl/clienttest.pl @@ -0,0 +1,232 @@ +#!/usr/bin/perl +# $Id: clienttest.pl $ +## @file +# This little perl program attempts to connect to a running VirtualBox +# webservice and calls various methods on it. Please refer to the SDK +# programming reference (SDKRef.pdf) for how to use this sample. +# +# Note! The following license applies to this file only +# + +# +# Copyright (C) 2008-2023 Oracle and/or its affiliates. +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +use strict; +use SOAP::Lite; +use vboxService; # generated by stubmaker, see SDKRef.pdf +use Data::Dumper; + +my $cmd = 'clienttest'; +my $optMode; +my $vmname; +my $disk; + +while (my $this = shift(@ARGV)) +{ + if (($this =~ /^-h/) || ($this =~ /^--help/)) + { + print "$cmd: test the VirtualBox web service.\n". + "Usage:\n". + " $cmd \n". + "with being one of 'version', 'list', 'start'; default is 'list'.\n". + " $cmd version: print version of VirtualBox web service.\n". + " $cmd list: list installed virtual machines.\n". + " $cmd startvm : start the virtual machine named .\n". + " $cmd acpipowerbutton : shutdown of the irtual machine named .\n"; + " $cmd openhd : open disk image .\n"; + exit 0; + } + elsif ( ($this eq 'version') + || ($this eq 'list') + ) + { + $optMode = $this; + } + elsif ( ($this eq 'startvm') + || ($this eq 'acpipowerbutton') + ) + { + $optMode = $this; + + if (!($vmname = shift(@ARGV))) + { + die "[$cmd] Missing parameter: You must specify the name of the VM to start.\nStopped"; + } + } + elsif ($this eq 'openhd') + { + $optMode = $this; + + if (!($disk = shift(@ARGV))) + { + die "[$cmd] Missing parameter: You must specify the name of the disk to open.\nStopped"; + } + } + else + { + die "[$cmd] Unknown option \"$this\"; stopped"; + } +} + +$optMode = "list" + if (!$optMode); + +# SOAP::Lite hacking to make it serialize the enum types we use correctly. +# In the long run, this needs to be done either by stubmaker.pl or something +# else, because the WSDL clearly says they're restricted strings. Quite silly +# that the default behavior is to ignore the parameter and just let the server +# use the default value for the type. + +sub SOAP::Serializer::as_LockType +{ + my ($self, $value, $name, $type, $attr) = @_; + die "String value expected instead of @{[ref $value]} reference\n" + if ref $value; + return [ + $name, + {'xsi:type' => 'vbox:LockType', %$attr}, + SOAP::Utils::encode_data($value) + ]; +} + +sub SOAP::Serializer::as_DeviceType +{ + my ($self, $value, $name, $type, $attr) = @_; + die "String value expected instead of @{[ref $value]} reference\n" + if ref $value; + return [ + $name, + {'xsi:type' => 'vbox:DeviceType', %$attr}, + SOAP::Utils::encode_data($value) + ]; +} + +sub SOAP::Serializer::as_AccessMode +{ + my ($self, $value, $name, $type, $attr) = @_; + die "String value expected instead of @{[ref $value]} reference\n" + if ref $value; + return [ + $name, + {'xsi:type' => 'vbox:AccessMode', %$attr}, + SOAP::Utils::encode_data($value) + ]; +} + +## @todo needs much more error handling, e.g. openhd never complains + +my $vbox = vboxService->IWebsessionManager_logon("test", "test"); + +if (!$vbox) +{ + die "[$cmd] Logon to session manager with user \"test\" and password \"test\" failed.\nStopped"; +} + +if ($optMode eq "version") +{ + my $v = vboxService->IVirtualBox_getVersion($vbox); + print "[$cmd] Version number of running VirtualBox web service: $v\n"; +} +elsif ($optMode eq "list") +{ + print "[$cmd] Listing machines:\n"; + my @result = vboxService->IVirtualBox_getMachines($vbox); + foreach my $idMachine (@result) + { + my $if = vboxService->IManagedObjectRef_getInterfaceName($idMachine); + my $name = vboxService->IMachine_getName($idMachine); + + print "machine $if $idMachine: $name\n"; + } +} +elsif ($optMode eq "startvm") +{ + my $machine = vboxService->IVirtualBox_findMachine($vbox, $vmname); + + die "[$cmd] Cannot find VM \"$vmname\"; stopped" + if (!$machine); + + my $session = vboxService->IWebsessionManager_getSessionObject($vbox); + die "[$cmd] Cannot get session object; stopped" + if (!$session); + + my $uuid = vboxService->IMachine_getId($machine); + die "[$cmd] Cannot get uuid for machine; stopped" + if (!$uuid); + + print "[$cmd] UUID: $uuid\n"; + + my @env = (); + my $progress = vboxService->IMachine_launchVMProcess($machine, + $session, + "headless", + @env); + die "[$cmd] Cannot launch VM; stopped" + if (!$progress); + + print("[$cmd] Waiting for the VM to start...\n"); + vboxService->IProgress_waitForCompletion($progress, -1); + + my $fCompleted; + $fCompleted = vboxService->IProgress_getCompleted($progress); + print("[$cmd] Completed: $fCompleted\n"); + + my $resultCode; + $resultCode = vboxService->IProgress_getResultCode($progress); + + print("[$cmd] Result: $resultCode\n"); + + vboxService->ISession_unlockMachine($session); + + vboxService->IWebsessionManager_logoff($vbox); +} +elsif ($optMode eq "acpipowerbutton") +{ + my $machine = vboxService->IVirtualBox_findMachine($vbox, $vmname); + + die "[$cmd] Cannot find VM \"$vmname\"; stopped" + if (!$machine); + + my $session = vboxService->IWebsessionManager_getSessionObject($vbox); + die "[$cmd] Cannot get session object; stopped" + if (!$session); + + vboxService->IMachine_lockMachine($machine, $session, 'Shared'); + + my $console = vboxService->ISession_getConsole($session); + + vboxService->IConsole_powerButton($console); + + vboxService->ISession_unlockMachine($session); + + vboxService->IWebsessionManager_logoff($vbox); +} +elsif ($optMode eq "openhd") +{ + my $medium = vboxService->IVirtualBox_openMedium($vbox, $disk, + 'HardDisk', + 'ReadWrite', + 0); +} diff --git a/src/VBox/Main/webservice/samples/php/clienttest.php b/src/VBox/Main/webservice/samples/php/clienttest.php new file mode 100644 index 00000000..dc5918c3 --- /dev/null +++ b/src/VBox/Main/webservice/samples/php/clienttest.php @@ -0,0 +1,108 @@ + "http://localhost:18083/")); + +//Logon to webservice +$websessionManager = new IWebsessionManager($connection); +// Dummy username and password (change to appropriate values or set authentication method to null) +$virtualbox = $websessionManager->logon("username","password"); + +//Get a list of registered machines +$machines = $virtualbox->machines; + +//Take a screenshot of the first vm we find that is running +foreach ($machines as $machine) +{ + if ( 'Running' == $machine->state ) + { + $session = $websessionManager->getSessionObject($virtualbox->handle); + $uuid = $machine->id; + $machine->lockMachine($session->handle, "Shared"); + try + { + $console = $session->console; + $display = $console->display; + list($screenWidth, $screenHeight, $screenBpp, $screenX, $screenY, $screenStatus) = $display->getScreenResolution(0 /* First screen */); + + $imageraw = $display->takeScreenShotToArray(0 /* First screen */, $screenWidth, $screenHeight, "RGBA"); + echo "Screenshot size: " . sizeof($imageraw) . "\n"; + + $filename = 'screenshot.png'; + echo "Saving screenshot of " . $machine->name . " (${screenWidth}x${screenHeight}, ${screenBpp}BPP) to $filename\n"; + $image = imagecreatetruecolor($screenWidth, $screenHeight); + + for ($height = 0; $height < $screenHeight; $height++) + { + for ($width = 0; $width < $screenWidth; $width++) + { + $start = ($height*$screenWidth + $width)*4; + $red = $imageraw[$start]; + $green = $imageraw[($start+1)]; + $blue = $imageraw[($start+2)]; + //$alpha = $image[$start+3]; + + $colour = imagecolorallocate($image, $red, $green, $blue); + + imagesetpixel($image, $width, $height, $colour); + } + } + + imagepng($image, $filename); + } + catch (Exception $ex) + { + echo $ex->getMessage(); + } + + $session->unlockMachine(); + + $machine->releaseRemote(); + $session->releaseRemote(); + + break; + } +} + +$websessionManager->logoff($virtualbox->handle); + +?> + diff --git a/src/VBox/Main/webservice/samples/python/Makefile b/src/VBox/Main/webservice/samples/python/Makefile new file mode 100644 index 00000000..a432351f --- /dev/null +++ b/src/VBox/Main/webservice/samples/python/Makefile @@ -0,0 +1,39 @@ +# $Id: Makefile $ +## @file +# Makefile for java samples. +# + +# +# Copyright (C) 2008-2023 Oracle and/or its affiliates. +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +all: run + +run: + @echo !!!! Don\'t forget to start webserver with \"vboxwebsrv -t 10000\" !!! + PYTHONPATH=../lib python ../../../glue/python/sample/vboxshell.py -w + +server: + nohup vboxwebsrv -t 10000 & + diff --git a/src/VBox/Main/webservice/samples/python/Makefile.glue b/src/VBox/Main/webservice/samples/python/Makefile.glue new file mode 100644 index 00000000..e188e5e8 --- /dev/null +++ b/src/VBox/Main/webservice/samples/python/Makefile.glue @@ -0,0 +1,35 @@ +# $Id: Makefile.glue $ +## @file +# Makefile for java samples. +# + +# +# Copyright (C) 2008-2023 Oracle and/or its affiliates. +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +all: wrappers + +wrappers: ../../vboxwebService.wsdl ../../vboxweb.wsdl + wsdl2py -b --file $< + diff --git a/src/VBox/Main/webservice/samples/python/clienttest.py b/src/VBox/Main/webservice/samples/python/clienttest.py new file mode 100755 index 00000000..ee416159 --- /dev/null +++ b/src/VBox/Main/webservice/samples/python/clienttest.py @@ -0,0 +1,132 @@ +#!/usr/bin/python + +__copyright__ = \ +""" +Copyright (C) 2012-2023 Oracle and/or its affiliates. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. +""" + + +# Things needed to be set up before running this sample: +# - Install Python and verify it works (2.7.2 will do, 3.x is untested yet) +# - On Windows: Install the PyWin32 extensions for your Python version +# (see http://sourceforge.net/projects/pywin32/) +# - If not already done, set the environment variable "VBOX_INSTALL_PATH" +# to point to your VirtualBox installation directory (which in turn must have +# the "sdk" subfolder") +# - Install the VirtualBox Python bindings by doing a +# "[python] vboxapisetup.py install" +# - Run this sample with "[python] clienttest.py" + +import os,sys +import traceback + +# +# Converts an enumeration to a printable string. +# +def enumToString(constants, enum, elem): + all = constants.all_values(enum) + for e in all.keys(): + if str(elem) == str(all[e]): + return e + return "" + +def main(argv): + + from vboxapi import VirtualBoxManager + # This is a VirtualBox COM/XPCOM API client, no data needed. + mgr = VirtualBoxManager(None, None) + + # Get the global VirtualBox object + vbox = mgr.getVirtualBox() + + print "Running VirtualBox version %s" %(vbox.version) + + # Get all constants through the Python manager code + vboxConstants = mgr.constants + + # Enumerate all defined machines + for mach in mgr.getArray(vbox, 'machines'): + + try: + # Be prepared for failures - the VM can be inaccessible + vmname = '' + try: + vmname = mach.name + except Exception, e: + None + vmid = ''; + try: + vmid = mach.id + except Exception, e: + None + + # Print some basic VM information even if there were errors + print "Machine name: %s [%s]" %(vmname,vmid) + if vmname == '' or vmid == '': + continue + + # Print some basic VM information + print " State: %s" %(enumToString(vboxConstants, "MachineState", mach.state)) + print " Session state: %s" %(enumToString(vboxConstants, "SessionState", mach.sessionState)) + + # Do some stuff which requires a running VM + if mach.state == vboxConstants.MachineState_Running: + + # Get the session object + session = mgr.getSessionObject() + + # Lock the current machine (shared mode, since we won't modify the machine) + mach.lockMachine(session, vboxConstants.LockType_Shared) + + # Acquire the VM's console and guest object + console = session.console + guest = console.guest + + # Retrieve the current Guest Additions runlevel and print + # the installed Guest Additions version + addRunLevel = guest.additionsRunLevel + print " Additions State: %s" %(enumToString(vboxConstants, "AdditionsRunLevelType", addRunLevel)) + if addRunLevel != vboxConstants.AdditionsRunLevelType_None: + print " Additions Ver: %s" %(guest.additionsVersion) + + # Get the VM's display object + display = console.display + + # Get the VM's current display resolution + bit depth + position + screenNum = 0 # From first screen + (screenW, screenH, screenBPP, screenX, screenY, _) = display.getScreenResolution(screenNum) + print " Display (%d): %dx%d, %d BPP at %d,%d" %(screenNum, screenW, screenH, screenBPP, screenX, screenY) + + # We're done -- don't forget to unlock the machine! + session.unlockMachine() + + except Exception, e: + print "Errror [%s]: %s" %(mach.name, str(e)) + traceback.print_exc() + + # Call destructor and delete manager + del mgr + +if __name__ == '__main__': + main(sys.argv) -- cgit v1.2.3