Skip to content

Instantly share code, notes, and snippets.

@dcbriccetti
Created January 24, 2011 20:55
Show Gist options
  • Save dcbriccetti/793928 to your computer and use it in GitHub Desktop.
Save dcbriccetti/793928 to your computer and use it in GitHub Desktop.
Any review comments for this “Hello VM” code for use with VI Java (VMware)?
package com.vmware.vim25.mo.samples
import java.net.URL
import org.apache.log4j.Logger
import com.vmware.vim25.mo._
object HelloVM {
val log = Logger.getLogger(getClass)
def sayHello(url: String, user: String, pwd: String) {
log.info("Starting")
val si = new ServiceInstance(new URL(url), user, pwd, true)
log.info("ServiceInstance created")
val rootFolder = si.getRootFolder
log.info("Root folder: " + rootFolder.getName)
log.info("Searching for VMs")
getVMs(rootFolder) match {
case firstVm :: others =>
log.info("Hello " + firstVm.getName)
log.info("GuestOS: " + firstVm.getConfig.getGuestFullName)
log.info("Multiple snapshots supported: " + firstVm.getCapability.isMultipleSnapshotsSupported)
case _ => log.warn("No VMs found")
}
si.getServerConnection.logout()
}
private def getVMs(rootFolder: Folder): List[VirtualMachine] =
new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine") match {
case null =>
log.error("searchManagedEntities returned null")
List[VirtualMachine]()
case vms => vms map(_.asInstanceOf[VirtualMachine]) toList
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment