From a387e0c77d06e627eee88c46d71f69249eba8a9f Mon Sep 17 00:00:00 2001 From: Sateesh Chodapuneedi Date: Wed, 23 May 2012 16:24:07 +0530 Subject: [PATCH] CS-9919: Support for Nexus Swiches (Cisco Vswitches) reviewed-by: Devdeep Updating the checks for VSM parameter validation while adding cluster. --- api/src/com/cloud/api/ApiConstants.java | 1 - .../com/cloud/api/commands/AddClusterCmd.java | 7 -- .../cloud/resource/ResourceManagerImpl.java | 109 +++++++++++------- 3 files changed, 66 insertions(+), 51 deletions(-) diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index 27b8ef82c6b..03d233115cd 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -353,7 +353,6 @@ public class ApiConstants { public static final String VSM_CONFIG_MODE = "vsmconfigmode"; public static final String VSM_CONFIG_STATE = "vsmconfigstate"; public static final String VSM_DEVICE_STATE = "vsmdevicestate"; - public static final String ADD_VSM_FLAG = "addvsmflag"; public enum HostDetails { all, capacity, events, stats, min; diff --git a/api/src/com/cloud/api/commands/AddClusterCmd.java b/api/src/com/cloud/api/commands/AddClusterCmd.java index 4776ee97e81..17d1b32910c 100755 --- a/api/src/com/cloud/api/commands/AddClusterCmd.java +++ b/api/src/com/cloud/api/commands/AddClusterCmd.java @@ -79,13 +79,6 @@ public class AddClusterCmd extends BaseCmd { @Parameter(name = ApiConstants.VCENTER_DC_NAME, type = CommandType.STRING, required = false, description = "the name of the vCenter Data Center the VSM associated with this cluster will serve") private String vcenterdcname; - @Parameter(name = ApiConstants.ADD_VSM_FLAG, type = CommandType.STRING, required = false, description = "flag that indicates a Cisco Nexus 1000v VSM is being associated with this cluster") - private String addVSMFlag; - - public String getAddVSMFlag() { - return addVSMFlag; - } - public String getvCenterDCName() { return vcenterdcname; } diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index c27b88f535f..631b5087bf7 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -415,51 +415,74 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma clusterId = cluster.getId(); result.add(cluster); - if (cmd.getAddVSMFlag() != null && cmd.getAddVSMFlag().equalsIgnoreCase("true")) { + if (hypervisorType == HypervisorType.VMware && + Boolean.parseBoolean(_configDao.getValue(Config.VmwareUseNexusVSwitch.toString()))) { + String vsmIp = cmd.getVSMIpaddress(); + String vsmUser = cmd.getVSMUsername(); + String vsmPassword = cmd.getVSMPassword(); + String vCenterIpaddr = cmd.getvCenterIPAddr(); + String vCenterDcName = cmd.getvCenterDCName(); - String vsmIp = cmd.getVSMIpaddress(); - String vsmUser = cmd.getVSMUsername(); - String vsmPassword = cmd.getVSMPassword(); - String vCenterIpaddr = cmd.getvCenterIPAddr(); - String vCenterDcName = cmd.getvCenterDCName(); - - if (vsmIp != null && vsmUser != null && vsmPassword != null && vCenterIpaddr != null && vCenterDcName != 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, vCenterIpaddr, vCenterDcName); - - 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(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); + _clusterDao.remove(clusterId); + throw new CloudRuntimeException(msg); + } + // persist credentials to database + CiscoNexusVSMDeviceVO vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword, vCenterIpaddr, vCenterDcName); + + Transaction txn = Transaction.currentTxn(); + try { + txn.start(); + vsm = _vsmDao.persist(vsm); + txn.commit(); + } catch (Exception e) { + txn.rollback(); + s_logger.error("Failed to persist Cisco Nexus 1000v VSM details to database. Exception: " + e.getMessage()); + // Removing the cluster record which was added already because the persistence of Nexus VSM credentials has failed. + _clusterDao.remove(clusterId); + 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 Cisco Nexus 1000v VSM with cluster: " + clusterName + ". Exception: " + e.getMessage()); + _clusterDao.remove(clusterId); + throw new CloudRuntimeException(e.getMessage()); + } } else { - throw new CloudRuntimeException("All required parameters for VSM not specified"); + String msg; + msg = "The global parameter " + Config.VmwareUseNexusVSwitch.toString() + + " is set to \"true\". Following mandatory parameters are not specified. "; + if(vsmIp == null) { + msg += "vsmipaddress: Management IP address of Cisco Nexus 1000v dvSwitch. "; + } + if(vsmUser == null) { + msg += "vsmusername: Name of a user account with admin privileges over Cisco Nexus 1000v dvSwitch. "; + } + if(vsmPassword == null) { + if(vsmUser != null) { + msg += "vsmpassword: Password of user account " + vsmUser + ". "; + } else { + msg += "vsmpassword: Password of user account with admin privileges over Cisco Nexus 1000v dvSwitch. "; + } + } + s_logger.error(msg); + // Cleaning up the cluster record as addCluster operation failed because Nexus dvSwitch credentials are supplied. + _clusterDao.remove(clusterId); + throw new CloudRuntimeException(msg); } }