use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.
the class MDSDialog method copyRunningConfigToStartupFabric.
/**
* Does a fabric wide copy running-configuration to startup-configuration.
* If for some reason this fails, then tries a local copy running-config startup-configuration as a fallback.
*
* @throws NetworkDeviceControllerException
*/
public void copyRunningConfigToStartupFabric() throws NetworkDeviceControllerException {
_log.info(MessageFormat.format("Host: {0}, Port: {1} - BEGIN copyRunningConfigToStartupFabric", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort() }));
if (!inConfigMode) {
throw NetworkDeviceControllerException.exceptions.mdsDeviceNotInConfigMode();
}
if (lastPrompt != SSHPrompt.MDS_CONFIG) {
throw NetworkDeviceControllerException.exceptions.mdsUnexpectedLastPrompt(lastPrompt.toString(), SSHPrompt.MDS_CONFIG.toString());
}
SSHPrompt[] prompts = { SSHPrompt.MDS_CONFIG, SSHPrompt.MDS_CONTINUE_QUERY };
StringBuilder buf = new StringBuilder();
// copy running-config
String payload = MDSDialogProperties.getString("MDSDialog.copyRunningConfigToStartupFabric.cmd");
// startup-config fabric\n
lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
if (lastPrompt == SSHPrompt.MDS_CONTINUE_QUERY) {
// y\n
payload = MDSDialogProperties.getString("MDSDialog.copyRunningConfigToStartupFabric.y.cmd");
SSHPrompt[] prompts2 = { SSHPrompt.MDS_CONFIG };
buf = new StringBuilder();
lastPrompt = sendWaitFor(payload, defaultTimeout, prompts2, buf);
String[] lines = getLines(buf);
String[] regex = { // .*100%.*
MDSDialogProperties.getString("MDSDialog.copyRunningConfigToStartupFabric.100Percent.match") };
String[] groups = new String[2];
boolean done = false;
for (String line : lines) {
int index = match(line, regex, groups);
switch(index) {
case // .*100%.*
0:
done = true;
break;
}
}
if (!done) {
_log.error("Copy running-config to startup-config fabric did not complete... trying non-fabric version");
copyRunningConfigToStartup();
}
}
_log.info(MessageFormat.format("Host: {0}, Port: {1} - END copyRunningConfigToStartupFabric", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort() }));
}
use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.
the class MDSDialog method showVersion.
/**
* Returns the device type and software version
*
* @return [0] device type, [1] software version
*/
public String[] showVersion() throws NetworkDeviceControllerException {
String[] returnVal = new String[2];
SSHPrompt[] prompts = { SSHPrompt.MDS_POUND, SSHPrompt.MDS_GREATER_THAN };
StringBuilder buf = new StringBuilder();
SSHPrompt prompt = sendWaitFor(// show version\n
MDSDialogProperties.getString("MDSDialog.showVersion.cmd"), 10000, prompts, buf);
String[] lines = getLines(buf);
String[] regex = { // .*system:\\s+version +(\\S+).*
MDSDialogProperties.getString("MDSDialog.showVersion.version.match"), // .*[Cc][Ii][Ss][Cc][Oo]\\s+(MDS\\s+\\S+).*
MDSDialogProperties.getString("MDSDialog.showVersion.MDS.match"), // *[Cc][Ii][Ss][Cc][Oo]\\s+(Nexus\\S+).*
MDSDialogProperties.getString("MDSDialog.showVersion.Nexus.match") };
String[] groups = new String[2];
for (String line : lines) {
int index = match(line, regex, groups);
switch(index) {
case // software version number
0:
returnVal[1] = groups[0];
break;
case // hardware type
1:
// MDS
returnVal[0] = groups[0];
break;
case 2:
// Nexus
returnVal[0] = groups[0];
break;
}
}
return returnVal;
}
use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.
the class MDSDialog method showVsan.
/**
* Returns a map of vsan id to Vsan object using "show vsans" and
* calling show zonesets and show zones.
*
* @param includeZonesets If true, the Vsan structures include zonesets and their descendents.
* @return a Map of Vsan ID to Vsan structure
*/
public Map<Integer, Vsan> showVsan(boolean includeZonesets) throws NetworkDeviceControllerException {
Map<Integer, Vsan> vsans = new HashMap<Integer, Vsan>();
SSHPrompt[] prompts = { SSHPrompt.POUND, SSHPrompt.GREATER_THAN };
StringBuilder buf = new StringBuilder();
// show vsan\n
sendWaitFor(MDSDialogProperties.getString("MDSDialog.showVsan.cmd"), defaultTimeout, prompts, buf);
String[] lines = getLines(buf);
Vsan vsan = null;
Integer vsanId = null;
String[] regex = { // vsan\\s+(\\d+).*
MDSDialogProperties.getString("MDSDialog.showVsan.vsan.match"), // \\s+name:\\s*(\\w+|\\w[\\w\\s]*\\w)\\s+state:(\\w+).*
MDSDialogProperties.getString("MDSDialog.showVsan.namestate.match") };
String[] groups = new String[10];
for (String line : lines) {
int index = match(line, regex, groups);
switch(index) {
case 0:
// Save the vsan id.
vsanId = new Integer(groups[0]);
break;
case 1:
String vsanName = groups[0];
vsan = new Vsan(vsanId.toString(), vsanName);
vsans.put(vsanId, vsan);
if (includeZonesets) {
List<Zoneset> zonesets = showZoneset(vsanId, false, null, false, false);
for (Zoneset zs : zonesets) {
if (zs.getActive()) {
vsan.setActiveZoneset(zs);
} else {
vsan.getInactiveZonesets().add(zs);
}
}
}
vsanId = null;
break;
}
}
return vsans;
}
use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.
the class MDSDialog method ivrZonesetMember.
/**
* member {ivrZoneName}
*
* @param pwwn
* @param vsanId
* @throws NetworkDeviceControllerException
*/
public void ivrZonesetMember(String ivrZonename, boolean isRemove) throws NetworkDeviceControllerException {
_log.info(MessageFormat.format("Host: {0}, Port: {1} - Add or remove ivrZonesetMember: {2} - Remove {3}", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort(), ivrZonename, isRemove }));
SSHPrompt[] prompts = { SSHPrompt.MDS_CONFIG_IVR_ZONESET };
if (!inConfigMode) {
throw NetworkDeviceControllerException.exceptions.mdsDeviceNotInConfigMode();
}
if (!Arrays.asList(prompts).contains(lastPrompt)) {
String message = Arrays.asList(prompts).toString();
throw NetworkDeviceControllerException.exceptions.mdsUnexpectedLastPrompt(lastPrompt.toString(), message);
}
// no
String noString = isRemove ? MDSDialogProperties.getString("MDSDialog.zoneNameVsan.no.cmd") : "";
StringBuilder buf = new StringBuilder();
// =member
String payload = MessageFormat.format(noString + MDSDialogProperties.getString("MDSDialog.ivr.zonesetMember.cmd"), ivrZonename);
// {zonename}
boolean retryNeeded = true;
for (int retryCount = 0; retryCount < sessionLockRetryMax && retryNeeded; retryCount++) {
lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
String[] lines = getLines(buf);
for (String line : lines) {
// throw exception only when trying to get into config mode, but not found
if (line.indexOf(MDSDialogProperties.getString("MDSDialog.ivr.zone.not.found")) >= 0 && !isRemove) {
throw new NetworkDeviceControllerException(line + ": " + ivrZonename);
}
}
retryNeeded = checkForEnhancedZoneSession(lines, retryCount);
}
}
use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.
the class MDSDialog method isSessionInProgress.
// /**
// * Returns a boolean indicating if enhanced zoning is enabled.
// * @param vsanId
// * @return
// * @throws NetworkControllerException
// */
// public boolean isEnhancedZoningEnabled(Integer vsanId) throws NetworkControllerException {
// assert(inConfigMode == false);
// SSHPrompt[] prompts = { SSHPrompt.MDS_POUND };
// StringBuilder buf = new StringBuilder();
// String payload = MessageFormat.format("show zone status vsan {0}\n", vsanId.toString());
// lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
// String[] lines = getLines(buf);
// String[] regex = {
// "\\s*mode:\\s+(\\w+).*"
// };
// String[] groups = new String[10];
// boolean enhanced = false;
// for (String line : lines) {
// int index = match(line, regex, groups);
// switch(index) {
// case 0:
// if (groups[0].equals("enhanced")) {
// enhanced = true;
// }
// }
// }
// return enhanced;
// }
/**
* Returns a boolean indicating if enhanced zoning is enabled.
* Also logs a message if enhanced zoning is not enabled.
*
* @param vsanId
* @return
* @throws NetworkDeviceControllerException
*/
public boolean isSessionInProgress(Integer vsanId) throws NetworkDeviceControllerException {
if (inConfigMode) {
throw NetworkDeviceControllerException.exceptions.mdsDeviceInConfigMode();
}
SSHPrompt[] prompts = { SSHPrompt.MDS_POUND };
StringBuilder buf = new StringBuilder();
String payload = MessageFormat.format(MDSDialogProperties.getString("MDSDialog.isSessionInProgress.showzonestatus.cmd"), // show zone status vsan {0}\n
vsanId.toString());
lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
String[] lines = getLines(buf);
String[] regex = { // \\s*session:\\s+(\\w+).*
MDSDialogProperties.getString("MDSDialog.isSessionInProgress.session.match"), // \\s*mode:\\s+(\\w+).*
MDSDialogProperties.getString("MDSDialog.isSessionInProgress.mode.match") };
String[] groups = new String[10];
boolean session = false;
boolean enhanced = false;
for (String line : lines) {
int index = match(line, regex, groups);
switch(index) {
case 0:
if (false == groups[0].equals(MDSDialogProperties.getString("MDSDialog.isSessionInProgress.none"))) {
// none
session = true;
}
case 1:
if (groups[0].equals(MDSDialogProperties.getString("MDSDialog.isSessionInProgress.enhanced"))) {
// enhanced
enhanced = true;
}
}
}
if (!enhanced) {
_log.warn("Enhanced zoning not enabled: " + vsanId);
}
return session;
}
Aggregations