use of com.vmware.photon.controller.model.adapters.vsphere.QueryConfigTargetRequest in project photon-model by vmware.
the class NetworkDeviceBackingFactory method getDistributedPortBackingInfo.
/**
* 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;
}
Aggregations