CS-9919 Support for Nexus Swiches (Cisco Vswitches)

Added VSM credentials to AddClusterCmd(optonal params only).
Cleanup.

Conflicts:

	api/src/com/cloud/api/commands/AddClusterCmd.java
This commit is contained in:
Sateesh Chodapuneedi 2012-05-15 21:53:36 +05:30 committed by Vijayendra Bhamidipati
parent 9709774b4b
commit c65199cd8c
6 changed files with 215 additions and 126 deletions

View File

@ -343,6 +343,9 @@ public class ApiConstants {
public static final String VCENTER_IP_ADDRESS = "vcenteripaddr"; public static final String VCENTER_IP_ADDRESS = "vcenteripaddr";
public static final String VCENTER_DC_NAME = "vcenterdcname"; public static final String VCENTER_DC_NAME = "vcenterdcname";
public static final String CISCO_NEXUS_VSM_NAME = "vsmname"; public static final String CISCO_NEXUS_VSM_NAME = "vsmname";
public static final String VSM_USERNAME = "vsmusername";
public static final String VSM_PASSWORD = "vsmpassword";
public static final String VSM_IPADDRESS = "vsmipaddress";
public enum HostDetails { public enum HostDetails {
all, capacity, events, stats, min; all, capacity, events, stats, min;

View File

@ -10,6 +10,7 @@
// limitations under the License. // limitations under the License.
// //
// Automatically generated by addcopyright.py at 04/03/2012 // Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.api.commands; package com.cloud.api.commands;
import java.util.ArrayList; import java.util.ArrayList;
@ -52,6 +53,7 @@ public class AddClusterCmd extends BaseCmd {
private String username; private String username;
@IdentityMapper(entityTableName="data_center") @IdentityMapper(entityTableName="data_center")
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the Zone ID for the cluster") @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the Zone ID for the cluster")
private Long zoneId; private Long zoneId;
@ -64,6 +66,27 @@ public class AddClusterCmd extends BaseCmd {
@Parameter(name=ApiConstants.ALLOCATION_STATE, type=CommandType.STRING, description="Allocation state of this cluster for allocation of new resources") @Parameter(name=ApiConstants.ALLOCATION_STATE, type=CommandType.STRING, description="Allocation state of this cluster for allocation of new resources")
private String allocationState; private String allocationState;
@Parameter(name = ApiConstants.VSM_USERNAME, type = CommandType.STRING, required = false, description = "the username for the VSM associated with this cluster")
private String vsmusername;
@Parameter(name = ApiConstants.VSM_PASSWORD, type = CommandType.STRING, required = false, description = "the password for the VSM associated with this cluster")
private String vsmpassword;
@Parameter(name = ApiConstants.VSM_IPADDRESS, type = CommandType.STRING, required = false, description = "the ipaddress of the VSM associated with this cluster")
private String vsmipaddress;
public String getVSMIpaddress() {
return vsmipaddress;
}
public String getVSMPassword() {
return vsmpassword;
}
public String getVSMUsername() {
return vsmusername;
}
public String getClusterName() { public String getClusterName() {
return clusterName; return clusterName;
} }

View File

@ -1474,7 +1474,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
} }
} }
String switchUuid; String dvSwitchUuid;
ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter(); ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter();
DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor); DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor);
@ -1487,10 +1487,10 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
Pair<ManagedObjectReference, String> networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo); Pair<ManagedObjectReference, String> networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo);
ManagedObjectReference dvsMor = dataCenterMo.getDvSwitchMor(networkInfo.first()); ManagedObjectReference dvsMor = dataCenterMo.getDvSwitchMor(networkInfo.first());
switchUuid = dataCenterMo.getDvSwitchUuid(dvsMor); dvSwitchUuid = dataCenterMo.getDvSwitchUuid(dvsMor);
s_logger.info("Preparing NIC device on dvSwitch : " + switchUuid); s_logger.info("Preparing NIC device on dvSwitch : " + dvSwitchUuid);
nic = VmwareHelper.prepareNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(), nicTo.getMac(), i, i + 1, true, true); nic = VmwareHelper.prepareDvNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(), dvSwitchUuid, nicTo.getMac(), i, i + 1, true, true);
deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec(); deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
deviceConfigSpecArray[i].setDevice(nic); deviceConfigSpecArray[i].setDevice(nic);
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.add); deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.add);
@ -4035,6 +4035,15 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
_privateNetworkVSwitchName = mgr.getPrivateVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware); _privateNetworkVSwitchName = mgr.getPrivateVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware);
_publicNetworkVSwitchName = mgr.getPublicVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware); _publicNetworkVSwitchName = mgr.getPublicVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware);
_guestNetworkVSwitchName = mgr.getGuestVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware); _guestNetworkVSwitchName = mgr.getGuestVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware);
Map<String, String> vsmCredentials;
if (mgr.getNexusVSwitchGlobalParameter()) {
vsmCredentials = mgr.getNexusVSMCredentials(_guid);
if (vsmCredentials != null) {
s_logger.info("Stocking credentials while configuring resource.");
context.registerStockObject("vsmcredentials", vsmCredentials);
}
}
} catch (Exception e) { } catch (Exception e) {
s_logger.error("Unexpected Exception ", e); s_logger.error("Unexpected Exception ", e);
} }

View File

@ -745,7 +745,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
mountPoint = mount(uri.getHost() + ":" + uri.getPath(), _mountParent); mountPoint = mount(uri.getHost() + ":" + uri.getPath(), _mountParent);
if(mountPoint == null) { if(mountPoint == null) {
s_logger.error("Unable to create mount point for " + storageUrl); s_logger.error("Unable to create mount point for " + storageUrl);
throw new CloudRuntimeException("Unable to create mount point for " + storageUrl); return "/mnt/sec"; // throw new CloudRuntimeException("Unable to create mount point for " + storageUrl);
} }
_storageMounts.put(storageUrl, mountPoint); _storageMounts.put(storageUrl, mountPoint);
@ -874,24 +874,19 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
@DB @DB
public Map<String, String> getNexusVSMCredentials(String hostGuid) { public Map<String, String> getNexusVSMCredentials(String hostGuid) {
CiscoNexusVSMDeviceVO nexusVSM = null; s_logger.info("Reading credentials from DB.");
ClusterVSMMapVO vsmMapVO = null;
HostVO host = _hostDao.findByGuid(hostGuid); HostVO host = _hostDao.findByGuid(hostGuid);
if (host != null) Map<String, String> vsmCredentials = null;
vsmMapVO = _vsmMapDao.findByClusterId(host.getClusterId()); long clusterId;
if (vsmMapVO != null) if (host != null) {
nexusVSM = _nexusDao.findById(vsmMapVO.getVsmId()); clusterId = host.getClusterId();
Map<String, String> nexusVSMCredentials = new HashMap<String, String>(); s_logger.info("cluster is : " + clusterId);
if (nexusVSM != null) { vsmCredentials = getNexusVSMCredentialsByClusterId(clusterId);
nexusVSMCredentials.put("vsmip", nexusVSM.getipaddr());
nexusVSMCredentials.put("vsmusername", nexusVSM.getUserName());
nexusVSMCredentials.put("vsmpassword", nexusVSM.getPassword());
} else {
nexusVSMCredentials.put("vsmip", "10.102.125.32");
nexusVSMCredentials.put("vsmusername", "admin");
nexusVSMCredentials.put("vsmpassword", "vCenter!9");
} }
return nexusVSMCredentials; else {
s_logger.info("Found invalid host object for hostGuid : " + hostGuid);
}
return vsmCredentials;
} }
@Override @DB @Override @DB
@ -1023,17 +1018,24 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
ClusterVSMMapVO vsmMapVO = null; ClusterVSMMapVO vsmMapVO = null;
vsmMapVO = _vsmMapDao.findByClusterId(clusterId); vsmMapVO = _vsmMapDao.findByClusterId(clusterId);
if (vsmMapVO != null) long vsmId = 0;
nexusVSM = _nexusDao.findById(vsmMapVO.getVsmId()); if (vsmMapVO != null) {
vsmId = vsmMapVO.getVsmId();
s_logger.info("vsmId is " + vsmId);
nexusVSM = _nexusDao.findById(vsmId);
s_logger.info("Fetching nexus vsm credentials from database.");
}
else {
s_logger.info("Found empty vsmMapVO.");
return null;
}
Map<String, String> nexusVSMCredentials = new HashMap<String, String>(); Map<String, String> nexusVSMCredentials = new HashMap<String, String>();
if (nexusVSM != null) { if (nexusVSM != null) {
nexusVSMCredentials.put("vsmip", nexusVSM.getipaddr()); nexusVSMCredentials.put("vsmip", nexusVSM.getipaddr());
nexusVSMCredentials.put("vsmusername", nexusVSM.getUserName()); nexusVSMCredentials.put("vsmusername", nexusVSM.getUserName());
nexusVSMCredentials.put("vsmpassword", nexusVSM.getPassword()); nexusVSMCredentials.put("vsmpassword", nexusVSM.getPassword());
} else { s_logger.info(nexusVSMCredentials.toString());
nexusVSMCredentials.put("vsmip", "10.102.125.32");
nexusVSMCredentials.put("vsmusername", "admin");
nexusVSMCredentials.put("vsmpassword", "vCenter!9");
} }
return nexusVSMCredentials; return nexusVSMCredentials;
} }

View File

@ -65,11 +65,13 @@ import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.ClusterDetailsDao; import com.cloud.dc.ClusterDetailsDao;
import com.cloud.dc.ClusterVO; import com.cloud.dc.ClusterVO;
import com.cloud.dc.ClusterVSMMapVO;
import com.cloud.dc.DataCenterIpAddressVO; import com.cloud.dc.DataCenterIpAddressVO;
import com.cloud.dc.DataCenterVO; import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO; import com.cloud.dc.HostPodVO;
import com.cloud.dc.PodCluster; import com.cloud.dc.PodCluster;
import com.cloud.dc.dao.ClusterDao; import com.cloud.dc.dao.ClusterDao;
import com.cloud.dc.dao.ClusterVSMMapDao;
import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.DataCenterIpAddressDao; import com.cloud.dc.dao.DataCenterIpAddressDao;
import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.HostPodDao;
@ -92,12 +94,14 @@ import com.cloud.host.dao.HostTagsDao;
import com.cloud.hypervisor.Hypervisor; import com.cloud.hypervisor.Hypervisor;
import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.kvm.resource.KvmDummyResourceBase; import com.cloud.hypervisor.kvm.resource.KvmDummyResourceBase;
import com.cloud.network.CiscoNexusVSMDeviceVO;
import com.cloud.network.IPAddressVO; import com.cloud.network.IPAddressVO;
import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.IPAddressDao;
import com.cloud.org.Cluster; import com.cloud.org.Cluster;
import com.cloud.org.Grouping; import com.cloud.org.Grouping;
import com.cloud.org.Managed;
import com.cloud.org.Grouping.AllocationState; import com.cloud.org.Grouping.AllocationState;
import com.cloud.org.Managed;
import com.cloud.service.ServiceOfferingVO; import com.cloud.service.ServiceOfferingVO;
import com.cloud.storage.GuestOSCategoryVO; import com.cloud.storage.GuestOSCategoryVO;
import com.cloud.storage.StorageManager; import com.cloud.storage.StorageManager;
@ -123,6 +127,7 @@ import com.cloud.user.UserContext;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.utils.StringUtils; import com.cloud.utils.StringUtils;
import com.cloud.utils.UriUtils; import com.cloud.utils.UriUtils;
import com.cloud.utils.cisco.n1kv.vsm.NetconfHelper;
import com.cloud.utils.component.Adapters; import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.Inject; import com.cloud.utils.component.Inject;
import com.cloud.utils.component.Manager; import com.cloud.utils.component.Manager;
@ -167,6 +172,10 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
@Inject @Inject
protected ClusterDao _clusterDao; protected ClusterDao _clusterDao;
@Inject @Inject
protected ClusterVSMMapDao _clusterVSMDao;
@Inject
protected CiscoNexusVSMDeviceDao _vsmDao;
@Inject
protected CapacityDao _capacityDao; protected CapacityDao _capacityDao;
@Inject @Inject
protected HostDao _hostDao; protected HostDao _hostDao;
@ -311,6 +320,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
} }
@DB
@Override @Override
public List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException { public List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException {
long dcId = cmd.getZoneId(); long dcId = cmd.getZoneId();
@ -421,6 +431,47 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
clusterId = cluster.getId(); clusterId = cluster.getId();
result.add(cluster); result.add(cluster);
String vsmIp = cmd.getVSMIpaddress();
String vsmUser = cmd.getVSMUsername();
String vsmPassword = cmd.getVSMPassword();
if (vsmIp != null && vsmUser != null && vsmPassword != null) {
NetconfHelper netconfClient;
try {
netconfClient = new NetconfHelper(vsmIp, vsmUser, vsmPassword);
netconfClient.disconnect();
} catch (CloudRuntimeException e) {
String msg = "Invalid credentials supplied for user " + vsmUser + " for Cisco Nexus 1000v VSM at " + vsmIp;
s_logger.error(msg);
throw new CloudRuntimeException(msg);
}
// persist credentials in database
CiscoNexusVSMDeviceVO vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword, "", "");
Transaction txn = Transaction.currentTxn();
try {
txn.start();
vsm = _vsmDao.persist(vsm);
txn.commit();
} catch (Exception e) {
txn.rollback();
s_logger.error("Failed to persist VSM details to database. Exception: " + e.getMessage());
throw new CloudRuntimeException(e.getMessage());
}
ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsm.getId());
txn = Transaction.currentTxn();
try {
txn.start();
_clusterVSMDao.persist(connectorObj);
txn.commit();
} catch (Exception e) {
txn.rollback();
s_logger.error("Failed to associate VSM with cluster: " + clusterName + ". Exception: " + e.getMessage());
throw new CloudRuntimeException(e.getMessage());
}
}
if (clusterType == Cluster.ClusterType.CloudManaged) { if (clusterType == Cluster.ClusterType.CloudManaged) {
return result; return result;
} }
@ -432,6 +483,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
details.put("password", password); details.put("password", password);
_clusterDetailsDao.persist(cluster.getId(), details); _clusterDetailsDao.persist(cluster.getId(), details);
boolean success = false; boolean success = false;
try { try {
try { try {

View File

@ -128,7 +128,7 @@ public class HypervisorHostHelper {
} }
public static Map<String, String> getValidatedVsmCredentials(VmwareContext context) throws Exception { public static Map<String, String> getValidatedVsmCredentials(VmwareContext context) throws Exception {
Map<String, String> vsmCredentials = context.getStockObject("vsmcredentials"); Map<String, String> vsmCredentials = context.getStockObject("vsmcredentials");
String msg; String msg;
if(vsmCredentials == null || vsmCredentials.size() != 3) { if(vsmCredentials == null || vsmCredentials.size() != 3) {
msg = "Failed to retrieve required credentials of Nexus VSM from database."; msg = "Failed to retrieve required credentials of Nexus VSM from database.";