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 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 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()); } }
/** * Restores the SwitchResult object for the network task * @param host * @throws RemoteException */ public void restoreNetwork(VirtualHost host) throws RemoteException { ComputeResource res = host.getComputeResource(hostPath); HostSystem hostSys = res.getHosts()[0]; Network network = null; for (Network n : hostSys.getNetworks()) { if (n.getName().equals(portGroupName)) { network = n; break; } } if (network == null) { throw new RemoteException("Could not restore network from xml."); } Path switchPath = new Path(hostPath, switchName); Path portGroupPath = new Path(hostPath, portGroupName); SwitchResult switchResult = new SwitchResult(network, switchPath, portGroupPath); this.vSwitch = switchResult; }
if (n.getName().equals(newPortGroupName)) { network = n; break;
public void attachNic(VirtualMachine vm, VirtualEthernetCard nic, Network network) throws RemoteException, InterruptedException { VirtualEthernetCardNetworkBackingInfo backing = (VirtualEthernetCardNetworkBackingInfo) nic.getBacking(); backing.setDeviceName(network.getName()); backing.setNetwork(network.getMOR()); nic.setBacking(backing); nic.getDeviceInfo().setSummary(network.getName()); VirtualDeviceConfigSpec nicSpec = new VirtualDeviceConfigSpec(); nicSpec.setOperation(VirtualDeviceConfigSpecOperation.edit); nicSpec.setDevice(nic); VirtualDeviceConfigSpec[] configSpecs = new VirtualDeviceConfigSpec[1]; configSpecs[0] = nicSpec; VirtualMachineConfigSpec machineConfigSpec = new VirtualMachineConfigSpec(); machineConfigSpec.setDeviceChange(configSpecs); Task task = vm.reconfigVM_Task(machineConfigSpec); String status = task.waitForTask(); if (!status.equals("success")) { String message = task.getTaskInfo().getError().getLocalizedMessage(); throw new RemoteException("Failed: " + message); } }
System.out.println("Network : " + host.getNetworks()[0].getName()); System.out.println("Datastore : " + host.getDatastores()[0].getName());
System.out.println("Network : " + host.getNetworks()[0].getName()); System.out.println("Datastore : " + host.getDatastores()[0].getName());
System.out.println("Network : " + host.getNetworks()[0].getName()); System.out.println("Datastore : " + host.getDatastores()[0].getName());
System.out.println("Network : " + host.getNetworks()[0].getName()); System.out.println("Datastore : " + host.getDatastores()[0].getName());