Search in sources :

Example 1 with VmwareDistributedVirtualSwitchVlanSpec

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

the class HypervisorHostHelper method createVmwareDVPortSettingSpec.

public static VMwareDVSPortSetting createVmwareDVPortSettingSpec(DVSTrafficShapingPolicy shapingPolicy, DVSSecurityPolicy secPolicy, VmwareDistributedVirtualSwitchVlanSpec vlanSpec) {
    VMwareDVSPortSetting dvsPortSetting = new VMwareDVSPortSetting();
    dvsPortSetting.setVlan(vlanSpec);
    dvsPortSetting.setSecurityPolicy(secPolicy);
    dvsPortSetting.setInShapingPolicy(shapingPolicy);
    dvsPortSetting.setOutShapingPolicy(shapingPolicy);
    return dvsPortSetting;
}
Also used : VMwareDVSPortSetting(com.vmware.vim25.VMwareDVSPortSetting)

Example 2 with VmwareDistributedVirtualSwitchVlanSpec

use of com.vmware.vim25.VmwareDistributedVirtualSwitchVlanSpec 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 3 with VmwareDistributedVirtualSwitchVlanSpec

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

the class HypervisorHostHelper method createVmwareDVPortSettingSpec.

public static VMwareDVSPortSetting createVmwareDVPortSettingSpec(DVSTrafficShapingPolicy shapingPolicy, DVSSecurityPolicy secPolicy, DVSMacManagementPolicy macManagementPolicy, VmwareDistributedVirtualSwitchVlanSpec vlanSpec, boolean dvSwitchSupportNewPolicies) {
    VMwareDVSPortSetting dvsPortSetting = new VMwareDVSPortSetting();
    dvsPortSetting.setVlan(vlanSpec);
    dvsPortSetting.setSecurityPolicy(secPolicy);
    if (dvSwitchSupportNewPolicies) {
        dvsPortSetting.setMacManagementPolicy(macManagementPolicy);
    }
    dvsPortSetting.setInShapingPolicy(shapingPolicy);
    dvsPortSetting.setOutShapingPolicy(shapingPolicy);
    return dvsPortSetting;
}
Also used : VMwareDVSPortSetting(com.vmware.vim25.VMwareDVSPortSetting)

Example 4 with VmwareDistributedVirtualSwitchVlanSpec

use of com.vmware.vim25.VmwareDistributedVirtualSwitchVlanSpec 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 5 with VmwareDistributedVirtualSwitchVlanSpec

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

the class HypervisorHostHelper method createPortGroup.

private static void createPortGroup(String physicalNetwork, String networkName, Integer vid, Integer spvlanid, DatacenterMO dataCenterMo, DVSTrafficShapingPolicy shapingPolicy, DVSSecurityPolicy secPolicy, VMwareDVSPortgroupPolicy portGroupPolicy, DistributedVirtualSwitchMO dvSwitchMo, int numPorts, boolean autoExpandSupported) throws Exception {
    VmwareDistributedVirtualSwitchVlanSpec vlanSpec = null;
    VmwareDistributedVirtualSwitchPvlanSpec pvlanSpec = null;
    VMwareDVSPortSetting dvsPortSetting = null;
    DVPortgroupConfigSpec newDvPortGroupSpec;
    // NOTE - VmwareDistributedVirtualSwitchPvlanSpec extends VmwareDistributedVirtualSwitchVlanSpec.
    if (vid == null || spvlanid == null) {
        vlanSpec = createDVPortVlanIdSpec(vid);
        dvsPortSetting = createVmwareDVPortSettingSpec(shapingPolicy, secPolicy, vlanSpec);
    } 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, pvlanSpec);
    }
    newDvPortGroupSpec = createDvPortGroupSpec(networkName, dvsPortSetting, numPorts, 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 {
            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)) {
            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);
            }
        }
    }
}
Also used : VMwareDVSPortSetting(com.vmware.vim25.VMwareDVSPortSetting) VmwareDistributedVirtualSwitchPvlanSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchPvlanSpec) VmwareDistributedVirtualSwitchVlanSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchVlanSpec) DVPortgroupConfigSpec(com.vmware.vim25.DVPortgroupConfigSpec) 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) DVPortgroupConfigInfo(com.vmware.vim25.DVPortgroupConfigInfo) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

VmwareDistributedVirtualSwitchVlanSpec (com.vmware.vim25.VmwareDistributedVirtualSwitchVlanSpec)8 VmwareDistributedVirtualSwitchVlanIdSpec (com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec)5 Test (org.junit.Test)5 VMwareDVSPortSetting (com.vmware.vim25.VMwareDVSPortSetting)4 VmwareDistributedVirtualSwitchTrunkVlanSpec (com.vmware.vim25.VmwareDistributedVirtualSwitchTrunkVlanSpec)4 VmwareDistributedVirtualSwitchPvlanSpec (com.vmware.vim25.VmwareDistributedVirtualSwitchPvlanSpec)3 CloudException (com.cloud.exception.CloudException)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 DVPortgroupConfigInfo (com.vmware.vim25.DVPortgroupConfigInfo)2 DVPortgroupConfigSpec (com.vmware.vim25.DVPortgroupConfigSpec)2 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 InvalidParameterException (java.security.InvalidParameterException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 SAXException (org.xml.sax.SAXException)2 NumericRange (com.vmware.vim25.NumericRange)1