Groovy web console

subscribe to the feed Subscribe
to this
site

VMWare vSphere administration from Groovy

Published 1 decade ago by glaforge with tags vmware vsphere vijava administration remote
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
/*
    Slightly Groovy-fied version of the following article:
    http://www.virtualinsanity.com/index.php/2010/04/16/easy-vmware-development-with-vi-java-api-and-groovy/
    Ie. how to leverage the VI-Java API for managing your VMware VI3.x / vSphere environments
*/

import java.net.URL import com.vmware.vim25.*
import com.vmware.vim25.mo.*

def si = new ServiceInstance("https://<ip address of vCenter or ESX>/sdk" as URL, "administrator", "password", true)
def rootFolder = si.rootFolder
println "Root folder: ${rootFolder.name}"

new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine").each {
    println """
        Hello ${it.name}
        Guest OS: ${it.config.guestFullName}
        Multiple snapshots supported?: ${it.capability.isMultipleSnapshotsSupported()}
    """
}
si.serverConnection.logout()