use of com.vmware.vim25.VmwareDistributedVirtualSwitchVlanSpec 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;
}
use of com.vmware.vim25.VmwareDistributedVirtualSwitchVlanSpec in project cloudstack by apache.
the class HypervisorHostHelper method createPortGroup.
private static void createPortGroup(String physicalNetwork, String networkName, String vlanRange, Integer vid, Integer spvlanid, DatacenterMO dataCenterMo, DVSTrafficShapingPolicy shapingPolicy, DVSSecurityPolicy secPolicy, DVSMacManagementPolicy macManagementPolicy, VMwareDVSPortgroupPolicy portGroupPolicy, DistributedVirtualSwitchMO dvSwitchMo, int numPorts, boolean autoExpandSupported, boolean dvSwitchSupportNewPolicies) throws Exception {
VmwareDistributedVirtualSwitchVlanSpec vlanSpec = null;
VmwareDistributedVirtualSwitchPvlanSpec pvlanSpec = null;
VMwareDVSPortSetting dvsPortSetting = null;
DVPortgroupConfigSpec newDvPortGroupSpec;
// NOTE - VmwareDistributedVirtualSwitchPvlanSpec extends VmwareDistributedVirtualSwitchVlanSpec.
if (vid == null || spvlanid == null) {
vlanSpec = createDVPortVlanSpec(vid, vlanRange);
dvsPortSetting = createVmwareDVPortSettingSpec(shapingPolicy, secPolicy, macManagementPolicy, vlanSpec, dvSwitchSupportNewPolicies);
} else if (spvlanid != null) {
// Create a pvlan spec. The pvlan spec is different from the pvlan config spec
// that we created earlier. The pvlan config spec is used to configure the switch
// with a <primary vlanId, secondary vlanId> tuple. The pvlan spec is used
// to configure a port group (i.e., a network) with a secondary vlan id. We don't
// need to mention more than the secondary vlan id because one secondary vlan id
// can be associated with only one primary vlan id. Give vCenter the secondary vlan id,
// and it will find out the associated primary vlan id and do the rest of the
// port group configuration.
pvlanSpec = createDVPortPvlanIdSpec(spvlanid);
dvsPortSetting = createVmwareDVPortSettingSpec(shapingPolicy, secPolicy, macManagementPolicy, pvlanSpec, dvSwitchSupportNewPolicies);
}
newDvPortGroupSpec = createDvPortGroupSpec(networkName, dvsPortSetting, autoExpandSupported);
if (portGroupPolicy != null) {
newDvPortGroupSpec.setPolicy(portGroupPolicy);
}
if (!dataCenterMo.hasDvPortGroup(networkName)) {
s_logger.info("Distributed Virtual Port group " + networkName + " not found.");
// TODO(sateesh): Handle Exceptions
try {
newDvPortGroupSpec.setNumPorts(numPorts);
dvSwitchMo.createDVPortGroup(newDvPortGroupSpec);
} catch (Exception e) {
String msg = "Failed to create distributed virtual port group " + networkName + " on dvSwitch " + physicalNetwork;
msg += ". " + VmwareHelper.getExceptionMessage(e);
throw new Exception(msg);
}
} else {
s_logger.info("Found Distributed Virtual Port group " + networkName);
DVPortgroupConfigInfo currentDvPortgroupInfo = dataCenterMo.getDvPortGroupSpec(networkName);
if (!isSpecMatch(currentDvPortgroupInfo, newDvPortGroupSpec, dvSwitchSupportNewPolicies)) {
s_logger.info("Updating Distributed Virtual Port group " + networkName);
newDvPortGroupSpec.setDefaultPortConfig(dvsPortSetting);
newDvPortGroupSpec.setConfigVersion(currentDvPortgroupInfo.getConfigVersion());
ManagedObjectReference morDvPortGroup = dataCenterMo.getDvPortGroupMor(networkName);
try {
dvSwitchMo.updateDvPortGroup(morDvPortGroup, newDvPortGroupSpec);
} catch (Exception e) {
String msg = "Failed to update distributed virtual port group " + networkName + " on dvSwitch " + physicalNetwork;
msg += ". " + VmwareHelper.getExceptionMessage(e);
throw new Exception(msg);
}
}
}
}
use of com.vmware.vim25.VmwareDistributedVirtualSwitchVlanSpec in project cloudstack by apache.
the class HypervisorHostHelperTest method testCreateDVPortVlanSpecNullVlanId.
@Test
public void testCreateDVPortVlanSpecNullVlanId() {
VmwareDistributedVirtualSwitchVlanSpec spec = HypervisorHostHelper.createDVPortVlanSpec(null, null);
assertTrue(spec instanceof VmwareDistributedVirtualSwitchVlanIdSpec);
assertTrue(((VmwareDistributedVirtualSwitchVlanIdSpec) spec).getVlanId() == 0);
}
use of com.vmware.vim25.VmwareDistributedVirtualSwitchVlanSpec 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);
}
use of com.vmware.vim25.VmwareDistributedVirtualSwitchVlanSpec in project cloudstack by apache.
the class HypervisorHostHelperTest method testCreateDVPortVlanSpecInvalidMissingVlanRange.
@Test
public void testCreateDVPortVlanSpecInvalidMissingVlanRange() {
VmwareDistributedVirtualSwitchVlanSpec spec = HypervisorHostHelper.createDVPortVlanSpec(null, "200-");
assertTrue(spec instanceof VmwareDistributedVirtualSwitchVlanIdSpec);
assertTrue(((VmwareDistributedVirtualSwitchVlanIdSpec) spec).getVlanId() == 0);
}
Aggregations