Search in sources :

Example 1 with VMwareDVSConfigInfo

use of com.vmware.vim25.VMwareDVSConfigInfo in project cloudstack by apache.

the class DistributedVirtualSwitchMO method retrieveVlanPvlan.

public Map<Integer, HypervisorHostHelper.PvlanType> retrieveVlanPvlan(int vlanid, int secondaryvlanid, ManagedObjectReference dvSwitchMor) throws Exception {
    assert (dvSwitchMor != null);
    Map<Integer, HypervisorHostHelper.PvlanType> result = new HashMap<Integer, HypervisorHostHelper.PvlanType>();
    VMwareDVSConfigInfo configinfo = (VMwareDVSConfigInfo) _context.getVimClient().getDynamicProperty(dvSwitchMor, "config");
    List<VMwareDVSPvlanMapEntry> pvlanconfig = null;
    pvlanconfig = configinfo.getPvlanConfig();
    if (null == pvlanconfig || 0 == pvlanconfig.size()) {
        return result;
    }
    for (VMwareDVSPvlanMapEntry mapEntry : pvlanconfig) {
        int entryVlanid = mapEntry.getPrimaryVlanId();
        int entryPvlanid = mapEntry.getSecondaryVlanId();
        if (entryVlanid == entryPvlanid) {
            // promiscuous
            if (vlanid == entryVlanid) {
                // pvlan type will always be promiscuous in this case.
                result.put(vlanid, HypervisorHostHelper.PvlanType.valueOf(mapEntry.getPvlanType()));
            } else if ((vlanid != secondaryvlanid) && secondaryvlanid == entryVlanid) {
                result.put(secondaryvlanid, HypervisorHostHelper.PvlanType.valueOf(mapEntry.getPvlanType()));
            }
        } else {
            if (vlanid == entryVlanid) {
                // vlan id in entry is promiscuous
                result.put(vlanid, HypervisorHostHelper.PvlanType.promiscuous);
            } else if (vlanid == entryPvlanid) {
                result.put(vlanid, HypervisorHostHelper.PvlanType.valueOf(mapEntry.getPvlanType()));
            }
            if ((vlanid != secondaryvlanid) && secondaryvlanid == entryVlanid) {
                //promiscuous
                result.put(secondaryvlanid, HypervisorHostHelper.PvlanType.promiscuous);
            } else if (secondaryvlanid == entryPvlanid) {
                result.put(secondaryvlanid, HypervisorHostHelper.PvlanType.valueOf(mapEntry.getPvlanType()));
            }
        }
        // go over the entire list. Return.
        if (result.containsKey(vlanid) && result.get(vlanid) != HypervisorHostHelper.PvlanType.promiscuous)
            return result;
        // If we've already found both vlanid and pvlanid, we have enough info to make a decision. Return.
        if (result.containsKey(vlanid) && result.containsKey(secondaryvlanid))
            return result;
    }
    return result;
}
Also used : VMwareDVSConfigInfo(com.vmware.vim25.VMwareDVSConfigInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) VMwareDVSPvlanMapEntry(com.vmware.vim25.VMwareDVSPvlanMapEntry)

Aggregations

VMwareDVSConfigInfo (com.vmware.vim25.VMwareDVSConfigInfo)1 VMwareDVSPvlanMapEntry (com.vmware.vim25.VMwareDVSPvlanMapEntry)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1