wwndesc  1.0-76
WWNDescription.java
Go to the documentation of this file.
1 /* smallfoot.org is owned by allan.clark */
2 package org.smallfoot.wwn;
3 
4 import gnu.getopt.Getopt;
5 import gnu.getopt.LongOpt;
6 
7 /**
8  * @file
9  */
10 
11 /**
12  * In situations where nicknames simply are not present, but we need descriptors in short-order,
13  * the "--wwn=" or "-w" ooption can be used to get a description of what the most likely Nickname
14  * would be. For example, "java -jar wwndesc.jar -w 5006048ACCC86A32" results in "Symm-182500953-05bA"
15  * matching http://www.emcstorageinfo.com/2007/08/how-to-decode-symmetrix-world-wide.html
16  * Note that --briefestimate and --nobriefestimate configure for more brief estimate/suggested nicknames
17  *
18  * @section Examples
19  *
20  * java -jar vict.jar --wwn 500610601234567
21  *
22  * java -jar vict.jar --briefestimate --wwn 500610601234567
23  *
24  * java -jar vict.jar --nobriefestimate --wwn 5000097301234564
25  *
26  * @section Known Issues
27  */
28 
29 public class WWNDescription
30 {
31  public boolean briefWWNEstimate = false; /**< setting to "true" via the "--briefestimate" commandline causes all descriptions later requested in getWWNDescriptor(String) to be "brief" (more concise) @see WWNDesc#toString() */
32 
33  /** test case: this matches a single item known to exist in the Demo Database */
34  public class DemoTestDesc extends WWNDesc
35  {
36  /** @copydoc WWNDesc#WWNDesc(String) */
37  public DemoTestDesc(String wwn)
38  {
39  super(wwn);
40  }
41  /**
42  * generates a test description or alias for this test class
43  *
44  * @returns "TestDevice" always
45  */
46  public String toString()
47  {
48  String res = super.toString();
49  if (null == res) res = "";
50 
51  return res + "TestDevice";
52  }
53  }
54 
55  /**
56  * Iterates WWNDescription decendents looking for which will accept responsibility, and if so, returns the instance it generates as a descriptor
57  *
58  * @return new instance of WWNDesc descendent, or null if no descendents accept responsibility to describe or provide an alias for that WWN
59  *
60  * @param val WWN to check
61  */
62  public WWNDesc getWWNDescriptor(String val)
63  {
64  return getWWNDescriptor(val,true);
65  }
66 
67  /**
68  * Iterates WWNDescription decendents looking for which will accept responsibility, and if so, returns the instance it generates as a descriptor
69  *
70  * @return new instance of WWNDesc descendent, or null if no descendents accept responsibility to describe or provide an alias for that WWN
71  *
72  * @param val WWN to check
73  * @param provideBase whether to provide a bogus WWNDesc instance rather than a null
74  */
75  public WWNDesc getWWNDescriptor(String val, boolean provideBase)
76  {
77  return getWWNDescriptor(val, provideBase, DevRole.TARGETbit);
78  }
79  /**
80  * @copydoc #getWWNDescriptor(String, boolean)
81  *
82  * @param role DevRole to check for
83  */
84  public WWNDesc getWWNDescriptor(String val, boolean provideBase, DevRole role)
85  {
86  return getWWNDescriptor(val, provideBase, role.value);
87  }
88  /**
89  * @copydoc #getWWNDescriptor(String, boolean, DevRole)
90  */
91  public WWNDesc getWWNDescriptor(String val, boolean provideBase, int role)
92  {
93  val = val.replaceAll(":","").toLowerCase();
94  WWNDesc d = null;
95 
96  if (null != (d = EMCSymmetrixDescription.getDesc(/* strong*/ false, briefWWNEstimate, val, role)))
97  return d;
98  else if (null != (d = EMCClariionDescription.getDesc(/* strong*/ false, briefWWNEstimate, val, role)))
99  return d;
100  else if (null != (d = EMCVMAXDescription.getDesc(/* strong*/ false, briefWWNEstimate, val, role)))
101  return d;
102  else if (null != (d = EMCVPLEXDescription.getDesc(/* strong*/ false, briefWWNEstimate, val, role)))
103  return d;
104  else if (null != (d = PureStorageDescription.getDesc(/* strong*/ false, briefWWNEstimate, val, role)))
105  return d;
106  else if (null != (d = NetAppDescription.getDesc(/* strong*/ false, briefWWNEstimate, val, role)))
107  return d;
108  else if (null != (d = HDSVSPDescription.getDesc(/* strong*/ false, briefWWNEstimate, val, role)))
109  return d;
110  else if (null != (d = IBMDescription.getDesc(/* strong*/ false, briefWWNEstimate, val, role)))
111  return d;
112  else if (null != (d = HP3ParDescription.getDesc(/* strong*/ false, briefWWNEstimate, val, role)))
113  return d;
114  else if (null != (d = HPDotHillDescription.getDesc(/* strong*/ false, briefWWNEstimate, val, role)))
115  return d;
116  else if (null != (d = OraclePillarDescription.getDesc(/* strong*/ false, briefWWNEstimate, val, role)))
117  return d;
118  else if (null != (d = SymbiosDescription.getDesc(/* strong*/ false, briefWWNEstimate, val, role)))
119  return d;
120 
121  else if (null != (d = CiscoSwitchDescription.getDesc(/* strong*/ false, briefWWNEstimate, val, role)))
122  return d;
123  else if (null != (d = CiscoUCSServerDescription.getDesc(/* strong*/ false, briefWWNEstimate, val, role)))
124  return d;
125  else if (null != (d = AIXLPARServerDescription.getDesc(/* strong*/ false, briefWWNEstimate, val, role)))
126  return d;
127  else if (null != (d = HPVirtualServerDescription.getDesc(/* strong*/ false, briefWWNEstimate, val, role)))
128  return d;
129 
130  else if (val.toLowerCase().equalsIgnoreCase("200100110d123400"))
131  return new DemoTestDesc(val);
132 
133  else if (provideBase)
134  return new WWNDesc(val);
135  else
136  return null;
137  }
138 
139 
140 
141  /** usage messages are useful to those of us with short memories as well (hey, I just need to add swap!)
142  *
143  * @param proc name of the process or program (ie wwndesc)
144  */
145  public void usage(String proc)
146  {
147  System.out.println("Usage: "+proc+" -V|--version|-H|--help");
148 
149  System.out.println(" : "+proc+" [--briefestimate] [--device[=switch|initiator|target] [--wwn|-w <WWN> [--port|-p <WWN>] [--wwn|-w <WWN> [--wwn|-w <WWN>]]]");
150  System.out.println(" ie: "+proc+" -w 2100000b08123450");
151  System.out.println(" ie: "+proc+" --wwn 2100000b08123450");
152  System.out.println(" ie: "+proc+" --briefestimate -w 2100000b08123450");
153  System.out.println(" ie: "+proc+" -w 21:00:00:0b:08:12:34:50");
154  System.out.println(" ie: "+proc+" -w 21:00:000b08:123450");
155  System.out.println(" ie: "+proc+" -p 21:00:00:0b:08:12:34:50");
156  System.out.println(" ie: "+proc+" --device=switch --port 21:00:000b08:123450");
157  }
158 
159 
160 
161  /**
162  * Main function, as you can tell.
163  *
164  * this function merely parses the command-line to dispatch actions to the meat of the meal above.
165  * I'm using an actual GetOpt because, yes, I'm a UNIX/C hack, re-using 3-decades-old knowledge,
166  * but this also preserves both extensibility and the ability to use longopts in scripts as a
167  * way to self-document what the tool's doing.
168  *
169  * No real intelligence herein except the parse-and-redirect action.
170  *
171  * @param args commandline arguments passed in by the JRE
172  */
173  public static void main(String args[])
174  {
175  WWNDescription m = new WWNDescription();
176  int role = DevRole.TARGETbit;
177 
178  java.util.Vector<LongOpt> options = new java.util.Vector();
179  /**
180  * Always always ALWAYS provide a quick reference and a version output
181  *
182  * @cmdopt -H|--help Show a simple help screen as a reminder of options which are understood by the application
183  * @cmdopt @code java -jar wwndesc.jar --help @endcode
184  *
185  * @cmdopt -V|--version Show the current release version for reference
186  * @cmdopt @code java -jar wwndesc.jar --version
187  * 1.0-76 @endcode
188  */
189 
190  /* Always always ALWAYS provide a quick reference and a version output */
191  options.add(new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'H'));
192  options.add(new LongOpt("version", LongOpt.NO_ARGUMENT, null, 'V'));
193 
194  options.add(new LongOpt("device", LongOpt.REQUIRED_ARGUMENT, null, 'd'));
195  options.add(new LongOpt("port", LongOpt.REQUIRED_ARGUMENT, null, 'p'));
196  options.add(new LongOpt("wwn", LongOpt.REQUIRED_ARGUMENT, null, 'w'));
197  options.add(new LongOpt("briefestimate", LongOpt.NO_ARGUMENT, null, 0x1000));
198  options.add(new LongOpt("nobriefestimate", LongOpt.NO_ARGUMENT, null, 0x1001));
199 
200  org.smallfoot.getopt.GetOpt g = new org.smallfoot.getopt.GetOpt("wwndesc", args, options);
201 
202  int c;
203  while ((c = g.getopt()) != -1)
204  {
205  switch(c)
206  {
207  /**
208  * @cmdopt --briefestimate change to shorter, more brief estimates or descriptions
209  * @cmdopt --nobriefestimate change to longer, more detailed estimates (default)
210  */
211  case 0x1000: /* switch to brief WWNDescs */
212  m.briefWWNEstimate = true;
213  break;
214  case 0x1001: /* switch to verbose WWNDescs */
215  m.briefWWNEstimate = false;
216  break;
217 
218  /**
219  * @cmdopt -d|--device(=) used mainly in testing, this option allows setting a device type
220  * @cmdopt { init(iator) | server | storage | switch | targ(et) }
221  */
222  case 'd': /* set a device type */
223  {
224  if (null == g.getOptarg()) role = DevRole.TARGETbit;
225 
226  else if (g.getOptarg().toLowerCase().startsWith("targ")) role = DevRole.TARGETbit;
227  else if (g.getOptarg().equalsIgnoreCase("storage")) role = DevRole.TARGETbit;
228  else if (g.getOptarg().equalsIgnoreCase("server")) role = DevRole.INITIATORbit;
229  else if (g.getOptarg().toLowerCase().startsWith("init")) role = DevRole.TARGETbit;
230  else if (g.getOptarg().equalsIgnoreCase("switch")) role = DevRole.SWITCHbit;
231  }
232  break;
233 
234  /**
235  * @cmdopt -p|--port used mainly in testing, this option shows the port-uniqueness of a device (which can be leveraged for de-duping an alias)
236  */
237  case 'p': /* inspect a WWPN's unique port */
238  {
239  WWNDesc wwn;
240  if ((null == g.getOptarg()) || (16 != g.getOptarg().replaceAll(":","").length()))
241  System.out.println("no result: parameter "+g.getOptarg()+" needs to be a 16-digit hexadecimal");
242  else if (null == (wwn = m.getWWNDescriptor(g.getOptarg(),true,role)))
243  System.out.println("no result: WWN "+g.getOptarg()+" has no descriptor");
244  else System.out.println(wwn.descPort());
245  }
246  break;
247 
248  /**
249  * @cmdopt -w|--wwn query for a description of a WWPN
250  * @cmdopt @code java -jar wwndesc.jar --wwn 5000097201234567
251  * VMax-HK194618641-10fD @endcode
252  * @cmdopt @code java -jar wwndesc.jar --briefestimate --wwn 5000097201234567
253  * VMax-18641-10fD @endcode
254  */
255  case 'w': /* inspect a WWN */
256  {
257  WWNDesc wwn;
258  if ((null == g.getOptarg()) || (16 != g.getOptarg().replaceAll(":","").length()))
259  System.out.println("no result: parameter "+g.getOptarg()+" needs to be a 16-digit hexadecimal");
260  else if (null == (wwn = m.getWWNDescriptor(g.getOptarg(),true,role)))
261  System.out.println("no result: WWN "+g.getOptarg()+" has no descriptor");
262  else System.out.println(wwn.toString());
263  }
264  break;
265 
266  /*
267  * Follows is the "house-keeping": versions, usage, and the catch-all for bad options.
268  */
269  case 'V': // print the version and quit
270  {
271  System.out.println(g.consistentVersion("1.0-76"));
272  return;
273  }
274 
275  default:
276  case '?':
277  // during build, this is just a dump of options; in shipping, this falls-thru to usage.
278  //System.out.println("option \""+c+"\" selected");
279  //System.out.println("long index = "+g.getLongind());
280 
281  case 'H':
282  m.usage(g.progname());
283  break;
284  }
285  }
286 
287  /*
288  * I had to add this since there seems to be a lack of dropping out when the options are done,
289  * or a delay huge enough that my impatience is triggered (ie 2 seconds or more!). Maybe
290  * invesitgate this further when there's more time, as this is redundant.
291  */
292  java.lang.System.exit(0);
293  }
294 }
WWNDesc getWWNDescriptor(String val, boolean provideBase, DevRole role)
Iterates WWNDescription decendents looking for which will accept responsibility, and if so...
HP3ParDescription (ie 3Par-1234:0:0:1) breaks out the serial, chassis, node, and port information fro...
static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...
static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...
CiscoSwitchDescription (ie Cisco-001560-0123456:0) breaks out the uniqueness number and port index fr...
static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...
static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...
AIXLPARServerDescription (ie LPAR-012345:0) breaks out the uniqueness number and port index from the ...
HPVirtualServerDescription (ie HP-123456:010) breaks out the uniqueness number and port index from th...
String descPort()
describe the WWPN's unique port label/index
Definition: WWNDesc.java:81
final int value
what bit-field is this constant?
Definition: DevRole.java:20
WWNDesc getWWNDescriptor(String val, boolean provideBase)
Iterates WWNDescription decendents looking for which will accept responsibility, and if so...
static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...
DemoTestDesc(String wwn)
create an instance with brief set to false.
WWNDesc getWWNDescriptor(String val, boolean provideBase, int role)
Iterates WWNDescription decendents looking for which will accept responsibility, and if so...
SymbiosDescription (ie DS3400-123456:A:FC1) breaks out the UUID, Controller, and FC port for a DS3400...
static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...
HDSVSPDescription (ie USPV-10098-CL2A) breaks out the model type, serial, and FA port from the WWPN...
In situations where nicknames simply are not present, but we need descriptors in short-order, the "--wwn=" or "-w" ooption can be used to get a description of what the most likely Nickname would be.
WWNDesc getWWNDescriptor(String val)
Iterates WWNDescription decendents looking for which will accept responsibility, and if so...
EMCVPLEXDescription (ie VPlex-07a3b-A0-FC00) breaks out the serial and FE/BE port from the WWPN...
HPDotHillDescription (ie P2000-123456-B1) breaks out a unique code and the port information from the ...
static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...
static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...
test case: this matches a single item known to exist in the Demo Database
EMCClariionDescription (ie CL-01234567-SPB1) describes the serial and CL of a Clariion; EMC doesn't s...
This class seeks to provide simple bitfield type-checking of a device in a fabric so that I can use t...
Definition: DevRole.java:18
static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...
EMCSymmetrixDescription (ie Symm-187900328-03dB or Symm-0328-03dB) breaks out the serial and FA port ...
WWNDesc is the basic generic class from which each vendor-specific pattern is built upon; similar to ...
Definition: WWNDesc.java:19
static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...
EMCVMAXDescription (ie VMax-HK192601234-12gB or VMax-1234-12gB) breaks out the country of manufacture...
CiscoUCSServerDescription (ie CiscoUCS-012-123:0) breaks out the uniqueness number and port index fro...
static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...
void usage(String proc)
usage messages are useful to those of us with short memories as well (hey, I just need to add swap!) ...
Centralize the sorting logic for various IBM products based on IBM Storage Systems WWPN Determination...
static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...
static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...
static void main(String args[])
Main function, as you can tell.
static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...
String toString()
describe the WWN: produce a short (shorter if this.brief = true) description suitable for use as an a...
Definition: WWNDesc.java:71
Descriptor for (Oracle) Pillar Data Systems' Service Lifecycle Management devices.
NetAppDescription (ie NetApp-123456-iGrp1-0a) breaks out the serial, IO Group, and port information f...
boolean briefWWNEstimate
setting to "true" via the "--briefestimate" commandline causes all descriptions later requested in ge...
BigInteger wwn
the WWN that the instance tried to describe
Definition: WWNDesc.java:21
String toString()
generates a test description or alias for this test class
PureStorageDescription (ie Pure-0123456-CT0.FC0) breaks out the serial number and port information fr...
static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...
static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...