use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.
the class MDSDialog method waitForIvrZonesetActivate.
/**
* Wait for activation finish processing
*
* @throws NetworkDeviceControllerException
*/
public void waitForIvrZonesetActivate() throws NetworkDeviceControllerException {
_log.info(MessageFormat.format("Host: {0}, Port: {1} - BEGIN waitForIvrZonesetActivate", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort() }));
_log.info("Waiting for ivr zoneset to activate");
SSHPrompt[] prompts = { SSHPrompt.MDS_POUND, SSHPrompt.MDS_GREATER_THAN, SSHPrompt.MDS_CONFIG, SSHPrompt.MDS_CONFIG_IVR_ZONE, SSHPrompt.MDS_CONFIG_IVR_ZONESET };
StringBuilder buf = new StringBuilder();
// show zone status vsan {0}\n
String payload = MDSDialogProperties.getString("MDSDialog.ivr.show.zoneset.status.cmd");
String[] regex = { // ^State:\\s+activating*
MDSDialogProperties.getString("MDSDialog.ivr.waitForZoneset.activate.inprogress.match"), // ^State:\\s+activation success*
MDSDialogProperties.getString("MDSDialog.ivr.waitForZoneset.activate.success.match") };
String[] groups = new String[2];
boolean completed = false;
for (int i = 0; i < defaultTimeout && completed == false; i += 1000) {
try {
// sleep one second
Thread.sleep(1000);
} catch (InterruptedException ex) {
_log.warn(ex.getLocalizedMessage());
}
lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
String[] lines = getLines(buf);
for (String line : lines) {
int index = match(line, regex, groups);
switch(index) {
case 0:
completed = false;
break;
case 1:
completed = true;
break;
case 2:
throw new NetworkDeviceControllerException("ivr zoneset activate Commit failed: " + line);
}
if (completed) {
break;
}
}
}
_log.info(MessageFormat.format("Host: {0}, Port: {1} -DONE waitForIvrZonesetActivate", 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 showFabricZones.
/**
* Collect the Zonesets, and their Zones, members for a specified Vsan ID.
*
* @param vsanId -- Integer vsanId
* @return a list of Zones
*/
public List<Zone> showFabricZones(Integer vsanId) throws NetworkDeviceControllerException {
List<Zone> zones = new ArrayList<Zone>();
SSHPrompt[] prompts = { SSHPrompt.POUND, SSHPrompt.GREATER_THAN };
StringBuilder buf = new StringBuilder();
sendWaitFor(MDSDialogProperties.getString("MDSDialog.showFabricZones.cmd") + vsanId.toString() + "\n", defaultTimeout, prompts, buf);
String[] lines = getLines(buf);
Zone zone = null;
String[] regex = { MDSDialogProperties.getString("MDSDialog.showZoneset.zonename.match"), MDSDialogProperties.getString("MDSDialog.showZoneset.pwwn.match"), MDSDialogProperties.getString("MDSDialog.showZoneset.deviceAlias.match") };
Map<String, String> aliasDatabase = showDeviceAliasDatabase();
String[] groups = new String[10];
for (String line : lines) {
ZoneMember member = null;
int index = match(line, regex, groups);
switch(index) {
case 0:
if (!vsanId.toString().equals(groups[1])) {
String message = "VSAN " + vsanId.toString() + " not the expected VSAN " + groups[1];
throw NetworkDeviceControllerException.exceptions.mdsUnexpectedDeviceState(message);
}
zone = new Zone(groups[0]);
zones.add(zone);
break;
case 1:
case 2:
member = new ZoneMember(ZoneMember.ConnectivityMemberType.WWPN);
zone.getMembers().add(member);
if (index == 1) {
member.setAddress(groups[0]);
// set alias field as well
if (groups.length >= 2 && groups[1] != null) {
member.setAlias(groups[1].replace("[", "").replace("]", ""));
}
} else if (index == 2) {
// match "device-alas <alias>" regex
// device alias
member.setAlias(groups[0]);
// indicate member is an alias type
member.setAliasType(true);
String pwwn = getDeviceAliasPwwn(groups[0], aliasDatabase);
if (!StringUtils.isEmpty(pwwn)) {
member.setAddress(pwwn);
}
}
break;
}
}
return zones;
}
use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.
the class MDSDialog method ivrZoneName.
/**
* Configure ivr zone or zone set depended on isZoneset flag.
*
* @param isZoneset indicate to config ivr zoneset, otherwise ivr zone
* @param zoneName
* @param isActivate make zoneset active
* @param isRemove remove zoneset
* @throws NetworkDeviceControllerException
*/
private void ivrZoneName(boolean isZoneset, String zoneName, boolean isActivate, boolean isRemove) throws NetworkDeviceControllerException {
_log.info(MessageFormat.format("Host: {0}, Port: {1} - BEGIN Configure {2}: {3} - Remove {4}", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort(), isZoneset ? "zoneset" : "zone", zoneName, isRemove }));
if (!inConfigMode) {
throw NetworkDeviceControllerException.exceptions.mdsDeviceNotInConfigMode();
}
SSHPrompt[] promptsToCheck = { SSHPrompt.MDS_CONFIG, SSHPrompt.MDS_CONFIG_IVR_ZONE, SSHPrompt.MDS_CONFIG_IVR_ZONESET };
if (!Arrays.asList(promptsToCheck).contains(lastPrompt)) {
String message = Arrays.asList(promptsToCheck).toString();
throw NetworkDeviceControllerException.exceptions.mdsUnexpectedLastPrompt(lastPrompt.toString(), message);
}
// cannot be activate and remove at the same time
if (isActivate && isRemove) {
String message = "cannot be activate and remove at the same time";
throw NetworkDeviceControllerException.exceptions.mdsUnexpectedDeviceState(message);
}
String ivrZoneNameResourceKey = "MDSDialog.ivr.zoneName.cmd";
if (isZoneset) {
// only zoneset can be activate
ivrZoneNameResourceKey = isActivate ? "MDSDialog.ivr.zonesetName.activate.cmd" : "MDSDialog.ivr.zonesetName.cmd";
}
SSHPrompt[] prompts = { isZoneset ? SSHPrompt.MDS_CONFIG_IVR_ZONESET : SSHPrompt.MDS_CONFIG_IVR_ZONE, SSHPrompt.MDS_CONFIG };
// no
String noString = isRemove ? MDSDialogProperties.getString("MDSDialog.zoneNameVsan.no.cmd") : "";
StringBuilder buf = new StringBuilder();
String payload = MessageFormat.format(noString + MDSDialogProperties.getString(ivrZoneNameResourceKey), zoneName);
boolean retryNeeded = true;
boolean error = false;
String errorMessage = MDSDialogProperties.getString("MDSDialog.ivr.waitForZoneset.activate.error.atLeast2Members");
for (int retryCount = 0; retryCount < sessionLockRetryMax && retryNeeded; retryCount++) {
lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
String[] lines = getLines(buf);
retryNeeded = checkForIvrZoneSession(lines, retryCount);
if (isActivate && isZoneset) {
for (String line : lines) {
error = line.indexOf(errorMessage) >= 0;
if (error) {
break;
}
}
}
}
// verify for appropriate prompt
if (isZoneset) {
SSHPrompt[] morePromptsToCheck = { SSHPrompt.MDS_CONFIG_IVR_ZONESET, SSHPrompt.MDS_CONFIG };
if (!Arrays.asList(morePromptsToCheck).contains(lastPrompt)) {
String message = Arrays.asList(morePromptsToCheck).toString();
throw NetworkDeviceControllerException.exceptions.mdsUnexpectedLastPrompt(lastPrompt.toString(), message);
}
} else {
SSHPrompt[] morePromptsToCheck = { SSHPrompt.MDS_CONFIG_IVR_ZONE, SSHPrompt.MDS_CONFIG };
if (!Arrays.asList(morePromptsToCheck).contains(lastPrompt)) {
String message = Arrays.asList(morePromptsToCheck).toString();
throw NetworkDeviceControllerException.exceptions.mdsUnexpectedLastPrompt(lastPrompt.toString(), message);
}
}
if (error) {
throw new NetworkDeviceControllerException(errorMessage + ": " + zoneName);
}
_log.info(MessageFormat.format("Host: {0}, Port: {1} - END Configure {2}: {3} - Remove {4}", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort(), isZoneset ? "zoneset" : "zone", zoneName, isRemove }));
}
use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.
the class MDSDialog method showZone.
/**
* Get Zone and its members for given zone name. Besure to resolve device alias if present.
*
* @param zoneName
* @param aliasDatabase
* @param excludeAliases
* @return
* @throws NetworkDeviceControllerException
*/
private Zone showZone(String zoneName, Map<String, String> aliasDatabase, boolean excludeAliases) throws NetworkDeviceControllerException {
Zone zone = new Zone(zoneName);
SSHPrompt[] prompts = { SSHPrompt.POUND, SSHPrompt.GREATER_THAN };
StringBuilder buf = new StringBuilder();
String payload = MessageFormat.format(MDSDialogProperties.getString("MDSDialog.showZone.name.cmd"), zoneName);
sendWaitFor(payload, defaultTimeout, prompts, buf);
String[] lines = getLines(buf);
ZoneMember member = null;
String[] regex = { // \\s*pwwn ([0-9a-fA-F:]+)\\s*(\\[\\S+\\])?
MDSDialogProperties.getString("MDSDialog.showZoneset.pwwn.match"), // \\s*device-alias \\s*(\\S+)\\s*
MDSDialogProperties.getString("MDSDialog.showZoneset.deviceAlias.match") };
String[] groups = new String[10];
Map<String, String> myAliasDatabase = aliasDatabase == null ? showDeviceAliasDatabase() : aliasDatabase;
if (excludeAliases) {
_log.info("Excluding aliases while getting zone members");
}
for (String line : lines) {
int index = match(line, regex, groups);
member = new ZoneMember(ZoneMember.ConnectivityMemberType.WWPN);
switch(index) {
case 0:
// set wwn id
member.setAddress(groups[0]);
// set alias field as well
if (!excludeAliases && groups.length >= 2 && groups[1] != null) {
member.setAlias(groups[1].replace("[", "").replace("]", ""));
}
zone.getMembers().add(member);
break;
case 1:
// matched "device-alias <alias>
if (!excludeAliases) {
// set alias
member.setAlias(groups[0]);
// indicate member type of alias
member.setAliasType(true);
}
String pwwn = getDeviceAliasPwwn(groups[0], myAliasDatabase);
if (!StringUtils.isEmpty(pwwn)) {
member.setAddress(pwwn);
}
zone.getMembers().add(member);
break;
}
}
return zone;
}
use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.
the class MDSDialog method waitForZoneCommit.
/**
* Waits for a zone commit to complete. Checks for in-progress and failed status.
*
* @param vsanId
* @throws NetworkDeviceControllerException
*/
public void waitForZoneCommit(Integer vsanId) throws NetworkDeviceControllerException {
_log.info(MessageFormat.format("Host: {0}, Port: {1} - BEGIN waitForZoneCommit", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort() }));
SSHPrompt[] prompts = { SSHPrompt.MDS_POUND, SSHPrompt.MDS_CONFIG };
StringBuilder buf = new StringBuilder();
String payload = MessageFormat.format(MDSDialogProperties.getString("MDSDialog.waitForZoneCommit.showzonestatusvsan.cmd"), // show zone status vsan {0}\n
vsanId.toString());
String[] regex = { // ^Status:\\s+Commit in progress.*
MDSDialogProperties.getString("MDSDialog.waitForZoneCommit.inprogress.match"), // ^Status:\\s+Commit complete.*
MDSDialogProperties.getString("MDSDialog.waitForZoneCommit.complete.match"), // ^Status:\\s+Operation failed.*
MDSDialogProperties.getString("MDSDialog.waitForZoneCommit.failed.match") };
String[] groups = new String[2];
/*
* compute retry attempts based on the configured timeout.
* will retry in every SLEEP_TIME_PER_RETRY until exceeded the timeout value
* Add one more attempt to ensure timeout value is reached
*/
int retryAttempts = defaultTimeout / MDSDialogProperties.SLEEP_TIME_PER_RETRY + 1;
boolean completed = false;
for (int retrys = 0; !completed && retrys < retryAttempts; retrys++) {
try {
Thread.sleep(MDSDialogProperties.SLEEP_TIME_PER_RETRY);
} catch (InterruptedException ex) {
_log.warn(ex.getLocalizedMessage());
}
lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
String[] lines = getLines(buf);
for (String line : lines) {
int index = match(line, regex, groups);
switch(index) {
case 0:
completed = false;
break;
case 1:
completed = true;
break;
case 2:
throw new NetworkDeviceControllerException("Zone Commit failed: " + line);
}
}
}
_log.info(MessageFormat.format("Host: {0}, Port: {1} - END waitForZoneCommit", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort() }));
}
Aggregations