Search in sources :

Example 1 with NumericRange

use of com.vmware.vim25.NumericRange 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)

Aggregations

NumericRange (com.vmware.vim25.NumericRange)1 VmwareDistributedVirtualSwitchTrunkVlanSpec (com.vmware.vim25.VmwareDistributedVirtualSwitchTrunkVlanSpec)1 VmwareDistributedVirtualSwitchVlanIdSpec (com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec)1