Search in sources :

Example 1 with DVSMacManagementPolicy

use of com.vmware.vim25.DVSMacManagementPolicy 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 2 with DVSMacManagementPolicy

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

the class HypervisorHostHelperTest method testDVSMacManagementPolicyDefault.

@Test
public void testDVSMacManagementPolicyDefault() {
    DVSMacManagementPolicy macManagementPolicy = HypervisorHostHelper.createDVSMacManagementPolicy(null);
    assertFalse(macManagementPolicy.isAllowPromiscuous());
    assertTrue(macManagementPolicy.isForgedTransmits());
    assertTrue(macManagementPolicy.isMacChanges());
    assertFalse(macManagementPolicy.getMacLearningPolicy().isEnabled());
}
Also used : DVSMacManagementPolicy(com.vmware.vim25.DVSMacManagementPolicy) Test(org.junit.Test)

Example 3 with DVSMacManagementPolicy

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

the class HypervisorHostHelperTest method testDVSMacManagementPolicyWithDetail.

@Test
public void testDVSMacManagementPolicyWithDetail() {
    Map<NetworkOffering.Detail, String> details = getNicDetails();
    details.put(NetworkOffering.Detail.ForgedTransmits, "true");
    details.put(NetworkOffering.Detail.MacLearning, "true");
    DVSMacManagementPolicy macManagementPolicy = HypervisorHostHelper.createDVSMacManagementPolicy(details);
    assertFalse(macManagementPolicy.isAllowPromiscuous());
    assertTrue(macManagementPolicy.isForgedTransmits());
    assertFalse(macManagementPolicy.isMacChanges());
    assertTrue(macManagementPolicy.getMacLearningPolicy().isEnabled());
}
Also used : DVSMacManagementPolicy(com.vmware.vim25.DVSMacManagementPolicy) Test(org.junit.Test)

Example 4 with DVSMacManagementPolicy

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

the class HypervisorHostHelper method prepareNetwork.

/**
 * Prepares network (for non-standard virtual switch) for the VM NIC based on the parameters.
 * Can create a new portgroup or update an existing.
 * @return Pair of network's ManagedObjectReference and name
 * @throws Exception
 */
public static Pair<ManagedObjectReference, String> prepareNetwork(String physicalNetwork, String namePrefix, HostMO hostMo, String vlanId, String secondaryvlanId, Integer networkRateMbps, Integer networkRateMulticastMbps, long timeOutMs, VirtualSwitchType vSwitchType, int numPorts, String gateway, boolean configureVServiceInNexus, BroadcastDomainType broadcastDomainType, Map<String, String> vsmCredentials, Map<NetworkOffering.Detail, String> details) throws Exception {
    ManagedObjectReference morNetwork = null;
    VmwareContext context = hostMo.getContext();
    ManagedObjectReference dcMor = hostMo.getHyperHostDatacenter();
    DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor);
    DistributedVirtualSwitchMO dvSwitchMo = null;
    ManagedObjectReference morEthernetPortProfile = null;
    String ethPortProfileName = null;
    ManagedObjectReference morDvSwitch = null;
    String dvSwitchName = null;
    boolean bWaitPortGroupReady = false;
    boolean createGCTag = false;
    String vcApiVersion;
    String minVcApiVersionSupportingAutoExpand;
    boolean autoExpandSupported;
    String networkName;
    Integer vid = null;
    // secondary pvlan id
    Integer spvlanid = 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 };
    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) {
        if (vSwitchType == VirtualSwitchType.NexusDistributedVirtualSwitch) {
            throw new InvalidParameterException("Nexus Distributed Virtualswitch is not supported with BroadcastDomainType " + broadcastDomainType);
        }
        /**
         * Nicira NVP requires all vms to be connected to a single port-group.
         * A unique vlan needs to be set per port. This vlan is specific to
         * this implementation and has no reference to other vlans in CS
         */
        // FIXME Should be set via a configuration item in CS
        networkName = "br-int";
        // No doubt about this, depending on vid=null to avoid lots of code below
        vid = null;
    } else {
        if (vlanId != null) {
            vlanId = vlanId.replace("vlan://", "");
        }
        networkName = composeCloudNetworkName(namePrefix, vlanId, secondaryvlanId, networkRateMbps, physicalNetwork);
        if (vlanId != null && !UNTAGGED_VLAN_NAME.equalsIgnoreCase(vlanId) && !StringUtils.containsAny(vlanId, ",-")) {
            createGCTag = true;
            vid = Integer.parseInt(vlanId);
        }
        if (vlanId != null && StringUtils.containsAny(vlanId, ",-")) {
            createGCTag = true;
        }
        if (secondaryvlanId != null) {
            spvlanid = Integer.parseInt(secondaryvlanId);
        }
    }
    if (vSwitchType == VirtualSwitchType.VMwareDistributedVirtualSwitch) {
        vcApiVersion = getVcenterApiVersion(context);
        minVcApiVersionSupportingAutoExpand = "5.0";
        autoExpandSupported = isFeatureSupportedInVcenterApiVersion(vcApiVersion, minVcApiVersionSupportingAutoExpand);
        dvSwitchName = physicalNetwork;
        // and switch types.
        if (dvSwitchName == null) {
            s_logger.warn("Detected null dvSwitch. Defaulting to dvSwitch0");
            dvSwitchName = "dvSwitch0";
        }
        morDvSwitch = dataCenterMo.getDvSwitchMor(dvSwitchName);
        if (morDvSwitch == null) {
            String msg = "Unable to find distributed vSwitch " + dvSwitchName;
            s_logger.error(msg);
            throw new Exception(msg);
        }
        dvSwitchMo = new DistributedVirtualSwitchMO(context, morDvSwitch);
        String dvSwitchVersion = dvSwitchMo.getDVSProductVersion(morDvSwitch);
        s_logger.debug(String.format("Found distributed vSwitch: %s with product version: %s", dvSwitchName, dvSwitchVersion));
        if (broadcastDomainType == BroadcastDomainType.Lswitch) {
            if (!dataCenterMo.hasDvPortGroup(networkName)) {
                throw new InvalidParameterException("NVP integration port-group " + networkName + " does not exist on the DVS " + dvSwitchName);
            }
            bWaitPortGroupReady = false;
        } else {
            boolean dvSwitchSupportNewPolicies = (isFeatureSupportedInVcenterApiVersion(vcApiVersion, MINIMUM_VCENTER_API_VERSION_WITH_DVS_NEW_POLICIES_SUPPORT) && isVersionEqualOrHigher(dvSwitchVersion, MINIMUM_DVS_VERSION_WITH_NEW_POLICIES_SUPPORT));
            DVSTrafficShapingPolicy shapingPolicy = getDVSShapingPolicy(networkRateMbps);
            DVSSecurityPolicy secPolicy = createDVSSecurityPolicy(details);
            DVSMacManagementPolicy macManagementPolicy = createDVSMacManagementPolicy(details);
            // First, if both vlan id and pvlan id are provided, we need to
            // reconfigure the DVSwitch to have a tuple <vlan id, pvlan id> of
            // type isolated.
            String pvlanType = MapUtils.isNotEmpty(details) ? details.get(NetworkOffering.Detail.pvlanType) : null;
            if (vid != null && spvlanid != null) {
                setupPVlanPair(dvSwitchMo, morDvSwitch, vid, spvlanid, pvlanType);
            }
            VMwareDVSPortgroupPolicy portGroupPolicy = null;
            // Next, create the port group. For this, we need to create a VLAN spec.
            createPortGroup(physicalNetwork, networkName, vlanId, vid, spvlanid, dataCenterMo, shapingPolicy, secPolicy, macManagementPolicy, portGroupPolicy, dvSwitchMo, numPorts, autoExpandSupported, dvSwitchSupportNewPolicies);
            bWaitPortGroupReady = true;
        }
    } else if (vSwitchType == VirtualSwitchType.NexusDistributedVirtualSwitch) {
        ethPortProfileName = physicalNetwork;
        // and switch types.
        if (ethPortProfileName == null) {
            s_logger.warn("Detected null ethrenet port profile. Defaulting to epp0.");
            ethPortProfileName = "epp0";
        }
        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);
        }
        long averageBandwidth = 0L;
        if (networkRateMbps != null && networkRateMbps.intValue() > 0) {
            averageBandwidth = networkRateMbps.intValue() * 1024L * 1024L;
        }
        // We chose 50% higher allocation than average bandwidth.
        // TODO(sateesh): Optionally let user specify the peak coefficient
        long peakBandwidth = (long) (averageBandwidth * 1.5);
        // TODO(sateesh): Optionally let user specify the burst coefficient
        long burstSize = 5 * averageBandwidth / 8;
        if (vsmCredentials != null) {
            s_logger.info("Stocking credentials of Nexus VSM");
            context.registerStockObject("vsmcredentials", vsmCredentials);
        }
        if (!dataCenterMo.hasDvPortGroup(networkName)) {
            s_logger.info("Port profile " + networkName + " not found.");
            createPortProfile(context, physicalNetwork, networkName, vid, networkRateMbps, peakBandwidth, burstSize, gateway, configureVServiceInNexus);
            bWaitPortGroupReady = true;
        } else {
            s_logger.info("Port profile " + networkName + " found.");
            updatePortProfile(context, physicalNetwork, 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 : VMwareDVSPortgroupPolicy(com.vmware.vim25.VMwareDVSPortgroupPolicy) DVSTrafficShapingPolicy(com.vmware.vim25.DVSTrafficShapingPolicy) InvalidParameterException(java.security.InvalidParameterException) CloudException(com.cloud.exception.CloudException) TransformerException(javax.xml.transform.TransformerException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DVSMacManagementPolicy(com.vmware.vim25.DVSMacManagementPolicy) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) InvalidParameterException(java.security.InvalidParameterException) BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) DVSSecurityPolicy(com.vmware.vim25.DVSSecurityPolicy) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Pair(com.cloud.utils.Pair)

Example 5 with DVSMacManagementPolicy

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

the class HypervisorHostHelper method createDVSMacManagementPolicy.

public static DVSMacManagementPolicy createDVSMacManagementPolicy(Map<NetworkOffering.Detail, String> nicDetails) {
    if (nicDetails == null) {
        nicDetails = getDefaultSecurityDetails();
    }
    DVSMacManagementPolicy macManagementPolicy = new DVSMacManagementPolicy();
    macManagementPolicy.setAllowPromiscuous(Boolean.valueOf(nicDetails.getOrDefault(NetworkOffering.Detail.PromiscuousMode, "false")));
    macManagementPolicy.setForgedTransmits(Boolean.valueOf(nicDetails.getOrDefault(NetworkOffering.Detail.ForgedTransmits, "false")));
    macManagementPolicy.setMacChanges(Boolean.valueOf(nicDetails.getOrDefault(NetworkOffering.Detail.MacAddressChanges, "false")));
    DVSMacLearningPolicy macLearningPolicy = new DVSMacLearningPolicy();
    macLearningPolicy.setEnabled(Boolean.parseBoolean(nicDetails.getOrDefault(NetworkOffering.Detail.MacLearning, "false")));
    macManagementPolicy.setMacLearningPolicy(macLearningPolicy);
    return macManagementPolicy;
}
Also used : DVSMacLearningPolicy(com.vmware.vim25.DVSMacLearningPolicy) DVSMacManagementPolicy(com.vmware.vim25.DVSMacManagementPolicy)

Aggregations

DVSMacManagementPolicy (com.vmware.vim25.DVSMacManagementPolicy)4 CloudException (com.cloud.exception.CloudException)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)2 VMwareDVSPortSetting (com.vmware.vim25.VMwareDVSPortSetting)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 Test (org.junit.Test)2 SAXException (org.xml.sax.SAXException)2 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)1 BroadcastDomainType (com.cloud.network.Networks.BroadcastDomainType)1 Pair (com.cloud.utils.Pair)1 DVPortgroupConfigInfo (com.vmware.vim25.DVPortgroupConfigInfo)1 DVPortgroupConfigSpec (com.vmware.vim25.DVPortgroupConfigSpec)1 DVSMacLearningPolicy (com.vmware.vim25.DVSMacLearningPolicy)1 DVSSecurityPolicy (com.vmware.vim25.DVSSecurityPolicy)1 DVSTrafficShapingPolicy (com.vmware.vim25.DVSTrafficShapingPolicy)1