Skip to content

Commit

Permalink
Merge pull request #43 from stmcginnis/actions
Browse files Browse the repository at this point in the history
Add actions to more objects
  • Loading branch information
stmcginnis authored Sep 13, 2019
2 parents f10a90e + c3d5542 commit da1d892
Show file tree
Hide file tree
Showing 10 changed files with 465 additions and 3 deletions.
42 changes: 42 additions & 0 deletions redfish/secureboot.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,33 @@ type SecureBoot struct {
// SecureBootMode shall contain the current Secure Boot mode, as defined in
// the UEFI Specification.
SecureBootMode SecureBootModeType
// resetKeysTarget is the URL to send ResetKeys requests.
resetKeysTarget string
}

// UnmarshalJSON unmarshals a SecureBoot object from the raw JSON.
func (secureboot *SecureBoot) UnmarshalJSON(b []byte) error {
type temp SecureBoot
type actions struct {
ResetKeys struct {
Target string
} `json:"#SecureBoot.ResetKeys"`
}
var t struct {
temp
Actions actions
}

err := json.Unmarshal(b, &t)
if err != nil {
return err
}

// Extract the links to other entities for later
*secureboot = SecureBoot(t.temp)
secureboot.resetKeysTarget = t.Actions.ResetKeys.Target

return nil
}

// GetSecureBoot will get a SecureBoot instance from the service.
Expand Down Expand Up @@ -118,3 +145,18 @@ func ListReferencedSecureBoots(c common.Client, link string) ([]*SecureBoot, err

return result, nil
}

// ResetKeys shall perform a reset of the Secure Boot key databases. The
// ResetAllKeysToDefault value shall reset the UEFI Secure Boot key databases to
// their default values. The DeleteAllKeys value shall delete the content of the
// UEFI Secure Boot key databases. The DeletePK value shall delete the content
// of the PK Secure boot key.
func (secureboot *SecureBoot) ResetKeys(resetType ResetKeysType) error {
type temp struct {
ResetKeysType ResetKeysType
}
t := temp{ResetKeysType: resetType}

_, err := secureboot.Client.Post(secureboot.resetKeysTarget, t)
return err
}
11 changes: 10 additions & 1 deletion redfish/secureboot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ var secureBootBody = strings.NewReader(
"Description": "SecureBoot One",
"SecureBootCurrentBoot": "Enabled",
"SecureBootEnable": true,
"SecureBootMode": "UserMode"
"SecureBootMode": "UserMode",
"Actions": {
"#SecureBoot.ResetKeys": {
"target": "/redfish/v1/SecureBoot/Actions/SecureBoot.ResetKeys"
}
}
}`)

// TestSecureBoot tests the parsing of SecureBoot objects.
Expand Down Expand Up @@ -51,4 +56,8 @@ func TestSecureBoot(t *testing.T) {
if result.SecureBootMode != UserModeSecureBootModeType {
t.Errorf("Invalid SecureBootMode: %s", result.SecureBootMode)
}

if result.resetKeysTarget != "/redfish/v1/SecureBoot/Actions/SecureBoot.ResetKeys" {
t.Errorf("Invalid ResetKeys target: %s", result.resetKeysTarget)
}
}
20 changes: 20 additions & 0 deletions redfish/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ type Storage struct {
enclosures []string
// EnclosuresCount is the number of enclosures.
EnclosuresCount int
// setEncryptionKeyTarget is the URL to send SetEncryptionKey requests.
setEncryptionKeyTarget string
}

// UnmarshalJSON unmarshals a Storage object from the raw JSON.
Expand All @@ -73,11 +75,17 @@ func (storage *Storage) UnmarshalJSON(b []byte) error {
Enclosures common.Links
EnclosuresCount int `json:"[email protected]"`
}
type actions struct {
SetEncryptionKey struct {
Target string
} `json:"#Storage.SetEncryptionKey"`
}
var t struct {
temp
Links links
Drives common.Links
Volumes common.Link
Actions actions
}

err := json.Unmarshal(b, &t)
Expand All @@ -92,6 +100,7 @@ func (storage *Storage) UnmarshalJSON(b []byte) error {
storage.EnclosuresCount = t.Links.EnclosuresCount
storage.drives = t.Drives.ToStrings()
storage.volumes = string(t.Volumes)
storage.setEncryptionKeyTarget = t.Actions.SetEncryptionKey.Target

return nil
}
Expand Down Expand Up @@ -170,6 +179,17 @@ func (storage *Storage) Volumes() ([]*Volume, error) {
return ListReferencedVolumes(storage.Client, storage.volumes)
}

// SetEncryptionKey shall set the encryption key for the storage subsystem.
func (storage *Storage) SetEncryptionKey(key string) error {
type temp struct {
EncryptionKey string
}
t := temp{EncryptionKey: key}

_, err := storage.Client.Post(storage.setEncryptionKeyTarget, t)
return err
}

// StorageController is used to represent a resource that represents a
// storage controller in the Redfish specification.
type StorageController struct {
Expand Down
9 changes: 9 additions & 0 deletions redfish/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ var storageBody = strings.NewReader(
}],
"Volumes": {
"@odata.id": "/redfish/v1/Volumes/1"
},
"Actions": {
"#Storage.SetEncryptionKey": {
"target": "/redfish/v1/Storage/Actions/Storage.SetEncryptionKey"
}
}
}`)

Expand Down Expand Up @@ -147,4 +152,8 @@ func TestStorage(t *testing.T) {
if result.StorageControllers[0].PCIeInterface.MaxPCIeType != Gen4PCIeTypes {
t.Errorf("Invalid MaxPCIeType: %s", result.StorageControllers[0].PCIeInterface.MaxPCIeType)
}

if result.setEncryptionKeyTarget != "/redfish/v1/Storage/Actions/Storage.SetEncryptionKey" {
t.Errorf("Invalid SetEncryptionKey target: %s", result.setEncryptionKeyTarget)
}
}
40 changes: 40 additions & 0 deletions swordfish/storagegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ type StorageGroup struct {
parentStorageGroups []string
// ParentStorageGroupsCount is the number of parent storage groups.
ParentStorageGroupsCount int
// exposeVolumesTarget is the URL to for the ExposeVolumes action.
exposeVolumesTarget string
// hideVolumesTarget is the URL to for the HideVolumes action.
hideVolumesTarget string
}

// UnmarshalJSON unmarshals a StorageGroup object from the raw JSON.
Expand All @@ -143,10 +147,19 @@ func (storagegroup *StorageGroup) UnmarshalJSON(b []byte) error {
ParentStorageGroups common.Links
ParentStorageGroupsCount int `json:"[email protected]"`
}
type actions struct {
ExposeVolumes struct {
Target string
} `json:"#StorageGroup.ExposeVolumes"`
HideVolumes struct {
Target string
} `json:"#StorageGroup.HideVolumes"`
}
var t struct {
temp
Links links
ServerEndpointGroups common.Links
Actions actions
}

err := json.Unmarshal(b, &t)
Expand All @@ -161,6 +174,8 @@ func (storagegroup *StorageGroup) UnmarshalJSON(b []byte) error {
storagegroup.classOfService = string(t.Links.ClassOfService)
storagegroup.parentStorageGroups = t.Links.ParentStorageGroups.ToStrings()
storagegroup.ParentStorageGroupsCount = t.Links.ParentStorageGroupsCount
storagegroup.exposeVolumesTarget = t.Actions.ExposeVolumes.Target
storagegroup.hideVolumesTarget = t.Actions.HideVolumes.Target

return nil
}
Expand Down Expand Up @@ -251,3 +266,28 @@ type MappedVolume struct {
// Volume shall reference a mapped Volume.
Volume common.Link
}

// ExposeVolumes exposes the storage of this group via the target endpoints
// named in the ServerEndpointGroups to the initiator endpoints named in the
// ClientEndpointGroups. The property VolumesAreExposed shall be set to true
// when this action is completed.
func (storagegroup *StorageGroup) ExposeVolumes() error {
_, err := storagegroup.Client.Post(storagegroup.exposeVolumesTarget, nil)
if err == nil {
// Only set to exposed if no error. Calling expose when already exposed
// could fail so we don't want to indicate they are not exposed.
storagegroup.VolumesAreExposed = true
}
return err
}

// HideVolumes hides the storage of this group from the initiator endpoints
// named in the ClientEndpointGroups. The property VolumesAreExposed shall be
// set to false when this action is completed.
func (storagegroup *StorageGroup) HideVolumes() error {
_, err := storagegroup.Client.Post(storagegroup.hideVolumesTarget, nil)
if err == nil {
storagegroup.VolumesAreExposed = false
}
return err
}
18 changes: 17 additions & 1 deletion swordfish/storagegroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ var storageGroupBody = strings.NewReader(
"State": "Enabled",
"Health": "OK"
},
"VolumesAreExposed": true
"VolumesAreExposed": true,
"Actions": {
"#StorageGroup.ExposeVolumes": {
"target": "/redfish/v1/StorageGroup/Actions/StorageGroup.ExposeVolumes"
},
"#StorageGroup.HideVolumes": {
"target": "/redfish/v1/StorageGroup/Actions/StorageGroup.HideVolumes"
}
}
}`)

// TestStorageGroup tests the parsing of StorageGroup objects.
Expand Down Expand Up @@ -96,4 +104,12 @@ func TestStorageGroup(t *testing.T) {
if !result.VolumesAreExposed {
t.Error("VolumesAreExposed should be True")
}

if result.exposeVolumesTarget != "/redfish/v1/StorageGroup/Actions/StorageGroup.ExposeVolumes" {
t.Errorf("Invalid ExposeVolumes target: %s", result.exposeVolumesTarget)
}

if result.hideVolumesTarget != "/redfish/v1/StorageGroup/Actions/StorageGroup.HideVolumes" {
t.Errorf("Invalid HideVolumes target: %s", result.hideVolumesTarget)
}
}
20 changes: 20 additions & 0 deletions swordfish/storageservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ type StorageService struct {
// Volumes is an array of references to Volumes managed by this storage
// service.
volumes string
// setEncryptionKeyTarget is the URL to send SetEncryptionKey requests.
setEncryptionKeyTarget string
}

// UnmarshalJSON unmarshals a StorageService object from the raw JSON.
Expand All @@ -102,6 +104,11 @@ func (storageservice *StorageService) UnmarshalJSON(b []byte) error {
// StorageController that hosts this service.
HostingSystem common.Link
}
type actions struct {
SetEncryptionKey struct {
Target string
} `json:"#StorageService.SetEncryptionKey"`
}
var t struct {
temp
ClassesOfService common.Link
Expand All @@ -122,6 +129,7 @@ func (storageservice *StorageService) UnmarshalJSON(b []byte) error {
StorageSubsystems common.Link
Volumes common.Link
Links links
Actions actions
}

err := json.Unmarshal(b, &t)
Expand Down Expand Up @@ -149,6 +157,7 @@ func (storageservice *StorageService) UnmarshalJSON(b []byte) error {
storageservice.storageSubsystems = string(t.StorageSubsystems)
storageservice.hostingSystem = string(t.Links.HostingSystem)
storageservice.volumes = string(t.Volumes)
storageservice.setEncryptionKeyTarget = t.Actions.SetEncryptionKey.Target

return nil
}
Expand Down Expand Up @@ -316,3 +325,14 @@ func (storageservice *StorageService) StorageGroups() ([]*StorageGroup, error) {
func (storageservice *StorageService) Volumes() ([]*Volume, error) {
return ListReferencedVolumes(storageservice.Client, storageservice.volumes)
}

// SetEncryptionKey shall set the encryption key for the storage subsystem.
func (storageservice *StorageService) SetEncryptionKey(key string) error {
type temp struct {
EncryptionKey string
}
t := temp{EncryptionKey: key}

_, err := storageservice.Client.Post(storageservice.setEncryptionKeyTarget, t)
return err
}
9 changes: 9 additions & 0 deletions swordfish/storageservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ var storageServiceBody = strings.NewReader(
},
"Volumes": {
"@odata.id": "/redfish/v1/Volumes/1"
},
"Actions": {
"#StorageService.SetEncryptionKey": {
"target": "/redfish/v1/StorageService/Actions/StorageService.SetEncryptionKey"
}
}
}`)

Expand Down Expand Up @@ -123,4 +128,8 @@ func TestStorageService(t *testing.T) {
if result.volumes != "/redfish/v1/Volumes/1" {
t.Errorf("Invalid volumes collection link: %s", result.volumes)
}

if result.setEncryptionKeyTarget != "/redfish/v1/StorageService/Actions/StorageService.SetEncryptionKey" {
t.Errorf("Invalid SetEncryptionKey link: %s", result.setEncryptionKeyTarget)
}
}
Loading

0 comments on commit da1d892

Please sign in to comment.