Search in sources :

Example 1 with HostPortGroupSpec

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

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

the class HostMO method getHostPortGroupSpec.

public HostPortGroupSpec getHostPortGroupSpec(String portGroupName) throws Exception {
    HostNetworkInfo hostNetInfo = getHostNetworkInfo();
    HostPortGroup[] portGroups = hostNetInfo.getPortgroup();
    if (portGroups != null) {
        for (HostPortGroup portGroup : portGroups) {
            HostPortGroupSpec spec = portGroup.getSpec();
            if (spec.getName().equals(portGroupName))
                return spec;
        }
    }
    return null;
}
Also used : HostNetworkInfo(com.vmware.vim25.HostNetworkInfo) HostPortGroup(com.vmware.vim25.HostPortGroup) HostPortGroupSpec(com.vmware.vim25.HostPortGroupSpec)

Example 3 with HostPortGroupSpec

use of com.vmware.vim25.HostPortGroupSpec 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 4 with HostPortGroupSpec

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

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

the class HostMO method getHostPortGroupSpec.

public HostPortGroupSpec getHostPortGroupSpec(String portGroupName) throws Exception {
    HostNetworkInfo hostNetInfo = getHostNetworkInfo();
    List<HostPortGroup> portGroups = hostNetInfo.getPortgroup();
    if (portGroups != null) {
        for (HostPortGroup portGroup : portGroups) {
            HostPortGroupSpec spec = portGroup.getSpec();
            if (spec.getName().equals(portGroupName))
                return spec;
        }
    }
    return null;
}
Also used : HostNetworkInfo(com.vmware.vim25.HostNetworkInfo) HostPortGroup(com.vmware.vim25.HostPortGroup) HostPortGroupSpec(com.vmware.vim25.HostPortGroupSpec)

Aggregations

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