1
2
3
4
5 package oshi.driver.unix.aix;
6
7 import java.util.List;
8
9 import oshi.annotation.concurrent.ThreadSafe;
10 import oshi.util.ExecutingCommand;
11 import oshi.util.ParseUtil;
12 import oshi.util.tuples.Pair;
13 import oshi.util.tuples.Triplet;
14
15
16
17
18 @ThreadSafe
19 public final class Lscfg {
20
21 private Lscfg() {
22 }
23
24
25
26
27
28
29 public static List<String> queryAllDevices() {
30 return ExecutingCommand.runNative("lscfg -vp");
31 }
32
33
34
35
36
37
38
39 public static Triplet<String, String, String> queryBackplaneModelSerialVersion(List<String> lscfg) {
40 final String planeMarker = "WAY BACKPLANE";
41 final String modelMarker = "Part Number";
42 final String serialMarker = "Serial Number";
43 final String versionMarker = "Version";
44 final String locationMarker = "Physical Location";
45
46
47
48
49
50
51
52
53
54
55
56 String model = null;
57 String serialNumber = null;
58 String version = null;
59 boolean planeFlag = false;
60 for (final String checkLine : lscfg) {
61 if (!planeFlag && checkLine.contains(planeMarker)) {
62 planeFlag = true;
63 } else if (planeFlag) {
64 if (checkLine.contains(modelMarker)) {
65 model = ParseUtil.removeLeadingDots(checkLine.split(modelMarker)[1].trim());
66 } else if (checkLine.contains(serialMarker)) {
67 serialNumber = ParseUtil.removeLeadingDots(checkLine.split(serialMarker)[1].trim());
68 } else if (checkLine.contains(versionMarker)) {
69 version = ParseUtil.removeLeadingDots(checkLine.split(versionMarker)[1].trim());
70 } else if (checkLine.contains(locationMarker)) {
71 break;
72 }
73 }
74 }
75 return new Triplet<>(model, serialNumber, version);
76 }
77
78
79
80
81
82
83
84 public static Pair<String, String> queryModelSerial(String device) {
85 String modelMarker = "Machine Type and Model";
86 String serialMarker = "Serial Number";
87 String model = null;
88 String serial = null;
89 for (String s : ExecutingCommand.runNative("lscfg -vl " + device)) {
90
91 if (model == null && s.contains(device)) {
92 String locDesc = s.split(device)[1].trim();
93 int idx = locDesc.indexOf(' ');
94 if (idx > 0) {
95 model = locDesc.substring(idx).trim();
96 }
97 }
98 if (s.contains(modelMarker)) {
99 model = ParseUtil.removeLeadingDots(s.split(modelMarker)[1].trim());
100 } else if (s.contains(serialMarker)) {
101 serial = ParseUtil.removeLeadingDots(s.split(serialMarker)[1].trim());
102 }
103 }
104 return new Pair<>(model, serial);
105 }
106 }