Guest User

Untitled

a guest
Jul 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. package com.vmware.vim25.mo.samples
  2.  
  3. import java.net.URL
  4. import org.apache.log4j.Logger
  5. import com.vmware.vim25.mo._
  6.  
  7. object HelloVM {
  8. val log = Logger.getLogger(getClass)
  9.  
  10. def sayHello(url: String, user: String, pwd: String) {
  11. log.info("Starting")
  12. val si = new ServiceInstance(new URL(url), user, pwd, true)
  13. log.info("ServiceInstance created")
  14. val rootFolder = si.getRootFolder
  15. log.info("Root folder: " + rootFolder.getName)
  16.  
  17. log.info("Searching for VMs")
  18.  
  19. getVMs(rootFolder) match {
  20. case firstVm :: others =>
  21. log.info("Hello " + firstVm.getName)
  22. log.info("GuestOS: " + firstVm.getConfig.getGuestFullName)
  23. log.info("Multiple snapshots supported: " + firstVm.getCapability.isMultipleSnapshotsSupported)
  24. case _ => log.warn("No VMs found")
  25. }
  26. si.getServerConnection.logout()
  27. }
  28.  
  29. private def getVMs(rootFolder: Folder): List[VirtualMachine] =
  30. new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine") match {
  31. case null =>
  32. log.error("searchManagedEntities returned null")
  33. List[VirtualMachine]()
  34. case vms => vms map(_.asInstanceOf[VirtualMachine]) toList
  35. }
  36. }
Add Comment
Please, Sign In to add comment