Search in sources :

Example 6 with DVPortgroupConfigInfo

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

the class HypervisorHostHelper method isSpecMatch.

public static boolean isSpecMatch(DVPortgroupConfigInfo currentDvPortgroupInfo, DVPortgroupConfigSpec newDvPortGroupSpec) {
    String dvPortGroupName = newDvPortGroupSpec.getName();
    s_logger.debug("Checking if configuration of dvPortGroup [" + dvPortGroupName + "] has changed.");
    boolean specMatches = true;
    DVSTrafficShapingPolicy currentTrafficShapingPolicy;
    currentTrafficShapingPolicy = currentDvPortgroupInfo.getDefaultPortConfig().getInShapingPolicy();
    assert (currentTrafficShapingPolicy != null);
    LongPolicy oldAverageBandwidthPolicy = currentTrafficShapingPolicy.getAverageBandwidth();
    LongPolicy oldBurstSizePolicy = currentTrafficShapingPolicy.getBurstSize();
    LongPolicy oldPeakBandwidthPolicy = currentTrafficShapingPolicy.getPeakBandwidth();
    BoolPolicy oldIsEnabledPolicy = currentTrafficShapingPolicy.getEnabled();
    Long oldAverageBandwidth = null;
    Long oldBurstSize = null;
    Long oldPeakBandwidth = null;
    Boolean oldIsEnabled = null;
    if (oldAverageBandwidthPolicy != null) {
        oldAverageBandwidth = oldAverageBandwidthPolicy.getValue();
    }
    if (oldBurstSizePolicy != null) {
        oldBurstSize = oldBurstSizePolicy.getValue();
    }
    if (oldPeakBandwidthPolicy != null) {
        oldPeakBandwidth = oldPeakBandwidthPolicy.getValue();
    }
    if (oldIsEnabledPolicy != null) {
        oldIsEnabled = oldIsEnabledPolicy.isValue();
    }
    DVSTrafficShapingPolicy newTrafficShapingPolicyInbound = newDvPortGroupSpec.getDefaultPortConfig().getInShapingPolicy();
    LongPolicy newAverageBandwidthPolicy = newTrafficShapingPolicyInbound.getAverageBandwidth();
    LongPolicy newBurstSizePolicy = newTrafficShapingPolicyInbound.getBurstSize();
    LongPolicy newPeakBandwidthPolicy = newTrafficShapingPolicyInbound.getPeakBandwidth();
    BoolPolicy newIsEnabledPolicy = newTrafficShapingPolicyInbound.getEnabled();
    Long newAverageBandwidth = null;
    Long newBurstSize = null;
    Long newPeakBandwidth = null;
    Boolean newIsEnabled = null;
    if (newAverageBandwidthPolicy != null) {
        newAverageBandwidth = newAverageBandwidthPolicy.getValue();
    }
    if (newBurstSizePolicy != null) {
        newBurstSize = newBurstSizePolicy.getValue();
    }
    if (newPeakBandwidthPolicy != null) {
        newPeakBandwidth = newPeakBandwidthPolicy.getValue();
    }
    if (newIsEnabledPolicy != null) {
        newIsEnabled = newIsEnabledPolicy.isValue();
    }
    if (!oldIsEnabled.equals(newIsEnabled)) {
        s_logger.info("Detected change in state of shaping policy (enabled/disabled) [" + newIsEnabled + "]");
        specMatches = false;
    }
    if (oldIsEnabled || newIsEnabled) {
        if (oldAverageBandwidth != null && !oldAverageBandwidth.equals(newAverageBandwidth)) {
            s_logger.info("Average bandwidth setting in new shaping policy doesn't match the existing setting.");
            specMatches = false;
        } else if (oldBurstSize != null && !oldBurstSize.equals(newBurstSize)) {
            s_logger.info("Burst size setting in new shaping policy doesn't match the existing setting.");
            specMatches = false;
        } else if (oldPeakBandwidth != null && !oldPeakBandwidth.equals(newPeakBandwidth)) {
            s_logger.info("Peak bandwidth setting in new shaping policy doesn't match the existing setting.");
            specMatches = false;
        }
    }
    boolean oldAutoExpandSetting = currentDvPortgroupInfo.isAutoExpand();
    boolean autoExpandEnabled = newDvPortGroupSpec.isAutoExpand();
    if (oldAutoExpandSetting != autoExpandEnabled) {
        specMatches = false;
    }
    if (!autoExpandEnabled) {
        // Allow update of number of dvports per dvPortGroup is auto expand is not enabled.
        int oldNumPorts = currentDvPortgroupInfo.getNumPorts();
        int newNumPorts = newDvPortGroupSpec.getNumPorts();
        if (oldNumPorts < newNumPorts) {
            s_logger.info("Need to update the number of dvports for dvPortGroup :[" + dvPortGroupName + "] from existing number of dvports " + oldNumPorts + " to " + newNumPorts);
            specMatches = false;
        } else if (oldNumPorts > newNumPorts) {
            s_logger.warn("Detected that new number of dvports [" + newNumPorts + "] in dvPortGroup [" + dvPortGroupName + "] is less than existing number of dvports [" + oldNumPorts + "]. Attempt to update this dvPortGroup may fail!");
            specMatches = false;
        }
    }
    VmwareDistributedVirtualSwitchVlanIdSpec oldVlanSpec = (VmwareDistributedVirtualSwitchVlanIdSpec) ((VMwareDVSPortSetting) currentDvPortgroupInfo.getDefaultPortConfig()).getVlan();
    VmwareDistributedVirtualSwitchVlanIdSpec newVlanSpec = (VmwareDistributedVirtualSwitchVlanIdSpec) ((VMwareDVSPortSetting) newDvPortGroupSpec.getDefaultPortConfig()).getVlan();
    int oldVlanId = oldVlanSpec.getVlanId();
    int newVlanId = newVlanSpec.getVlanId();
    if (oldVlanId != newVlanId) {
        s_logger.info("Detected that new VLAN [" + newVlanId + "] of dvPortGroup [" + dvPortGroupName + "] is different from current VLAN [" + oldVlanId + "]");
        specMatches = false;
    }
    return specMatches;
}
Also used : LongPolicy(com.vmware.vim25.LongPolicy) DVSTrafficShapingPolicy(com.vmware.vim25.DVSTrafficShapingPolicy) BoolPolicy(com.vmware.vim25.BoolPolicy) VmwareDistributedVirtualSwitchVlanIdSpec(com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec)

Example 7 with DVPortgroupConfigInfo

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

DVPortgroupConfigInfo (com.vmware.vim25.DVPortgroupConfigInfo)4 BoolPolicy (com.vmware.vim25.BoolPolicy)3 DVSTrafficShapingPolicy (com.vmware.vim25.DVSTrafficShapingPolicy)3 LongPolicy (com.vmware.vim25.LongPolicy)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 DynamicProperty (com.vmware.vim25.DynamicProperty)2 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)2 ObjectContent (com.vmware.vim25.ObjectContent)2 ObjectSpec (com.vmware.vim25.ObjectSpec)2 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)2 PropertySpec (com.vmware.vim25.PropertySpec)2 TraversalSpec (com.vmware.vim25.TraversalSpec)2 URISyntaxException (java.net.URISyntaxException)2 CloudException (com.cloud.exception.CloudException)1 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)1 Pair (com.cloud.utils.Pair)1 DVPortgroupConfigSpec (com.vmware.vim25.DVPortgroupConfigSpec)1 VMwareDVSPortSetting (com.vmware.vim25.VMwareDVSPortSetting)1 VmwareDistributedVirtualSwitchPvlanSpec (com.vmware.vim25.VmwareDistributedVirtualSwitchPvlanSpec)1 VmwareDistributedVirtualSwitchVlanIdSpec (com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec)1