Search in sources :

Example 1 with VmwareDistributedVirtualSwitchTrunkVlanSpec

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

the class HypervisorHostHelper method isDVSPortConfigSame.

private static boolean isDVSPortConfigSame(String dvPortGroupName, VMwareDVSPortSetting currentPortSetting, VMwareDVSPortSetting newPortSetting, boolean dvSwitchSupportNewPolicies) {
    if (areDVSSecurityPoliciesDifferent(currentPortSetting.getSecurityPolicy(), newPortSetting.getSecurityPolicy())) {
        return false;
    }
    if (dvSwitchSupportNewPolicies && areDVSMacManagementPoliciesDifferent(currentPortSetting.getMacManagementPolicy(), newPortSetting.getMacManagementPolicy())) {
        return false;
    }
    VmwareDistributedVirtualSwitchVlanSpec oldVlanSpec = currentPortSetting.getVlan();
    VmwareDistributedVirtualSwitchVlanSpec newVlanSpec = newPortSetting.getVlan();
    int oldVlanId, newVlanId;
    if (oldVlanSpec instanceof VmwareDistributedVirtualSwitchPvlanSpec && newVlanSpec instanceof VmwareDistributedVirtualSwitchPvlanSpec) {
        VmwareDistributedVirtualSwitchPvlanSpec oldpVlanSpec = (VmwareDistributedVirtualSwitchPvlanSpec) oldVlanSpec;
        VmwareDistributedVirtualSwitchPvlanSpec newpVlanSpec = (VmwareDistributedVirtualSwitchPvlanSpec) newVlanSpec;
        oldVlanId = oldpVlanSpec.getPvlanId();
        newVlanId = newpVlanSpec.getPvlanId();
    } else if (oldVlanSpec instanceof VmwareDistributedVirtualSwitchTrunkVlanSpec && newVlanSpec instanceof VmwareDistributedVirtualSwitchTrunkVlanSpec) {
        VmwareDistributedVirtualSwitchTrunkVlanSpec oldpVlanSpec = (VmwareDistributedVirtualSwitchTrunkVlanSpec) oldVlanSpec;
        VmwareDistributedVirtualSwitchTrunkVlanSpec newpVlanSpec = (VmwareDistributedVirtualSwitchTrunkVlanSpec) newVlanSpec;
        oldVlanId = oldpVlanSpec.getVlanId().get(0).getStart();
        newVlanId = newpVlanSpec.getVlanId().get(0).getStart();
    } else if (oldVlanSpec instanceof VmwareDistributedVirtualSwitchVlanIdSpec && newVlanSpec instanceof VmwareDistributedVirtualSwitchVlanIdSpec) {
        VmwareDistributedVirtualSwitchVlanIdSpec oldVlanIdSpec = (VmwareDistributedVirtualSwitchVlanIdSpec) oldVlanSpec;
        VmwareDistributedVirtualSwitchVlanIdSpec newVlanIdSpec = (VmwareDistributedVirtualSwitchVlanIdSpec) newVlanSpec;
        oldVlanId = oldVlanIdSpec.getVlanId();
        newVlanId = newVlanIdSpec.getVlanId();
    } else {
        s_logger.debug(String.format("Old and new vlan spec type mismatch found for dvPortGroup: %s. Old spec type is: %s, and new spec type is: %s", dvPortGroupName, oldVlanSpec.getClass(), newVlanSpec.getClass()));
        return false;
    }
    if (oldVlanId != newVlanId) {
        s_logger.info(String.format("Detected that new VLAN [%d] is different from current VLAN [%d] of dvPortGroup: %s", newVlanId, oldVlanId, dvPortGroupName));
        return false;
    }
    return true;
}
Also used : VmwareDistributedVirtualSwitchTrunkVlanSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchTrunkVlanSpec) VmwareDistributedVirtualSwitchPvlanSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchPvlanSpec) VmwareDistributedVirtualSwitchVlanSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchVlanSpec) VmwareDistributedVirtualSwitchVlanIdSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec)

Example 2 with VmwareDistributedVirtualSwitchTrunkVlanSpec

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

the class HypervisorHostHelperTest method testCreateDVPortVlanSpecInvalidInputVlanRange.

@Test
public void testCreateDVPortVlanSpecInvalidInputVlanRange() {
    VmwareDistributedVirtualSwitchVlanSpec spec = HypervisorHostHelper.createDVPortVlanSpec(null, "a-b");
    assertTrue(spec instanceof VmwareDistributedVirtualSwitchTrunkVlanSpec);
    assertTrue(((VmwareDistributedVirtualSwitchTrunkVlanSpec) spec).getVlanId().get(0).getStart() == 0);
    assertTrue(((VmwareDistributedVirtualSwitchTrunkVlanSpec) spec).getVlanId().get(0).getEnd() == 0);
}
Also used : VmwareDistributedVirtualSwitchTrunkVlanSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchTrunkVlanSpec) VmwareDistributedVirtualSwitchVlanSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchVlanSpec) Test(org.junit.Test)

Example 3 with VmwareDistributedVirtualSwitchTrunkVlanSpec

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

the class HypervisorHostHelper method createDVPortVlanSpec.

public static VmwareDistributedVirtualSwitchVlanSpec createDVPortVlanSpec(Integer vlanId, String vlanRange) {
    if (vlanId != null && vlanId == 4095) {
        vlanId = null;
        vlanRange = "0-4094";
    }
    if (vlanId == null && vlanRange != null && !vlanRange.isEmpty()) {
        s_logger.debug("Creating dvSwitch port vlan-trunk spec with range: " + vlanRange);
        VmwareDistributedVirtualSwitchTrunkVlanSpec trunkVlanSpec = new VmwareDistributedVirtualSwitchTrunkVlanSpec();
        for (final String vlanRangePart : vlanRange.split(",")) {
            if (vlanRangePart == null || vlanRange.isEmpty()) {
                continue;
            }
            final NumericRange numericRange = new NumericRange();
            if (vlanRangePart.contains("-")) {
                final String[] range = vlanRangePart.split("-");
                if (range.length == 2 && range[0] != null && range[1] != null) {
                    numericRange.setStart(NumbersUtil.parseInt(range[0], 0));
                    numericRange.setEnd(NumbersUtil.parseInt(range[1], 0));
                } else {
                    continue;
                }
            } else {
                numericRange.setStart(NumbersUtil.parseInt(vlanRangePart, 0));
                numericRange.setEnd(NumbersUtil.parseInt(vlanRangePart, 0));
            }
            trunkVlanSpec.getVlanId().add(numericRange);
        }
        if (trunkVlanSpec.getVlanId().size() != 0) {
            return trunkVlanSpec;
        }
    }
    VmwareDistributedVirtualSwitchVlanIdSpec vlanIdSpec = new VmwareDistributedVirtualSwitchVlanIdSpec();
    vlanIdSpec.setVlanId(vlanId == null ? 0 : vlanId);
    s_logger.debug("Creating dvSwitch port vlan-id spec with id: " + vlanIdSpec.getVlanId());
    return vlanIdSpec;
}
Also used : NumericRange(com.vmware.vim25.NumericRange) VmwareDistributedVirtualSwitchTrunkVlanSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchTrunkVlanSpec) VmwareDistributedVirtualSwitchVlanIdSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec)

Example 4 with VmwareDistributedVirtualSwitchTrunkVlanSpec

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

the class HypervisorHostHelperTest method testCreateDVPortVlanSpecValidVlanRange.

@Test
public void testCreateDVPortVlanSpecValidVlanRange() {
    VmwareDistributedVirtualSwitchVlanSpec spec = HypervisorHostHelper.createDVPortVlanSpec(null, "200-250");
    assertTrue(spec instanceof VmwareDistributedVirtualSwitchTrunkVlanSpec);
    assertTrue(((VmwareDistributedVirtualSwitchTrunkVlanSpec) spec).getVlanId().get(0).getStart() == 200);
    assertTrue(((VmwareDistributedVirtualSwitchTrunkVlanSpec) spec).getVlanId().get(0).getEnd() == 250);
}
Also used : VmwareDistributedVirtualSwitchTrunkVlanSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchTrunkVlanSpec) VmwareDistributedVirtualSwitchVlanSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchVlanSpec) Test(org.junit.Test)

Aggregations

VmwareDistributedVirtualSwitchTrunkVlanSpec (com.vmware.vim25.VmwareDistributedVirtualSwitchTrunkVlanSpec)4 VmwareDistributedVirtualSwitchVlanSpec (com.vmware.vim25.VmwareDistributedVirtualSwitchVlanSpec)3 VmwareDistributedVirtualSwitchVlanIdSpec (com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec)2 Test (org.junit.Test)2 NumericRange (com.vmware.vim25.NumericRange)1 VmwareDistributedVirtualSwitchPvlanSpec (com.vmware.vim25.VmwareDistributedVirtualSwitchPvlanSpec)1