Search in sources :

Example 1 with SSHPrompt

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

the class MDSDialog method zonesetClone.

/**
 * Creates a clone of the zoneset.
 * cmd : zoneset clone <existing_zoneset_name> <zoneset_clone_name> vsan <vsan id>
 *
 * @throws NetworkDeviceControllerException
 */
public void zonesetClone(Integer vsanId, String zonesetToClone) throws NetworkDeviceControllerException {
    _log.info(MessageFormat.format("Host: {0}, Port: {1} - BEGIN zonesetClone", 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 };
    String errorString = MDSDialogProperties.getString("MDSDialog.zonesetClone.invalidname.cmd");
    StringBuilder buf = new StringBuilder();
    String newZoneset = generateZonesetCloneName(zonesetToClone);
    List<String> zonesetClonesToDelete = findZonesetClonesToDelete(vsanId);
    _log.info("Creating new zoneset clone : " + newZoneset);
    boolean retryNeeded = true;
    // zoneset clone {0} {1} vsan {2}\n
    String payload = MessageFormat.format(MDSDialogProperties.getString("MDSDialog.zonesetClone.cmd"), zonesetToClone, newZoneset, vsanId);
    for (int retryCount = 0; retryCount < sessionLockRetryMax && retryNeeded; retryCount++) {
        lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
        String[] lines = getLines(buf);
        for (String line : lines) {
            if (line.indexOf(errorString) >= 0) {
                _log.info("Zoneset clone operation failed");
                throw NetworkDeviceControllerException.exceptions.zonesetCloneFailed(newZoneset, line);
            }
        }
        retryNeeded = checkForEnhancedZoneSession(lines, retryCount);
    }
    // Delete older clones
    for (String zonesetClone : zonesetClonesToDelete) {
        _log.info(String.format("Removing zoneset (clone) %s", zonesetClone));
        zonesetNameVsan(zonesetClone, vsanId, true);
    }
    _log.info(MessageFormat.format("Host: {0}, Port: {1} - END zonesetClone", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort() }));
}
Also used : SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Example 2 with SSHPrompt

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

the class MDSDialog method showDeviceAliasDatabase.

/**
 * Query device aliases via "show device-alias database" cli, and include pending change if <code>includePending</code> is specified
 *
 * @param includePending true to include pending change
 * @return
 * @throws NetworkDeviceControllerException
 */
public Map<String, String> showDeviceAliasDatabase(boolean includePending) throws NetworkDeviceControllerException {
    String[] regex = { // device-alias name \\s(\\S+)\\s*pwwn \\s*(\\S+)\\s*
    MDSDialogProperties.getString("MDSDialog.deviceAliasName.match") };
    Map<String, String> deviceAliasMap = new HashMap<String, String>();
    SSHPrompt[] prompts = { SSHPrompt.POUND, SSHPrompt.GREATER_THAN };
    StringBuilder buf = new StringBuilder();
    // show device-alias
    sendWaitFor(MDSDialogProperties.getString("MDSDialog.showDeviceAlias.cmd"), defaultTimeout, prompts, buf);
    // get pending database as well
    if (includePending) {
        StringBuilder buf2 = new StringBuilder();
        // show
        sendWaitFor(MDSDialogProperties.getString("MDSDialog.showDeviceAlias.pending.cmd"), defaultTimeout, prompts, buf2);
        // device-alias
        // pending\n
        buf.append(buf2.toString());
    }
    String[] groups = new String[10];
    String[] lines = getLines(buf);
    for (String line : lines) {
        int index = match(line, regex, groups);
        switch(index) {
            case 0:
                // Save the device alias
                String deviceAlias = groups[0];
                String pwwn = groups[1];
                if (deviceAlias != null) {
                    deviceAliasMap.put(deviceAlias, pwwn);
                }
                deviceAlias = null;
                break;
        }
    }
    return deviceAliasMap;
}
Also used : HashMap(java.util.HashMap) SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Example 3 with SSHPrompt

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

the class MDSDialog method showZoneset.

/**
 * Collect the Zonesets, and their Zones, members for a specified Vsan ID.
 *
 * @param vsanId -- Integer vsanId
 * @param activeZonesetOnly - only return active zoneset. Otherwise, return all zonesets
 * @param zoneName - only returns zone with given zoneName. Return all zones, if not specified.
 * @param excludeMembers - true, do not include member with zone. Include members, if not specified.
 * @param excludeAliases - true, do not include aliases with zone. Include aliases, if not specified.
 * @return List<Zoneset> zonesets within that fabric. If zoneName is specified, and there is a match, then only one zone is returned.
 */
public List<Zoneset> showZoneset(Integer vsanId, boolean activeZonesetOnly, String zoneName, boolean excludeMembers, boolean excludeAliases) throws NetworkDeviceControllerException {
    List<Zoneset> zonesets = new ArrayList<Zoneset>();
    SSHPrompt[] prompts = { SSHPrompt.POUND, SSHPrompt.GREATER_THAN };
    StringBuilder buf = new StringBuilder();
    String zonesetCommand = MDSDialogProperties.getString("MDSDialog.showZoneset.cmd");
    sendWaitFor(// show zoneset vsan
    zonesetCommand + vsanId.toString() + "\n", defaultTimeout, prompts, buf);
    if (buf.toString().indexOf(MDSDialogProperties.getString("MDSDialog.showZoneset.not.configured")) >= 0) {
        throw NetworkDeviceControllerException.exceptions.fabricNotFoundInNetwork(vsanId.toString(), "");
    }
    String[] lines = getLines(buf);
    Zoneset zoneset = null;
    Zone zone = null;
    ZoneMember member = null;
    String[] regex = { // \\s*zoneset name ([-\\w]+) vsan (\\d+).*
    MDSDialogProperties.getString("MDSDialog.showZoneset.zonesetname.match"), // \\s*zone name ([-\\w]+) vsan (\\d+).*
    MDSDialogProperties.getString("MDSDialog.showZoneset.zonename.match"), // \\s*pwwn ([0-9a-fA-F:]+)\\s*(\\[\\S+\\])?\\s*(\\w*)
    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> aliasDatabase = showDeviceAliasDatabase();
    String filterCriteria = null;
    if (!StringUtils.isEmpty(zoneName) && zoneName.startsWith(NetworkDeviceController.ZONESET_QUERY_FILTER)) {
        filterCriteria = zoneName.substring(NetworkDeviceController.ZONESET_QUERY_FILTER.length());
    }
    for (String line : lines) {
        int index = match(line, regex, groups);
        switch(index) {
            case 0:
                zoneset = new Zoneset(groups[0]);
                if (!vsanId.toString().equals(groups[1])) {
                    String message = "VSAN " + vsanId.toString() + " not the expected VSAN " + groups[1];
                    throw NetworkDeviceControllerException.exceptions.mdsUnexpectedDeviceState(message);
                }
                zonesets.add(zoneset);
                break;
            case 1:
                // Or, if there was a filter specified, check the name for that. Otherwise, ignore it.
                if (StringUtils.isEmpty(zoneName) || StringUtils.equals(groups[0], zoneName) || (!StringUtils.isEmpty(filterCriteria) && groups[0].contains(filterCriteria))) {
                    zone = new Zone(groups[0]);
                    zoneset.getZones().add(zone);
                } else {
                    // 
                    zone = null;
                }
                break;
            case 2:
            case 3:
                // if zone is to be ignored, or members are excluded, break out
                if (zone == null || excludeMembers) {
                    break;
                }
                member = new ZoneMember(ZoneMember.ConnectivityMemberType.WWPN);
                zone.getMembers().add(member);
                if (excludeAliases) {
                    _log.info("Excluding aliases while getting zone members");
                }
                if (index == 2) {
                    // 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("]", ""));
                    }
                } else if (index == 3) {
                    // 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], aliasDatabase);
                    if (!StringUtils.isEmpty(pwwn)) {
                        member.setAddress(pwwn);
                    }
                }
                break;
        }
    }
    if (zonesets.isEmpty()) {
        return zonesets;
    }
    // Now find the active zoneset
    sendWaitFor(// show zoneset active vsan
    MDSDialogProperties.getString("MDSDialog.showZoneset.showzonesetactivevsan.cmd") + vsanId.toString() + "\n", defaultTimeout, prompts, buf);
    lines = getLines(buf);
    String[] regex2 = { // \\s*zoneset name ([-\\w]+) vsan (\\d+).*
    MDSDialogProperties.getString("MDSDialog.showZoneset.zonesetname2.match"), // \\s*zone name ([-\\w]+) vsan (\\d+).*
    MDSDialogProperties.getString("MDSDialog.showZoneset.zonename2.match") };
    Zoneset activeZoneset = null;
    for (String line : lines) {
        int index = match(line, regex2, groups);
        switch(index) {
            case // found the active one
            0:
                String activeName = groups[0];
                for (Zoneset zs : zonesets) {
                    if (zs.getName().equals(activeName)) {
                        activeZoneset = zs;
                        zs.setActive(true);
                    } else {
                        zs.setActive(false);
                    }
                }
                break;
            case 1:
                if (zoneset != null) {
                    // if there is an active zoneset
                    for (Zone zo : activeZoneset.getZones()) {
                        if (zo.getName().equals(groups[0])) {
                            zo.setActive(true);
                        }
                    }
                }
        }
    }
    // if only want active zone set, return only active one if found
    if (activeZonesetOnly) {
        zonesets.clear();
        if (activeZoneset != null) {
            zonesets.add(activeZoneset);
        }
    }
    return zonesets;
}
Also used : ArrayList(java.util.ArrayList) SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Example 4 with SSHPrompt

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

the class MDSDialog method showIvrVsanTopology.

/**
 * Get ivr vsan topology of the switch
 *
 * @return
 * @throws NetworkDeviceControllerException
 */
public List<IvrVsanConfiguration> showIvrVsanTopology() throws NetworkDeviceControllerException {
    List<IvrVsanConfiguration> ivrVsans = new ArrayList<IvrVsanConfiguration>();
    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.ivr.vsan.topology.cmd"), defaultTimeout, prompts, buf);
    String[] lines = getLines(buf);
    String[] regex = { MDSDialogProperties.getString("MDSDialog.ivr.showTopology.wwn.match") };
    String[] groups = new String[10];
    for (String line : lines) {
        int index = match(line, regex, groups);
        switch(index) {
            case 0:
                IvrVsanConfiguration ivrVsan = new IvrVsanConfiguration();
                ivrVsan.setSwitchWwn(groups[0] + groups[2]);
                // local switch is indicated by present of * character
                ivrVsan.setLocalSwitch("*".equalsIgnoreCase(groups[3]));
                try {
                    // get the first vsan in the line
                    int vsanId = Integer.valueOf(groups[4]);
                    // and get all ivr vsans via StringSplit
                    if (vsanId > 0) {
                        String vsansText = line.substring(line.indexOf(groups[4], line.indexOf(ivrVsan.getSwitchWwn()) + ivrVsan.getSwitchWwn().length()));
                        String[] vsans = vsansText.split(",");
                        for (String vsan : vsans) {
                            // get vsan range
                            if (vsan.indexOf('-') > 0) {
                                String[] range = vsan.split("-");
                                ivrVsan.getVsansRanges().add(new IntRange(Integer.valueOf(range[0].trim()), Integer.valueOf(range[1].trim())));
                            } else {
                                ivrVsan.getVsans().add(Integer.valueOf(vsan.trim()));
                            }
                        }
                    }
                } catch (Exception e) {
                // not ivr vsan
                }
                ivrVsans.add(ivrVsan);
                break;
        }
    }
    return ivrVsans;
}
Also used : ArrayList(java.util.ArrayList) IntRange(org.apache.commons.lang.math.IntRange) SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 5 with SSHPrompt

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

the class MDSDialog method showZoneNamesForPwwn.

/**
 * Get list of zone names where the given pwwn belongs to
 *
 * @param pwwn
 * @param vsanId
 * @param activeOnly only list names of active zones
 * @return
 * @throws NetworkDeviceControllerException
 */
public Set<String> showZoneNamesForPwwn(String pwwn, Integer vsanId, boolean activeOnly) throws NetworkDeviceControllerException {
    Set<String> zoneNames = Sets.newHashSet();
    SSHPrompt[] prompts = { SSHPrompt.POUND, SSHPrompt.GREATER_THAN };
    StringBuilder buf = new StringBuilder();
    String cmdKey = activeOnly ? "MDSDialog.showZone.pwwn.active.cmd" : "MDSDialog.showZone.pwwn.cmd";
    String payload = MessageFormat.format(MDSDialogProperties.getString(cmdKey), pwwn, vsanId.toString());
    sendWaitFor(payload, defaultTimeout, prompts, buf);
    String[] lines = getLines(buf);
    String[] regex = { // regex expression is \\s*zone\\s+([-\\w]+)
    MDSDialogProperties.getString("MDSDialog.zoneName.match") };
    String[] groups = new String[10];
    for (String line : lines) {
        int index = match(line, regex, groups);
        switch(index) {
            case 0:
                zoneNames.add(groups[0]);
                break;
        }
    }
    return zoneNames;
}
Also used : 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