Search in sources :

Example 1 with HostNetworkTrafficShapingPolicy

use of com.vmware.vim25.HostNetworkTrafficShapingPolicy in project CloudStack-archive by CloudStack-extras.

the class HostMO method createPortGroup.

public void createPortGroup(HostVirtualSwitch vSwitch, String portGroupName, Integer vlanId, HostNetworkTrafficShapingPolicy shapingPolicy) throws Exception {
    assert (portGroupName != null);
    HostNetworkSystemMO hostNetMo = getHostNetworkSystemMO();
    assert (hostNetMo != null);
    HostPortGroupSpec spec = new HostPortGroupSpec();
    spec.setName(portGroupName);
    if (vlanId != null)
        spec.setVlanId(vlanId.intValue());
    HostNetworkPolicy policy = new HostNetworkPolicy();
    policy.setShapingPolicy(shapingPolicy);
    spec.setPolicy(policy);
    spec.setVswitchName(vSwitch.getName());
    hostNetMo.addPortGroup(spec);
}
Also used : HostNetworkPolicy(com.vmware.vim25.HostNetworkPolicy) HostPortGroupSpec(com.vmware.vim25.HostPortGroupSpec)

Example 2 with HostNetworkTrafficShapingPolicy

use of com.vmware.vim25.HostNetworkTrafficShapingPolicy in project CloudStack-archive by CloudStack-extras.

the class HypervisorHostHelper method prepareNetwork.

public static Pair<ManagedObjectReference, String> prepareNetwork(String vSwitchName, String namePrefix, HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps, long timeOutMs, boolean syncPeerHosts) throws Exception {
    HostVirtualSwitch vSwitch;
    vSwitch = hostMo.getHostVirtualSwitchByName(vSwitchName);
    if (vSwitch == null) {
        String msg = "Unable to find vSwitch" + vSwitchName;
        s_logger.error(msg);
        throw new Exception(msg);
    }
    boolean createGCTag = false;
    String networkName;
    Integer vid = null;
    if (vlanId != null && !UNTAGGED_VLAN_NAME.equalsIgnoreCase(vlanId)) {
        createGCTag = true;
        vid = Integer.parseInt(vlanId);
    }
    networkName = composeCloudNetworkName(namePrefix, vlanId, networkRateMbps, vSwitchName);
    HostNetworkTrafficShapingPolicy shapingPolicy = null;
    if (networkRateMbps != null && networkRateMbps.intValue() > 0) {
        shapingPolicy = new HostNetworkTrafficShapingPolicy();
        shapingPolicy.setEnabled(true);
        shapingPolicy.setAverageBandwidth((long) networkRateMbps.intValue() * 1024L * 1024L);
        // 
        // TODO : people may have different opinion on how to set the following
        //
        // give 50% premium to peek
        shapingPolicy.setPeakBandwidth((long) (shapingPolicy.getAverageBandwidth() * 1.5));
        // allow 5 seconds of burst transfer
        shapingPolicy.setBurstSize(5 * shapingPolicy.getAverageBandwidth() / 8);
    }
    boolean bWaitPortGroupReady = false;
    if (!hostMo.hasPortGroup(vSwitch, networkName)) {
        hostMo.createPortGroup(vSwitch, networkName, vid, shapingPolicy);
        bWaitPortGroupReady = true;
    } else {
        HostPortGroupSpec spec = hostMo.getPortGroupSpec(networkName);
        if (!isSpecMatch(spec, vid, shapingPolicy)) {
            hostMo.updatePortGroup(vSwitch, networkName, vid, shapingPolicy);
            bWaitPortGroupReady = true;
        }
    }
    ManagedObjectReference morNetwork;
    if (bWaitPortGroupReady)
        morNetwork = waitForNetworkReady(hostMo, networkName, timeOutMs);
    else
        morNetwork = hostMo.getNetworkMor(networkName);
    if (morNetwork == null) {
        String msg = "Failed to create guest network " + networkName;
        s_logger.error(msg);
        throw new Exception(msg);
    }
    if (createGCTag) {
        NetworkMO networkMo = new NetworkMO(hostMo.getContext(), morNetwork);
        networkMo.setCustomFieldValue(CustomFieldConstants.CLOUD_GC, "true");
    }
    if (syncPeerHosts) {
        ManagedObjectReference morParent = hostMo.getParentMor();
        if (morParent != null && morParent.getType().equals("ClusterComputeResource")) {
            // to be conservative, lock cluster
            GlobalLock lock = GlobalLock.getInternLock("ClusterLock." + morParent.get_value());
            try {
                if (lock.lock(DEFAULT_LOCK_TIMEOUT_SECONDS)) {
                    try {
                        ManagedObjectReference[] hosts = (ManagedObjectReference[]) hostMo.getContext().getServiceUtil().getDynamicProperty(morParent, "host");
                        if (hosts != null) {
                            for (ManagedObjectReference otherHost : hosts) {
                                if (!otherHost.get_value().equals(hostMo.getMor().get_value())) {
                                    HostMO otherHostMo = new HostMO(hostMo.getContext(), otherHost);
                                    try {
                                        if (s_logger.isDebugEnabled())
                                            s_logger.debug("Prepare network on other host, vlan: " + vlanId + ", host: " + otherHostMo.getHostName());
                                        prepareNetwork(vSwitchName, namePrefix, otherHostMo, vlanId, networkRateMbps, networkRateMulticastMbps, timeOutMs, false);
                                    } catch (Exception e) {
                                        s_logger.warn("Unable to prepare network on other host, vlan: " + vlanId + ", host: " + otherHostMo.getHostName());
                                    }
                                }
                            }
                        }
                    } finally {
                        lock.unlock();
                    }
                } else {
                    s_logger.warn("Unable to lock cluster to prepare guest network, vlan: " + vlanId);
                }
            } finally {
                lock.releaseRef();
            }
        }
    }
    s_logger.info("Network " + networkName + " is ready on vSwitch " + vSwitchName);
    return new Pair<ManagedObjectReference, String>(morNetwork, networkName);
}
Also used : HostPortGroupSpec(com.vmware.vim25.HostPortGroupSpec) URISyntaxException(java.net.URISyntaxException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) GlobalLock(com.cloud.utils.db.GlobalLock) HostVirtualSwitch(com.vmware.vim25.HostVirtualSwitch) HostNetworkTrafficShapingPolicy(com.vmware.vim25.HostNetworkTrafficShapingPolicy) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Pair(com.cloud.utils.Pair)

Example 3 with HostNetworkTrafficShapingPolicy

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

the class HostMO method updatePortGroup.

public void updatePortGroup(HostVirtualSwitch vSwitch, String portGroupName, Integer vlanId, HostNetworkSecurityPolicy secPolicy, HostNetworkTrafficShapingPolicy shapingPolicy) throws Exception {
    assert (portGroupName != null);
    HostNetworkSystemMO hostNetMo = getHostNetworkSystemMO();
    assert (hostNetMo != null);
    HostPortGroupSpec spec = new HostPortGroupSpec();
    spec.setName(portGroupName);
    if (vlanId != null)
        spec.setVlanId(vlanId.intValue());
    HostNetworkPolicy policy = new HostNetworkPolicy();
    if (secPolicy != null)
        policy.setSecurity(secPolicy);
    policy.setShapingPolicy(shapingPolicy);
    spec.setPolicy(policy);
    spec.setVswitchName(vSwitch.getName());
    hostNetMo.updatePortGroup(portGroupName, spec);
}
Also used : HostNetworkPolicy(com.vmware.vim25.HostNetworkPolicy) HostPortGroupSpec(com.vmware.vim25.HostPortGroupSpec)

Example 4 with HostNetworkTrafficShapingPolicy

use of com.vmware.vim25.HostNetworkTrafficShapingPolicy in project CloudStack-archive by CloudStack-extras.

the class HostMO method updatePortGroup.

public void updatePortGroup(HostVirtualSwitch vSwitch, String portGroupName, Integer vlanId, HostNetworkTrafficShapingPolicy shapingPolicy) throws Exception {
    assert (portGroupName != null);
    HostNetworkSystemMO hostNetMo = getHostNetworkSystemMO();
    assert (hostNetMo != null);
    HostPortGroupSpec spec = new HostPortGroupSpec();
    spec.setName(portGroupName);
    if (vlanId != null)
        spec.setVlanId(vlanId.intValue());
    HostNetworkPolicy policy = new HostNetworkPolicy();
    policy.setShapingPolicy(shapingPolicy);
    spec.setPolicy(policy);
    spec.setVswitchName(vSwitch.getName());
    hostNetMo.updatePortGroup(portGroupName, spec);
}
Also used : HostNetworkPolicy(com.vmware.vim25.HostNetworkPolicy) HostPortGroupSpec(com.vmware.vim25.HostPortGroupSpec)

Example 5 with HostNetworkTrafficShapingPolicy

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

the class HypervisorHostHelper method prepareNetwork.

public static Pair<ManagedObjectReference, String> prepareNetwork(String vSwitchName, String namePrefix, HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps, long timeOutMs, boolean syncPeerHosts, BroadcastDomainType broadcastDomainType, String nicUuid) throws Exception {
    HostVirtualSwitch vSwitch;
    if (vSwitchName == null) {
        s_logger.info("Detected vswitch name as undefined. Defaulting to vSwitch0");
        vSwitchName = "vSwitch0";
    }
    vSwitch = hostMo.getHostVirtualSwitchByName(vSwitchName);
    if (vSwitch == null) {
        String msg = "Unable to find vSwitch" + vSwitchName;
        s_logger.error(msg);
        throw new Exception(msg);
    }
    boolean createGCTag = false;
    String networkName;
    Integer vid = null;
    /** This is the list of BroadcastDomainTypes we can actually
         * prepare networks for in this function.
         */
    BroadcastDomainType[] supportedBroadcastTypes = new BroadcastDomainType[] { BroadcastDomainType.Lswitch, BroadcastDomainType.LinkLocal, BroadcastDomainType.Native, BroadcastDomainType.Pvlan, BroadcastDomainType.Storage, BroadcastDomainType.UnDecided, BroadcastDomainType.Vlan, BroadcastDomainType.Vsp };
    if (!Arrays.asList(supportedBroadcastTypes).contains(broadcastDomainType)) {
        throw new InvalidParameterException("BroadcastDomainType " + broadcastDomainType + " it not supported on a VMWare hypervisor at this time.");
    }
    if (broadcastDomainType == BroadcastDomainType.Lswitch) {
        /**
             * Nicira NVP requires each vm to have its own port-group with a dedicated
             * vlan. We'll set the name of the pg to the uuid of the nic.
             */
        networkName = nicUuid;
        // No doubt about this, depending on vid=null to avoid lots of code below
        vid = null;
    } else {
        networkName = composeCloudNetworkName(namePrefix, vlanId, null, networkRateMbps, vSwitchName);
        if (vlanId != null && !UNTAGGED_VLAN_NAME.equalsIgnoreCase(vlanId)) {
            createGCTag = true;
            vid = Integer.parseInt(vlanId);
        }
    }
    HostNetworkSecurityPolicy secPolicy = null;
    if (namePrefix.equalsIgnoreCase("cloud.private")) {
        secPolicy = new HostNetworkSecurityPolicy();
        secPolicy.setAllowPromiscuous(Boolean.TRUE);
        secPolicy.setForgedTransmits(Boolean.TRUE);
        secPolicy.setMacChanges(Boolean.TRUE);
    }
    HostNetworkTrafficShapingPolicy shapingPolicy = null;
    if (networkRateMbps != null && networkRateMbps.intValue() > 0) {
        shapingPolicy = new HostNetworkTrafficShapingPolicy();
        shapingPolicy.setEnabled(true);
        shapingPolicy.setAverageBandwidth(networkRateMbps.intValue() * 1024L * 1024L);
        //
        // TODO : people may have different opinion on how to set the following
        //
        // give 50% premium to peek
        shapingPolicy.setPeakBandwidth((long) (shapingPolicy.getAverageBandwidth() * 1.5));
        // allow 5 seconds of burst transfer
        shapingPolicy.setBurstSize(5 * shapingPolicy.getAverageBandwidth() / 8);
    }
    boolean bWaitPortGroupReady = false;
    if (broadcastDomainType == BroadcastDomainType.Lswitch) {
        //if NSX API VERSION >= 4.2, connect to br-int (nsx.network), do not create portgroup else previous behaviour
        if (NiciraNvpApiVersion.isApiVersionLowerThan("4.2")) {
            //Previous behaviour
            if (!hostMo.hasPortGroup(vSwitch, networkName)) {
                createNvpPortGroup(hostMo, vSwitch, networkName, shapingPolicy);
                bWaitPortGroupReady = true;
            } else {
                bWaitPortGroupReady = false;
            }
        }
    } else {
        if (!hostMo.hasPortGroup(vSwitch, networkName)) {
            hostMo.createPortGroup(vSwitch, networkName, vid, secPolicy, shapingPolicy, timeOutMs);
            // Setting flag "bWaitPortGroupReady" to false.
            // This flag indicates whether we need to wait for portgroup on vCenter.
            // Above createPortGroup() method itself ensures creation of portgroup as well as wait for portgroup.
            bWaitPortGroupReady = false;
        } else {
            HostPortGroupSpec spec = hostMo.getPortGroupSpec(networkName);
            if (!isSpecMatch(spec, vid, shapingPolicy)) {
                hostMo.updatePortGroup(vSwitch, networkName, vid, secPolicy, shapingPolicy);
                bWaitPortGroupReady = true;
            }
        }
    }
    ManagedObjectReference morNetwork = null;
    if (broadcastDomainType != BroadcastDomainType.Lswitch || (broadcastDomainType == BroadcastDomainType.Lswitch && NiciraNvpApiVersion.isApiVersionLowerThan("4.2"))) {
        if (bWaitPortGroupReady)
            morNetwork = waitForNetworkReady(hostMo, networkName, timeOutMs);
        else
            morNetwork = hostMo.getNetworkMor(networkName);
        if (morNetwork == null) {
            String msg = "Failed to create guest network " + networkName;
            s_logger.error(msg);
            throw new Exception(msg);
        }
        if (createGCTag) {
            NetworkMO networkMo = new NetworkMO(hostMo.getContext(), morNetwork);
            networkMo.setCustomFieldValue(CustomFieldConstants.CLOUD_GC, "true");
        }
    }
    if (syncPeerHosts) {
        ManagedObjectReference morParent = hostMo.getParentMor();
        if (morParent != null && morParent.getType().equals("ClusterComputeResource")) {
            // to be conservative, lock cluster
            GlobalLock lock = GlobalLock.getInternLock("ClusterLock." + morParent.getValue());
            try {
                if (lock.lock(DEFAULT_LOCK_TIMEOUT_SECONDS)) {
                    try {
                        List<ManagedObjectReference> hosts = hostMo.getContext().getVimClient().getDynamicProperty(morParent, "host");
                        if (hosts != null) {
                            for (ManagedObjectReference otherHost : hosts) {
                                if (!otherHost.getValue().equals(hostMo.getMor().getValue())) {
                                    HostMO otherHostMo = new HostMO(hostMo.getContext(), otherHost);
                                    try {
                                        if (s_logger.isDebugEnabled())
                                            s_logger.debug("Prepare network on other host, vlan: " + vlanId + ", host: " + otherHostMo.getHostName());
                                        prepareNetwork(vSwitchName, namePrefix, otherHostMo, vlanId, networkRateMbps, networkRateMulticastMbps, timeOutMs, false, broadcastDomainType, nicUuid);
                                    } catch (Exception e) {
                                        s_logger.warn("Unable to prepare network on other host, vlan: " + vlanId + ", host: " + otherHostMo.getHostName());
                                    }
                                }
                            }
                        }
                    } finally {
                        lock.unlock();
                    }
                } else {
                    s_logger.warn("Unable to lock cluster to prepare guest network, vlan: " + vlanId);
                }
            } finally {
                lock.releaseRef();
            }
        }
    }
    s_logger.info("Network " + networkName + " is ready on vSwitch " + vSwitchName);
    return new Pair<ManagedObjectReference, String>(morNetwork, networkName);
}
Also used : HostNetworkSecurityPolicy(com.vmware.vim25.HostNetworkSecurityPolicy) HostPortGroupSpec(com.vmware.vim25.HostPortGroupSpec) 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) GlobalLock(com.cloud.utils.db.GlobalLock) InvalidParameterException(java.security.InvalidParameterException) BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) HostVirtualSwitch(com.vmware.vim25.HostVirtualSwitch) HostNetworkTrafficShapingPolicy(com.vmware.vim25.HostNetworkTrafficShapingPolicy) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Pair(com.cloud.utils.Pair)

Aggregations

HostPortGroupSpec (com.vmware.vim25.HostPortGroupSpec)8 HostNetworkPolicy (com.vmware.vim25.HostNetworkPolicy)4 HostNetworkSecurityPolicy (com.vmware.vim25.HostNetworkSecurityPolicy)4 HostNetworkTrafficShapingPolicy (com.vmware.vim25.HostNetworkTrafficShapingPolicy)4 Pair (com.cloud.utils.Pair)3 GlobalLock (com.cloud.utils.db.GlobalLock)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 HostVirtualSwitch (com.vmware.vim25.HostVirtualSwitch)3 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)3 URISyntaxException (java.net.URISyntaxException)3 InvalidParameterException (java.security.InvalidParameterException)3 CloudException (com.cloud.exception.CloudException)2 BroadcastDomainType (com.cloud.network.Networks.BroadcastDomainType)2 IOException (java.io.IOException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 SAXException (org.xml.sax.SAXException)2 HostPortGroup (com.vmware.vim25.HostPortGroup)1 ArrayList (java.util.ArrayList)1