/** * @return the IpAddress of this VM. */ @Override public String getIpAddress() { GuestInfo guest = vm.getGuest(); return guest.getIpAddress(); }
/** * Returns the guest OS short description of a virtual machine */ private void getVmGuestShortName(String vmName, PrintWriter out) throws IOException { try { VirtualMachine vm = (VirtualMachine) getManagedEntity(vmName, "VirtualMachine"); String guestShortName = ""; if (vm == null) { LOG.warn("No vm named '" + vmName + "' found"); } else { GuestInfo gInfo = vm.getGuest(); if (gInfo == null) { LOG.info("Cannot query guest OS for VM '" + vmName); } else { guestShortName = gInfo.getGuestFamily(); } } out.print(guestShortName); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
/** * Searches for all ip addresses of a virtual machine * * @param virtualMachine the virtual machine to query * @return the ip addresses of the virtual machine, the first one is the primary */ public TreeSet<String> getVirtualMachineIpAddresses(VirtualMachine virtualMachine) { TreeSet<String> ipAddresses = new TreeSet<String>(); // add the Ip address reported by VMware tools, this should be primary if (virtualMachine.getGuest().getIpAddress() != null) { ipAddresses.add(virtualMachine.getGuest().getIpAddress()); } // if possible, iterate over all virtual networks networks and add interface Ip addresses if (virtualMachine.getGuest().getNet() != null) { for (GuestNicInfo guestNicInfo : virtualMachine.getGuest().getNet()) { if (guestNicInfo.getIpAddress() != null) { for (String ipAddress : guestNicInfo.getIpAddress()) { ipAddresses.add(ipAddress); } } } } return ipAddresses; }
setVal(n, "vmw_morType", moType); setVal(n, "vmw_annotation", cfg.getAnnotation()); setVal(n, "vmw_guestToolsVersion", g.getToolsVersion()); setVal(n, "vmw_guestId", g.getGuestId()); setVal(n, "vmw_guestFamily", g.getGuestFamily()); setVal(n, "vmw_guestFullName", g.getGuestFullName()); setVal(n, "vmw_guestIpAddress", g.getIpAddress()); setVal(n, "vmw_guestId", g.getGuestId()); setVal(n, "vmw_guestHostName", g.getHostName()); setVal(n, "vmw_guestAlternateName", cfg.getAlternateGuestName()); setVal(n, "vmw_guestToolsRunningStatus",""+g.getToolsRunningStatus()); setVal(n, "vmw_guestState",""+g.getGuestState());
public static void main(String[] args) throws Exception { long start = System.currentTimeMillis(); ServiceInstance si = SampleUtil.createServiceInstance(); long end = System.currentTimeMillis(); Folder rootFolder = si.getRootFolder(); System.out.println("time taken:" + (end - start)); String name = rootFolder.getName(); System.out.println("vc root folder:" + name); ManagedEntity[] mes = new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine"); if (mes == null || mes.length == 0) { return; } VirtualMachine vm = (VirtualMachine) mes[0]; VirtualMachineConfigInfo vminfo = vm.getConfig(); VirtualMachineCapability vmc = vm.getCapability(); System.out.println("Name: " + vm.getName()); System.out.println("IP: " + vm.getGuest().getIpAddress()); System.out.println("FQDN: " + vm.getGuest().getHostName()); System.out.println("MOID: " + vm.getMOR().val); System.out.println("InstanceUUID: " + vm.getSummary().getConfig().getInstanceUuid()); System.out.println("GuestOS: " + vminfo.getGuestFullName()); System.out.println("Multiple snapshot supported: " + vmc.isMultipleSnapshotsSupported()); si.getServerConnection().logout(); }
if (virtualMachine.getGuest().getGuestFullName() != null) { node.putAsset(new RequisitionAsset("operatingSystem", virtualMachine.getGuest().getGuestFullName()));
/** * Retrieves IP addresses on the VM from vCenter. The VI Java API's method for returning * the IP addresses can be unreliable - it depends on when the VM is polled by Terraform. * Only IPv4 addresses will be added - IPv6 addresses are ignored right now. * Sets the IP addresses as a comma-separated list. This will be written out to XML. */ public void setIpListFromVmInfo() { ipList.clear(); GuestNicInfo[] nicInfos = vm.getGuest().getNet(); if (nicInfos == null) { log.warn("problem retrieving network info from VM"); } else { for (int i=0; i<nicInfos.length; i++) { String[] nicInfoIpList = nicInfos[i].getIpAddress(); for (int j=0; j<nicInfoIpList.length; j++) { //ip4 addresses only; vsphere 5 likes to return ip4 and ip6 String unparsedIp = nicInfoIpList[j]; if (!unparsedIp.contains(":")) { Ip4 newIp = new Ip4(unparsedIp); ipList.add(newIp); } } } } }
/** * Create an instance of {@link GuestInfo } * */ public GuestInfo createGuestInfo() { return new GuestInfo(); }
if (virtualMachine.getGuest().getGuestFullName() != null) { node.putAsset(new RequisitionAsset("operatingSystem", virtualMachine.getGuest().getGuestFullName()));
/** * @return the IpAddress of this VM. */ private String getIpAddress() { GuestInfo guest = vm.getGuest(); return guest.getIpAddress(); } }
/** * Searches for all ip addresses of a virtual machine * * @param virtualMachine the virtual machine to query * @return the ip addresses of the virtual machine, the first one is the primary */ public TreeSet<String> getVirtualMachineIpAddresses(VirtualMachine virtualMachine) { TreeSet<String> ipAddresses = new TreeSet<String>(); // add the Ip address reported by VMware tools, this should be primary if (virtualMachine.getGuest().getIpAddress() != null) { ipAddresses.add(virtualMachine.getGuest().getIpAddress()); } // if possible, iterate over all virtual networks networks and add interface Ip addresses if (virtualMachine.getGuest().getNet() != null) { for (GuestNicInfo guestNicInfo : virtualMachine.getGuest().getNet()) { if (guestNicInfo.getIpAddress() != null) { for (String ipAddress : guestNicInfo.getIpAddress()) { ipAddresses.add(ipAddress); } } } } return ipAddresses; }
String osFamily = vm.getGuest().getGuestFamily(); System.out.println("osFamily: " + osFamily); boolean isWindows = osFamily.contains("windowsGuest");
public void waitForIp(VirtualMachine vm) throws RemoteException, InterruptedException { long pollInterval = 3000L; long timeoutInterval = 10L * 60L * 1000L; long start = System.currentTimeMillis(); String address = vm.getGuest().getIpAddress(); while (address == null) { if (System.currentTimeMillis() - start > timeoutInterval) { throw new RemoteException("Timeout waiting for IP"); } Thread.sleep(pollInterval); address = vm.getGuest().getIpAddress(); } assert address != null; }
/** * Deploy virtual machines, according to universe parameters */ public void deploy() { log.info("Vm deployment"); Map<String, VirtualMachine> deployment = new HashMap<>(); List<CompletableFuture<VirtualMachine>> asyncDeployment = universeParams.getVmIpAddresses() .keySet() .stream() .map(this::deployVmAsync) .collect(Collectors.toList()); asyncDeployment .stream() .map(CompletableFuture::join) .forEach(vm -> { universeParams.updateIpAddress(vm.getName(), vm.getGuest().getIpAddress()); deployment.put(vm.getName(), vm); }); log.info("The deployed VMs are: {}", universeParams.getVmIpAddresses()); vms.putAll(deployment); }
/** * @return an instance of {@link Layout} that is built from the existing parameters. */ private Layout buildLayout() { long epoch = 0; UUID clusterId = UUID.randomUUID(); List<String> servers = params.getNodesParams() .stream() .map(this::getVmServerParams) .map(vmParams -> vms.get(vmParams.getVmName()).getGuest().getIpAddress() + ":" + vmParams.getPort()) .collect(Collectors.toList()); Layout.LayoutSegment segment = new Layout.LayoutSegment( Layout.ReplicationMode.CHAIN_REPLICATION, 0L, -1L, Collections.singletonList(new Layout.LayoutStripe(servers)) ); return new Layout(servers, servers, Collections.singletonList(segment), epoch, clusterId); }
TimeUnit.SECONDS.sleep(universeParams.getReadinessTimeout().getSeconds()); GuestInfo guest = vm.getGuest(); cloneVmIpAddress = guest.getIpAddress();
privateIp = instance.getGuest().getIpAddress();