private void displayProperties(String[] args) { _service = cb.getConnection().Service; _sic = cb.getConnection().ServiceContent; String hostName = cb.get_option("hostname"); ManagedObjectReference hmor = _service.FindByDnsName(_sic.searchIndex, null, hostName, false); if (hmor != null) { ArrayList supportedVersions = VersionUtil.getSupportedVersions(cb.get_option("url")); if (VersionUtil.isApiVersionSupported(supportedVersions, "2.5")) { _service = cb.getConnection().Service; _sic = cb.getConnection().ServiceContent; Object[] vmProps = getProperties(hmor, new String[] { "name" }); String serverName = (String)vmProps[0]; Console.WriteLine("Server Name " + serverName); HostRuntimeInfo runtimeInfo = (HostRuntimeInfo)getObjectProperty(hmor, "runtime"); DateTime dt = runtimeInfo.bootTime; Console.WriteLine("Boot Time " + dt.ToString()); String powerState = runtimeInfo.powerState.ToString(); Console.WriteLine("Power State " + powerState); HostConfigInfo configInfo = (HostConfigInfo)getObjectProperty(hmor, "config"); String timeZone = configInfo.dateTimeInfo.timeZone.key; Console.WriteLine("Time Zone " + timeZone); Boolean flag = VersionUtil.isApiVersionSupported(supportedVersions, "4.0"); if (flag) { Console.WriteLine("\nProperties added in 4.0 VI API\n"); Object objFlag = getObjectProperty(hmor, "capability.ipmiSupported"); if (objFlag != null) { Boolean infoFlag = (Boolean)objFlag; Console.WriteLine("IPMI Supported " + infoFlag); } else { Console.WriteLine("\nIPMI Flag not set"); } objFlag = getObjectProperty(hmor, "capability.tpmSupported"); if (objFlag != null) { Boolean infoFlag = (Boolean)objFlag; Console.WriteLine("TPM Supported " + infoFlag); } else { Console.WriteLine("\nTPM Flag not set"); } } } else { Object[] vmProps = getProperties(hmor, new String[] { "name" }); String serverName = (String)vmProps[0]; Console.WriteLine("Server Name " + serverName); } } else { Console.WriteLine("Host Not Found"); } }
/** Excercise the SearchIndex API * * @param args Usage is: * <url> <user> <password> <Datacenter Name> <A VM DNS Name> * <A Host DNS Name> <A VM Inventory Path> */ public static void Main(String[] args) { try { SearchIndex app = new SearchIndex(); cb = AppUtil.AppUtil.initialize("SearchIndex" , SearchIndex.constructOptions() , args); cb.connect(); String dcName = cb.get_option("dcName"); String vmDnsName = cb.get_option("vmDnsName"); String hostDnsName = cb.get_option("hostDnsName"); String vmPath = cb.get_option("vmPath"); String vmIP = cb.get_option("vmIP"); content = cb.getConnection()._sic; service = cb.getConnection()._service; // Find the Datacenter by using findChild() ManagedObjectReference dcMoRef = cb.getServiceUtil().GetDecendentMoRef(null, "Datacenter", dcName); if (dcMoRef != null) { Console.WriteLine("Found Datacenter with name: " + dcName + ", MoRef: " + dcMoRef.Value); } else { Console.WriteLine("Datacenter not Found with name: " + dcName); } if (vmDnsName != null) { ManagedObjectReference vmMoRef = service.FindByDnsName(content.searchIndex, dcMoRef, vmDnsName, true); if (vmMoRef != null) { Console.WriteLine("Found VirtualMachine with DNS name: " + vmDnsName + ", MoRef: " + vmMoRef.Value); } else { Console.WriteLine("VirtualMachine not Found with DNS name: " + vmDnsName); } } if (vmPath != null) { ManagedObjectReference vmMoRef = service.FindByInventoryPath( content.searchIndex, vmPath); if (vmMoRef != null) { Console.WriteLine("Found VirtualMachine with Path: " + vmPath + ", MoRef: " + vmMoRef.Value); } else { Console.WriteLine("VirtualMachine not found with vmPath " + "address: " + vmPath); } } if (vmIP != null) { ManagedObjectReference vmMoRef = service.FindByIp(content.searchIndex, dcMoRef, vmIP, true); if (vmMoRef != null) { Console.WriteLine("Found VirtualMachine with IP " + "address " + vmIP + ", MoRef: " + vmMoRef.Value); } else { Console.WriteLine("VirtualMachine not found with IP " + "address: " + vmIP); } } if (hostDnsName != null) { ManagedObjectReference hostMoRef = service.FindByDnsName(content.searchIndex, null, hostDnsName, false); if (hostMoRef != null) { Console.WriteLine("Found HostSystem with DNS name " + hostDnsName + ", MoRef: " + hostMoRef.Value); } else { Console.WriteLine("HostSystem not Found with DNS name:" + hostDnsName); } } cb.disConnect(); Console.WriteLine("Press enter to exit: "); Console.Read(); } catch (SoapException e) { } }
/// <summary> /// The main entry point for the application. /// </summary> public static void Main(String[] args) { try { PropertyCollector app = new PropertyCollector(); cb = AppUtil.AppUtil.initialize("PropertyCollector", PropertyCollector.constructOptions(), args); cb.connect(); ManagedObjectReference sic = cb.getConnection().ServiceRef; _sic = cb.getConnection()._sic; _service = cb.getConnection()._service; String dcName = cb.get_option("dcName"); String vmDnsName = cb.get_option("vmDnsName"); ObjectContent[] ocs = null; ManagedObjectReference dcMoRef = cb.getServiceUtil().GetDecendentMoRef(null, "Datacenter", dcName); if (dcMoRef == null) { Console.WriteLine("Datacenter not found"); } else { ManagedObjectReference vmMoRef = _service.FindByDnsName(_sic.searchIndex, dcMoRef, vmDnsName, true); if (vmMoRef == null) { Console.WriteLine("The virtual machine with DNS '" + vmDnsName + "' not found "); } else { // Retrieve name and powerState from a Virtual Machine Object[] properties = getProperties(vmMoRef, new String[] { "name", "runtime.powerState" }); String vmName = (String)properties[0]; VirtualMachinePowerState vmState = (VirtualMachinePowerState)properties[1]; if (vmName != null && vmState != null) { Console.WriteLine("The VM with DNS name \'" + vmDnsName + "\' is named \'" + vmName + "\' and is " + vmState.ToString()); } ocs = getDatacenters(); printObjectContent(ocs, "All Datacenters"); // Find all the VMs in the Datacenter ocs = getVMs(dcMoRef); printObjectContent(ocs, "All VMs in the Datacenter: " + dcName); //Find all the Hosts in the Datacenter ocs = getHosts(dcMoRef); printObjectContent(ocs, "All Hosts in the Datacenter: " + dcName); // Display summary information about a VM ocs = getVMInfo(vmMoRef); printVmInfo(ocs); // Display all of inventory ocs = getInventory(); printInventoryTree(ocs); ocs = getNetworkInfo(dcMoRef); printNetworkInfo(ocs); cb.disConnect(); Console.WriteLine("Press any key to exit:"); Console.Read(); } } } catch (SoapException e) { if (e.Detail.FirstChild.LocalName.Equals("DuplicateNameFault")) { Console.WriteLine("Managed Entity with the name already exists"); } else if (e.Detail.FirstChild.LocalName.Equals("InvalidArgumentFault")) { Console.WriteLine("Specification is invalid"); } else if (e.Detail.FirstChild.LocalName.Equals("InvalidNameFault")) { Console.WriteLine("Managed Entity Name is empty or too long"); } else if (e.Detail.FirstChild.LocalName.Equals("RuntimeFault")) { Console.WriteLine(e.Message.ToString() + "Either parent name or item name is invalid"); } else if (e.Detail.FirstChild.LocalName.Equals("RuntimeFault")) { Console.WriteLine(e.Message.ToString() + " " + "The Operation is not supported on this object"); } else { Console.WriteLine(e.Message.ToString() + " " + "The Operation is not supported on this object"); } } Console.Read(); }
private void displayProperties(String[] args) { _service = cb.getConnection().Service; _sic = cb.getConnection().ServiceContent; String hostName = cb.get_option("hostname"); ManagedObjectReference hmor = _service.FindByDnsName(_sic.searchIndex, null, hostName, false); if (hmor != null) { ArrayList supportedVersions = VersionUtil.getSupportedVersions(cb.get_option("url")); if (VersionUtil.isApiVersionSupported(supportedVersions, "2.5")) { _service = cb.getConnection().Service; _sic = cb.getConnection().ServiceContent; Object[] vmProps = getProperties(hmor, new String[] { "name" }); String serverName = (String)vmProps[0]; Console.WriteLine("Server Name " + serverName); HostRuntimeInfo runtimeInfo = (HostRuntimeInfo)getObjectProperty(hmor, "runtime"); DateTime dt = runtimeInfo.bootTime; Console.WriteLine("Boot Time " + dt.ToString()); String powerState = runtimeInfo.powerState.ToString(); Console.WriteLine("Power State " + powerState); HostConfigInfo configInfo = (HostConfigInfo)getObjectProperty(hmor, "config"); String timeZone = configInfo.dateTimeInfo.timeZone.key; Console.WriteLine("Time Zone " + timeZone); Boolean flag = VersionUtil.isApiVersionSupported(supportedVersions, "4.0"); if (flag) { Console.WriteLine("\nProperties added in 4.0 VI API\n"); Object objFlag = getObjectProperty(hmor, "capability.ipmiSupported"); if (objFlag != null) { Boolean infoFlag = (Boolean)objFlag; Console.WriteLine("IPMI Supported " + infoFlag); } else { Console.WriteLine("\nIPMI Flag not set"); } objFlag = getObjectProperty(hmor, "capability.tpmSupported"); if (objFlag != null) { Boolean infoFlag = (Boolean)objFlag; Console.WriteLine("TPM Supported " + infoFlag); } else { Console.WriteLine("\nTPM Flag not set"); } } } else { Object[] vmProps = getProperties(hmor, new String[] { "name" }); String serverName = (String)vmProps[0]; Console.WriteLine("Server Name " + serverName); } } else { Console.WriteLine("Host Not Found"); } }
/** Excercise the SearchIndex API * * @param args Usage is: * <url> <user> <password> <Datacenter Name> <A VM DNS Name> * <A Host DNS Name> <A VM Inventory Path> */ public static void Main(String[] args) { try { SearchIndex app = new SearchIndex(); cb = AppUtil.AppUtil.initialize("SearchIndex" ,SearchIndex.constructOptions() ,args); cb.connect(); String dcName = cb.get_option("dcName"); String vmDnsName = cb.get_option("vmDnsName"); String hostDnsName =cb.get_option("hostDnsName"); String vmPath = cb.get_option("vmPath"); String vmIP = cb.get_option("vmIP"); content = cb.getConnection()._sic; service = cb.getConnection()._service; // Find the Datacenter by using findChild() ManagedObjectReference dcMoRef = cb.getServiceUtil().GetDecendentMoRef(null, "Datacenter", dcName); if (dcMoRef !=null){ Console.WriteLine("Found Datacenter with name: " +dcName+", MoRef: " + dcMoRef.Value); }else{ Console.WriteLine("Datacenter not Found with name: "+dcName); } if (vmDnsName != null){ ManagedObjectReference vmMoRef = service.FindByDnsName(content.searchIndex, dcMoRef, vmDnsName, true); if (vmMoRef !=null){ Console.WriteLine("Found VirtualMachine with DNS name: "+ vmDnsName+", MoRef: " + vmMoRef.Value); } else{ Console.WriteLine("VirtualMachine not Found with DNS name: " + vmDnsName); } } if (vmPath != null){ ManagedObjectReference vmMoRef = service.FindByInventoryPath( content.searchIndex, vmPath); if (vmMoRef !=null) { Console.WriteLine("Found VirtualMachine with Path: "+ vmPath+", MoRef: " + vmMoRef.Value); } else{ Console.WriteLine("VirtualMachine not found with vmPath "+ "address: "+ vmPath); } } if (vmIP != null){ ManagedObjectReference vmMoRef = service.FindByIp(content.searchIndex, dcMoRef, vmIP, true); if (vmMoRef !=null){ Console.WriteLine("Found VirtualMachine with IP "+ "address "+ vmIP + ", MoRef: " + vmMoRef.Value); }else{ Console.WriteLine("VirtualMachine not found with IP "+ "address: "+vmIP); } } if (hostDnsName != null) { ManagedObjectReference hostMoRef = service.FindByDnsName(content.searchIndex, null, hostDnsName, false); if (hostMoRef !=null) { Console.WriteLine("Found HostSystem with DNS name "+ hostDnsName+", MoRef: " + hostMoRef.Value); } else{ Console.WriteLine("HostSystem not Found with DNS name:"+ hostDnsName); } } cb.disConnect(); Console.WriteLine("Press enter to exit: "); Console.Read(); } catch(SoapException e) { } }