Search in sources :

Example 1 with DVPortgroupConfigInfo

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

the class DatacenterMO method getDvPortGroupSpec.

public DVPortgroupConfigInfo getDvPortGroupSpec(String dvPortGroupName) throws Exception {
    DVPortgroupConfigInfo configSpec = null;
    String nameProperty = null;
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("DistributedVirtualPortgroup");
    pSpec.setPathSet(new String[] { "name", "config" });
    TraversalSpec datacenter2DvPortGroupTraversal = new TraversalSpec();
    datacenter2DvPortGroupTraversal.setType("Datacenter");
    datacenter2DvPortGroupTraversal.setPath("network");
    datacenter2DvPortGroupTraversal.setName("datacenter2DvPortgroupTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.setSelectSet(new SelectionSpec[] { datacenter2DvPortGroupTraversal });
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.setPropSet(new PropertySpec[] { pSpec });
    pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
    ObjectContent[] ocs = _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            DynamicProperty[] props = oc.getPropSet();
            if (props != null) {
                assert (props.length == 2);
                for (DynamicProperty prop : props) {
                    if (prop.getName().equals("config")) {
                        configSpec = (DVPortgroupConfigInfo) prop.getVal();
                    } else {
                        nameProperty = prop.getVal().toString();
                    }
                }
                if (nameProperty.equalsIgnoreCase(dvPortGroupName)) {
                    return configSpec;
                }
            }
        }
    }
    return null;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) DynamicProperty(com.vmware.vim25.DynamicProperty) TraversalSpec(com.vmware.vim25.TraversalSpec) DVPortgroupConfigInfo(com.vmware.vim25.DVPortgroupConfigInfo)

Example 2 with DVPortgroupConfigInfo

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

the class HypervisorHostHelper method isSpecMatch.

public static boolean isSpecMatch(DVPortgroupConfigInfo configInfo, Integer vid, DVSTrafficShapingPolicy shapingPolicy) {
    DVSTrafficShapingPolicy currentTrafficShapingPolicy;
    currentTrafficShapingPolicy = configInfo.getDefaultPortConfig().getInShapingPolicy();
    assert (currentTrafficShapingPolicy != null);
    LongPolicy averageBandwidth = currentTrafficShapingPolicy.getAverageBandwidth();
    LongPolicy burstSize = currentTrafficShapingPolicy.getBurstSize();
    LongPolicy peakBandwidth = currentTrafficShapingPolicy.getPeakBandwidth();
    BoolPolicy isEnabled = currentTrafficShapingPolicy.getEnabled();
    if (!isEnabled.equals(shapingPolicy.getEnabled())) {
        return false;
    }
    if (averageBandwidth != null && !averageBandwidth.equals(shapingPolicy.getAverageBandwidth())) {
        if (s_logger.isInfoEnabled()) {
            s_logger.info("Average bandwidth setting in shaping policy doesn't match with existing setting.");
        }
        return false;
    } else if (burstSize != null && !burstSize.equals(shapingPolicy.getBurstSize())) {
        if (s_logger.isInfoEnabled()) {
            s_logger.info("Burst size setting in shaping policy doesn't match with existing setting.");
        }
        return false;
    } else if (peakBandwidth != null && !peakBandwidth.equals(shapingPolicy.getPeakBandwidth())) {
        if (s_logger.isInfoEnabled()) {
            s_logger.info("Peak bandwidth setting in shaping policy doesn't match with existing setting.");
        }
        return false;
    }
    return true;
}
Also used : LongPolicy(com.vmware.vim25.LongPolicy) DVSTrafficShapingPolicy(com.vmware.vim25.DVSTrafficShapingPolicy) BoolPolicy(com.vmware.vim25.BoolPolicy)

Example 3 with DVPortgroupConfigInfo

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

the class HypervisorHostHelper method prepareNetwork.

/**
	 * @param ethPortProfileName
	 * @param namePrefix
	 * @param hostMo
	 * @param vlanId
	 * @param networkRateMbps
	 * @param networkRateMulticastMbps
	 * @param timeOutMs
	 * @return
	 * @throws Exception
	 */
public static Pair<ManagedObjectReference, String> prepareNetwork(String ethPortProfileName, String namePrefix, HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps, long timeOutMs) throws Exception {
    ManagedObjectReference morNetwork = null;
    VmwareContext context = hostMo.getContext();
    ManagedObjectReference dcMor = hostMo.getHyperHostDatacenter();
    DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor);
    ManagedObjectReference morEthernetPortProfile = dataCenterMo.getDvPortGroupMor(ethPortProfileName);
    if (morEthernetPortProfile == null) {
        String msg = "Unable to find Ethernet port profile " + ethPortProfileName;
        s_logger.error(msg);
        throw new Exception(msg);
    } else {
        s_logger.info("Found Ethernet port profile " + ethPortProfileName);
    }
    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, ethPortProfileName);
    // TODO(sateesh): Enable this for VMware DVS.
    //        DVSTrafficShapingPolicy shapingPolicy = null;
    //        if (networkRateMbps != null && networkRateMbps.intValue() > 0) {
    //            shapingPolicy = new DVSTrafficShapingPolicy();
    //            BoolPolicy isEnabled = new BoolPolicy();
    //            LongPolicy averageBandwidth = new LongPolicy();
    //            LongPolicy peakBandwidth = new LongPolicy();
    //            LongPolicy burstSize = new LongPolicy();
    //
    //            isEnabled.setValue(true);
    //            averageBandwidth.setValue((long) networkRateMbps.intValue() * 1024L * 1024L);
    //            // We chose 50% higher allocation than average bandwidth.
    //            // TODO(sateesh): Also let user specify the peak coefficient
    //            peakBandwidth.setValue((long) (averageBandwidth.getValue() * 1.5));
    //            // TODO(sateesh): Also let user specify the burst coefficient
    //            burstSize.setValue((long) (5 * averageBandwidth.getValue() / 8));
    //
    //            shapingPolicy.setEnabled(isEnabled);
    //            shapingPolicy.setAverageBandwidth(averageBandwidth);
    //            shapingPolicy.setPeakBandwidth(peakBandwidth);
    //            shapingPolicy.setBurstSize(burstSize);
    //        }
    DVPortgroupConfigInfo spec = dataCenterMo.getDvPortGroupSpec(networkName);
    long averageBandwidth = 0L;
    if (networkRateMbps != null && networkRateMbps.intValue() > 0) {
        averageBandwidth = (long) (networkRateMbps.intValue() * 1024L * 1024L);
    }
    // We chose 50% higher allocation than average bandwidth.
    // TODO(sateesh): Also let user specify the peak coefficient
    long peakBandwidth = (long) (averageBandwidth * 1.5);
    // TODO(sateesh): Also let user specify the burst coefficient
    long burstSize = 5 * averageBandwidth / 8;
    boolean bWaitPortGroupReady = false;
    if (!dataCenterMo.hasDvPortGroup(networkName)) {
        s_logger.info("Port profile " + networkName + " not found.");
        createPortProfile(context, ethPortProfileName, networkName, vid, networkRateMbps, peakBandwidth, burstSize);
        bWaitPortGroupReady = true;
    } else {
        s_logger.info("Port profile " + networkName + " found.");
        bWaitPortGroupReady = true;
        updatePortProfile(context, ethPortProfileName, networkName, vid, networkRateMbps, peakBandwidth, burstSize);
    }
    // Wait for dvPortGroup on vCenter		
    if (bWaitPortGroupReady)
        morNetwork = waitForDvPortGroupReady(dataCenterMo, networkName, timeOutMs);
    else
        morNetwork = dataCenterMo.getDvPortGroupMor(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_DVP, "true");
        s_logger.debug("Added custom field : " + CustomFieldConstants.CLOUD_GC_DVP);
    }
    return new Pair<ManagedObjectReference, String>(morNetwork, networkName);
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) URISyntaxException(java.net.URISyntaxException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) DVPortgroupConfigInfo(com.vmware.vim25.DVPortgroupConfigInfo) Pair(com.cloud.utils.Pair)

Example 4 with DVPortgroupConfigInfo

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

the class HypervisorHostHelper method isSpecMatch.

// This method would be used for VMware Distributed Virtual Switch.
private static boolean isSpecMatch(DVPortgroupConfigInfo spec, Integer vid, DVSTrafficShapingPolicy shapingPolicy) {
    DVSTrafficShapingPolicy currentTrafficShapingPolicy;
    currentTrafficShapingPolicy = spec.getDefaultPortConfig().getInShapingPolicy();
    assert (currentTrafficShapingPolicy != null);
    LongPolicy averageBandwidth = currentTrafficShapingPolicy.getAverageBandwidth();
    LongPolicy burstSize = currentTrafficShapingPolicy.getBurstSize();
    LongPolicy peakBandwidth = currentTrafficShapingPolicy.getPeakBandwidth();
    BoolPolicy isEnabled = currentTrafficShapingPolicy.getEnabled();
    if (!isEnabled.getValue())
        return false;
    if (averageBandwidth != null && !averageBandwidth.equals(shapingPolicy.getAverageBandwidth())) {
        if (s_logger.isInfoEnabled()) {
            s_logger.info("Average bandwidth setting in shaping policy doesn't match with existing setting.");
        }
        return false;
    } else if (burstSize != null && !burstSize.equals(shapingPolicy.getBurstSize())) {
        if (s_logger.isInfoEnabled()) {
            s_logger.info("Burst size setting in shaping policy doesn't match with existing setting.");
        }
        return false;
    } else if (peakBandwidth != null && !peakBandwidth.equals(shapingPolicy.getPeakBandwidth())) {
        if (s_logger.isInfoEnabled()) {
            s_logger.info("Peak bandwidth setting in shaping policy doesn't match with existing setting.");
        }
        return false;
    }
    return true;
}
Also used : LongPolicy(com.vmware.vim25.LongPolicy) DVSTrafficShapingPolicy(com.vmware.vim25.DVSTrafficShapingPolicy) BoolPolicy(com.vmware.vim25.BoolPolicy)

Example 5 with DVPortgroupConfigInfo

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

the class DatacenterMO method getDvPortGroupSpec.

public DVPortgroupConfigInfo getDvPortGroupSpec(String dvPortGroupName) throws Exception {
    DVPortgroupConfigInfo configSpec = null;
    String nameProperty = null;
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("DistributedVirtualPortgroup");
    pSpec.getPathSet().add("name");
    pSpec.getPathSet().add("config");
    TraversalSpec datacenter2DvPortGroupTraversal = new TraversalSpec();
    datacenter2DvPortGroupTraversal.setType("Datacenter");
    datacenter2DvPortGroupTraversal.setPath("network");
    datacenter2DvPortGroupTraversal.setName("datacenter2DvPortgroupTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(datacenter2DvPortGroupTraversal);
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);
    List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            List<DynamicProperty> props = oc.getPropSet();
            if (props != null) {
                assert (props.size() == 2);
                for (DynamicProperty prop : props) {
                    if (prop.getName().equals("config")) {
                        configSpec = (DVPortgroupConfigInfo) prop.getVal();
                    } else {
                        nameProperty = prop.getVal().toString();
                    }
                }
                if (nameProperty.equalsIgnoreCase(dvPortGroupName)) {
                    return configSpec;
                }
            }
        }
    }
    return null;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) DynamicProperty(com.vmware.vim25.DynamicProperty) TraversalSpec(com.vmware.vim25.TraversalSpec) ArrayList(java.util.ArrayList) DVPortgroupConfigInfo(com.vmware.vim25.DVPortgroupConfigInfo)

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