public Folder getRootFolder() { return serviceInstance.getRootFolder(); }
/** * Initialize the necessary Managed Object References needed here */ private void initialize() { _eventManager = si.getEventManager(); _rootFolder = si.getRootFolder(); }
/** * Initialize the necessary Managed Object References needed here */ private void initialize() { _eventManager = si.getEventManager(); _rootFolder = si.getRootFolder(); }
/** * 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); }
/** * 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); }
@Override public InventoryNavigator create() throws IOException { ServiceInstance serviceInstance = new ServiceInstance(this.url, this.username, this.password, true); return new InventoryNavigator(serviceInstance.getRootFolder()); }
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()); } } }
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()); } }
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 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 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!"); }
public Iterable<HostSystem> findAllHostSystems() { try { InventoryNavigator nav = new InventoryNavigator( getServiceInstance().getRootFolder()); ManagedEntity[] entitites = nav .searchManagedEntities(ManagedObjectTypes.HOST_SYSTEM); List<HostSystem> vmList = Lists.newArrayList(); for (ManagedEntity me : entitites) { vmList.add((HostSystem) me); } return java.util.Collections.unmodifiableList(vmList); } catch (RemoteException e) { throw new VMWareExceptionWrapper(e); } }
public Iterable<VirtualMachine> findAllVirtualMachines() { try { InventoryNavigator nav = new InventoryNavigator( getServiceInstance().getRootFolder()); ManagedEntity[] entitites = nav .searchManagedEntities(VIRTUAL_MACHINE); List<VirtualMachine> vmList = Lists.newArrayList(); for (ManagedEntity me : entitites) { vmList.add((VirtualMachine) me); } return java.util.Collections.unmodifiableList(vmList); } catch (RemoteException e) { throw new VMWareExceptionWrapper(e); } }
public void convertToTemplate(ServiceInstance si, String vmName) throws Exception { VirtualMachine vm = (VirtualMachine) new InventoryNavigator(si.getRootFolder()).searchManagedEntity("VirtualMachine", vmName); if (vm == null) { System.out.println("Not found vm " + vmName); return; } if (vm.getConfig().isTemplate()) { System.out.println("The vm " + vmName + " is already a template!"); return; } vm.markAsTemplate(); System.out.println("Convert vm " + vmName + " to template successfully!"); }
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 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); }
public void listNetworkAdapter(ServiceInstance si, String vmName) throws Exception { VirtualMachine vm = (VirtualMachine) new InventoryNavigator(si.getRootFolder()).searchManagedEntity("VirtualMachine", vmName); if (vm == null) { System.out.println("Not found vm:" + vmName); return; } System.out.println("List NIC:"); VirtualMachineDeviceManager vmdm = new VirtualMachineDeviceManager(vm); List<VirtualEthernetCard> vics = vmdm.getVirtualDevicesOfType(VirtualEthernetCard.class); for (VirtualEthernetCard vic : vics) { System.out.println(vic.getDeviceInfo().getLabel()); } }
public Datacenter getDatacenter(Path path) throws RemoteException { Datacenter result = null; String name = path.getDatacenterName(); Folder root = serviceInstance.getRootFolder(); for (ManagedEntity e : root.getChildEntity()) { if (e instanceof Datacenter && e.getName().equals(name)) { result = (Datacenter) e; break; } } if (result == null) { log.warn("could not find datacenter at beginning of path " + path.toString()); throw new NotFound(); } return result; }
private static boolean migrateVM(String targetVMName, String newHostName, boolean tryAnotherVM, boolean tryAnotherHost) throws Exception { ServiceInstance si = new ServiceInstance(new URL(url), username, password, true); try { Folder rootFolder = si.getRootFolder(); HostSystem newHost = (HostSystem)new InventoryNavigator(rootFolder) .searchManagedEntity("HostSystem", newHostName); return migrateVM(si, rootFolder, newHost, targetVMName, newHostName, tryAnotherVM, tryAnotherHost); } finally { si.getServerConnection().logout(); } }
public void addPortGroup(ServiceInstance si, String hostName, String switchName, 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(); HostPortGroupSpec portGroupSpec = new HostPortGroupSpec(); portGroupSpec.setName(portGroupName); portGroupSpec.setVlanId(0); portGroupSpec.setVswitchName(switchName); portGroupSpec.setPolicy(new HostNetworkPolicy()); network.addPortGroup(portGroupSpec); System.out.println("Create port group:" + portGroupName + " on switch:" + switchName + " successfully!"); }