Search in sources :

Example 11 with SSHPrompt

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

the class MDSDialog method getVsanWwns.

/**
 * Returns a map from Vsan ID to the fabric WWN as determined by the principal switch.
 * Note this value is not immutable; if a new principal switch is elected, then the mapping
 * will change.
 *
 * @param vsanId If non null, only returns result for specificed Vsan. If null, all Vsans.
 * @return Map keyed by Vsan ID to WWN of Fabric
 * @throws NetworkDeviceControllerException
 */
public Map<Integer, String> getVsanWwns(Integer vsanId) throws NetworkDeviceControllerException {
    Map<Integer, String> vsanToWwns = new HashMap<Integer, String>();
    SSHPrompt[] prompts = { SSHPrompt.POUND, SSHPrompt.GREATER_THAN };
    StringBuilder buf = new StringBuilder();
    // show fcdomain
    String cmd = MDSDialogProperties.getString("MDSDialog.getVsanWwns.showfcdomain.cmd");
    if (vsanId != null) {
        cmd = // \ vsan
        cmd + MDSDialogProperties.getString("MDSDialog.getVsanWwns.vsan.cmd") + vsanId.toString() + "\n";
    } else {
        cmd = cmd + "\n";
    }
    sendWaitFor(cmd, defaultTimeout, prompts, buf);
    String[] lines = getLines(buf);
    String[] regex = { // \\s*VSAN\\s+(\\d+).*
    MDSDialogProperties.getString("MDSDialog.getVsanWwns.VSAN.match"), // .*Running fabric name:\\s+(
    MDSDialogProperties.getString("MDSDialog.getVsanWwns.Runningfabricname.match") + wwnRegex + // ).*
    MDSDialogProperties.getString("MDSDialog.getVsanWwns.Runningfabricname2.match") };
    String[] groups = new String[10];
    Integer vsan = null;
    for (String line : lines) {
        int index = match(line, regex, groups);
        switch(index) {
            case // "\\s*VSAN\\s+(\\d+).*"
            0:
                vsan = new Integer(groups[0]);
                break;
            case // ".*Running fabric name:\\s+(" + wwnRegex + ").*"
            1:
                String wwn = groups[0];
                if (vsan != null) {
                    vsanToWwns.put(vsan, wwn);
                    vsan = null;
                } else if (vsanId != null) {
                    // "show fcdomain vsan 3180" has different format output
                    vsanToWwns.put(vsanId, wwn);
                }
        }
    }
    return vsanToWwns;
}
Also used : HashMap(java.util.HashMap) SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Example 12 with SSHPrompt

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

the class MDSDialog method zonesetMember.

/**
 * Makes a zoneset member.
 * member {zoneName}
 *
 * @param zoneName
 * @throws NetworkDeviceControllerException
 */
public void zonesetMember(String zoneName, boolean no) throws NetworkDeviceControllerException {
    if (!inConfigMode) {
        throw NetworkDeviceControllerException.exceptions.mdsDeviceNotInConfigMode();
    }
    if (lastPrompt != SSHPrompt.MDS_CONFIG_ZONESET) {
        throw NetworkDeviceControllerException.exceptions.mdsUnexpectedLastPrompt(lastPrompt.toString(), SSHPrompt.MDS_CONFIG_ZONESET.toString());
    }
    SSHPrompt[] prompts = { SSHPrompt.MDS_CONFIG_ZONESET };
    // no
    String noString = no ? MDSDialogProperties.getString("MDSDialog.zonesetMember.no.cmd") : "";
    StringBuilder buf = new StringBuilder();
    boolean retryNeeded = true;
    for (int retryCount = 0; retryCount < sessionLockRetryMax && retryNeeded; retryCount++) {
        // member
        String payload = MessageFormat.format(MDSDialogProperties.getString("MDSDialog.zonesetMember.member.cmd"), zoneName, noString);
        // {0}\n
        lastPrompt = sendWaitFor(payload, defaultTimeout, prompts, buf);
        String[] lines = getLines(buf);
        retryNeeded = checkForEnhancedZoneSession(lines, retryCount);
    }
}
Also used : SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Example 13 with SSHPrompt

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

the class MDSDialog method showIvrZones.

/**
 * Get switch ivr zones
 *
 * @return
 * @throws NetworkDeviceControllerException
 */
public List<IvrZone> showIvrZones(boolean active) throws NetworkDeviceControllerException {
    List<IvrZone> zones = new ArrayList<IvrZone>();
    SSHPrompt[] prompts = { SSHPrompt.POUND, SSHPrompt.GREATER_THAN };
    StringBuilder buf = new StringBuilder();
    String cmdKey = active ? "MDSDialog.ivr.show.zone.active.cmd" : "MDSDialog.ivr.show.zone.cmd";
    sendWaitFor(MDSDialogProperties.getString(cmdKey), defaultTimeout, prompts, buf);
    String[] lines = getLines(buf);
    IvrZone zone = null;
    IvrZoneMember member = null;
    String[] regex = { MDSDialogProperties.getString("MDSDialog.ivr.showZoneset.zone.name.match"), MDSDialogProperties.getString("MDSDialog.ivr.showZoneset.zone.member.match") };
    String[] groups = new String[10];
    for (String line : lines) {
        int index = match(line, regex, groups);
        switch(index) {
            case 0:
                zone = new IvrZone(groups[0]);
                zones.add(zone);
                break;
            case 1:
                member = new IvrZoneMember(groups[0], Integer.valueOf(groups[3]));
                zone.getMembers().add(member);
                break;
        }
    }
    return zones;
}
Also used : ArrayList(java.util.ArrayList) SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Example 14 with SSHPrompt

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

the class MDSDialog method showFcnsDatabase.

/**
 * Generates a set of FCPortConnection entries for the specified vsan id (or all
 * Vsans if vsanId is null).
 *
 * @param vsanId used to qualify command to one vsan
 * @return list of FCPortConnections
 */
public List<FCEndpoint> showFcnsDatabase(Integer vsanId) throws NetworkDeviceControllerException {
    Map<Integer, String> vsanToWwns = getVsanWwns(vsanId);
    List<FCEndpoint> connections = new ArrayList<FCEndpoint>();
    SSHPrompt[] prompts = { SSHPrompt.MDS_POUND, SSHPrompt.MDS_GREATER_THAN };
    StringBuilder buf = new StringBuilder();
    // show fcns database detail
    String cmd = MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.cmd");
    if (vsanId != null) {
        // \ vsan
        cmd = cmd + MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.vsan.cmd") + vsanId.toString() + "\n";
    } else {
        // $NON-NLS-1$
        cmd = cmd + "\n";
    }
    SSHPrompt prompt = sendWaitFor(cmd, defaultTimeout, prompts, buf);
    String[] lines = getLines(buf);
    String[] regex = { // VSAN:(\\d+)\\s+FCID:(0x[0-9a-fA-F:]+)\\s*
    MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.VSAN.match"), // port-wwn[^:]+:([0-9a-fA-F:]+).*
    MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.portwwn.match"), // node-wwn[^:]+:([0-9a-fA-F:]+).*
    MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.nodewwn.match"), // fabric-port-wwn[^:]+:([0-9a-fA-F:]+).*
    MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.fabricportwwn.match"), // Connected Interface[^:]+:(fc\\S+)
    MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.ConnectedInterface.match"), // Switch Name[^:]+:(.*)
    MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.SwitchName.match"), // \\s*\\[(\\S+)\\]\\s*:q
    MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.deviceAlias.match") };
    String[] groups = new String[10];
    FCEndpoint conn = null;
    for (String line : lines) {
        int index = match(line, regex, groups, Pattern.CASE_INSENSITIVE);
        switch(index) {
            case 0:
                conn = new FCEndpoint();
                // vsan
                conn.setFabricId(groups[0]);
                // fcid
                conn.setFcid(groups[1]);
                String fabricWwn = vsanToWwns.get(new Integer(groups[0]));
                if (fabricWwn != null) {
                    conn.setFabricWwn(fabricWwn);
                }
                connections.add(conn);
                break;
            case 1:
                // remote wwpn
                conn.setRemotePortName(groups[0]);
                break;
            case 2:
                // remote wwnn
                conn.setRemoteNodeName(groups[0]);
                break;
            case 3:
                // local wwpn
                conn.setSwitchPortName(groups[0]);
                break;
            case 4:
                // switch interface
                conn.setSwitchInterface(groups[0]);
                break;
            case 5:
                // switch name
                conn.setSwitchName(groups[0]);
                break;
            case 6:
                // pwwn alias
                conn.setRemotePortAlias(groups[0]);
        }
    }
    return connections;
}
Also used : ArrayList(java.util.ArrayList) SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Example 15 with SSHPrompt

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

the class MDSDialog method showTopology.

/**
 * Return map vsan 's peer devices' ip address
 *
 * @return a Map of Vsan ID to set of peer devices ( identify by ip address )
 */
public Map<Integer, Set<String>> showTopology() throws NetworkDeviceControllerException {
    Map<Integer, Set<String>> peerDevicesMap = new HashMap<Integer, Set<String>>();
    SSHPrompt[] prompts = { SSHPrompt.POUND, SSHPrompt.GREATER_THAN };
    StringBuilder buf = new StringBuilder();
    // show topology\n
    sendWaitFor(MDSDialogProperties.getString("MDSDialog.show.topology.cmd"), 10000, prompts, buf);
    String[] lines = getLines(buf);
    Integer vsanId = null;
    String[] regex = { // FC Topology for VSAN\\s+(\\d+).*
    MDSDialogProperties.getString("MDSDialog.show.topology.vsan.match"), // .*\\s+(([0-9]{1,3}\\.){3})([0-9]{1,3}).*
    MDSDialogProperties.getString("MDSDialog.show.topology.peer.ip.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:
                Set<String> peerDevicesIpAddr = peerDevicesMap.get(vsanId);
                if (peerDevicesIpAddr == null) {
                    peerDevicesIpAddr = Sets.newHashSet();
                    peerDevicesMap.put(vsanId, peerDevicesIpAddr);
                }
                String peerDevice = groups[0] + groups[2];
                peerDevicesIpAddr.add(peerDevice);
                break;
        }
    }
    return peerDevicesMap;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) 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