private VirtualMachine getVirtualMachine(String virtualmachineName) throws RemoteException { if( Utils.isEmptyOrWhitespaces( virtualmachineName )) return null; Folder rootFolder = this.vmwareServiceInstance.getRootFolder(); return (VirtualMachine) new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine", virtualmachineName); }
/** * Searches for a managed entity by a given type. * * @param type the type string to search for * @return the list of managed entities found * @throws RemoteException */ public ManagedEntity[] searchManagedEntities(String type) throws RemoteException { return (new InventoryNavigator(m_serviceInstance.getRootFolder())).searchManagedEntities(type); }
/** * Retrieve content recursively with multiple properties. * the typeinfo array contains typename + properties to retrieve. * * @param typeinfo 2D array of properties for each typename * @param recurse retrieve contents recursively from the root down * * @return retrieved object contents * @throws RemoteException * @throws RuntimeFault * @throws InvalidProperty */ public ManagedEntity[] searchManagedEntities(String[][] typeinfo, boolean recurse ) throws InvalidProperty, RuntimeFault, RemoteException { ObjectContent[] ocs = retrieveObjectContents(typeinfo, recurse); return createManagedEntities(ocs); }
Datacenter dc = (Datacenter) new InventoryNavigator( rootFolder).searchManagedEntity("Datacenter", dcName); ResourcePool rp = (ResourcePool) new InventoryNavigator( dc).searchManagedEntities("ResourcePool")[0];
/** * Get the first ManagedObjectReference from current node for the specified type */ public ManagedEntity[] searchManagedEntities(String type) throws InvalidProperty, RuntimeFault, RemoteException { String[][] typeinfo = new String[][] { new String[] { type, "name",}, }; return searchManagedEntities(typeinfo, true); }
@Override public InventoryNavigator create() throws IOException { ServiceInstance serviceInstance = new ServiceInstance(this.url, this.username, this.password, true); return new InventoryNavigator(serviceInstance.getRootFolder()); }
@Override public void destroy(Member member) throws DestructionException { try { VirtualMachine virtualMachine = (VirtualMachine) this.inventoryNavigatorFactory.create() .searchManagedEntity("VirtualMachine", member.getId()); Assert.notNull(virtualMachine, String.format("virtualMachine must not be null for %s", member)); handleTask(virtualMachine.powerOffVM_Task()); } catch (InterruptedException | IOException e) { throw new DestructionException(String.format("Unable to destroy %s", member), e); } }
Datacenter dc = (Datacenter) new InventoryNavigator( rootFolder).searchManagedEntity("Datacenter", dcName); ResourcePool rp = (ResourcePool) new InventoryNavigator( dc).searchManagedEntities("ResourcePool")[0];
/** * Retrieve container contents from specified parent recursively if requested. * @param recurse retrieve contents recursively from the root down * @throws RemoteException * @throws RuntimeFault * @throws InvalidProperty */ public ManagedEntity[] searchManagedEntities(boolean recurse) throws InvalidProperty, RuntimeFault, RemoteException { String[][] typeinfo = new String[][] { new String[] { "ManagedEntity", }}; return searchManagedEntities(typeinfo, recurse); }
public static synchronized Boolean updateConnection() throws IOException { try { serviceInstance = new ServiceInstance(new URL(sdkUrl), uname, passwd, true, connectTimeout, readTimeout); if (serviceInstance == null) { LOG.error("serviceInstance in null! Connection failed."); return false; } Folder rootFolder = serviceInstance.getRootFolder(); inventoryNavigator = new InventoryNavigator(serviceInstance.getRootFolder()); performanceManager = serviceInstance.getPerformanceManager(); // retrieve all the available performance counters PerfCounterInfo[] pcis = performanceManager.getPerfCounter(); return true; } catch (Exception ex) { ex.printStackTrace(); } return false; }
public void listPortGroupForCluster(ServiceInstance si, String clusterName) throws InvalidProperty, RuntimeFault, RemoteException { ClusterComputeResource cluster = (ClusterComputeResource) (new InventoryNavigator(si.getRootFolder())).searchManagedEntity("ClusterComputeResource", clusterName); if (cluster == null) { System.out.println("Not found cluster:" + cluster); return; } System.out.println("List port groups for cluster:" + clusterName); Network[] networks = cluster.getNetworks(); for (int i = 0; i < networks.length; i++) { System.out.println(i + ": " + networks[i].getName()); } }
/** * Searches for a managed entity by a given type. * * @param type the type string to search for * @return the list of managed entities found * @throws RemoteException */ public ManagedEntity[] searchManagedEntities(String type) throws RemoteException { return (new InventoryNavigator(m_serviceInstance.getRootFolder())).searchManagedEntities(type); }
private ManagedEntity[] getManagedEntities(String meType) throws IOException { ManagedEntity[] mes = inventoryNavigator.searchManagedEntities(meType); return mes; }
public void addNetworkAdapter(ServiceInstance si, String vmName, VirtualNetworkAdapterType type, String networkName, String macAddress, boolean wakeOnLan, boolean startConnected) throws Exception { VirtualMachine vm = (VirtualMachine) new InventoryNavigator(si.getRootFolder()).searchManagedEntity("VirtualMachine", vmName); if (vm == null) { System.out.println("Not found vm:" + vmName); return; } VirtualMachineDeviceManager vmdm = new VirtualMachineDeviceManager(vm); vmdm.createNetworkAdapter(type, networkName, macAddress, wakeOnLan, startConnected); System.out.println("Add network:" + networkName + " for vm:" + vmName + " sucessfully!"); }
public void listPortGroup(ServiceInstance si) throws InvalidProperty, RuntimeFault, RemoteException { ManagedEntity[] networks = (new InventoryNavigator(si.getRootFolder())).searchManagedEntities("Network"); if (networks != null) { System.out.println("List all port groups:"); for (int i = 0; i < networks.length; i++) { Network network = (Network) networks[i]; System.out.println(i + ": " + network.getName()); } } }
private Datastore retrieveDatastore(InventoryNavigator in) throws RemoteException { return (Datastore) in.searchManagedEntities("Datastore")[0]; }
public void listPortGroupForHost(ServiceInstance si, String hostName) throws InvalidProperty, RuntimeFault, RemoteException { HostSystem host = (HostSystem) (new InventoryNavigator(si.getRootFolder())).searchManagedEntity("HostSystem", hostName); if (host == null) { System.out.println("Not found host:" + hostName); return; } System.out.println("List port groups for host:" + hostName); Network[] networks = host.getNetworks(); for (int i = 0; i < networks.length; i++) { System.out.println(i + ": " + networks[i].getName()); } }
public Iterable<ClusterComputeResource> findAllClusters() { try { List<ClusterComputeResource> list = Lists.newArrayList(); InventoryNavigator nav = new InventoryNavigator( getServiceInstance().getRootFolder()); for (ManagedEntity me : nav.searchManagedEntities("ComputeResource")) { ClusterComputeResource cluster = (ClusterComputeResource) me; list.add(cluster); } return list; } catch (RemoteException e) { throw new VMWareExceptionWrapper(e); } }
private ResourcePool retrieveResourcePool(InventoryNavigator in) throws RemoteException { return (ResourcePool) in.searchManagedEntities("ResourcePool")[0]; }
public void removePortGroup(ServiceInstance si, String hostName, String portGroupName) throws IOException { HostSystem host = (HostSystem) (new InventoryNavigator(si.getRootFolder())).searchManagedEntity("HostSystem", hostName); if (host == null) { System.out.println("Not found host:" + hostName); return; } HostNetworkSystem network = host.getHostNetworkSystem(); network.removePortGroup(portGroupName); System.out.println("Remove port group:" + portGroupName + " successfully!"); }