wwndesc  1.0-76
PureStorageDescription.java
1 /* smallfoot.org is owned by allan.clark */
2 package org.smallfoot.wwn;
3 
4 import java.math.BigInteger;
5 
6 /**
7  * PureStorageDescription (ie Pure-0123456-CT0.FC0) breaks out the serial number and port information from the WWPN. Although Pure re-purposes Qlogic HBAs, they have the generosity and forethought to rebadge the WWPN with their own OUI. Thanks, Pure!
8  */
10 {
11  /** @copydoc WWNDesc#WWNDesc(String) */
12  public PureStorageDescription(String wwn)
13  {
14  super(wwn);
15  }
16 
17  /**
18  * If this class matches or describes the given WWN, returns a new instance of this class loaded with the given WWN.
19  *
20  * @return new instance of this class, or null if the given wwn does not match this class
21  * @param strong used to restrict matching to strong-matches only. This is a weak-confidence description, so will return null for strong-only matching
22  * @param brief is used to ask for a shorter description: a more concise nickname or alias
23  * @param wwn the WWN (WWPN or WWNN, but typically WWPN) to match
24  */
25  public static WWNDesc getDesc(boolean strong, boolean brief, String wwn)
26  {
27  return getDesc(strong, brief, wwn, DevRole.max()-1);
28  }
29  /**
30  * @copydoc #getDesc(boolean, boolean, String)
31  * @param role Role (Initiator/Switch/Target) to check for
32  */
33  public static WWNDesc getDesc (boolean strong, boolean brief, String wwn, int role)
34  {
35  if (!isA(role))
36  return null;
37  else if (strong)
38  return null;
39  else if (wwn.matches("^524a937.*"))
40  return new PureStorageDescription(brief, wwn);
41  else
42  return null;
43  }
44 
45  /** @copydoc WWNDesc#WWNDesc(boolean,String) */
46  public PureStorageDescription(boolean brief, String wwn)
47  {
48  super(brief, wwn);
49  }
50  /**
51  * return a description or alias for this WWN; if brief is set to true during the call to getDesc(), then a shorter description or alias will be returned
52  *
53  * @see getDesc(boolean,boolean,String)
54  *
55  * @return generated alias or nickname for the WWN
56  */
57  public String toString()
58  {
59  String res = super.toString();
60  if (null == res) res = "";
61 
62  /* for example start with 52:4a:93:7d:74:f1:14:10 or 5:24a937:d74f114:10 broken apart */
63 
64  BigInteger serDirPort = wwn.subtract(wwn.shiftRight(36).shiftLeft(36));
65 
66  /* our example now has d74f114:10 */
67  BigInteger serPort[] = serDirPort.divideAndRemainder(new BigInteger("100",16));
68 
69  if (brief)
70  return res + String.format("Pure-%07x:%d:%d",serPort[0].intValue(),serPort[1].intValue()/16,serPort[1].intValue() % 16);
71  else
72  return res + String.format("Pure-%07x-CT%d.FC%d",serPort[0].intValue(),serPort[1].intValue()/16,serPort[1].intValue() % 16);
73  }
74 
75  /**
76  * describe the WWPN's unique port label/index
77  *
78  * @return the unique name for the port WWPN
79  */
80  public String descPort()
81  {
82  BigInteger serPort[] = wwn.divideAndRemainder(new BigInteger("10",16));
83  return String.format("FC%d",serPort[1].intValue() % 16);
84  }
85 }
String descPort()
describe the WWPN's unique port label/index
String toString()
return a description or alias for this WWN; if brief is set to true during the call to getDesc()...
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 boolean isA(int role)
convenience function to use bit-masks to check for membership in this role
Definition: WWNDesc.java:158
DevRole role
role of the device: Target, Switch, Initiator
Definition: WWNDesc.java:24
PureStorageDescription(boolean brief, String wwn)
create an instance with the given WWN.
boolean brief
whether a more brief output should be offered in toString() (ie the difference between "VMax-HK192601...
Definition: WWNDesc.java:22
static int max
global singleton to keep track of the max DevRole.value so far
Definition: DevRole.java:21
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
PureStorageDescription(String wwn)
create an instance with brief set to false.
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, int role)
If this class matches or describes the given WWN, returns a new instance of this class loaded with th...
simple pass-thru class to define internal value for a Target in an idempotent way ...
Definition: WWNDesc.java:139
BigInteger wwn
the WWN that the instance tried to describe
Definition: WWNDesc.java:21
PureStorageDescription (ie Pure-0123456-CT0.FC0) breaks out the serial number and port information fr...