protected VirtualEthernetCard editEthernetCards(VirtualMachine machine, String networkName) { // ネットワークアダプタ E1000を使用する VirtualEthernetCard ethernetCard = new VirtualE1000(); // 分散ポートグループ情報取得 DistributedVirtualPortgroupInfo dvPortgroupInfo = getDVPortgroupInfo(machine, networkName); if (dvPortgroupInfo != null) { // 分散ポートグループの場合 VirtualEthernetCardDistributedVirtualPortBackingInfo nicBacking = new VirtualEthernetCardDistributedVirtualPortBackingInfo(); nicBacking.setPort(new DistributedVirtualSwitchPortConnection()); nicBacking.getPort().setPortgroupKey(dvPortgroupInfo.getPortgroupKey()); nicBacking.getPort().setSwitchUuid(dvPortgroupInfo.getSwitchUuid()); ethernetCard.setBacking(nicBacking); } else { // 標準ポートグループの場合 VirtualEthernetCardNetworkBackingInfo backingInfo = new VirtualEthernetCardNetworkBackingInfo(); backingInfo.setDeviceName(networkName); ethernetCard.setBacking(backingInfo); } return ethernetCard; }
public DistributedVirtualPortgroupInfo getDVPortgroupInfo(VirtualMachine machine, String networkName) { HostSystem host = new HostSystem(machine.getServerConnection(), machine.getRuntime().getHost()); ComputeResource computeResource = (ComputeResource) host.getParent(); EnvironmentBrowser envBrowser = computeResource.getEnvironmentBrowser(); DistributedVirtualPortgroupInfo dvPortgroupInfo = null; try { ConfigTarget configTarget = envBrowser.queryConfigTarget(host); // 分散ポートグループの場合 if (configTarget.getDistributedVirtualPortgroup() != null) { // 分散ポートグループ情報を取得 dvPortgroupInfo = findDVPortgroupInfo(configTarget.getDistributedVirtualPortgroup(), networkName); } } catch (RemoteException e) { throw new RuntimeException(e); } return dvPortgroupInfo; }
protected DistributedVirtualPortgroupInfo findDVPortgroupInfo( DistributedVirtualPortgroupInfo[] hostDistributedVirtualPortgroupInfo, String portgroupName) { DistributedVirtualPortgroupInfo result = null; // 分散ポートグループの場合、該当するネットワークの分散ポートグループ情報を返却する if (hostDistributedVirtualPortgroupInfo != null) { for (DistributedVirtualPortgroupInfo portgroupInfo : hostDistributedVirtualPortgroupInfo) { if (portgroupInfo.getPortgroupName().equalsIgnoreCase(portgroupName)) { result = portgroupInfo; break; } } } return result; }
private void validateDVPortGroupForVNicConnection(DistributedVirtualPortgroupInfo dvPortgroupInfo) { if (dvPortgroupInfo.uplinkPortgroup) { throw new RuntimeException("The vDS portgroup's uplinkPortgroup should not be null"); } DistributedVirtualPortgroupPortgroupType portgroupType = DistributedVirtualPortgroupPortgroupType.valueOf(dvPortgroupInfo.portgroupType); String prodLineId = vm.getServerConnection().getServiceInstance().getAboutInfo().getProductLineId(); // standalone host cannot do early or late binding if (prodLineId.indexOf("ESX")!=-1 && (portgroupType == DistributedVirtualPortgroupPortgroupType.earlyBinding || portgroupType == DistributedVirtualPortgroupPortgroupType.lateBinding)) { throw new RuntimeException("ESX does not support early or late binding!"); } }
private static DistributedVirtualPortgroupInfo findDVPortgroupInfo(DistributedVirtualPortgroupInfo[] hostDistributedVirtualPortgroupInfo, String portgroupName) { DistributedVirtualPortgroupInfo result = null; if (hostDistributedVirtualPortgroupInfo != null) { for (DistributedVirtualPortgroupInfo portgroupInfo : hostDistributedVirtualPortgroupInfo) { if (portgroupInfo.portgroupName.equalsIgnoreCase(portgroupName)) { result = portgroupInfo; break; } } } return result; }
/** * Backing info for distributed virtual switch port or portgroup */ private static VirtualEthernetCardDistributedVirtualPortBackingInfo getDistributedPortBackingInfo( CustomProperties props, QueryConfigTargetRequest queryConfigTargetRequest) { DistributedVirtualSwitchPortConnection port = new DistributedVirtualSwitchPortConnection(); String portGroupKey = props.getString(DvsProperties.PORT_GROUP_KEY); String dvsUuid = props.getString(DvsProperties.DVS_UUID); if (StringUtil.isNullOrEmpty(dvsUuid)) { // NSX-V sets the value to a list of dvPortGroupsKeys as the logical switch is // created in a transport zone which could be associated with multiple clusters. // Hence dvPortGroup is created per cluster. The configTarget will filter based on // the cluster where machine is being provisioned. Type listType = new TypeToken<ArrayList<String>>(){}.getType(); final List<String> portGroupIds = Utils.fromJson(portGroupKey, listType); // NSX-V doesn't have UUID information in its API response DistributedVirtualPortgroupInfo info = null; try { ConfigTarget configTarget = queryConfigTargetRequest.getConfigTarget(); info = configTarget.getDistributedVirtualPortgroup() .stream() .filter(d -> { return portGroupIds.contains(d.getPortgroupKey()); }) .findFirst() .orElse(null); } catch (Exception e) { logger.error("getDistributedPortBackingInfo::Failed to get dvportgroup info.", e); } if (info == null) { throw new IllegalArgumentException("getDistributedPortBackingInfo::The port group " + "information is not found for key: " + portGroupKey); } portGroupKey = info.getPortgroupKey(); dvsUuid = info.getSwitchUuid(); } port.setPortgroupKey(portGroupKey); port.setSwitchUuid(dvsUuid); VirtualEthernetCardDistributedVirtualPortBackingInfo backing = new VirtualEthernetCardDistributedVirtualPortBackingInfo(); backing.setPort(port); return backing; }