Skip to content

Commit 70fbee2

Browse files
Sateesh ChodapuneediVijayendra Bhamidipati
authored andcommitted
CS-9919: Support for Nexus Swiches (Cisco Vswitches)
Updating the checks for VSM parameter validation while adding cluster. Conflicts: server/src/com/cloud/resource/ResourceManagerImpl.java
1 parent 63de97e commit 70fbee2

1 file changed

Lines changed: 65 additions & 42 deletions

File tree

‎server/src/com/cloud/resource/ResourceManagerImpl.java‎

Lines changed: 65 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -431,51 +431,74 @@ public List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws Illegal
431431
clusterId = cluster.getId();
432432
result.add(cluster);
433433

434-
if (cmd.getAddVSMFlag() != null && cmd.getAddVSMFlag().equalsIgnoreCase("true")) {
435-
434+
if (hypervisorType == HypervisorType.VMware &&
435+
Boolean.parseBoolean(_configDao.getValue(Config.VmwareUseNexusVSwitch.toString()))) {
436436
String vsmIp = cmd.getVSMIpaddress();
437-
String vsmUser = cmd.getVSMUsername();
438-
String vsmPassword = cmd.getVSMPassword();
439-
String vCenterIpaddr = cmd.getvCenterIPAddr();
440-
String vCenterDcName = cmd.getvCenterDCName();
441-
442-
if (vsmIp != null && vsmUser != null && vsmPassword != null && vCenterIpaddr != null && vCenterDcName != null) {
443-
NetconfHelper netconfClient;
444-
try {
445-
netconfClient = new NetconfHelper(vsmIp, vsmUser, vsmPassword);
446-
netconfClient.disconnect();
447-
} catch (CloudRuntimeException e) {
448-
String msg = "Invalid credentials supplied for user " + vsmUser + " for Cisco Nexus 1000v VSM at " + vsmIp;
449-
s_logger.error(msg);
450-
throw new CloudRuntimeException(msg);
451-
}
452-
// persist credentials in database
453-
CiscoNexusVSMDeviceVO vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword, vCenterIpaddr, vCenterDcName);
454-
455-
Transaction txn = Transaction.currentTxn();
456-
try {
457-
txn.start();
458-
vsm = _vsmDao.persist(vsm);
459-
txn.commit();
460-
} catch (Exception e) {
461-
txn.rollback();
462-
s_logger.error("Failed to persist VSM details to database. Exception: " + e.getMessage());
463-
throw new CloudRuntimeException(e.getMessage());
437+
String vsmUser = cmd.getVSMUsername();
438+
String vsmPassword = cmd.getVSMPassword();
439+
String vCenterIpaddr = cmd.getvCenterIPAddr();
440+
String vCenterDcName = cmd.getvCenterDCName();
441+
442+
if(vsmIp != null && vsmUser != null && vsmPassword != null) {
443+
NetconfHelper netconfClient;
444+
try {
445+
netconfClient = new NetconfHelper(vsmIp, vsmUser, vsmPassword);
446+
netconfClient.disconnect();
447+
} catch (CloudRuntimeException e) {
448+
String msg = "Invalid credentials supplied for user " + vsmUser + " for Cisco Nexus 1000v VSM at " + vsmIp;
449+
s_logger.error(msg);
450+
_clusterDao.remove(clusterId);
451+
throw new CloudRuntimeException(msg);
452+
}
453+
// persist credentials to database
454+
CiscoNexusVSMDeviceVO vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword, vCenterIpaddr, vCenterDcName);
455+
456+
Transaction txn = Transaction.currentTxn();
457+
try {
458+
txn.start();
459+
vsm = _vsmDao.persist(vsm);
460+
txn.commit();
461+
} catch (Exception e) {
462+
txn.rollback();
463+
s_logger.error("Failed to persist Cisco Nexus 1000v VSM details to database. Exception: " + e.getMessage());
464+
// Removing the cluster record which was added already because the persistence of Nexus VSM credentials has failed.
465+
_clusterDao.remove(clusterId);
466+
throw new CloudRuntimeException(e.getMessage());
467+
}
468+
469+
ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsm.getId());
470+
txn = Transaction.currentTxn();
471+
try {
472+
txn.start();
473+
_clusterVSMDao.persist(connectorObj);
474+
txn.commit();
475+
} catch (Exception e) {
476+
txn.rollback();
477+
s_logger.error("Failed to associate Cisco Nexus 1000v VSM with cluster: " + clusterName + ". Exception: " + e.getMessage());
478+
_clusterDao.remove(clusterId);
479+
throw new CloudRuntimeException(e.getMessage());
480+
}
481+
} else {
482+
String msg;
483+
msg = "The global parameter " + Config.VmwareUseNexusVSwitch.toString() +
484+
" is set to \"true\". Following mandatory parameters are not specified. ";
485+
if(vsmIp == null) {
486+
msg += "vsmipaddress: Management IP address of Cisco Nexus 1000v dvSwitch. ";
487+
}
488+
if(vsmUser == null) {
489+
msg += "vsmusername: Name of a user account with admin privileges over Cisco Nexus 1000v dvSwitch. ";
464490
}
465-
466-
ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsm.getId());
467-
txn = Transaction.currentTxn();
468-
try {
469-
txn.start();
470-
_clusterVSMDao.persist(connectorObj);
471-
txn.commit();
472-
} catch (Exception e) {
473-
txn.rollback();
474-
s_logger.error("Failed to associate VSM with cluster: " + clusterName + ". Exception: " + e.getMessage());
475-
throw new CloudRuntimeException(e.getMessage());
491+
if(vsmPassword == null) {
492+
if(vsmUser != null) {
493+
msg += "vsmpassword: Password of user account " + vsmUser + ". ";
494+
} else {
495+
msg += "vsmpassword: Password of user account with admin privileges over Cisco Nexus 1000v dvSwitch. ";
496+
}
476497
}
477-
} else {
478-
throw new CloudRuntimeException("All required parameters for VSM not specified");
498+
s_logger.error(msg);
499+
// Cleaning up the cluster record as addCluster operation failed because Nexus dvSwitch credentials are supplied.
500+
_clusterDao.remove(clusterId);
501+
throw new CloudRuntimeException(msg);
479502
}
480503
}
481504

0 commit comments

Comments
 (0)