Search in sources :

Example 1 with VMwareDVSPvlanConfigSpec

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

the class HypervisorHostHelper method createDVPortPvlanConfigSpec.

public static VMwareDVSPvlanConfigSpec createDVPortPvlanConfigSpec(int vlanId, int secondaryVlanId, PvlanType pvlantype, PvlanOperation operation) {
    VMwareDVSPvlanConfigSpec pvlanConfigSpec = new VMwareDVSPvlanConfigSpec();
    VMwareDVSPvlanMapEntry map = new VMwareDVSPvlanMapEntry();
    map.setPvlanType(pvlantype.toString());
    map.setPrimaryVlanId(vlanId);
    map.setSecondaryVlanId(secondaryVlanId);
    pvlanConfigSpec.setPvlanEntry(map);
    pvlanConfigSpec.setOperation(operation.toString());
    return pvlanConfigSpec;
}
Also used : VMwareDVSPvlanConfigSpec(com.vmware.vim25.VMwareDVSPvlanConfigSpec) VMwareDVSPvlanMapEntry(com.vmware.vim25.VMwareDVSPvlanMapEntry)

Example 2 with VMwareDVSPvlanConfigSpec

use of com.vmware.vim25.VMwareDVSPvlanConfigSpec 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;
        }
    }
}
Also used : AlreadyExistsFaultMsg(com.vmware.vim25.AlreadyExistsFaultMsg) VMwareDVSConfigSpec(com.vmware.vim25.VMwareDVSConfigSpec) VMwareDVSPvlanConfigSpec(com.vmware.vim25.VMwareDVSPvlanConfigSpec) URISyntaxException(java.net.URISyntaxException) InvalidParameterException(java.security.InvalidParameterException) CloudException(com.cloud.exception.CloudException) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

VMwareDVSPvlanConfigSpec (com.vmware.vim25.VMwareDVSPvlanConfigSpec)2 CloudException (com.cloud.exception.CloudException)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 AlreadyExistsFaultMsg (com.vmware.vim25.AlreadyExistsFaultMsg)1 VMwareDVSConfigSpec (com.vmware.vim25.VMwareDVSConfigSpec)1 VMwareDVSPvlanMapEntry (com.vmware.vim25.VMwareDVSPvlanMapEntry)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 InvalidParameterException (java.security.InvalidParameterException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 SAXException (org.xml.sax.SAXException)1