Created
January 24, 2011 20:55
-
-
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)?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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