Search in sources :

Example 1 with ConfigTarget

use of com.vmware.vim25.ConfigTarget 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;
}
Also used : ResourceState(com.vmware.photon.controller.model.resources.ResourceState) TypeToken(com.google.gson.reflect.TypeToken) Logger(org.slf4j.Logger) DistributedVirtualPortgroupInfo(com.vmware.vim25.DistributedVirtualPortgroupInfo) VirtualEthernetCardOpaqueNetworkBackingInfo(com.vmware.vim25.VirtualEthernetCardOpaqueNetworkBackingInfo) LoggerFactory(org.slf4j.LoggerFactory) VirtualDeviceBackingInfo(com.vmware.vim25.VirtualDeviceBackingInfo) VirtualEthernetCardDistributedVirtualPortBackingInfo(com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo) StringUtil(io.netty.util.internal.StringUtil) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) VirtualEthernetCardNetworkBackingInfo(com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo) ArrayList(java.util.ArrayList) List(java.util.List) Utils(com.vmware.xenon.common.Utils) CustomProperties(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties) Type(java.lang.reflect.Type) ConfigTarget(com.vmware.vim25.ConfigTarget) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) QueryConfigTargetRequest(com.vmware.photon.controller.model.adapters.vsphere.QueryConfigTargetRequest) DistributedVirtualSwitchPortConnection(com.vmware.vim25.DistributedVirtualSwitchPortConnection) Type(java.lang.reflect.Type) VirtualEthernetCardDistributedVirtualPortBackingInfo(com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo) ArrayList(java.util.ArrayList) ConfigTarget(com.vmware.vim25.ConfigTarget) DistributedVirtualSwitchPortConnection(com.vmware.vim25.DistributedVirtualSwitchPortConnection) DistributedVirtualPortgroupInfo(com.vmware.vim25.DistributedVirtualPortgroupInfo)

Aggregations

TypeToken (com.google.gson.reflect.TypeToken)1 CustomProperties (com.vmware.photon.controller.model.adapters.vsphere.CustomProperties)1 QueryConfigTargetRequest (com.vmware.photon.controller.model.adapters.vsphere.QueryConfigTargetRequest)1 VimNames (com.vmware.photon.controller.model.adapters.vsphere.util.VimNames)1 NetworkState (com.vmware.photon.controller.model.resources.NetworkService.NetworkState)1 ResourceState (com.vmware.photon.controller.model.resources.ResourceState)1 ConfigTarget (com.vmware.vim25.ConfigTarget)1 DistributedVirtualPortgroupInfo (com.vmware.vim25.DistributedVirtualPortgroupInfo)1 DistributedVirtualSwitchPortConnection (com.vmware.vim25.DistributedVirtualSwitchPortConnection)1 VirtualDeviceBackingInfo (com.vmware.vim25.VirtualDeviceBackingInfo)1 VirtualEthernetCardDistributedVirtualPortBackingInfo (com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo)1 VirtualEthernetCardNetworkBackingInfo (com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo)1 VirtualEthernetCardOpaqueNetworkBackingInfo (com.vmware.vim25.VirtualEthernetCardOpaqueNetworkBackingInfo)1 Utils (com.vmware.xenon.common.Utils)1 StringUtil (io.netty.util.internal.StringUtil)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1