use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.
the class MDSDialog method showSwitchWwn.
/**
* Get switch 's wwn
*
* @return
* @throws NetworkDeviceControllerException
*/
public String showSwitchWwn() throws NetworkDeviceControllerException {
SSHPrompt[] prompts = { SSHPrompt.POUND, SSHPrompt.GREATER_THAN, SSHPrompt.MDS_CONFIG, SSHPrompt.MDS_CONFIG_IVR_ZONE, SSHPrompt.MDS_CONFIG_IVR_ZONESET };
StringBuilder buf = new StringBuilder();
sendWaitFor(MDSDialogProperties.getString("MDSDialog.show.wwn.switch.cmd"), defaultTimeout, prompts, buf);
String[] lines = getLines(buf);
String[] regex = { MDSDialogProperties.getString("MDSDialog.show.wwn.switch.match") };
String switchWwn = null;
String[] groups = new String[10];
for (String line : lines) {
int index = match(line, regex, groups);
switch(index) {
case 0:
switchWwn = groups[0];
break;
}
if (switchWwn != null) {
break;
}
}
return switchWwn;
}
use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.
the class MDSDialog method initialize.
/**
* This initializes a new session, gathering the prompts, and setting the terminal length.
*
* @throws NetworkDeviceControllerException
*/
public void initialize() throws NetworkDeviceControllerException {
SSHPrompt[] prompts = { SSHPrompt.POUND, SSHPrompt.GREATER_THAN };
StringBuilder buf = new StringBuilder();
SSHPrompt got = waitFor(prompts, defaultTimeout, buf, true);
String[] lines = buf.toString().split("[\n\r]+");
String lastLine = lines[lines.length - 1];
String[] groups = new String[2];
if (match(lastLine, new String[] { MDSDialogProperties.getString("MDSDialog.initalize.match") + got.getRegex() }, groups) == 0) {
// \\s*([-_A-Za-z0-9]+)
devname = groups[0];
}
// terminal length 0\n
sendWaitFor(MDSDialogProperties.getString("MDSDialog.initialize.termlength.cmd"), 5000, prompts, buf);
_log.info(buf.toString());
}
use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.
the class MDSDialog method showInterface.
/**
* Issues the "show interface" command and collects in information into a list of
* interfaces. For now only parses fiber channel interfaces starting with "fc",
* e.g. fc1/1, fc2/20, ...
* This method is not currently used.
*
* @return List<Interface>
*/
public List<Interface> showInterface() throws NetworkDeviceControllerException {
List<Interface> interfaces = new ArrayList<Interface>();
SSHPrompt[] prompts = { SSHPrompt.POUND, SSHPrompt.GREATER_THAN };
StringBuilder buf = new StringBuilder();
SSHPrompt prompt = sendWaitFor(// show interface\n
MDSDialogProperties.getString("MDSDialog.showInterface.cmd"), 60000, prompts, buf);
String[] lines = getLines(buf);
String[] regex = { // (fc\\d+/\\d+) is (\\S+).*
MDSDialogProperties.getString("MDSDialog.showInterface.interfacename.match"), // \\s+Port description is (.*)
MDSDialogProperties.getString("MDSDialog.showInterface.Portdescription.match"), // \\s+Port WWN is ([0-9a-fA-F:]+)\\s*
MDSDialogProperties.getString("MDSDialog.showInterface.PortWWN.match"), // \\s+Port mode is (\\w*), FCID is
MDSDialogProperties.getString("MDSDialog.showInterface.PortmodeFCID.match"), // \\s+Port vsan is (\\d+)\\s*
MDSDialogProperties.getString("MDSDialog.showInterface.Portvsan.match"), // \\s+Port mode is (\\w*)\\s*
MDSDialogProperties.getString("MDSDialog.showInterface.Portmode.match") };
String[] groups = new String[10];
Interface intf = null;
for (String line : lines) {
int index = match(line, regex, groups);
switch(index) {
case 0:
// save name
intf = new Interface(groups[0]);
intf.setStatus(groups[1]);
interfaces.add(intf);
break;
case 1:
intf.setDescription(groups[0]);
break;
case 2:
intf.setWwpn(groups[0]);
break;
case 3:
intf.setMode(groups[0]);
intf.setFcid(groups[1]);
break;
case 4:
intf.setVsan(groups[0]);
break;
case 5:
intf.setMode(groups[0]);
break;
}
}
return interfaces;
}
use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.
the class MDSDialog method zonesetActivate.
/**
* zoneset activate name {zonesetName} vsan {vsanId}
* no zoneset activate name {zonesetName} vsan {vsanId}
*
* @param zonesetName
* @param vsanId
* @param no (boolean) if true, issues "no" form of this command
* @throws NetworkDeviceControllerException
*/
public void zonesetActivate(String zonesetName, Integer vsanId, boolean no) throws NetworkDeviceControllerException {
if (!inConfigMode) {
throw NetworkDeviceControllerException.exceptions.mdsDeviceNotInConfigMode();
}
if (lastPrompt != SSHPrompt.MDS_CONFIG) {
throw NetworkDeviceControllerException.exceptions.mdsUnexpectedLastPrompt(lastPrompt.toString(), SSHPrompt.MDS_CONFIG.toString());
}
// no
String noString = no ? MDSDialogProperties.getString("MDSDialog.zonesetActivate.no.cmd") : "";
SSHPrompt[] prompts = { SSHPrompt.MDS_CONFIG, SSHPrompt.MDS_CONTINUE_QUERY };
StringBuilder buf = new StringBuilder();
boolean retryNeeded = true;
for (int retryCount = 0; retryCount < sessionLockRetryMax && retryNeeded; retryCount++) {
String payload = MessageFormat.format(MDSDialogProperties.getString("MDSDialog.zonesetActivate.cmd"), zonesetName, vsanId.toString(), // {2}zoneset activate name {0} vsan {1}\n
noString);
lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
// error, throw exception. Otherwise check for enhance zone session
if (buf.toString().indexOf(MDSDialogProperties.getString("MDSDialog.zonesetActivate.no.zone.members")) >= 0) {
throw new NetworkDeviceControllerException("Activate zoneset/vsan: " + zonesetName + "/" + vsanId + " failed. One or more zone do not have members");
} else {
// check for user input
if (lastPrompt == SSHPrompt.MDS_CONTINUE_QUERY) {
// y\n
payload = MDSDialogProperties.getString("MDSDialog.zonesetActivate.continue.y.cmd");
SSHPrompt[] prompts2 = { SSHPrompt.MDS_CONFIG };
buf = new StringBuilder();
lastPrompt = sendWaitFor(payload, defaultTimeout, prompts2, buf);
}
String[] lines = getLines(buf);
retryNeeded = checkForEnhancedZoneSession(lines, retryCount);
}
}
}
use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.
the class MDSDialog method showIvrZone.
/**
* Get Zone and its members for given ivr zone name.
*
* @param zoneName
* @return zone
* @throws NetworkDeviceControllerException
*/
private Zone showIvrZone(String zoneName) {
Zone zone = new Zone(zoneName);
SSHPrompt[] prompts = { SSHPrompt.POUND, SSHPrompt.GREATER_THAN };
StringBuilder buf = new StringBuilder();
String payload = MessageFormat.format(MDSDialogProperties.getString("MDSDialog.ivr.show.zoneName.cmd"), zoneName);
sendWaitFor(payload, defaultTimeout, prompts, buf);
String[] lines = getLines(buf);
ZoneMember member = null;
String[] regex = { MDSDialogProperties.getString("MDSDialog.ivr.showZoneset.zone.member.match") };
String[] groups = new String[10];
for (String line : lines) {
int index = match(line, regex, groups);
member = new ZoneMember(ZoneMember.ConnectivityMemberType.WWPN);
switch(index) {
case 0:
member.setAddress(groups[0]);
zone.getMembers().add(member);
break;
}
}
return zone;
}
Aggregations