cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [1/5] git commit: updated refs/heads/master to 219da64
Date Wed, 18 Nov 2015 12:13:32 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master 95ae7963d -> 219da6402


CLOUDSTACK-8956: Deploy VM on NSX managed network changes if NSX Api Version >= 4.2: has
to connect to "br-int" of "nsx.network" type


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/e1d1a403
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/e1d1a403
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/e1d1a403

Branch: refs/heads/master
Commit: e1d1a403257d94790bb44180b4584ed967d73fec
Parents: 2386ae5
Author: nvazquez <nicolas.m.vazquez@gmail.com>
Authored: Mon Oct 19 16:28:28 2015 -0200
Committer: nvazquez <nicovazquez90@gmail.com>
Committed: Mon Nov 16 11:29:30 2015 -0800

----------------------------------------------------------------------
 .../vmware/resource/VmwareResource.java         | 42 +++++++++++------
 .../com/cloud/hypervisor/vmware/mo/HostMO.java  | 19 +++++++-
 .../vmware/mo/HypervisorHostHelper.java         | 45 ++++++++++--------
 .../hypervisor/vmware/util/VmwareHelper.java    | 48 +++++++++++++++++++-
 4 files changed, 120 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e1d1a403/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index da97cdd..5cb7fda 100644
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -83,6 +83,7 @@ import com.vmware.vim25.VirtualDisk;
 import com.vmware.vim25.VirtualEthernetCard;
 import com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo;
 import com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo;
+import com.vmware.vim25.VirtualEthernetCardOpaqueNetworkBackingInfo;
 import com.vmware.vim25.VirtualMachineConfigSpec;
 import com.vmware.vim25.VirtualMachineFileInfo;
 import com.vmware.vim25.VirtualMachineFileLayoutEx;
@@ -270,6 +271,7 @@ import com.cloud.utils.exception.ExceptionUtil;
 import com.cloud.utils.mgmt.JmxUtil;
 import com.cloud.utils.mgmt.PropertyMapDynamicBean;
 import com.cloud.utils.net.NetUtils;
+import com.cloud.utils.nicira.nvp.plugin.NiciraNvpApiVersion;
 import com.cloud.utils.ssh.SshHelper;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachine.PowerState;
@@ -1677,26 +1679,35 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
             if (s_logger.isDebugEnabled())
                 s_logger.debug("VM " + vmInternalCSName + " will be started with NIC device
type: " + nicDeviceType);
 
+            NiciraNvpApiVersion.logNiciraApiVersion();
+
             for (NicTO nicTo : sortNicsByDeviceId(nics)) {
                 s_logger.info("Prepare NIC device based on NicTO: " + _gson.toJson(nicTo));
 
                 boolean configureVServiceInNexus = (nicTo.getType() == TrafficType.Guest)
&& (vmSpec.getDetails().containsKey("ConfigureVServiceInNexus"));
                 VirtualMachine.Type vmType = cmd.getVirtualMachine().getType();
                 Pair<ManagedObjectReference, String> networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(),
nicTo, configureVServiceInNexus, vmType);
-                if (VmwareHelper.isDvPortGroup(networkInfo.first())) {
-                    String dvSwitchUuid;
-                    ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter();
-                    DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor);
-                    ManagedObjectReference dvsMor = dataCenterMo.getDvSwitchMor(networkInfo.first());
-                    dvSwitchUuid = dataCenterMo.getDvSwitchUuid(dvsMor);
-                    s_logger.info("Preparing NIC device on dvSwitch : " + dvSwitchUuid);
-                    nic =
-                            VmwareHelper.prepareDvNicDevice(vmMo, networkInfo.first(), nicDeviceType,
networkInfo.second(), dvSwitchUuid, nicTo.getMac(), nicUnitNumber++,
-                                    i + 1, true, true);
-                } else {
-                    s_logger.info("Preparing NIC device on network " + networkInfo.second());
-                    nic =
-                            VmwareHelper.prepareNicDevice(vmMo, networkInfo.first(), nicDeviceType,
networkInfo.second(), nicTo.getMac(), nicUnitNumber++, i + 1, true, true);
+                if ((nicTo.getBroadcastType() != BroadcastDomainType.Lswitch) ||
+                        (nicTo.getBroadcastType() == BroadcastDomainType.Lswitch &&
NiciraNvpApiVersion.isApiVersionLowerThan("4.2"))){
+                    if (VmwareHelper.isDvPortGroup(networkInfo.first())) {
+                        String dvSwitchUuid;
+                        ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter();
+                        DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor);
+                        ManagedObjectReference dvsMor = dataCenterMo.getDvSwitchMor(networkInfo.first());
+                        dvSwitchUuid = dataCenterMo.getDvSwitchUuid(dvsMor);
+                        s_logger.info("Preparing NIC device on dvSwitch : " + dvSwitchUuid);
+                        nic =
+                                VmwareHelper.prepareDvNicDevice(vmMo, networkInfo.first(),
nicDeviceType, networkInfo.second(), dvSwitchUuid, nicTo.getMac(), nicUnitNumber++,
+                                        i + 1, true, true);
+                    } else {
+                        s_logger.info("Preparing NIC device on network " + networkInfo.second());
+                        nic =
+                                VmwareHelper.prepareNicDevice(vmMo, networkInfo.first(),
nicDeviceType, networkInfo.second(), nicTo.getMac(), nicUnitNumber++, i + 1, true, true);
+                    }
+                }
+                else{
+                    //if NSX API VERSION >= 4.2, connect to br-int (nsx.network), do not
create portgroup else previous behaviour
+                    nic = VmwareHelper.prepareNicOpaque(vmMo, nicDeviceType, networkInfo.second(),
nicTo.getMac(), nicUnitNumber++, i + 1, true, true);
                 }
 
                 deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
@@ -2076,6 +2087,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
                 } else if (backing instanceof VirtualEthernetCardNetworkBackingInfo) {
                     // This NIC is connected to a Virtual Switch
                     // Nothing to do
+                } else if (backing instanceof VirtualEthernetCardOpaqueNetworkBackingInfo)
{
+                    //if NSX API VERSION >= 4.2, connect to br-int (nsx.network), do not
create portgroup else previous behaviour
+                    //OK, connected to OpaqueNetwork
                 } else {
                     s_logger.error("nic device backing is of type " + backing.getClass().getName());
                     throw new Exception("Incompatible backing for a VirtualDevice for nic
" + nicIndex); //FIXME Generic exceptions are bad

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e1d1a403/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
index 4513b52..1cd9d72 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java
@@ -46,6 +46,7 @@ import com.vmware.vim25.HostNetworkInfo;
 import com.vmware.vim25.HostNetworkPolicy;
 import com.vmware.vim25.HostNetworkSecurityPolicy;
 import com.vmware.vim25.HostNetworkTrafficShapingPolicy;
+import com.vmware.vim25.HostOpaqueNetworkInfo;
 import com.vmware.vim25.HostPortGroup;
 import com.vmware.vim25.HostPortGroupSpec;
 import com.vmware.vim25.HostRuntimeInfo;
@@ -62,7 +63,6 @@ import com.vmware.vim25.PropertySpec;
 import com.vmware.vim25.TraversalSpec;
 import com.vmware.vim25.VirtualMachineConfigSpec;
 import com.vmware.vim25.VirtualNicManagerNetConfig;
-
 import com.cloud.hypervisor.vmware.util.VmwareContext;
 import com.cloud.hypervisor.vmware.util.VmwareHelper;
 import com.cloud.utils.Pair;
@@ -357,6 +357,23 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost {
         return null;
     }
 
+    public boolean hasOpaqueNSXNetwork() throws Exception{
+        HostNetworkInfo netInfo = getHostNetworkInfo();
+        List<HostOpaqueNetworkInfo> opaqueNetworks = netInfo.getOpaqueNetwork();
+        if (opaqueNetworks != null){
+            for (HostOpaqueNetworkInfo opaqueNetwork : opaqueNetworks){
+                if (opaqueNetwork.getOpaqueNetworkId() != null && opaqueNetwork.getOpaqueNetworkId().equals("br-int")
+                        && opaqueNetwork.getOpaqueNetworkType() != null &&
opaqueNetwork.getOpaqueNetworkType().equals("nsx.network")){
+                    return true;
+                }
+            }
+            throw new Exception("NSX API VERSION >= 4.2 BUT br-int (nsx.network) NOT FOUND");
+        }
+        else {
+            throw new Exception("NSX API VERSION >= 4.2 BUT br-int (nsx.network) NOT FOUND");
+        }
+    }
+
     public boolean hasPortGroup(HostVirtualSwitch vSwitch, String portGroupName) throws Exception
{
         ManagedObjectReference morNetwork = getNetworkMor(portGroupName);
         if (morNetwork != null)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e1d1a403/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
index 44c6a85..4b11593 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java
@@ -43,6 +43,7 @@ import com.cloud.utils.cisco.n1kv.vsm.VsmCommand.SwitchPortMode;
 import com.cloud.utils.db.GlobalLock;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.net.NetUtils;
+import com.cloud.utils.nicira.nvp.plugin.NiciraNvpApiVersion;
 import com.vmware.vim25.AlreadyExistsFaultMsg;
 import com.vmware.vim25.BoolPolicy;
 import com.vmware.vim25.CustomFieldStringValue;
@@ -1061,12 +1062,16 @@ public class HypervisorHostHelper {
 
         boolean bWaitPortGroupReady = false;
         if (broadcastDomainType == BroadcastDomainType.Lswitch) {
-            if (!hostMo.hasPortGroup(vSwitch, networkName)) {
-                createNvpPortGroup(hostMo, vSwitch, networkName, shapingPolicy);
+            //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;
+                    bWaitPortGroupReady = true;
+                } else {
+                    bWaitPortGroupReady = false;
+                }
             }
         } else {
             if (!hostMo.hasPortGroup(vSwitch, networkName)) {
@@ -1081,20 +1086,24 @@ public class HypervisorHostHelper {
             }
         }
 
-        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);
-        }
+        ManagedObjectReference morNetwork = null;
 
-        if (createGCTag) {
-            NetworkMO networkMo = new NetworkMO(hostMo.getContext(), morNetwork);
-            networkMo.setCustomFieldValue(CustomFieldConstants.CLOUD_GC, "true");
+        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) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e1d1a403/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
index 817ce26..204b1cd 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareHelper.java
@@ -56,12 +56,12 @@ import com.vmware.vim25.VirtualE1000;
 import com.vmware.vim25.VirtualEthernetCard;
 import com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo;
 import com.vmware.vim25.VirtualEthernetCardNetworkBackingInfo;
+import com.vmware.vim25.VirtualEthernetCardOpaqueNetworkBackingInfo;
 import com.vmware.vim25.VirtualMachineConfigSpec;
 import com.vmware.vim25.VirtualMachineSnapshotTree;
 import com.vmware.vim25.VirtualPCNet32;
 import com.vmware.vim25.VirtualVmxnet2;
 import com.vmware.vim25.VirtualVmxnet3;
-
 import com.cloud.hypervisor.vmware.mo.HostMO;
 import com.cloud.hypervisor.vmware.mo.LicenseAssignmentManagerMO;
 import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType;
@@ -79,6 +79,52 @@ public class VmwareHelper {
         return deviceNumber == 7;
     }
 
+    public static VirtualDevice prepareNicOpaque(VirtualMachineMO vmMo, VirtualEthernetCardType
deviceType, String portGroupName,
+            String macAddress, int deviceNumber, int contextNumber, boolean conntected, boolean
connectOnStart) throws Exception {
+
+        assert(vmMo.getRunningHost().hasOpaqueNSXNetwork());
+
+        VirtualEthernetCard nic;
+        switch (deviceType) {
+        case E1000:
+            nic = new VirtualE1000();
+            break;
+
+        case PCNet32:
+            nic = new VirtualPCNet32();
+            break;
+
+        case Vmxnet2:
+            nic = new VirtualVmxnet2();
+            break;
+
+        case Vmxnet3:
+            nic = new VirtualVmxnet3();
+            break;
+
+        default:
+            assert (false);
+            nic = new VirtualE1000();
+        }
+
+        VirtualEthernetCardOpaqueNetworkBackingInfo nicBacking = new VirtualEthernetCardOpaqueNetworkBackingInfo();
+        nicBacking.setOpaqueNetworkId("br-int");
+        nicBacking.setOpaqueNetworkType("nsx.network");
+
+        nic.setBacking(nicBacking);
+
+        VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
+        connectInfo.setAllowGuestControl(true);
+        connectInfo.setConnected(conntected);
+        connectInfo.setStartConnected(connectOnStart);
+        nic.setAddressType("Manual");
+        nic.setConnectable(connectInfo);
+        nic.setMacAddress(macAddress);
+        nic.setUnitNumber(deviceNumber);
+        nic.setKey(-contextNumber);
+        return nic;
+    }
+
     public static VirtualDevice prepareNicDevice(VirtualMachineMO vmMo, ManagedObjectReference
morNetwork, VirtualEthernetCardType deviceType, String portGroupName,
             String macAddress, int deviceNumber, int contextNumber, boolean conntected, boolean
connectOnStart) throws Exception {
 


Mime
View raw message