use of com.vmware.vim25.VMwareDVSConfigSpec in project cloudstack by apache.
the class DistributedVirtualSwitchMO method updateVMWareDVSwitchGetTask.
public TaskInfo updateVMWareDVSwitchGetTask(ManagedObjectReference dvSwitchMor, VMwareDVSConfigSpec dvsSpec) throws Exception {
ManagedObjectReference task = _context.getService().reconfigureDvsTask(dvSwitchMor, dvsSpec);
TaskInfo info = (TaskInfo) (_context.getVimClient().getDynamicProperty(task, "info"));
_context.getVimClient().waitForTask(task);
return info;
}
use of com.vmware.vim25.VMwareDVSConfigSpec in project cloudstack by apache.
the class HypervisorHostHelper method setupPVlanPair.
private static void setupPVlanPair(DistributedVirtualSwitchMO dvSwitchMo, ManagedObjectReference morDvSwitch, Integer vid, Integer spvlanid) throws Exception {
Map<Integer, HypervisorHostHelper.PvlanType> vlanmap = dvSwitchMo.retrieveVlanPvlan(vid, spvlanid, morDvSwitch);
if (!vlanmap.isEmpty()) {
// First the primary pvlan id.
if (vlanmap.containsKey(vid) && !vlanmap.get(vid).equals(HypervisorHostHelper.PvlanType.promiscuous)) {
// This VLAN ID is already setup as a non-promiscuous vlan id on the DVS. Throw an exception.
String msg = "Specified primary PVLAN ID " + vid + " is already in use as a " + vlanmap.get(vid).toString() + " VLAN on the DVSwitch";
s_logger.error(msg);
throw new Exception(msg);
}
// Next the secondary pvlan id.
if (spvlanid.equals(vid)) {
if (vlanmap.containsKey(spvlanid) && !vlanmap.get(spvlanid).equals(HypervisorHostHelper.PvlanType.promiscuous)) {
String msg = "Specified secondary PVLAN ID " + spvlanid + " is already in use as a " + vlanmap.get(spvlanid).toString() + " VLAN in the DVSwitch";
s_logger.error(msg);
throw new Exception(msg);
}
} else {
if (vlanmap.containsKey(spvlanid) && !vlanmap.get(spvlanid).equals(HypervisorHostHelper.PvlanType.isolated)) {
// This PVLAN ID is already setup as a non-isolated vlan id on the DVS. Throw an exception.
String msg = "Specified secondary PVLAN ID " + spvlanid + " is already in use as a " + vlanmap.get(spvlanid).toString() + " VLAN in the DVSwitch";
s_logger.error(msg);
throw new Exception(msg);
}
}
}
// First create a DVSconfig spec.
VMwareDVSConfigSpec dvsSpec = new VMwareDVSConfigSpec();
// Next, add the required primary and secondary vlan config specs to the dvs config spec.
if (!vlanmap.containsKey(vid)) {
VMwareDVSPvlanConfigSpec ppvlanConfigSpec = createDVPortPvlanConfigSpec(vid, vid, PvlanType.promiscuous, PvlanOperation.add);
dvsSpec.getPvlanConfigSpec().add(ppvlanConfigSpec);
}
if (!vid.equals(spvlanid) && !vlanmap.containsKey(spvlanid)) {
VMwareDVSPvlanConfigSpec spvlanConfigSpec = createDVPortPvlanConfigSpec(vid, spvlanid, PvlanType.isolated, PvlanOperation.add);
dvsSpec.getPvlanConfigSpec().add(spvlanConfigSpec);
}
if (dvsSpec.getPvlanConfigSpec().size() > 0) {
// We have something to configure on the DVS... so send it the command.
// When reconfiguring a vmware DVSwitch, we need to send in the configVersion in the spec.
// Let's retrieve this switch's configVersion first.
String dvsConfigVersion = dvSwitchMo.getDVSConfigVersion(morDvSwitch);
dvsSpec.setConfigVersion(dvsConfigVersion);
// Reconfigure the dvs using this spec.
try {
dvSwitchMo.updateVMWareDVSwitchGetTask(morDvSwitch, dvsSpec);
} catch (AlreadyExistsFaultMsg e) {
s_logger.info("Specified vlan id (" + vid + ") private vlan id (" + spvlanid + ") tuple already configured on VMWare DVSwitch");
// Do nothing, good if the tuple's already configured on the dvswitch.
} catch (Exception e) {
// Rethrow the exception
s_logger.error("Failed to configure vlan/pvlan tuple on VMware DVSwitch: " + vid + "/" + spvlanid + ", failure message: ", e);
throw e;
}
}
}
Aggregations