mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CS-9919 Support for Nexus Swiches (Cisco Vswitches)
Description: Retreving physical network configuration from database. Passing configuration down to resource. Cleanup. Conflicts: core/src/com/cloud/hypervisor/vmware/manager/VmwareManager.java server/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java
This commit is contained in:
parent
8d1b9c2477
commit
b6687faf89
@ -16,7 +16,6 @@ import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
//import com.cloud.cluster.CheckPointManager;
|
||||
import com.cloud.hypervisor.vmware.mo.HostMO;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.cloud.utils.Pair;
|
||||
@ -62,4 +61,8 @@ public interface VmwareManager {
|
||||
void endExclusiveOperation();
|
||||
|
||||
Map<String, String> getNexusVSMCredentials(String hostGuid);
|
||||
|
||||
boolean getNexusVSwitchGlobalParameter();
|
||||
|
||||
Map<String, String> getNexusVSMCredentialsByClusterId(Long clusterId);
|
||||
}
|
||||
|
||||
@ -61,7 +61,6 @@ import com.cloud.hypervisor.vmware.manager.VmwareStorageMount;
|
||||
import com.cloud.hypervisor.vmware.mo.DiskControllerType;
|
||||
import com.cloud.hypervisor.vmware.mo.HostFirewallSystemMO;
|
||||
import com.cloud.hypervisor.vmware.mo.HostMO;
|
||||
import com.cloud.hypervisor.vmware.mo.HostVirtualNicType;
|
||||
import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper;
|
||||
import com.cloud.hypervisor.vmware.mo.TaskMO;
|
||||
import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType;
|
||||
@ -69,6 +68,7 @@ import com.cloud.hypervisor.vmware.mo.VmwareHostType;
|
||||
import com.cloud.hypervisor.vmware.resource.SshHelper;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.cloud.network.CiscoNexusVSMDeviceVO;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
|
||||
import com.cloud.network.router.VirtualNetworkApplianceManager;
|
||||
import com.cloud.org.Cluster.ClusterType;
|
||||
@ -91,7 +91,6 @@ import com.cloud.utils.script.Script;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.google.gson.Gson;
|
||||
import com.vmware.apputils.vim25.ServiceUtil;
|
||||
import com.vmware.vim25.AboutInfo;
|
||||
import com.vmware.vim25.HostConnectSpec;
|
||||
import com.vmware.vim25.HostPortGroupSpec;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
@ -110,6 +109,8 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
||||
private String _instance;
|
||||
|
||||
@Inject AgentManager _agentMgr;
|
||||
@Inject
|
||||
protected NetworkManager _netMgr;
|
||||
@Inject HostDao _hostDao;
|
||||
@Inject ClusterDao _clusterDao;
|
||||
@Inject ClusterDetailsDao _clusterDetailsDao;
|
||||
@ -132,7 +133,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
||||
String _privateNetworkVSwitchType;
|
||||
String _publicNetworkVSwitchType;
|
||||
String _guestNetworkVSwitchType;
|
||||
Boolean _nexusVSwitchActive;
|
||||
boolean _nexusVSwitchActive;
|
||||
String _serviceConsoleName;
|
||||
String _managemetPortGroupName;
|
||||
String _defaultSystemVmNicAdapterType = VirtualEthernetCardType.E1000.toString();
|
||||
@ -358,6 +359,10 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
||||
return _name;
|
||||
}
|
||||
|
||||
public boolean getNexusVSwitchGlobalParameter() {
|
||||
return _nexusVSwitchActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String composeWorkerName() {
|
||||
return UUID.randomUUID().toString().replace("-", "");
|
||||
@ -367,6 +372,13 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
||||
public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceContext, long dcId, Long podId, Long clusterId,
|
||||
String hostInventoryPath) throws Exception {
|
||||
ManagedObjectReference mor = serviceContext.getHostMorByPath(hostInventoryPath);
|
||||
String privateTrafficLabel = null;
|
||||
if (_nexusVSwitchActive) {
|
||||
privateTrafficLabel = serviceContext.getStockObject("privateTrafficLabel");
|
||||
if (privateTrafficLabel == null) {
|
||||
privateTrafficLabel = _privateNetworkVSwitchName;
|
||||
}
|
||||
}
|
||||
if(mor != null) {
|
||||
List<ManagedObjectReference> returnedHostList = new ArrayList<ManagedObjectReference>();
|
||||
|
||||
@ -397,7 +409,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
||||
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
||||
}
|
||||
else {
|
||||
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000);
|
||||
HypervisorHostHelper.prepareNetwork(privateTrafficLabel, "cloud.private", hostMo, vlanId, null, null, 180000);
|
||||
}
|
||||
returnedHostList.add(hosts[0]);
|
||||
return returnedHostList;
|
||||
@ -435,7 +447,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
||||
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
||||
}
|
||||
else {
|
||||
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000);
|
||||
HypervisorHostHelper.prepareNetwork(privateTrafficLabel, "cloud.private", hostMo, vlanId, null, null, 180000);
|
||||
}
|
||||
returnedHostList.add(morHost);
|
||||
}
|
||||
@ -464,7 +476,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
||||
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
||||
}
|
||||
else {
|
||||
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000);
|
||||
HypervisorHostHelper.prepareNetwork(privateTrafficLabel, "cloud.private", hostMo, vlanId, null, null, 180000);
|
||||
}
|
||||
returnedHostList.add(mor);
|
||||
return returnedHostList;
|
||||
@ -962,4 +974,17 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
||||
public int getRouterExtraPublicNics() {
|
||||
return this._routerExtraPublicNics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getNexusVSMCredentialsByClusterId(Long clusterId) {
|
||||
ClusterVSMMapVO vsmMapVO = _vsmMapDao.findByClusterId(clusterId);
|
||||
CiscoNexusVSMDeviceVO nexusVSM = _nexusDao.findById(vsmMapVO.getVsmId());
|
||||
if (nexusVSM == null)
|
||||
return null;
|
||||
Map<String, String> nexusVSMCredentials = new HashMap<String, String>();
|
||||
nexusVSMCredentials.put("vsmip", nexusVSM.getipaddr());
|
||||
nexusVSMCredentials.put("vsmusername", nexusVSM.getUserName());
|
||||
nexusVSMCredentials.put("vsmpassword", nexusVSM.getPassword());
|
||||
return nexusVSMCredentials;
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
|
||||
package com.cloud.hypervisor.vmware;
|
||||
|
||||
import java.net.URI;
|
||||
@ -43,6 +44,7 @@ import com.cloud.hypervisor.vmware.mo.HostMO;
|
||||
import com.cloud.hypervisor.vmware.resource.VmwareContextFactory;
|
||||
import com.cloud.hypervisor.vmware.resource.VmwareResource;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
|
||||
import com.cloud.resource.Discoverer;
|
||||
import com.cloud.resource.DiscovererBase;
|
||||
@ -50,7 +52,6 @@ import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.resource.ResourceStateAdapter;
|
||||
import com.cloud.resource.ServerResource;
|
||||
import com.cloud.resource.UnableDeleteHostException;
|
||||
import com.cloud.resource.ResourceStateAdapter.DeleteHostAnswer;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.Storage.TemplateType;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
@ -75,6 +76,8 @@ public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer
|
||||
@Inject ResourceManager _resourceMgr;
|
||||
|
||||
@Inject CiscoNexusVSMDeviceDao _nexusDao;
|
||||
@Inject
|
||||
NetworkManager _netmgr;
|
||||
|
||||
@Override
|
||||
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url,
|
||||
@ -103,11 +106,38 @@ public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer
|
||||
throw new DiscoveredWithErrorException(msg);
|
||||
}
|
||||
|
||||
String privateTrafficLabel = null;
|
||||
Map<String, String> vsmCredentials = null;
|
||||
if (_vmwareMgr.getNexusVSwitchGlobalParameter()) {
|
||||
// Get physical network label
|
||||
privateTrafficLabel = _netmgr.getDefaultManagementTrafficLabel(dcId, HypervisorType.VMware);
|
||||
if (privateTrafficLabel != null) {
|
||||
s_logger.info("Detected private network label : " + privateTrafficLabel);
|
||||
}
|
||||
// Get credentials
|
||||
vsmCredentials = _vmwareMgr.getNexusVSMCredentialsByClusterId(clusterId);
|
||||
}
|
||||
|
||||
VmwareContext context = null;
|
||||
try {
|
||||
context = VmwareContextFactory.create(url.getHost(), username, password);
|
||||
if (_vmwareMgr.getNexusVSwitchGlobalParameter()) {
|
||||
// Get physical network label
|
||||
privateTrafficLabel = _netmgr.getDefaultManagementTrafficLabel(dcId, HypervisorType.VMware);
|
||||
if (privateTrafficLabel != null) {
|
||||
context.registerStockObject("privateTrafficLabel", privateTrafficLabel);
|
||||
s_logger.info("Detected private network label : " + privateTrafficLabel);
|
||||
}
|
||||
// Get credentials
|
||||
vsmCredentials = _vmwareMgr.getNexusVSMCredentialsByClusterId(clusterId);
|
||||
if (vsmCredentials != null)
|
||||
context.registerStockObject("vsmCredentials", vsmCredentials);
|
||||
}
|
||||
List<ManagedObjectReference> morHosts = _vmwareMgr.addHostToPodCluster(context, dcId, podId, clusterId,
|
||||
URLDecoder.decode(url.getPath()));
|
||||
if (privateTrafficLabel != null)
|
||||
context.uregisterStockObject("privateTrafficLabel");
|
||||
|
||||
if(morHosts == null) {
|
||||
s_logger.error("Unable to find host or cluster based on url: " + URLDecoder.decode(url.getPath()));
|
||||
return null;
|
||||
@ -159,6 +189,9 @@ public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer
|
||||
params.put("pod", Long.toString(podId));
|
||||
params.put("cluster", Long.toString(clusterId));
|
||||
params.put("guid", guid);
|
||||
if (privateTrafficLabel != null) {
|
||||
params.put("private.network.vswitch.name", privateTrafficLabel);
|
||||
}
|
||||
|
||||
VmwareResource resource = new VmwareResource();
|
||||
try {
|
||||
|
||||
@ -20,7 +20,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mortbay.jetty.servlet.Context;
|
||||
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareHelper;
|
||||
@ -35,10 +34,8 @@ import com.cloud.utils.db.GlobalLock;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.vmware.vim25.BoolPolicy;
|
||||
import com.vmware.vim25.DVPortgroupConfigSpec;
|
||||
import com.vmware.vim25.DVSTrafficShapingPolicy;
|
||||
//import com.vmware.vim25.DistributedVirtualSwitchKeyedOpaqueBlob;
|
||||
import com.vmware.vim25.DVPortgroupConfigInfo;
|
||||
import com.vmware.vim25.DVSTrafficShapingPolicy;
|
||||
import com.vmware.vim25.DynamicProperty;
|
||||
import com.vmware.vim25.HostNetworkTrafficShapingPolicy;
|
||||
import com.vmware.vim25.HostPortGroupSpec;
|
||||
@ -130,7 +127,7 @@ public class HypervisorHostHelper {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static Map<String, String> getValidatedVsmCredentials(VmwareContext context) throws Exception, CloudRuntimeException {
|
||||
public static Map<String, String> getValidatedVsmCredentials(VmwareContext context) throws Exception {
|
||||
Map<String, String> vsmCredentials = context.getStockObject("vsmcredentials");
|
||||
String msg;
|
||||
if(vsmCredentials == null || vsmCredentials.size() != 3) {
|
||||
@ -145,12 +142,12 @@ public class HypervisorHostHelper {
|
||||
if(vsmIp == null || vsmIp.isEmpty() || vsmUserName == null || vsmUserName.isEmpty() || vsmPassword == null || vsmPassword.isEmpty()) {
|
||||
msg = "Detected invalid credentials for Nexus VSM";
|
||||
s_logger.error(msg);
|
||||
throw new CloudRuntimeException(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
return vsmCredentials;
|
||||
}
|
||||
|
||||
public static void createPortProfile(VmwareContext context, String ethPortProfileName, String networkName, Integer vid, Integer networkRateMbps) throws Exception, CloudRuntimeException {
|
||||
public static void createPortProfile(VmwareContext context, String ethPortProfileName, String networkName, Integer vid, Integer networkRateMbps) throws Exception {
|
||||
Map<String, String> vsmCredentials = getValidatedVsmCredentials(context);
|
||||
String vsmIp = vsmCredentials.get("vsmip");
|
||||
String vsmUserName = vsmCredentials.get("vsmusername");
|
||||
@ -187,7 +184,7 @@ public class HypervisorHostHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static void updatePortProfile(VmwareContext context, String ethPortProfileName, Integer vid, Integer networkRateMbps) throws CloudRuntimeException, Exception {
|
||||
public static void updatePortProfile(VmwareContext context, String ethPortProfileName, Integer vid, Integer networkRateMbps) throws Exception {
|
||||
Map<String, String> vsmCredentials = getValidatedVsmCredentials(context);
|
||||
String vsmIp = vsmCredentials.get("vsmip");
|
||||
String vsmUserName = vsmCredentials.get("vsmusername");
|
||||
@ -218,7 +215,7 @@ public class HypervisorHostHelper {
|
||||
|
||||
public static Pair<ManagedObjectReference, String> prepareNetwork(String ethPortProfileName, String namePrefix,
|
||||
HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps,
|
||||
long timeOutMs) throws Exception, CloudRuntimeException {
|
||||
long timeOutMs) throws Exception {
|
||||
ManagedObjectReference morNetwork = null;
|
||||
VmwareContext context = hostMo.getContext();
|
||||
ManagedObjectReference dcMor = hostMo.getHyperHostDatacenter();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user