Search in sources :

Example 21 with SSHPrompt

use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.

the class MDSDialog method deviceAliasCommit.

/**
 * commit device alias configuration
 *
 * @throws NetworkDeviceControllerException
 */
public void deviceAliasCommit() throws NetworkDeviceControllerException {
    if (lastPrompt != SSHPrompt.MDS_CONFIG_DEVICE_ALIAS) {
        throw NetworkDeviceControllerException.exceptions.mdsUnexpectedLastPrompt(lastPrompt.toString(), SSHPrompt.MDS_CONFIG_DEVICE_ALIAS.toString());
    }
    SSHPrompt[] prompts = { SSHPrompt.MDS_CONFIG };
    StringBuilder buf = new StringBuilder();
    // device-alias commit
    String payload = MDSDialogProperties.getString("MDSDialog.config.deviceAlias.commit.cmd");
    boolean retryNeeded = true;
    for (int retryCount = 0; retryCount < sessionLockRetryMax && retryNeeded; retryCount++) {
        retryNeeded = false;
        lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
        String[] lines = getLines(buf);
        String waitReason = "";
        for (String line : lines) {
            // retry again if device alias database is locked or busy
            if (line.indexOf(MDSDialogProperties.getString("MDSDialog.deviceAlias.busy")) >= 0 || line.indexOf(MDSDialogProperties.getString("MDSDialog.deviceAlias.locked")) >= 0) {
                retryNeeded = true;
                waitReason = line;
                break;
            }
        }
        // if retry needed, sleep for a bit (defaultTimeout), and retry again
        if (retryNeeded) {
            if (retryCount + 1 >= sessionLockRetryMax) {
                // exceed retry, throw exception
                _log.error("Devias alias database is busy or locked, gave up after " + sessionLockRetryMax + " retries!");
                throw NetworkDeviceControllerException.exceptions.deviceAliasDatabaseLockedOrBusy(retryCount + 1);
            } else {
                _log.info("Lock/Busy msg: " + waitReason);
                _log.info("Devias alias database is busy or locked, will retry after " + defaultTimeout / 1000 + " seconds...");
                try {
                    Thread.sleep(defaultTimeout);
                } catch (InterruptedException ex) {
                    _log.warn(ex.getLocalizedMessage());
                }
            }
        }
    }
}
Also used : SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Example 22 with SSHPrompt

use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.

the class MDSDialog method showSystemUptime.

/**
 * Returns the system uptime.
 *
 * @return systme uptime
 * @throws NetworkDeviceControllerException
 */
public String showSystemUptime() throws NetworkDeviceControllerException {
    SSHPrompt[] prompts = { SSHPrompt.MDS_POUND, SSHPrompt.MDS_GREATER_THAN };
    StringBuilder buf = new StringBuilder();
    String systemUptime = null;
    String[] regex = { // System uptime:\\s+(.*)
    MDSDialogProperties.getString("MDSDialog.showSystem.systemUptime.match") };
    SSHPrompt prompt = sendWaitFor(// show system uptime\n
    MDSDialogProperties.getString("MDSDialog.showSystem.systemUptime.cmd"), 10000, prompts, buf);
    String[] lines = getLines(buf);
    String[] groups = new String[1];
    for (String line : lines) {
        if (match(line, regex, groups) == 0) {
            systemUptime = groups[0];
            break;
        }
    }
    return systemUptime;
}
Also used : SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt)

Example 23 with SSHPrompt

use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.

the class MDSDialog method showIvrZonesets.

/**
 * Collect the active ivr zoneset, and its zones, members
 *
 * @return a ivr zoneset
 */
public List<IvrZoneset> showIvrZonesets(boolean active) throws NetworkDeviceControllerException {
    List<IvrZoneset> zonesets = new ArrayList<IvrZoneset>();
    SSHPrompt[] prompts = { SSHPrompt.POUND, SSHPrompt.GREATER_THAN, SSHPrompt.MDS_CONFIG, SSHPrompt.MDS_CONFIG_IVR_ZONE, SSHPrompt.MDS_CONFIG_IVR_ZONESET };
    StringBuilder buf = new StringBuilder();
    String cmdKey = active ? "MDSDialog.ivr.show.zoneset.active.cmd" : "MDSDialog.ivr.show.zoneset.cmd";
    sendWaitFor(MDSDialogProperties.getString(cmdKey), defaultTimeout, prompts, buf);
    String[] lines = getLines(buf);
    String[] regex = { MDSDialogProperties.getString("MDSDialog.ivr.showZoneset.zoneset.name.match"), MDSDialogProperties.getString("MDSDialog.ivr.showZoneset.zone.name.match"), MDSDialogProperties.getString("MDSDialog.ivr.showZoneset.zone.member.match") };
    IvrZoneset zoneset = null;
    IvrZone zone = null;
    IvrZoneMember member = null;
    String[] groups = new String[10];
    for (String line : lines) {
        // remove un-need * char
        line = line.replace('*', ' ');
        int index = match(line, regex, groups);
        switch(index) {
            case 0:
                zoneset = new IvrZoneset(groups[0]);
                zonesets.add(zoneset);
                zoneset.setActive(active);
                break;
            case 1:
                zone = new IvrZone(groups[0]);
                zone.setActive(active);
                zoneset.getZones().add(zone);
                break;
            case 2:
                member = new IvrZoneMember(groups[0], Integer.valueOf(groups[3]));
                zone.getMembers().add(member);
                break;
        }
    }
    return zonesets;
}
Also used : ArrayList(java.util.ArrayList) SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Example 24 with SSHPrompt

use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.

the class MDSDialog method ivrZoneMember.

/**
 * member pwwn {pwwn} vsan {vsanId}
 *
 * @param pwwn
 * @param vsanId
 * @throws NetworkDeviceControllerException
 */
public void ivrZoneMember(String pwwn, Integer vsanId, boolean isRemove) throws NetworkDeviceControllerException {
    _log.info(MessageFormat.format("Host: {0}, Port: {1} - BEGIN  Add or remove ivrZoneMember: pwwn {2} vsan {3} - Remove {4}", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort(), pwwn, vsanId, isRemove }));
    SSHPrompt[] prompts = { SSHPrompt.MDS_CONFIG_IVR_ZONE };
    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);
    }
    if (!pwwn.matches(wwnRegex)) {
        String message = "port wwn " + pwwn + " is not formatted correctly";
        throw NetworkDeviceControllerException.exceptions.mdsUnexpectedDeviceState(message);
    }
    if (!isIvrVsan(vsanId)) {
        String message = "VSAN " + vsanId.toString() + " is not an IVR VSAN.";
        throw NetworkDeviceControllerException.exceptions.mdsUnexpectedDeviceState(message);
    }
    // no
    String noString = isRemove ? MDSDialogProperties.getString("MDSDialog.zoneNameVsan.no.cmd") : "";
    StringBuilder buf = new StringBuilder();
    String payload = MessageFormat.format(noString + MDSDialogProperties.getString("MDSDialog.ivr.zoneMember.cmd"), pwwn, // =member pwwn {0} vsan {0}\n
    vsanId.toString());
    boolean retryNeeded = true;
    for (int retryCount = 0; retryCount < sessionLockRetryMax && retryNeeded; retryCount++) {
        lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
        String[] lines = getLines(buf);
        retryNeeded = checkForEnhancedZoneSession(lines, retryCount);
    }
    _log.info(MessageFormat.format("Host: {0}, Port: {1} - END - Add or remove ivrZoneMember: pwwn {2} vsan {3} - Remove {4}", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort(), pwwn, vsanId, isRemove }));
}
Also used : SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Example 25 with SSHPrompt

use of com.emc.storageos.networkcontroller.SSHPrompt in project coprhd-controller by CoprHD.

the class MDSDialog method zoneAddRemoveMember.

/**
 * Add zone "member device-alias {alias}" if useAlias is set to true, other
 * uses "member pwwn {pwwn}"
 *
 * @param address
 * @param useAlias
 * @throws NetworkDeviceControllerException
 */
private void zoneAddRemoveMember(String address, boolean useAlias, boolean remove) throws NetworkDeviceControllerException {
    String mdsCommand = "";
    if (!inConfigMode) {
        throw NetworkDeviceControllerException.exceptions.mdsDeviceNotInConfigMode();
    }
    if (lastPrompt != SSHPrompt.MDS_CONFIG_ZONE) {
        throw NetworkDeviceControllerException.exceptions.mdsUnexpectedLastPrompt(lastPrompt.toString(), SSHPrompt.MDS_CONFIG_ZONE.toString());
    }
    if (useAlias) {
        // add memeber via device-alias
        mdsCommand = MDSDialogProperties.getString("MDSDialog.zoneMemberAlias.cmd");
    } else {
        // add member via pwwn
        if (!address.matches(wwnRegex)) {
            String message = "port wwn " + address + " is not formatted correctly";
            throw NetworkDeviceControllerException.exceptions.mdsUnexpectedDeviceState(message);
        }
        mdsCommand = MDSDialogProperties.getString("MDSDialog.zoneMemberPwwn.cmd");
    }
    if (remove) {
        mdsCommand = MDSDialogProperties.getString("MDSDialog.zonesetActivate.no.cmd") + " " + mdsCommand;
    }
    SSHPrompt[] prompts = { SSHPrompt.MDS_CONFIG_ZONE };
    StringBuilder buf = new StringBuilder();
    boolean retryNeeded = true;
    for (int retryCount = 0; retryCount < sessionLockRetryMax && retryNeeded; retryCount++) {
        // =member pwwn {0}\n
        String payload = MessageFormat.format(mdsCommand, address);
        lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
        String[] lines = getLines(buf);
        for (String line : lines) {
            // add mode - throw exception if alias is not found
            if (!remove) {
                if (line.indexOf(MDSDialogProperties.getString("MDSDialog.not.present")) >= 0) {
                    throw new NetworkDeviceControllerException(line + ": " + address);
                }
            }
        }
        retryNeeded = checkForEnhancedZoneSession(lines, retryCount);
    }
}
Also used : NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Aggregations

SSHPrompt (com.emc.storageos.networkcontroller.SSHPrompt)33 FCEndpoint (com.emc.storageos.db.client.model.FCEndpoint)31 NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)1 Set (java.util.Set)1 IntRange (org.apache.commons.lang.math.IntRange)1