forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
computersystem.go
1071 lines (946 loc) · 41.6 KB
/
computersystem.go
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
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"fmt"
"reflect"
"strings"
"github.com/stmcginnis/gofish/common"
)
// BootOrderTypes is the choice of boot order property to use when controller
// the persistent boot order for this computer system.
type BootOrderTypes string
const (
// BootOrderBootOrderTypes indicates an ordered array of persistent boot
// order for this system.
BootOrderBootOrderTypes BootOrderTypes = "BootOrder"
// AliasBootOrderBootOrderTypes indicates an ordered array of aliased
// persistent boot order for this system.
AliasBootOrderBootOrderTypes BootOrderTypes = "AliasBootOrder"
)
// BootSourceOverrideEnabled describes the state of the Boot Source Override feature.
type BootSourceOverrideEnabled string
const (
// DisabledBootSourceOverrideEnabled the system will boot normally.
DisabledBootSourceOverrideEnabled BootSourceOverrideEnabled = "Disabled"
// OnceBootSourceOverrideEnabled on its next boot cycle, the system will
// boot (one time) to the Boot Source Override Target. The value of
// BootSourceOverrideEnabled is then reset back to Disabled.
OnceBootSourceOverrideEnabled BootSourceOverrideEnabled = "Once"
// ContinuousBootSourceOverrideEnabled the system will boot to the target
// specified in the BootSourceOverrideTarget until this property is set
// to Disabled.
ContinuousBootSourceOverrideEnabled BootSourceOverrideEnabled = "Continuous"
)
// BootSourceOverrideTarget the current boot source to be used at next boot instead of the normal boot device, if BootSourceOverrideEnabled is true.
type BootSourceOverrideTarget string
const (
// NoneBootSourceOverrideTarget boot from the normal boot device
NoneBootSourceOverrideTarget BootSourceOverrideTarget = "None"
// PxeBootSourceOverrideTarget boot from the Pre-Boot EXecution (PXE) environment.
PxeBootSourceOverrideTarget BootSourceOverrideTarget = "Pxe"
// FloppyBootSourceOverrideTarget boot from the floppy disk drive
FloppyBootSourceOverrideTarget BootSourceOverrideTarget = "Floppy"
// CdBootSourceOverrideTarget boot from the CD/DVD disc
CdBootSourceOverrideTarget BootSourceOverrideTarget = "Cd"
// UsbBootSourceOverrideTarget boot from a USB device as specified by the system BIOS
UsbBootSourceOverrideTarget BootSourceOverrideTarget = "Usb"
// HddBootSourceOverrideTarget boot from a hard drive
HddBootSourceOverrideTarget BootSourceOverrideTarget = "Hdd"
// BiosSetupBootSourceOverrideTarget boot to the BIOS Setup Utility
BiosSetupBootSourceOverrideTarget BootSourceOverrideTarget = "BiosSetup"
// UtilitiesBootSourceOverrideTarget boot the manufacturer's Utilities program(s)
UtilitiesBootSourceOverrideTarget BootSourceOverrideTarget = "Utilities"
// DiagsBootSourceOverrideTarget boot the manufacturer's Diagnostics program
DiagsBootSourceOverrideTarget BootSourceOverrideTarget = "Diags"
// UefiShellBootSourceOverrideTarget boot to the UEFI Shell.
UefiShellBootSourceOverrideTarget BootSourceOverrideTarget = "UefiShell"
// UefiTargetBootSourceOverrideTarget boot to the UEFI Device specified in the UefiTargetBootSourceOverride property.
UefiTargetBootSourceOverrideTarget BootSourceOverrideTarget = "UefiTarget"
// SDCardBootSourceOverrideTarget boot from an SD Card
SDCardBootSourceOverrideTarget BootSourceOverrideTarget = "SDCard"
// UefiHTTPBootSourceOverrideTarget boot from a UEFI HTTP network location
UefiHTTPBootSourceOverrideTarget BootSourceOverrideTarget = "UefiHttp"
// RemoteDriveBootSourceOverrideTarget boot from a remote drive (e.g. iSCSI).
RemoteDriveBootSourceOverrideTarget BootSourceOverrideTarget = "RemoteDrive"
// UefiBootNextBootSourceOverrideTarget boot to the UEFI Device specified in the BootNext property
UefiBootNextBootSourceOverrideTarget BootSourceOverrideTarget = "UefiBootNext"
)
// BootSourceOverrideMode is the BIOS mode (Legacy or UEFI) to be used.
type BootSourceOverrideMode string
const (
// LegacyBootSourceOverrideMode the system will boot in non-UEFI boot
// mode to the Boot Source Override Target.
LegacyBootSourceOverrideMode BootSourceOverrideMode = "Legacy"
// UEFIBootSourceOverrideMode the system will boot in UEFI boot mode to
// the Boot Source Override Target.
UEFIBootSourceOverrideMode BootSourceOverrideMode = "UEFI"
)
// HostingRole specifies different features that the hosting ComputerSystem supports.
type HostingRole string
const (
// ApplicationServerHostingRole the system hosts functionality that
// supports general purpose applications.
ApplicationServerHostingRole HostingRole = "ApplicationServer"
// StorageServerHostingRole the system hosts functionality that supports
// the system acting as a storage server.
StorageServerHostingRole HostingRole = "StorageServer"
// SwitchHostingRole the system hosts functionality that supports the
// system acting as a switch.
SwitchHostingRole HostingRole = "Switch"
)
// InterfaceType is the Trusted Platform Module type.
type InterfaceType string
const (
// TPM1_2InterfaceType Trusted Platform Module (TPM) 1.2.
TPM1_2InterfaceType InterfaceType = "TPM1_2"
// TPM2_0InterfaceType Trusted Platform Module (TPM) 2.0.
TPM2_0InterfaceType InterfaceType = "TPM2_0"
// TCM1_0InterfaceType Trusted Cryptography Module (TCM) 1.0.
TCM1_0InterfaceType InterfaceType = "TCM1_0"
)
// InterfaceTypeSelection specify the method for switching the TrustedModule
// InterfaceType, for instance between TPM1_2 and TPM2_0, if supported.
type InterfaceTypeSelection string
const (
// NoneInterfaceTypeSelection the TrustedModule does not support
// switching the InterfaceType.
NoneInterfaceTypeSelection InterfaceTypeSelection = "None"
// FirmwareUpdateInterfaceTypeSelection the TrustedModule supports
// switching InterfaceType via a firmware update.
FirmwareUpdateInterfaceTypeSelection InterfaceTypeSelection = "FirmwareUpdate"
// BiosSettingInterfaceTypeSelection the TrustedModule supports switching
// InterfaceType via platform software, such as a BIOS configuration
// Attribute.
BiosSettingInterfaceTypeSelection InterfaceTypeSelection = "BiosSetting"
// OemMethodInterfaceTypeSelection the TrustedModule supports switching
// InterfaceType via an OEM proprietary mechanism.
OemMethodInterfaceTypeSelection InterfaceTypeSelection = "OemMethod"
)
// MemoryMirroring indicates the memory mirroring setting
type MemoryMirroring string
const (
// SystemMemoryMirroring the system supports DIMM mirroring at the System
// level. Individual DIMMs are not paired for mirroring in this mode.
SystemMemoryMirroring MemoryMirroring = "System"
// DIMMMemoryMirroring the system supports DIMM mirroring at the DIMM
// level. Individual DIMMs can be mirrored.
DIMMMemoryMirroring MemoryMirroring = "DIMM"
// HybridMemoryMirroring the system supports a hybrid mirroring at the
// system and DIMM levels. Individual DIMMs can be mirrored.
HybridMemoryMirroring MemoryMirroring = "Hybrid"
// NoneMemoryMirroring the system does not support DIMM mirroring.
NoneMemoryMirroring MemoryMirroring = "None"
)
// PowerRestorePolicyTypes specifies the choice of power state for the system
// when power is applied.
type PowerRestorePolicyTypes string
const (
// AlwaysOnPowerRestorePolicyTypes the system will always power on when
// power is applied.
AlwaysOnPowerRestorePolicyTypes PowerRestorePolicyTypes = "AlwaysOn"
// AlwaysOffPowerRestorePolicyTypes the system will always remain powered
// off when power is applied.
AlwaysOffPowerRestorePolicyTypes PowerRestorePolicyTypes = "AlwaysOff"
// LastStatePowerRestorePolicyTypes the system will return to its last
// power state (on or off) when power is applied.
LastStatePowerRestorePolicyTypes PowerRestorePolicyTypes = "LastState"
)
// PowerState is the power state of the system.
type PowerState string
const (
// OnPowerState the system is powered on.
OnPowerState PowerState = "On"
// OffPowerState the system is powered off, although some components may
// continue to have AUX power such as management controller.
OffPowerState PowerState = "Off"
// PoweringOnPowerState A temporary state between Off and On. This
// temporary state can be very short.
PoweringOnPowerState PowerState = "PoweringOn"
// PoweringOffPowerState A temporary state between On and Off. The power
// off action can take time while the OS is in the shutdown process.
PoweringOffPowerState PowerState = "PoweringOff"
)
// SystemType is the type of system.
type SystemType string
const (
// PhysicalSystemType is a System Type of Physical is typically used when
// representing the hardware aspects of a system such as is done by a
// management controller.
PhysicalSystemType SystemType = "Physical"
// VirtualSystemType is a System Type of Virtual is typically used when
// representing a system that is actually a virtual machine instance.
VirtualSystemType SystemType = "Virtual"
// OSSystemType is a System Type of OS is typically used when representing
// an OS or hypervisor view of the system.
OSSystemType SystemType = "OS"
// PhysicallyPartitionedSystemType is a System Type of PhysicallyPartition is
// typically used when representing a single system constructed from
// one or more physical systems via a firmware or hardware-based service.
PhysicallyPartitionedSystemType SystemType = "PhysicallyPartitioned"
// VirtuallyPartitionedSystemType is a System Type of VirtuallyPartition is
// typically used when representing a single system constructed from
// one or more virtual systems via a software-based service.
VirtuallyPartitionedSystemType SystemType = "VirtuallyPartitioned"
// ComposedSystemType is a System Type of Composed is typically used when
// representing a single system constructed from disaggregated resource
// via the Redfish Composition service.
ComposedSystemType SystemType = "Composed"
)
// WatchdogTimeoutActions specifies the choice of action to take when the Host
// Watchdog Timer reaches its timeout value.
type WatchdogTimeoutActions string
const (
// NoneWatchdogTimeoutActions means no action taken.
NoneWatchdogTimeoutActions WatchdogTimeoutActions = "None"
// ResetSystemWatchdogTimeoutActions means reset the system.
ResetSystemWatchdogTimeoutActions WatchdogTimeoutActions = "ResetSystem"
// PowerCycleWatchdogTimeoutActions means power cycle the system.
PowerCycleWatchdogTimeoutActions WatchdogTimeoutActions = "PowerCycle"
// PowerDownWatchdogTimeoutActions means power down the system.
PowerDownWatchdogTimeoutActions WatchdogTimeoutActions = "PowerDown"
// OEMWatchdogTimeoutActions means perform an OEM-defined action.
OEMWatchdogTimeoutActions WatchdogTimeoutActions = "OEM"
)
// WatchdogWarningActions specifies the choice of action to take when the Host
// Watchdog Timer is close (typically 3-10 seconds) to reaching its timeout value.
type WatchdogWarningActions string
const (
// NoneWatchdogWarningActions means no action taken.
NoneWatchdogWarningActions WatchdogWarningActions = "None"
// DiagnosticInterruptWatchdogWarningActions means raise a (typically non-
// maskable) Diagnostic Interrupt.
DiagnosticInterruptWatchdogWarningActions WatchdogWarningActions = "DiagnosticInterrupt"
// SMIWatchdogWarningActions means raise a Systems Management Interrupt (SMI).
SMIWatchdogWarningActions WatchdogWarningActions = "SMI"
// MessagingInterruptWatchdogWarningActions means raise a legacy IPMI messaging
// interrupt.
MessagingInterruptWatchdogWarningActions WatchdogWarningActions = "MessagingInterrupt"
// SCIWatchdogWarningActions means raise an interrupt using the ACPI System
// Control Interrupt (SCI).
SCIWatchdogWarningActions WatchdogWarningActions = "SCI"
// OEMWatchdogWarningActions means perform an OEM-defined action.
OEMWatchdogWarningActions WatchdogWarningActions = "OEM"
)
// Boot contains properties which describe boot information for a system.
type Boot struct {
// AliasBootOrder shall be an ordered array
// of boot source aliases (of type BootSource) representing the
// persistent Boot Order of this computer system.
AliasBootOrder []string `json:",omitempty"`
AutomaticRetryAttempts int `json:",omitempty"`
AutomaticRetryConfig string `json:",omitempty"`
// BootNext shall be the
// BootOptionReference of the UEFI Boot Option for one time boot, as
// defined by the UEFI Specification. The valid values for this property
// are specified in the values of the BootOrder array.
// BootSourceOverrideEnabled = Continuous is not supported for UEFI
// BootNext as this setting is defined in UEFI as a one-time boot only.
BootNext string `json:",omitempty"`
// bootOptions is a link to the collection of the UEFI boot options
// associated with this computer system.
bootOptions string
// BootOrder shall be an ordered array of
// BootOptionReference strings representing the persistent Boot Order of
// this computer system. For UEFI systems, this is the UEFI BootOrder as
// defined by the UEFI Specification.
BootOrder []string `json:",omitempty"`
// BootOrderPropertySelection shall
// indicate which boot order property the system uses when specifying the
// persistent boot order.
BootOrderPropertySelection string `json:",omitempty"`
// BootSourceOverrideEnabled shall be Once
// if this is a one time boot override and Continuous if this selection
// should remain active until cancelled. If the property value is set to
// Once, the value will be reset back to Disabled after the
// BootSourceOverrideTarget actions have been completed. Changes to this
// property do not alter the BIOS persistent boot order configuration.
BootSourceOverrideEnabled BootSourceOverrideEnabled `json:",omitempty"`
// BootSourceOverrideMode shall be Legacy
// for non-UEFI BIOS boot or UEFI for UEFI boot from boot source
// specified in BootSourceOverrideTarget property.
BootSourceOverrideMode BootSourceOverrideMode `json:",omitempty"`
// BootSourceOverrideTarget shall contain
// the source to boot the system from, overriding the normal boot order.
// The valid values for this property are specified through the
// Redfish.AllowableValues annotation. Pxe indicates to PXE boot from the
// primary NIC; Floppy, Cd, Usb, Hdd indicates to boot from their devices
// respectively. BiosSetup indicates to boot into the native BIOS screen
// setup. Utilities and Diags indicate to boot from the local utilities
// or diags partitions. UefiTarget indicates to boot from the UEFI device
// path found in UefiTargetBootSourceOverride. UefiBootNext indicates to
// boot from the UEFI BootOptionReference found in BootNext. Changes to
// this property do not alter the BIOS persistent boot order
// configuration.
BootSourceOverrideTarget BootSourceOverrideTarget `json:",omitempty"`
// UefiTargetBootSourceOverride shall be
// the UEFI device path of the override boot target. The valid values for
// this property are specified through the Redfish.AllowableValues
// annotation. BootSourceOverrideEnabled = Continuous is not supported
// for UEFI Boot Source Override as this setting is defined in UEFI as a
// one time boot only. Changes to this property do not alter the BIOS
// persistent boot order configuration.
UefiTargetBootSourceOverride string `json:",omitempty"`
}
// UnmarshalJSON unmarshals a Boot object from the raw JSON.
func (boot *Boot) UnmarshalJSON(b []byte) error {
type temp Boot
var t struct {
temp
BootOptions common.Link
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
*boot = Boot(t.temp)
// Extract the links to other entities for later
boot.bootOptions = t.BootOptions.String()
return nil
}
// BootOption represents the properties of a bootable device available in the
// system.
type BootOption struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// Alias is the alias of this boot source if one exists.
Alias BootSourceOverrideTarget
// BootOptionEnabled is an indication of whether the boot option is
// enabled. If true , it is enabled. If false, the boot option that the
// boot order array on the computer system contains is skipped. In the
// UEFI context, this property shall influence the load option active
// flag for the boot option.
BootOptionEnabled bool
// BootOptionReference is the unique identifier seen in Boot.BootOrder.
BootOptionReference string
// DisplayName is the user-readable display name of the boot option
// that appears in the boot order list in the user interface.
DisplayName string
// UefiDevicePath is the UEFI device path to access this UEFI boot
// option.
UefiDevicePath string
}
// GetBootOption will get a BootOption instance from the service.
func GetBootOption(c common.Client, uri string) (*BootOption, error) {
var bootoption BootOption
return &bootoption, bootoption.Get(c, uri, &bootoption)
}
// ResetType describe the type off reset to be issue by the resource
type ResetType string
const (
// OnResetType shall be used to power on the machine
OnResetType ResetType = "On"
// ForceOnResetType shall be used to power on the machine immediately
ForceOnResetType ResetType = "ForceOn"
// ForceOffResetType shall be used to power off the machine without wait the OS to shutdown
ForceOffResetType ResetType = "ForceOff"
// ForceRestartResetType shall be used to restart the machine without wait the OS to shutdown
ForceRestartResetType ResetType = "ForceRestart"
// GracefulRestartResetType shall be used to restart the machine waiting the OS shutdown gracefully
GracefulRestartResetType ResetType = "GracefulRestart"
// GracefulShutdownResetType shall be used to restart the machine waiting the OS shutdown gracefully
GracefulShutdownResetType ResetType = "GracefulShutdown"
// PushPowerButtonResetType shall be used to emulate pushing the power button
PushPowerButtonResetType ResetType = "PushPowerButton"
// PowerCycleResetType shall be used to power cycle the machine
PowerCycleResetType ResetType = "PowerCycle"
// NmiResetType shall be used to trigger a crash/core dump file
NmiResetType ResetType = "Nmi"
)
// ComputerSystem is used to represent resources that represent a
// computing system in the Redfish specification.
type ComputerSystem struct {
common.Entity
// ODataContext is the @odata.context
ODataContext string `json:"@odata.context"`
// ODataType is the @odata.type
ODataType string `json:"@odata.type"`
// AssetTag shall contain the value of the asset tag of the system.
AssetTag string
// bios shall be a link to a resource of
// type Bios that lists the Bios settings for this system.
bios string
// BIOSVersion shall be the version string
// of the currently installed and running BIOS (for x86 systems). For
// other systems, the value may contain a version string representing the
// primary system firmware.
BIOSVersion string `json:"BiosVersion"`
// Boot describes boot information for the current resource.
Boot Boot
// Description is the resource description.
Description string
// EthernetInterfaces shall be a link to a
// collection of type EthernetInterfaceCollection.
ethernetInterfaces string
// HostName shall be the host name for this
// system, as reported by the operating system or hypervisor. This value
// is typically provided to the Manager by a service running in the host
// operating system.
HostName string
// HostWatchdogTimer shall contain properties which
// describe the host watchdog timer functionality for this
// ComputerSystem.
HostWatchdogTimer WatchdogTimer
// hostedServices shall describe services supported by this computer system.
// hostedServices string
// HostingRoles shall be the hosting roles supported by this computer system.
HostingRoles []string
// IndicatorLED shall contain the indicator
// light state for the indicator light associated with this system.
IndicatorLED common.IndicatorLED
// logServices shall be a link to a collection of type LogServiceCollection.
logServices string
// Manufacturer shall contain a value that represents the manufacturer of the system.
Manufacturer string
// Memory shall be a link to a collection of type MemoryCollection.
memory string
// memoryDomains shall be a link to a collection of type MemoryDomainCollection.
memoryDomains string
// MemorySummary is This object shall contain properties which describe
// the central memory for the current resource.
MemorySummary MemorySummary
// Model shall contain the information
// about how the manufacturer references this system. This is typically
// the product name, without the manufacturer name.
Model string
// Name is the resource name.
Name string
// networkInterfaces shall be a link to a collection of type
// NetworkInterfaceCollection.
networkInterfaces string
// PCIeDevices shall be an array of references of type PCIeDevice.
pcieDevices []string
// PCIeDevicesCount is the number of PCIeDevices.
PCIeDevicesCount int `json:"PCIeDevices@odata.count"`
// PCIeFunctions shall be an array of references of type PCIeFunction.
pcieFunctions []string
// PCIeFunctionsCount is the number of PCIeFunctions.
PCIeFunctionsCount int `json:"PCIeFunctions@odata.count"`
// PartNumber shall contain the part number
// for the system as defined by the manufacturer.
PartNumber string
// PowerRestorePolicy is the desired
// PowerState of the system when power is applied to the system. A value
// of 'LastState' shall return the system to the PowerState it was in
// when power was lost.
PowerRestorePolicy PowerState
// PowerState shall contain the power state of the system.
PowerState PowerState
// ProcessorSummary shall contain properties which
// describe the central processors for the current resource.
ProcessorSummary ProcessorSummary
// Processors shall be a link to a collection of type ProcessorCollection.
processors string
// Redundancy references a redundancy
// entity that specifies a kind and level of redundancy and a collection
// (RedundancySet) of other ComputerSystems that provide the specified
// redundancy to this ComputerSystem.
Redundancy string
// RedundancyCount is the number of Redundancy objects.
RedundancyCount string `json:"Redundancy@odata.count"`
// SKU shall contain the Stock Keeping Unit (SKU) for the system.
SKU string
// secureBoot shall be a link to a resource of type SecureBoot.
secureBoot string
// SerialNumber shall contain the serial number for the system.
SerialNumber string
// SimpleStorage shall be a link to a collection of type SimpleStorageCollection.
simpleStorage string
// Status shall contain any status or health properties
// of the resource.
Status common.Status
// storage shall be a link to a collection
// of type StorageCollection.
storage string
// SubModel shall contain the information
// about the sub-model (or config) of the system. This shall not include
// the model/product name or the manufacturer name.
SubModel string
// SystemType indicates the kind of system that this resource represents.
SystemType SystemType
// TrustedModules shall contain an array of objects with
// properties which describe the trusted modules for the current resource.
TrustedModules []TrustedModules
// UUID is used to contain a universal unique identifier number for the
// system. RFC4122 describes methods that can be used to create the
// value. The value should be considered to be opaque. Client software
// should only treat the overall value as a universally unique identifier
// and should not interpret any sub-fields within the UUID. If the system
// supports SMBIOS, the value of the property should be formed by
// following the SMBIOS 2.6+ recommendation for converting the SMBIOS
// 16-byte UUID structure into the redfish canonical xxxxxxxx-xxxx-xxxx-
// xxxx-xxxxxxxxxxxx string format so that the property value matches the
// byte order presented by current OS APIs such as WMI and dmidecode.
UUID string
// Chassis is an array of references to the chassis in which this system is contained.
chassis []string
// resetTarget is the internal URL to send reset targets to.
resetTarget string
// SupportedResetTypes, if provided, is the reset types this system supports.
SupportedResetTypes []ResetType
// setDefaultBootOrderTarget is the URL to send SetDefaultBootOrder actions to.
setDefaultBootOrderTarget string
settingsTarget string
// settingsApplyTimes is a set of allowed settings update apply times. If none
// are specified, then the system does not provide that information.
settingsApplyTimes []common.ApplyTime
// ManagedBy An array of references to the Managers responsible for this system.
// This is temporary until a proper method can be implemented to actually
// retrieve those objects directly.
ManagedBy []string
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
}
// UnmarshalJSON unmarshals a ComputerSystem object from the raw JSON.
func (computersystem *ComputerSystem) UnmarshalJSON(b []byte) error {
type CSActions struct {
ComputerSystemReset struct {
AllowedResetTypes []ResetType `json:"ResetType@Redfish.AllowableValues"`
Target string
} `json:"#ComputerSystem.Reset"`
SetDefaultBootOrder struct {
Target string
} `json:"#ComputerSystem.SetDefaultBootOrder"`
}
type temp ComputerSystem
var t struct {
temp
Actions CSActions
Bios common.Link
Processors common.Link
Memory common.Link
EthernetInterfaces common.Link
SimpleStorage common.Link
SecureBoot common.Link
Storage common.Link
NetworkInterfaces common.Link
LogServices common.Link
MemoryDomains common.Link
PCIeDevices common.Links
PCIeFunctions common.Links
Links CSLinks
Settings common.Settings `json:"@Redfish.Settings"`
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
*computersystem = ComputerSystem(t.temp)
// Extract the links to other entities for later
computersystem.bios = t.Bios.String()
computersystem.processors = t.Processors.String()
computersystem.memory = t.Memory.String()
computersystem.ethernetInterfaces = t.EthernetInterfaces.String()
computersystem.simpleStorage = t.SimpleStorage.String()
computersystem.networkInterfaces = t.NetworkInterfaces.String()
computersystem.secureBoot = t.SecureBoot.String()
computersystem.storage = t.Storage.String()
computersystem.logServices = t.LogServices.String()
computersystem.memoryDomains = t.MemoryDomains.String()
computersystem.pcieDevices = t.PCIeDevices.ToStrings()
computersystem.pcieFunctions = t.PCIeFunctions.ToStrings()
computersystem.chassis = t.Links.Chassis.ToStrings()
computersystem.resetTarget = t.Actions.ComputerSystemReset.Target
computersystem.SupportedResetTypes = t.Actions.ComputerSystemReset.AllowedResetTypes
computersystem.setDefaultBootOrderTarget = t.Actions.SetDefaultBootOrder.Target
computersystem.ManagedBy = t.Links.ManagedBy.ToStrings()
computersystem.settingsApplyTimes = t.Settings.SupportedApplyTimes
// Some implementations use a @Redfish.Settings object to direct settings updates to a
// different URL than the object being updated. Others don't, so handle both.
computersystem.settingsTarget = t.Settings.SettingsObject.String()
if computersystem.settingsTarget == "" {
computersystem.settingsTarget = computersystem.ODataID
}
// This is a read/write object, so we need to save the raw object data for later
computersystem.rawData = b
return nil
}
// Update commits updates to this object's properties to the running system.
func (computersystem *ComputerSystem) Update() error {
// Get a representation of the object's original state so we can find what
// to update.
cs := new(ComputerSystem)
err := cs.UnmarshalJSON(computersystem.rawData)
if err != nil {
return err
}
readWriteFields := []string{
"AssetTag",
"HostName",
"IndicatorLED",
"PowerRestorePolicy",
}
originalElement := reflect.ValueOf(cs).Elem()
currentElement := reflect.ValueOf(computersystem).Elem()
return computersystem.Entity.Update(originalElement, currentElement, readWriteFields)
}
// GetComputerSystem will get a ComputerSystem instance from the service.
func GetComputerSystem(c common.Client, uri string) (*ComputerSystem, error) {
var computersystem ComputerSystem
return &computersystem, computersystem.Get(c, uri, &computersystem)
}
// ListReferencedComputerSystems gets the collection of ComputerSystem from
// a provided reference.
func ListReferencedComputerSystems(c common.Client, link string) ([]*ComputerSystem, error) { //nolint:dupl
var result []*ComputerSystem
if link == "" {
return result, nil
}
type GetResult struct {
Item *ComputerSystem
Link string
Error error
}
ch := make(chan GetResult)
collectionError := common.NewCollectionError()
get := func(link string) {
computersystem, err := GetComputerSystem(c, link)
ch <- GetResult{Item: computersystem, Link: link, Error: err}
}
go func() {
err := common.CollectList(get, c, link)
if err != nil {
collectionError.Failures[link] = err
}
close(ch)
}()
for r := range ch {
if r.Error != nil {
collectionError.Failures[r.Link] = r.Error
} else {
result = append(result, r.Item)
}
}
if collectionError.Empty() {
return result, nil
}
return result, collectionError
}
// Bios gets the Bios information for this ComputerSystem.
func (computersystem *ComputerSystem) Bios() (*Bios, error) {
if computersystem.bios == "" {
return nil, nil
}
return GetBios(computersystem.Client, computersystem.bios)
}
// BootOptions gets all BootOption items for this system.
func (computersystem *ComputerSystem) BootOptions() ([]*BootOption, error) {
var result []*BootOption
if computersystem.Boot.bootOptions == "" {
return result, nil
}
c := computersystem.Client
type GetResult struct {
Item *BootOption
Link string
Error error
}
ch := make(chan GetResult)
collectionError := common.NewCollectionError()
get := func(link string) {
bootoption, err := GetBootOption(c, link)
ch <- GetResult{Item: bootoption, Link: link, Error: err}
}
go func() {
err := common.CollectList(get, c, computersystem.Boot.bootOptions)
if err != nil {
collectionError.Failures[computersystem.Boot.bootOptions] = err
}
close(ch)
}()
for r := range ch {
if r.Error != nil {
collectionError.Failures[r.Link] = r.Error
} else {
result = append(result, r.Item)
}
}
if collectionError.Empty() {
return result, nil
}
return result, collectionError
}
// EthernetInterfaces get this system's ethernet interfaces.
func (computersystem *ComputerSystem) EthernetInterfaces() ([]*EthernetInterface, error) {
return ListReferencedEthernetInterfaces(computersystem.Client, computersystem.ethernetInterfaces)
}
// LogServices get this system's log services.
func (computersystem *ComputerSystem) LogServices() ([]*LogService, error) {
return ListReferencedLogServices(computersystem.Client, computersystem.logServices)
}
// Memory gets this system's memory.
func (computersystem *ComputerSystem) Memory() ([]*Memory, error) {
return ListReferencedMemorys(computersystem.Client, computersystem.memory)
}
// MemoryDomains gets this system's memory domains.
func (computersystem *ComputerSystem) MemoryDomains() ([]*MemoryDomain, error) {
return ListReferencedMemoryDomains(computersystem.Client, computersystem.memoryDomains)
}
// NetworkInterfaces returns a collection of network interfaces in this system.
func (computersystem *ComputerSystem) NetworkInterfaces() ([]*NetworkInterface, error) {
return ListReferencedNetworkInterfaces(computersystem.Client, computersystem.networkInterfaces)
}
// PCIeDevices gets all PCIeDevices for this system.
func (computersystem *ComputerSystem) PCIeDevices() ([]*PCIeDevice, error) {
var result []*PCIeDevice
collectionError := common.NewCollectionError()
for _, pciedeviceLink := range computersystem.pcieDevices {
pciedevice, err := GetPCIeDevice(computersystem.Client, pciedeviceLink)
if err != nil {
collectionError.Failures[pciedeviceLink] = err
} else {
result = append(result, pciedevice)
}
}
if collectionError.Empty() {
return result, nil
}
return result, collectionError
}
// PCIeFunctions gets all PCIeFunctions for this system.
func (computersystem *ComputerSystem) PCIeFunctions() ([]*PCIeFunction, error) {
var result []*PCIeFunction
collectionError := common.NewCollectionError()
for _, pciefunctionLink := range computersystem.pcieFunctions {
pciefunction, err := GetPCIeFunction(computersystem.Client, pciefunctionLink)
if err != nil {
collectionError.Failures[pciefunctionLink] = err
} else {
result = append(result, pciefunction)
}
}
if collectionError.Empty() {
return result, nil
}
return result, collectionError
}
// Processors returns a collection of processors from this system
func (computersystem *ComputerSystem) Processors() ([]*Processor, error) {
return ListReferencedProcessors(computersystem.Client, computersystem.processors)
}
// SecureBoot gets the secure boot information for the system.
func (computersystem *ComputerSystem) SecureBoot() (*SecureBoot, error) {
if computersystem.secureBoot == "" {
return nil, nil
}
return GetSecureBoot(computersystem.Client, computersystem.secureBoot)
}
// SetBoot set a boot object based on a payload request
func (computersystem *ComputerSystem) SetBoot(b Boot) error { //nolint
t := struct {
Boot Boot
}{Boot: b}
return computersystem.Patch(computersystem.ODataID, t)
}
// Reset shall perform a reset of the ComputerSystem. For systems which implement
// ACPI Power Button functionality, the PushPowerButton value shall perform or
// emulate an ACPI Power Button push. The ForceOff value shall remove power from
// the system or perform an ACPI Power Button Override (commonly known as a
// 4-second hold of the Power Button). The ForceRestart value shall perform a
// ForceOff action followed by a On action.
func (computersystem *ComputerSystem) Reset(resetType ResetType) error {
// Make sure the requested reset type is supported by the system
valid := false
if len(computersystem.SupportedResetTypes) > 0 {
for _, allowed := range computersystem.SupportedResetTypes {
if resetType == allowed {
valid = true
break
}
}
} else {
// No allowed values supplied, assume we are OK
valid = true
}
if !valid {
return fmt.Errorf("reset type '%s' is not supported by this service",
resetType)
}
t := struct {
ResetType ResetType
}{ResetType: resetType}
return computersystem.Post(computersystem.resetTarget, t)
}
// UpdateBootAttributesApplyAt is used to update attribute values and set apply time together
func (computersystem *ComputerSystem) UpdateBootAttributesApplyAt(attrs SettingsAttributes, applyTime common.ApplyTime) error { //nolint:dupl
payload := make(map[string]interface{})
// Get a representation of the object's original state so we can find what
// to update.
original := new(Bios)
err := original.UnmarshalJSON(computersystem.rawData)
if err != nil {
return err
}
for key := range attrs {
if strings.HasPrefix(key, "BootTypeOrder") ||
original.Attributes[key] != attrs[key] {
payload[key] = attrs[key]
}
}
resp, err := computersystem.Client.Get(computersystem.settingsTarget)
if err != nil {
return err
}
defer resp.Body.Close()
// If there are any allowed updates, try to send updates to the system and
// return the result.
if len(payload) > 0 {
data := map[string]interface{}{"Boot": payload}
if applyTime != "" {
data["@Redfish.SettingsApplyTime"] = map[string]string{"ApplyTime": string(applyTime)}
}
var header = make(map[string]string)
if resp.Header["Etag"] != nil {
header["If-Match"] = resp.Header["Etag"][0]
}
resp, err = computersystem.Client.PatchWithHeaders(computersystem.settingsTarget, data, header)
if err != nil {
return err
}
defer resp.Body.Close()
}
return nil
}
// UpdateBootAttributes is used to update attribute values.
func (computersystem *ComputerSystem) UpdateBootAttributes(attrs SettingsAttributes) error {
return computersystem.UpdateBootAttributesApplyAt(attrs, "")
}
// SetDefaultBootOrder shall set the BootOrder array to the default settings.
func (computersystem *ComputerSystem) SetDefaultBootOrder() error {
// This action wasn't added until 1.5.0, make sure this is supported.
if computersystem.setDefaultBootOrderTarget == "" {
return fmt.Errorf("SetDefaultBootOrder is not supported by this system") //nolint:golint
}
return computersystem.Post(computersystem.setDefaultBootOrderTarget, nil)
}
// SimpleStorages gets all simple storage services of this system.
func (computersystem *ComputerSystem) SimpleStorages() ([]*SimpleStorage, error) {
return ListReferencedSimpleStorages(computersystem.Client, computersystem.simpleStorage)
}
// Storage gets the storage associated with this system.
func (computersystem *ComputerSystem) Storage() ([]*Storage, error) {
return ListReferencedStorages(computersystem.Client, computersystem.storage)
}
// CSLinks are references to resources that are related to, but not contained
// by (subordinate to), this resource.
type CSLinks struct {
// Chassis shall reference a resource of
// type Chassis that represents the physical container associated with
// this resource.
Chassis common.Links
// ChassisCount is
ChassisCount int `json:"Chassis@odata.count"`
// ConsumingComputerSystems shall be an array of references
// to ComputerSystems that are realized, in whole or in part, from this
// ComputerSystem.
ConsumingComputerSystems common.Links
// ConsumingComputerSystemsCount is
ConsumingComputerSystemsCount int `json:"ConsumingComputerSystems@odata.count"`
// CooledBy shall be an array of IDs
// containing pointers consistent with JSON pointer syntax to the
// resource that powers this computer system.
CooledBy common.Links
// CooledByCount is
CooledByCount int `json:"CooledBy@odata.count"`
// Endpoints shall be a reference to the
// resources that this system is associated with and shall reference a
// resource of type Endpoint.
Endpoints common.Links
// EndpointsCount is
EndpointsCount int `json:"Endpoints@odata.count"`
// ManagedBy shall reference a resource of
// type manager that represents the resource with management
// responsibility for this resource.
ManagedBy common.Links
// ManagedByCount is
ManagedByCount int `json:"ManagedBy@odata.count"`
// PoweredBy shall be an array of IDs
// containing pointers consistent with JSON pointer syntax to the
// resource that powers this computer system.
PoweredBy common.Links
// PoweredByCount is the number of PoweredBy objects.
PoweredByCount int `json:"PoweredBy@odata.count"`
// ResourceBlocks is used in this Computer System.
ResourceBlocks common.Links
// ResourceBlocksCount is the number of ResourceBlocks.
ResourceBlocksCount int `json:"ResourceBlocks@odata.count"`
// SupplyingComputerSystems shall be an array of references
// to ComputerSystems that contribute, in whole or in part, to the
// implementation of this ComputerSystem.
SupplyingComputerSystems common.Links
// SupplyingComputerSystemsCount is the number of SupplyingComputerSystems.
SupplyingComputerSystemsCount int `json:"SupplyingComputerSystems@odata.count"`
}