Quantcast
Channel: VMware Communities : Popular Discussions - VIX API
Viewing all articles
Browse latest Browse all 34639

Vix 1.5 FindItems - All registered virtual machines

$
0
0

 

Hi there,

 

 

Hopefully someone can aid me on this, I feel like I'm bashing my head against a brick wall!

 

 

First, my system setup:

 

 

Running VM Server 2.0 RC1 on a Windows 2003 host,

Using Vix 1.5,

Scripting in VBScript, running on the VM Server host machine.

 

 

Task I'm attempting to accomplish:

 

 

I wish to automate the process of shutting down all running VMs, then copying the VM source files of all registered VMs to a backup location, then restarting all the VMs that were originally started.

 

 

Problem:

 

 

Trying (and failing) to obtain a list of all registered VMs using the FindItems function and the VIX_FIND_REGISTERED_VMS constant.

 

 

The problem is I'm not sure how to obtain the list of VMs once I've run the FindItems function. I was planning on using the job.Wait() function immediately following the FindItems call to wait on completion and then return the results, but I can't figure out which VIX_PROPERTY to use in the Wait function call - I keep getting error 6000, unrecognised property returned.

 

 

The relevant code is as follows:

 

Dim lib, job
Set lib = CreateObject("VixCOM.VixLib")

Function hostConnect(ByRef err)
     Dim results ' vars used in the creation of a handle to the host.
Dim username, password ' Username & Password to connect to the server.
Set results = Nothing
username = "username"
password = "password"

' Connect to the local installation of Server. This also intializes the VIX API.
Set job = lib.Connect(VixCOM.Constants.VIX_API_VERSION, _
VixCOM.Constants.VIX_SERVICEPROVIDER_VMWARE_VI_SERVER, _
"https://localhost:8333/sdk", _
0, _
username, _
password, _
0, _
Nothing, _
Nothing)

     err = job.Wait(Array(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE), results)
If lib.ErrorIndicatesFailure(err) Then
Set hostConnect = Nothing
Exit Function
End If

Set hostConnect = results(0)
End Function
Function hostDisconnect(host)
'Remove the handle to the VM Server host. This should appear after all work on the server has been completed.
host.Disconnect()
End Function

Function suspendGuests()
     Dim machineList, machine, host, err, results
Set host = hostConnect(err)
If (host Is Nothing) Then
MsgBox("Error opening handle to VM Server software." & VBCrLf & "Error ID: " & CStr(err))
Else
Set job = host.FindItems(VixCOM.Constants.VIX_FIND_RUNNING_VMS, _
Nothing, _
-1, _
Nothing)
err = job.Wait(Array(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE), results)
'machine = results(0)
MsgBox(err)
'MsgBox(machine)
End If

     hostDisconnect(host)
End Function

suspendGuests() ' Start the code running

 

If anyone has any ideas I'd be eternally grateful!

 

 

Many thanks in advance,

 

 

Steve

 

 

 

 

 


Viewing all articles
Browse latest Browse all 34639

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>