-
Notifications
You must be signed in to change notification settings - Fork 245
/
sysinfo
executable file
·790 lines (693 loc) · 21.9 KB
/
sysinfo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
#!/bin/bash
#
# Copyright (c) 2012 Joyent Inc., All rights reserved.
#
# Output some info representing the system. Default: JSON
#
# IMPORTANT:
#
# - Don't use anything here that you don't include in the live image!
#
# - This data gets cached in /tmp/.sysinfo.* and *DOES NOT* automatically
# have the cache refreshed. If you change something where the change
# needs to be visible to sysinfo, make sure you run this with either
# the -f or -u flag after changing the system's state.
#
#set -o xtrace
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/smartdc/bin:/opt/local/bin:/opt/local/sbin
CACHE_FILE_PARSABLE="/tmp/.sysinfo.parsable"
CACHE_FILE_JSON="/tmp/.sysinfo.json"
CACHE="true"
UNAME_S=$(uname -s)
ZONENAME=$(zonename)
FORCE=
PARSABLE=
UPDATE_ONLY=
while getopts fnpu? name
do
case $name in
f)
# Force re-running commands (don't read the cached values)
FORCE="true"
;;
p)
# Output key=value format, not json
PARSABLE="true"
;;
u)
# Update cache *only*, do not output.
FORCE="true"
UPDATE_ONLY="true"
;;
?)
printf "Usage: %s: [-f] [-p] [-u]\n" $0
exit 2
;;
esac
done
if [[ ${UNAME_S} != "SunOS" ]]; then
echo "This program is for use in SmartOS only."
exit 1
fi
if [[ ${EUID} != 0 ]]; then
echo "This program can only be run as root."
exit 1
fi
# If we're not forcing update and we have a cached version, use that!
if [[ -z ${FORCE} ]]; then
if [[ -z ${PARSABLE} && -s ${CACHE_FILE_JSON} ]]; then
exec cat ${CACHE_FILE_JSON}
exit 3
elif [[ -s ${CACHE_FILE_PARSABLE} ]]; then
exec cat ${CACHE_FILE_PARSABLE}
exit 3
fi
fi
# configfile here is only used on headnode
configfile="$(svcprop -p 'joyentfs/usb_copy_path' svc:/system/filesystem/smartdc:default 2>/dev/null)/config"
if [[ ! -f ${configfile} ]]; then
configfile="/mnt/$(svcprop -p 'joyentfs/usb_mountpoint' svc:/system/filesystem/smartdc:default 2>/dev/null)/config"
fi
# helper to set global "normalized" to the expanded version of MAC ($1)
function normalize_mac()
{
local mac=$1
if [ -z "${mac}" ]; then
echo "FATAL: unable to normalize empty mac!"
exit 1
fi
normalized=`echo ${mac} | awk -F':' '{ print $1, $2, $3, $4, $5, $6 }' | { read o1 o2 o3 o4 o5 o6 junk
printf "%02x:%02x:%02x:%02x:%02x:%02x" 0x${o1} 0x${o2} 0x${o3} 0x${o4} 0x${o5} 0x${o6}
}`
# ensure results are 'normal'
echo "${normalized}" | grep "[a-fA-F0-9]\{2\}\:[a-fA-F0-9]\{2\}\:[a-fA-F0-9]\{2\}\:[a-fA-F0-9]\{2\}\:[a-fA-F0-9]\{2\}\:[a-fA-F0-9]\{2\}" >/dev/null 2>&1
if [ "$?" != "0" ]; then
echo "FATAL: failed to normalize MAC '${mac}'"
exit 1
fi
}
function get_smbios_system_info()
{
# This puts the variables we're pulling out into the local environment
eval $(smbios -t SMB_TYPE_SYSTEM | tr -d "\"" \
| egrep "Manufacturer: |Product: |Serial Number: |UUID: " \
| sed -e 's/^ *//' \
| sed -e 's/: /="/' \
| sed -e 's/ *$/"/' \
| sed -e 's/Serial Number/Serial_Number/')
# overwrite UUID if config dictates otherwise
tmp_uuid=$(/usr/bin/bootparams | grep "^override_uuid=" | cut -f2 -d'=')
if [[ -n $tmp_uuid ]]; then
UUID=$tmp_uuid
fi
#echo "${UUID}"
#echo "${Product}"
#echo "${Serial_Number}"
#echo "${Manufacturer}"
}
function get_nonglobal_info()
{
UUID=$(/usr/sbin/mdata-get sdc:uuid)
QUOTA=$(/usr/sbin/zfs get -Ho value quota /)
}
function get_memory_mib()
{
# Get (misnamed in prtconf) memory size in Mebibytes
Memory_in_MiB=`prtconf 2>/dev/null \
| grep "Memory size: [0-9]* Megabytes" \
| cut -d' ' -f3`
#echo "${Memory_in_MiB}"
}
function get_smartos_cpu_info()
{
if [[ ${ZONENAME} == "global" ]]; then
CPU_Version=`smbios -t SMB_TYPE_PROCESSOR | grep -v "Version: 0000000000" \
| grep "Version: " \
| head -n1 \
| tr -s ' ' \
| sed -e 's/^ *Version: //' \
| sed -e 's/ *$//'`
CPU_Count=`smbios -t SMB_TYPE_PROCESSOR | grep -v "Version: 0000000000" \
| grep "Version: " \
| wc -l \
| tr -d ' '`
isainfo=$(isainfo -x)
if [[ -n $(echo " ${isainfo} " | /usr/bin/grep " vmx ") ]]; then
CPU_Virtualization="vmx"
elif [[ -n $(echo " ${isainfo} " | /usr/bin/grep " amd_svm ") ]]; then
CPU_Virtualization="svm"
else
CPU_Virtualization="none"
fi
fi
CPU_Cores=`psrinfo \
| grep "^[0-9]" \
| wc -l \
| tr -d ' '`
#echo "${CPU_Version}"
#echo "${CPU_Count}"
#echo "${CPU_Cores}"
}
function get_live_image_buildstamp()
{
# Add joyent buildstamp to SYSTEM_INFO
Live_Image=$(uname -v | sed -e "s/.*_//")
#echo "${Live_Image}"
}
function get_system_type()
{
Uname_System=${UNAME_S}
}
function get_vm_capable()
{
# XXX all compute nodes should now support VMs
VM_Capable="true"
}
function get_hostname()
{
Hostname=$(hostname)
}
function get_zpool_disks()
{
local zpool=$1
Zpool_disks=
for disk in $(/usr/bin/disklist -n); do
local disk_in_pool=$(/usr/sbin/zpool status ${zpool} | grep ${disk})
if [[ -n ${disk_in_pool} ]]; then
Zpool_disks="${Zpool_disks},${disk}"
fi
done
Zpool_disks=${Zpool_disks/#,/}
}
function get_zpool_profile()
{
local zpool=$1
local profiles=( mirror raidz3 raidz2 raidz )
Zpool_profile="striped"
for profile in ${profiles[*]}; do
if [[ -n $(/usr/sbin/zpool status ${zpool} | grep ${profile}) ]]; then
Zpool_profile=${profile}
break
fi
done
}
function get_zpool()
{
if [[ $(zpool list) != "no pools available" ]]; then
Zpool=$(svcprop -p "config/zpool" svc:/system/smartdc/init);
local used=$(zfs get -Hp -o value used ${Zpool})
local available=$(zfs get -Hp -o value available ${Zpool})
local size=$(( $used + $available ))
Zpool_size=$(($size / 1024 / 1024 / 1024))
get_zpool_disks ${Zpool}
get_zpool_profile ${Zpool}
fi
}
function get_disks()
{
ORIGIFS=$IFS
# set $IFS to end-of-line
IFS=`echo -en "\n\b"`
count=1
for line in $(/usr/bin/disklist -s 2>/dev/null); do
Disks[${count}]=${line}
((count++))
done
# set $IFS back
IFS=$ORIGIFS
}
function get_nic_mappings()
{
admin_nic=`/usr/bin/bootparams 2>/dev/null | grep "^admin_nic=" | cut -d '=' -f2-`
if [[ -z ${admin_nic} ]] && [[ -f ${configfile} ]]; then
admin_nic=`grep "^admin_nic=" ${configfile} | cut -f2- -d'='`
fi
if [[ -n ${admin_nic} ]]; then
normalize_mac ${admin_nic}
ADMIN_NIC=${normalized}
fi
external_nic=`/usr/bin/bootparams 2>/dev/null | grep "^external_nic=" | cut -d '=' -f2-`
if [[ -z ${external_nic} ]] && [[ -f ${configfile} ]]; then
external_nic=`grep "^external_nic=" ${configfile} | cut -f2- -d'='`
fi
if [[ -n ${external_nic} ]]; then
normalize_mac ${external_nic}
EXTERNAL_NIC=${normalized}
fi
internal_nic=`/usr/bin/bootparams 2>/dev/null | grep "^internal_nic=" | cut -d '=' -f2-`
if [[ -z ${internal_nic} ]] && [[ -f ${configfile} ]]; then
internal_nic=`grep "^internal_nic=" ${configfile} | cut -f2- -d'='`
fi
if [[ -n ${internal_nic} ]]; then
normalize_mac ${internal_nic}
INTERNAL_NIC=${normalized}
fi
#echo "${ADMIN_NIC}"
#echo "${EXTERNAL_NIC}"
#echo "${INTERNAL_NIC}"
}
function get_smartos_network_interfaces()
{
count=1
nic_tag_count=1
NicTagList="admin"
seen_nic_tag_admin="true"
# ignore 'LINK SLOT ADDRESS INUSE CLIENT' line
for line in $(pfexec /sbin/dladm show-phys -m \
| grep -v "^LINK " | awk '{ print $1,$3 }' | tr ' ' '='); do
nicnames=
fields=(${line//=/ })
iface=${fields[0]}
normalize_mac ${fields[1]}
mac=${normalized}
ip4addr=$(ifconfig ${iface} 2>/dev/null \
| grep "inet " | awk '{ print $2 }')
if [[ -n "${ADMIN_NIC}" ]] && [[ "${ADMIN_NIC}" == "${mac}" ]]; then
nicnames="admin"
NIC_admin=${iface}
fi
if [[ -n "${EXTERNAL_NIC}" ]] && [[ "${EXTERNAL_NIC}" == "${mac}" ]]; then
[[ -n ${nicnames} ]] && nicnames="${nicnames},"
nicnames="${nicnames}external"
NicTagList="${NicTagList},external"
NIC_external=${iface}
fi
if [[ -n "${INTERNAL_NIC}" ]] && [[ "${INTERNAL_NIC}" == "${mac}" ]]; then
[[ -n ${nicnames} ]] && nicnames="${nicnames},"
nicnames="${nicnames}internal"
NicTagList="${NicTagList},internal"
NIC_internal=${iface}
fi
for tag in "${NicTagsMacs[@]}"; do
tag_fields=(${tag//=/ })
tag_name=${tag_fields[0]}
normalize_mac ${tag_fields[1]}
tag_mac=${normalized}
if [[ "${tag_mac}" == "${mac}" ]]; then
[[ -n ${nicnames} ]] && nicnames="${nicnames},"
nicnames="${nicnames}${tag_name}"
NicTags[${nic_tag_count}]="${tag_name}=${iface}"
((nic_tag_count++))
fi
# Build up the list of tags
eval "seen_nic_tag=\${seen_nic_tag_${tag_name}}"
if [[ -z "${seen_nic_tag}" ]]; then
NicTagList="${NicTagList},${tag_name}"
eval "seen_nic_tag_${tag_name}=true"
fi
done
NetworkInterfaces[${count}]=${iface}
eval "Network_Interface_${iface}_MAC_Address=${mac}"
eval "Network_Interface_${iface}_IPv4_Address=${ip4addr}"
if [[ -n ${nicnames} ]]; then
eval "Network_Interface_${iface}_NIC_Names=${nicnames}"
fi
((count++))
done
for line in $(dladm show-phys -p -olink,state); do
fields=(${line//:/ })
iface=${fields[0]}
link_status=${fields[1]}
eval "Network_Interface_${iface}_Link_Status=${link_status}"
done
#echo "${NIC_admin}"
#echo "${NIC_external}"
#echo "${NIC_internal}"
#for iface in "${NetworkInterfaces[@]}"
#do
# eval "mac=\${Network_Interface_${iface}_MAC_Address}"
# eval "ipv4=\${Network_Interface_${iface}_IPv4_Address}"
# eval "nicnames=\${Network_Interface_${iface}_NIC_Names}"
# echo "mac: ${mac} ---- ${ipv4} ---- ${nicnames}"
#done
}
function get_smartos_vnics()
{
count=1
# ignore 'LINK SLOT ADDRESS INUSE CLIENT' line
for line in $(pfexec /sbin/dladm show-vnic -z '' \
| grep -v "^LINK " | awk '{ print $1,$2,$4,$6 }' | tr ' ' '='); do
fields=(${line//=/ })
iface=${fields[0]}
over=${fields[1]}
normalize_mac ${fields[2]}
mac=${normalized}
vlan=${fields[3]}
link_status=$(pfexec /sbin/dladm show-link -p -o state ${iface})
ip4addr=$(ifconfig ${iface} 2>/dev/null \
| grep "inet " | awk '{ print $2 }')
VirtualNetworkInterfaces[${count}]=${iface}
eval "Virtual_Network_Interface_${iface}_MAC_Address=${mac}"
eval "Virtual_Network_Interface_${iface}_IPv4_Address=${ip4addr}"
eval "Virtual_Network_Interface_${iface}_Link_Status=${link_status}"
eval "Virtual_Network_Interface_${iface}_VLAN=${vlan}"
eval "Virtual_Network_Interface_${iface}_Host_Interface=${over}"
((count++))
done
}
function get_nic_tags()
{
count=1
for line in $(/usr/bin/bootparams 2>/dev/null \
| grep "^[a-zA-Z0-9_]*_nic=" \
; grep "^[a-zA-Z0-9_]*_nic=" ${configfile} 2>/dev/null); do
fields=(${line//=/ })
key=${fields[0]}
if [[ $key != "admin_nic" ]] \
&& [[ $key != "external_nic" ]] \
&& [[ $key != "internal_nic" ]]; then
NicTagsMacs[${count}]=$(echo ${line} | sed -e 's/_nic//')
((count++))
fi
done
}
function get_bootparams()
{
WHICH_GREP="/usr/xpg4/bin/grep"
count=1
for line in $(/usr/bin/bootparams); do
fields=(${line//=/ })
key=$(echo ${fields[0]} | sed -e "s/\-/\_/g")
if ! (echo "${key}" | ${WHICH_GREP} \
-e "^tty" \
-e "^atapi" \
-e "^ata_dma" \
-e "^keyboard_" \
-e "^bios_boot_device" \
-e "^lba_access_" \
-e "^boot_ncpus" \
-e "^boot_file" \
-e "^whoami" \
-e "^mfg_name" \
-e "^impl_arch_name" \
-e "_max_ncpus$" \
>/dev/null); then
Bootparams[${count}]=${line}
((count++))
fi
done
}
function get_boot_time()
{
# This is all there is to it.
Boot_Time=$(/usr/bin/kstat -p -m unix -n system_misc -s boot_time | cut -f2)
}
function get_dc_info()
{
if [[ -f /.dcinfo ]]; then
Datacenter_Name=$(source /.dcinfo; echo "${SDC_DATACENTER_NAME}")
# Headnode ID is only valid if it's an integer.
Headnode_ID=$(source /.dcinfo; echo "${SDC_DATACENTER_HEADNODE_ID}" \
| grep "^[0-9]*$")
fi
}
function output_parsable()
{
cat <<END
Live_Image='${Live_Image}'
System_Type='${Uname_System}'
Boot_Time='${Boot_Time}'
END
if [[ -n ${Datacenter_Name} ]]; then
cat <<END
Datacenter_Name='${Datacenter_Name}'
END
fi
if [[ -n ${Headnode_ID} ]]; then
cat <<END
Headnode_ID=${Headnode_ID}
END
fi
if [[ ${ZONENAME} == "global" ]]; then
cat <<END
Manufacturer='${Manufacturer}'
Product='${Product}'
Serial_Number='${Serial_Number}'
VM_Capable='${VM_Capable}'
CPU_Type='${CPU_Version}'
CPU_Virtualization='${CPU_Virtualization}'
CPU_Physical_Cores=${CPU_Count}
Nic_Tags=${NicTagList}
END
else
echo "Zfs_Quota='${QUOTA}'"
fi
cat <<END
UUID='${UUID}'
Hostname='${Hostname}'
CPU_Total_Cores=${CPU_Cores}
MiB_of_Memory=${Memory_in_MiB}
END
for entry in "${Disks[@]}"; do
fields=(${entry//=/ })
disk=${fields[0]}
size=${fields[1]}
gb_size=$((${size} / 1000000000))
echo "Disk_${disk}_size_in_GB=${gb_size}"
done
[[ -n ${NIC_admin} ]] && echo "NIC_admin='${NIC_admin}'"
[[ -n ${NIC_external} ]] && echo "NIC_external='${NIC_external}'"
[[ -n ${NIC_internal} ]] && echo "NIC_internal='${NIC_internal}'"
for tag in "${NicTags[@]}"; do
tag_fields=(${tag//=/ })
tag_name=${tag_fields[0]}
int=${tag_fields[1]}
echo "NIC_${tag_name}='${int}'"
done
for iface in "${NetworkInterfaces[@]}"; do
mac_var="Network_Interface_${iface}_MAC_Address"
ipv4_var="Network_Interface_${iface}_IPv4_Address"
nicnames_var="Network_Interface_${iface}_NIC_Names"
link_status_var="Network_Interface_${iface}_Link_Status"
detected_tag_var="Network_Interface_${iface}_Detected_Nic_Tag"
eval "mac=\${${mac_var}}"
eval "ipv4=\${${ipv4_var}}"
eval "nicnames=\${${nicnames_var}}"
link_status="unknown"
eval "link_status=\${${link_status_var}}"
eval "detected_tag=\${${detected_tag_var}}"
echo "${mac_var}='${mac}'"
echo "${ipv4_var}='${ipv4}'"
echo "${nicnames_var}='${nicnames}'"
echo "${link_status_var}='${link_status}'"
if [[ -n "${detected_tag}" ]] ; then
echo "${detected_tag_var}='${detected_tag}'"
fi
done
for iface in "${VirtualNetworkInterfaces[@]}"; do
mac_var="Virtual_Network_Interface_${iface}_MAC_Address"
ipv4_var="Virtual_Network_Interface_${iface}_IPv4_Address"
link_status_var="Virtual_Network_Interface_${iface}_Link_Status"
vlan_var="Virtual_Network_Interface_${iface}_VLAN"
host_var="Virtual_Network_Interface_${iface}_Host_Interface"
eval "mac=\${${mac_var}}"
eval "ipv4=\${${ipv4_var}}"
eval "link_status=\${${link_status_var}}"
eval "vlan=\${${vlan_var}}"
eval "host=\${${host_var}}"
echo "${mac_var}='${mac}'"
echo "${ipv4_var}='${ipv4}'"
echo "${link_status_var}='${link_status}'"
echo "${vlan_var}='${vlan}'"
if [[ ${ZONENAME} == "global" ]]; then
echo "${host_var}='${host}'"
fi
done
for entry in "${Bootparams[@]}"; do
fields=(${entry//=/ })
key=$(echo ${fields[0]} | sed -e "s/\-/\_/g")
val=${fields[1]}
echo "Bootparam_${key}='${val}'"
done
}
function output_json()
{
cat <<END
{
"Live Image": "${Live_Image}",
"System Type": "${Uname_System}",
"Boot Time": "${Boot_Time}",
END
if [[ -n ${Datacenter_Name} ]]; then
cat <<END
"Datacenter Name": "${Datacenter_Name}",
END
fi
if [[ -n ${Headnode_ID} ]]; then
cat <<END
"Headnode ID": ${Headnode_ID},
END
fi
if [[ ${ZONENAME} == "global" ]]; then
cat <<END
"Manufacturer": "${Manufacturer}",
"Product": "${Product}",
"Serial Number": "${Serial_Number}",
"VM Capable": ${VM_Capable},
"CPU Type": "${CPU_Version}",
"CPU Virtualization": "${CPU_Virtualization}",
"CPU Physical Cores": ${CPU_Count},
END
else
echo " \"ZFS Quota\": \"${QUOTA}\","
fi
cat <<END
"UUID": "${UUID}",
"Hostname": "${Hostname}",
"CPU Total Cores": ${CPU_Cores},
"MiB of Memory": "${Memory_in_MiB}",
END
if [[ ${ZONENAME} == "global" ]]; then
if [[ -n ${Zpool} ]]; then
echo ' "Zpool": "'${Zpool}'",'
echo ' "Zpool Disks": "'${Zpool_disks}'",'
echo ' "Zpool Profile": "'${Zpool_profile}'",'
echo ' "Zpool Size in GiB":' ${Zpool_size}','
fi
echo ' "Disks": {'
printed=0
for entry in "${Disks[@]}"; do
fields=(${entry//=/ })
disk=${fields[0]}
size=${fields[1]}
gb_size=$((${size} / 1000000000))
((printed++))
trailing_comma=","
[[ ${printed} -eq ${#Disks[*]} ]] && trailing_comma=''
echo " \"${disk}\": {\"Size in GB\": ${gb_size}}${trailing_comma}"
done
cat <<END
},
"Boot Parameters": {
END
printed=0
for entry in "${Bootparams[@]}"; do
fields=(${entry//=/ })
key=$(echo ${fields[0]} | sed -e "s/\-/\_/g")
val=${fields[1]}
((printed++))
trailing_comma=","
[[ ${printed} -eq ${#Bootparams[*]} ]] && trailing_comma=''
echo " \"${key}\": \"$val\"${trailing_comma}"
done
cat <<END
},
"Network Interfaces": {
END
printed=0
for iface in "${NetworkInterfaces[@]}"; do
mac_var="Network_Interface_${iface}_MAC_Address"
ipv4_var="Network_Interface_${iface}_IPv4_Address"
nicnames_var="Network_Interface_${iface}_NIC_Names"
link_status_var="Network_Interface_${iface}_Link_Status"
detected_tag_var="Network_Interface_${iface}_Detected_Nic_Tag"
nic_names_fmt=
detected_fmt=
eval "mac=\${${mac_var}}"
eval "ipv4=\${${ipv4_var}}"
eval "nicnames=\${${nicnames_var}}"
eval "link_status=\${${link_status_var}}"
eval "detected_tag=\${${detected_tag_var}}"
if [[ -n "${detected_tag}" ]] ; then
detected_fmt="\"Detected NIC Name\": \"${detected_tag}\", "
fi
nic_names_array=$(echo "${nicnames}" | sed -e "s/,/\", \"/g")
if [[ -n ${nic_names_array} ]]; then
nic_names_fmt="\"${nic_names_array}\""
fi
((printed++))
trailing_comma=","
[[ ${printed} -eq ${#NetworkInterfaces[*]} ]] && trailing_comma=''
echo -n " \"${iface}\": {"
echo -n "\"MAC Address\": \"${mac}\", "
echo -n "\"ip4addr\": \"${ipv4}\", "
echo -n "\"Link Status\": \"${link_status}\", "
echo -n "${detected_fmt}"
echo -n "\"NIC Names\": [${nic_names_fmt}]}"
echo "${trailing_comma}"
done
echo " },"
fi
cat << END
"Virtual Network Interfaces": {
END
printed=0
for iface in "${VirtualNetworkInterfaces[@]}"; do
mac_var="Virtual_Network_Interface_${iface}_MAC_Address"
ipv4_var="Virtual_Network_Interface_${iface}_IPv4_Address"
link_status_var="Virtual_Network_Interface_${iface}_Link_Status"
vlan_var="Virtual_Network_Interface_${iface}_VLAN"
parent_var="Virtual_Network_Interface_${iface}_Host_Interface"
eval "mac=\${${mac_var}}"
eval "ipv4=\${${ipv4_var}}"
eval "link_status=\${${link_status_var}}"
eval "vlan=\${${vlan_var}}"
eval "host=\${${host_var}}"
((printed++))
trailing_comma=","
[[ ${printed} -eq ${#VirtualNetworkInterfaces[*]} ]] && trailing_comma=''
echo -n " \"${iface}\": {"
echo -n "\"MAC Address\": \"${mac}\", "
echo -n "\"ip4addr\": \"${ipv4}\", "
echo -n "\"Link Status\": \"${link_status}\", "
if [[ ${ZONENAME} == "global" ]]; then
echo -n "\"Host Interface\": \"${host}\", "
fi
echo -n "\"VLAN\": \"${vlan}\"}"
echo "${trailing_comma}"
done
cat <<END
}
}
END
}
if [[ ${ZONENAME} == "global" ]]; then
get_smbios_system_info
get_vm_capable
get_zpool
get_disks
get_bootparams
else
get_nonglobal_info
fi
get_memory_mib
get_smartos_cpu_info
get_live_image_buildstamp
get_system_type
get_hostname
get_nic_mappings
get_nic_tags
get_smartos_network_interfaces
get_smartos_vnics
get_boot_time
get_dc_info
# whenever we update the cache, update both
if [[ ${CACHE} == "true" ]]; then
output_parsable >> ${CACHE_FILE_PARSABLE}.new.$$ \
&& chmod 600 ${CACHE_FILE_PARSABLE}.new.$$ \
&& mv ${CACHE_FILE_PARSABLE}.new.$$ ${CACHE_FILE_PARSABLE}
output_json >> ${CACHE_FILE_JSON}.new.$$ \
&& chmod 600 ${CACHE_FILE_JSON}.new.$$ \
&& mv ${CACHE_FILE_JSON}.new.$$ ${CACHE_FILE_JSON}
fi
# if we also want output, give it now
if [[ -z ${UPDATE_ONLY} ]]; then
if [[ ${PARSABLE} == "true" ]]; then
if [[ -z ${CACHE} ]]; then
# We shouldn't read/write cache
output_parsable
else
cat ${CACHE_FILE_PARSABLE} \
|| output_parsable
fi
else
if [[ -z ${CACHE} ]]; then
# We shouldn't read/write cache
output_json
else
cat ${CACHE_FILE_JSON} \
|| output_json
fi
fi
fi
exit 0