1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
| '======================================
'
' Description: VMware VmCOM 1.0 Type Library
'
' Name: VMCOMLib
' Version: 1.0 [of Type Library]
' GUID: {0407CAC2-41D7-4EB4-898B-4EC06C57BB81}
'
' File: VmCOM.dll
' Version: 1.0.0.1 [of file]
'
' Extracted on: 2002.08.28 00:53:08
'
'=====================================
' VmErr
'=====================================
Const vmErr_ALREADYCONNECTED = -2147220980
Const vmErr_BADRESPONSE = -2147220978
Const vmErr_BADSTATE = -2147220984
Const vmErr_BADVERSION = -2147220986
Const vmErr_DISCONNECT = -2147220979
Const vmErr_GARBAGE = -2147220977
Const vmErr_INSUFFICIENT_RESOURCES = -2147220970
Const vmErr_INVALIDARGS = -2147220989
Const vmErr_INVALIDVM = -2147220974
Const vmErr_NEEDINPUT = -2147220976
Const vmErr_NETFAIL = -2147220990
Const vmErr_NOACCESS = -2147220988
Const vmErr_NOEXECVMAUTHD = -2147220983
Const vmErr_NOMEM = -2147220991
Const vmErr_NOPROPERTY = -2147220982
Const vmErr_NOSUCHVM = -2147220981
Const vmErr_NOTCONNECTED = -2147220987
Const vmErr_NOTSUPPORTED = -2147220975
Const vmErr_PROXYFAIL = -2147220969
Const vmErr_TIMEOUT = -2147220985
Const vmErr_UNSPECIFIED = -2147219993
Const vmErr_VMBUSY = -2147220971
Const vmErr_VMEXISTS = -2147220972
Const vmErr_VMINITFAILED = -2147220973
'=====================================
' VmExecutionState
'=====================================
Const vmExecutionState_Off = 2
Const vmExecutionState_On = 1
Const vmExecutionState_Stuck = 4
Const vmExecutionState_Suspended = 3
Const vmExecutionState_Unknown = 5
'=====================================
' VmPlatform
'=====================================
Const vmPlatform_LINUX = 2
Const vmPlatform_UNKNOWN = 4
Const vmPlatform_VMNIX = 3
Const vmPlatform_WINDOWS = 1
'=====================================
' VmPowerOpMode
'=====================================
Const vmPowerOpMode_Hard = 1
Const vmPowerOpMode_Soft = 2
Const vmPowerOpMode_TrySoft = 3
'=====================================
' VmProdInfoType
'=====================================
Const vmProdInfo_Build = 3
Const vmProdInfo_Platform = 2
Const vmProdInfo_Product = 1
Const vmProdInfo_Version_Major = 4
Const vmProdInfo_Version_Minor = 5
Const vmProdInfo_Version_Revision = 6
'=====================================
' VmProduct
'=====================================
Const vmProduct_ESX = 3
Const vmProduct_GSX = 2
Const vmProduct_UNKNOWN = 4
Const vmProduct_WS = 1
'=====================================
' VmTimeoutId
'=====================================
Const vmTimeoutId_Default = 1
'
' VmCOM VBScript Sample Program 3
' Copyright 1998 VMware, Inc. All rights reserved. -- VMware Confidential
'
' Permission is hereby granted, free of charge, to any person obtaining a
' copy of the software in this file (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 names "VMware" and "VMware, Inc." must not be used to endorse or
' promote products derived from the Software without the prior written
' permission of VMware, Inc.
'
' Products derived from the Software may not be called "VMware", nor may
' "VMware" appear in their name, without the prior written permission of
' VMware, Inc.
'
' 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
' VMWARE,INC. 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.
'
' ------
'
' This program is for educational purposes only.
' It is not to be used in production environments.
'
' Description:
'
' This script gets a list of virtual machines registered on
' the local server. It attempts to power-on each VM that
' is not already running and has a line in the config file:
'
' autostart=true
'
'
' Instructions for Windows 2000 and Windows XP host:
'
' - save the contents of this file to a file named 'sample3.vbs'
'
' - there should be an accompanying file named 'sample3.wsf'
' It is placed in the same directory as this file during
' product installation. This file is responsible for setting
' up the Windows Script Host environment and loading the
' VmCOM type library, thereby enabling this script to
' reference symbolic constants such as vmExecutionState_On
'
' - in a command line window, type:
' cscript //nologo sample3.wsf
'
Set connect_params = CreateObject("VmCOM.VmConnectParams")
' By default, connects to the local server.
' To connect to a remote server, uncomment these lines and set
' the values appropriately.
'
' connect_params.hostname = "<host>"
' connect_params.username = "<user>"
' connect_params.password = "<password>"
'
' And use this if your port number is different
' connect_params.port = 902
Set vm_server = CreateObject("VmCOM.VmServerCtl")
' Handle errors non-fatally from here on
On Error Resume Next
'
' Try connecting to server a few times. It's possible the VMware services
' are still in the process of starting up. We'll wait a maximum of
' 12 * 10 = 120 seconds = 2 minutes
'
connected = false
for tries = 1 to 12
vm_server.Connect connect_params
if Err.number = 0 then
connected = true
exit for
end if
WScript.Echo "Could not connect to server: " & Err.Description
WScript.Echo "Retrying in 10 seconds ..."
WScript.Sleep 10000
Err.clear
next
if not connected then
WScript.Echo "Failed to connect to server. Giving up."
WScript.Quit
end if
' Get a list of all VMs from the server.
Set vmlist = vm_server.RegisteredVmNames
for each config in vmlist
' Connect to the VM
Set vm = CreateObject("VmCOM.VmCtl")
vm.Connect connect_params, config
if Err.Number <> 0 then
WScript.Echo "Could not connect to VM " & config & ": " & Err.Description
Err.Clear
else
' Check that the VM should be started automatically
auto_start = vm.Config("autostart")
auto_start ="true"
if Err.Number <> 0 then
if Err.Number <> vmErr_NOPROPERTY then
WScript.Echo "Could not read autostart variable: " & Err.Number & ": " & Err.Description
else
WScript.Echo "This VM is not configured for autostart: " & config
end if
Err.Clear
else
if auto_start = "true" or auto_start = "TRUE" or auto_start = "poweron" then
' Check that the VM is powered off
power_state = vm.ExecutionState
if Err.Number <> 0 then
WScript.Echo "Error getting execution state: " & Err.Number & ": " & Err.Description
Err.Clear
Else
if power_state = vmExecutionState_Off or power_state = vmExecutionState_On then
vm.Suspend(vmPowerOpMode_Hard)
if Err.Number <> 0 then
WScript.Echo "Error powering on " & config & ": " & Err.Description
Err.Clear
else
' Wait between starting up VMs to smooth out the load on the server
WScript.Sleep 5000
end if
end if
end if
end if
end if
end if
Next
Do While vm.ExecutionState<> vmExecutionState_Suspended
Sleep(100)
Loop
Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")
oShell.run "test.ub4"
'
' VmCOM VBScript Sample Program 3
' Copyright 1998 VMware, Inc. All rights reserved. -- VMware Confidential
'
' Permission is hereby granted, free of charge, to any person obtaining a
' copy of the software in this file (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 names "VMware" and "VMware, Inc." must not be used to endorse or
' promote products derived from the Software without the prior written
' permission of VMware, Inc.
'
' Products derived from the Software may not be called "VMware", nor may
' "VMware" appear in their name, without the prior written permission of
' VMware, Inc.
'
' 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
' VMWARE,INC. 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.
'
' ------
'
' This program is for educational purposes only.
' It is not to be used in production environments.
'
' Description:
'
' This script gets a list of virtual machines registered on
' the local server. It attempts to power-on each VM that
' is not already running and has a line in the config file:
'
' autostart=true
'
'
' Instructions for Windows 2000 and Windows XP host:
'
' - save the contents of this file to a file named 'sample3.vbs'
'
' - there should be an accompanying file named 'sample3.wsf'
' It is placed in the same directory as this file during
' product installation. This file is responsible for setting
' up the Windows Script Host environment and loading the
' VmCOM type library, thereby enabling this script to
' reference symbolic constants such as vmExecutionState_On
'
' - in a command line window, type:
' cscript //nologo sample3.wsf
'
Set connect_params = CreateObject("VmCOM.VmConnectParams")
' By default, connects to the local server.
' To connect to a remote server, uncomment these lines and set
' the values appropriately.
'
' connect_params.hostname = "<host>"
' connect_params.username = "<user>"
' connect_params.password = "<password>"
'
' And use this if your port number is different
' connect_params.port = 902
Set vm_server = CreateObject("VmCOM.VmServerCtl")
' Handle errors non-fatally from here on
On Error Resume Next
'
' Try connecting to server a few times. It's possible the VMware services
' are still in the process of starting up. We'll wait a maximum of
' 12 * 10 = 120 seconds = 2 minutes
'
connected = false
for tries = 1 to 12
vm_server.Connect connect_params
if Err.number = 0 then
connected = true
exit for
end if
WScript.Echo "Could not connect to server: " & Err.Description
WScript.Echo "Retrying in 10 seconds ..."
WScript.Sleep 10000
Err.clear
next
if not connected then
WScript.Echo "Failed to connect to server. Giving up."
WScript.Quit
end if
' Get a list of all VMs from the server.
Set vmlist = vm_server.RegisteredVmNames
for each config in vmlist
' Connect to the VM
Set vm = CreateObject("VmCOM.VmCtl")
vm.Connect connect_params, config
if Err.Number <> 0 then
WScript.Echo "Could not connect to VM " & config & ": " & Err.Description
Err.Clear
else
' Check that the VM should be started automatically
auto_start = vm.Config("autostart")
auto_start ="true"
if Err.Number <> 0 then
if Err.Number <> vmErr_NOPROPERTY then
WScript.Echo "Could not read autostart variable: " & Err.Number & ": " & Err.Description
else
WScript.Echo "This VM is not configured for autostart: " & config
end if
Err.Clear
else
if auto_start = "true" or auto_start = "TRUE" or auto_start = "poweron" then
' Check that the VM is powered off
power_state = vm.ExecutionState
if Err.Number <> 0 then
WScript.Echo "Error getting execution state: " & Err.Number & ": " & Err.Description
Err.Clear
Else
if power_state = vmExecutionState_Off or power_state = vmExecutionState_Suspended then
vm.Start(vmPowerOpMode_Soft)
if Err.Number <> 0 then
WScript.Echo "Error powering on " & config & ": " & Err.Description
Err.Clear
else
' Wait between starting up VMs to smooth out the load on the server
WScript.Sleep 5000
end if
end if
end if
end if
end if
end if
next |
Partager