@Test public void example() throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg { BasicConnection conn = new BasicConnection(); String url = System.getProperty("vsphere.url"); String username = System.getProperty("vsphere.username"); String password = System.getProperty("vsphere.password"); conn.setURI(URI.create(url)); conn.setUsername(username); conn.setPassword(password); conn.setIgnoreSslErrors(true); conn.setRequestTimeout(30, TimeUnit.SECONDS); conn.connect(); AboutInfo about = conn.getServiceContent().getAbout(); System.out.println(Utils.toJsonHtml(about)); ManagedObjectReference rootFolder = conn.getServiceContent().getRootFolder(); GetMoRef getMoRef = new GetMoRef(conn); String name = getMoRef.entityProp(rootFolder, "name"); System.out.println("Root folder is called \'" + name + "\'"); }
@Action public void main() { String hostName = connection.getHost(); AboutInfo aboutInfo = connection.connect().getServiceContent().getAbout(); System.out.printf("You are connected to %s %n", hostName); System.out.printf("Host %s is running SDK version: %s %n", hostName, aboutInfo.getVersion()); System.out.printf("Host %s is a %s %n", hostName, aboutInfo.getApiType()); }
@Test public void vSphereLocationSupplierTest() throws IOException { ServerConnection serverConnection = PowerMock.createMock(ServerConnection.class); WSClient wsClient = PowerMock.createMock(WSClient.class); ManagedObjectReference managedObjectReference = PowerMock.createMock(ManagedObjectReference.class); ServiceInstance serviceInstance = PowerMock.createMock(ServiceInstance.class); CreateAndConnectVSphereClient supplier = PowerMock.createMock(CreateAndConnectVSphereClient.class); VSphereServiceInstance vSphereServiceInstance = PowerMock.createMock(VSphereServiceInstance.class); Folder rootFolder = PowerMock.createMock(Folder.class); expect(supplier.get()).andReturn(vSphereServiceInstance); expect(vSphereServiceInstance.getInstance()).andReturn(serviceInstance); expect(serviceInstance.getRootFolder()).andReturn(rootFolder); expect(rootFolder.getServerConnection()).andReturn(serverConnection).anyTimes(); expect(rootFolder.getMOR()).andReturn(managedObjectReference); expect(serverConnection.getServiceInstance()).andReturn(serviceInstance).anyTimes(); expect(serverConnection.getVimService()).andReturn(new VimPortType(wsClient)).anyTimes(); AboutInfo aboutInfo = new AboutInfo(); aboutInfo.setApiVersion("5.1"); expect(serviceInstance.getPropertyCollector()).andReturn(new PropertyCollector(serverConnection, managedObjectReference)); expect(serviceInstance.getAboutInfo()).andReturn(aboutInfo); vSphereServiceInstance.close(); replay(supplier, vSphereServiceInstance, serviceInstance, rootFolder, serverConnection); VSphereLocationSupplier vSphereLocationSupplier = new VSphereLocationSupplier(supplier); Set<? extends Location> location = vSphereLocationSupplier.get(); Assert.assertEquals(1, location.size()); for (Location l : location) { Assert.assertEquals("default", l.getId()); } verify(supplier, vSphereServiceInstance, serviceInstance, rootFolder, serverConnection); }
public VmwareHostType getHostType() throws Exception { AboutInfo aboutInfo = getHostAboutInfo(); if ("VMware ESXi".equals(aboutInfo.getName())) return VmwareHostType.ESXi; else if ("VMware ESX".equals(aboutInfo.getName())) return VmwareHostType.ESX; throw new Exception("Unrecognized VMware host type " + aboutInfo.getName()); }
public AboutInfo getHostAboutInfo() throws Exception { return (AboutInfo)_context.getVimClient().getDynamicProperty(_mor, "config.product"); }
@Override public StartupCommand[] initialize() { try { String hostApiVersion = "4.1"; VmwareContext context = getServiceContext(); try { VmwareHypervisorHost hyperHost = getHyperHost(context); assert (hyperHost instanceof HostMO); if (!((HostMO)hyperHost).isHyperHostConnected()) { s_logger.info("Host " + hyperHost.getHyperHostName() + " is not in connected state"); return null; } ((HostMO)hyperHost).enableVncOnHostFirewall(); AboutInfo aboutInfo = ((HostMO)hyperHost).getHostAboutInfo(); hostApiVersion = aboutInfo.getApiVersion(); } catch (Exception e) { String msg = "VmwareResource intialize() failed due to : " + VmwareHelper.getExceptionMessage(e); s_logger.error(msg); invalidateServiceContext(); return null; } StartupRoutingCommand cmd = new StartupRoutingCommand(); fillHostInfo(cmd); cmd.setHypervisorType(HypervisorType.VMware); cmd.setCluster(_cluster); cmd.setHypervisorVersion(hostApiVersion); List<StartupStorageCommand> storageCmds = initializeLocalStorage(); StartupCommand[] answerCmds = new StartupCommand[1 + storageCmds.size()]; answerCmds[0] = cmd; for (int i = 0; i < storageCmds.size(); i++) { answerCmds[i + 1] = storageCmds.get(i); } return answerCmds; } finally { recycleServiceContext(); } }