Skip to content

Commit

Permalink
Merge pull request #67 from stmcginnis/swordfish-update
Browse files Browse the repository at this point in the history
Update Swordfish objects and add Update calls for rw
  • Loading branch information
stmcginnis authored May 23, 2020
2 parents 9cc13b5 + feb2cab commit de6aaee
Show file tree
Hide file tree
Showing 25 changed files with 1,104 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: BSD-3-Clause
#

PKGS := $(shell go list ./... | grep -v example)
PKGS := $(shell go list ./... | grep -v example | grep -v tools)

all: build test

Expand Down
4 changes: 2 additions & 2 deletions swordfish/classofservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stmcginnis/gofish/common"
)

// ClassOfService is This resource shall define a service option composed
// ClassOfService shall define a service option composed
// of one or more line of service entities. ITIL defines a service
// option as a choice of utility or warranty for a service.
type ClassOfService struct {
Expand All @@ -22,7 +22,7 @@ type ClassOfService struct {
ODataEtag string `json:"@odata.etag"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// ClassOfServiceVersion is The version describing the creation or last
// ClassOfServiceVersion is the version describing the creation or last
// modification of this service option specification. The string
// representing the version shall be in the form: M + '.' + N + '.' + U
// Where: M - The major version (in numeric form). N - The minor version
Expand Down
30 changes: 30 additions & 0 deletions swordfish/dataprotectionloscapabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package swordfish

import (
"encoding/json"
"reflect"

"github.com/stmcginnis/gofish/common"
)
Expand Down Expand Up @@ -111,6 +112,8 @@ type DataProtectionLoSCapabilities struct {
// supportedReplicaOptions shall contain known and supported replica Classes
// of Service.
supportedReplicaOptions []string
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
}

// UnmarshalJSON unmarshals a DataProtectionLoSCapabilities object from the raw JSON.
Expand Down Expand Up @@ -142,9 +145,36 @@ func (dataprotectionloscapabilities *DataProtectionLoSCapabilities) UnmarshalJSO
dataprotectionloscapabilities.SupportedReplicaOptionsCount = t.Links.SupportedReplicaOptionsCount
dataprotectionloscapabilities.supportedLinesOfService = t.SupportedLinesOfService.ToStrings()

// This is a read/write object, so we need to save the raw object data for later
dataprotectionloscapabilities.rawData = b

return nil
}

// Update commits updates to this object's properties to the running system.
func (dataprotectionloscapabilities *DataProtectionLoSCapabilities) Update() error {

// Get a representation of the object's original state so we can find what
// to update.
original := new(DataProtectionLoSCapabilities)
original.UnmarshalJSON(dataprotectionloscapabilities.rawData)

readWriteFields := []string{
"SupportedLinesOfService",
"SupportedMinLifetimes",
"SupportedRecoveryGeographicObjectives",
"SupportedRecoveryPointObjectiveTimes",
"SupportedRecoveryTimeObjectives",
"SupportedReplicaTypes",
"SupportsIsolated",
}

originalElement := reflect.ValueOf(original).Elem()
currentElement := reflect.ValueOf(dataprotectionloscapabilities).Elem()

return dataprotectionloscapabilities.Entity.Update(originalElement, currentElement, readWriteFields)
}

// GetDataProtectionLoSCapabilities will get a DataProtectionLoSCapabilities instance from the service.
func GetDataProtectionLoSCapabilities(c common.Client, uri string) (*DataProtectionLoSCapabilities, error) {
resp, err := c.Get(uri)
Expand Down
35 changes: 31 additions & 4 deletions swordfish/dataprotectionloscapabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"encoding/json"
"strings"
"testing"

"github.com/stmcginnis/gofish/common"
)

var dataProtectionLoSCapabilitiesBody = strings.NewReader(
`{
var dataProtectionLoSCapabilitiesBody = `{
"@odata.context": "/redfish/v1/$metadata#DataProtectionLoSCapabilities.DataProtectionLoSCapabilities",
"@odata.type": "#DataProtectionLoSCapabilities.v1_1_2.DataProtectionLoSCapabilities",
"@odata.id": "/redfish/v1/DataProtectionLoSCapabilities",
Expand Down Expand Up @@ -45,12 +46,12 @@ var dataProtectionLoSCapabilitiesBody = strings.NewReader(
"Clone"
],
"SupportsIsolated": true
}`)
}`

// TestDataProtectionLoSCapabilities tests the parsing of DataProtectionLoSCapabilities objects.
func TestDataProtectionLoSCapabilities(t *testing.T) {
var result DataProtectionLoSCapabilities
err := json.NewDecoder(dataProtectionLoSCapabilitiesBody).Decode(&result)
err := json.NewDecoder(strings.NewReader(dataProtectionLoSCapabilitiesBody)).Decode(&result)

if err != nil {
t.Errorf("Error decoding JSON: %s", err)
Expand All @@ -77,3 +78,29 @@ func TestDataProtectionLoSCapabilities(t *testing.T) {
t.Errorf("Invalid supported replica type: %s", result.SupportedReplicaTypes[0])
}
}

// TestDataProtectionLoSCapabilitiesUpdate tests the Update call.
func TestDataProtectionLoSCapabilitiesUpdate(t *testing.T) {
var result DataProtectionLoSCapabilities
err := json.NewDecoder(strings.NewReader(dataProtectionLoSCapabilitiesBody)).Decode(&result)

if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}

testClient := &common.TestClient{}
result.SetClient(testClient)

result.SupportsIsolated = false
err = result.Update()

if err != nil {
t.Errorf("Error making Update call: %s", err)
}

calls := testClient.CapturedCalls()

if !strings.Contains(calls[0].Payload, "SupportsIsolated:false") {
t.Errorf("Unexpected SupportsIsolated update payload: %s", calls[0].Payload)
}
}
50 changes: 50 additions & 0 deletions swordfish/datasecurityloscapabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,58 @@ type DataSecurityLoSCapabilities struct {
// SupportedUserAuthenticationTypes shall specify supported authentication
// types for users (or programs).
SupportedUserAuthenticationTypes []AuthenticationType
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
}

// // UnmarshalJSON unmarshals a DataSecurityLoSCapabilities object from the raw JSON.
// func (datasecurityloscapabilities *DataSecurityLoSCapabilities) UnmarshalJSON(b []byte) error {
// type temp DataSecurityLoSCapabilities
// var t struct {
// temp
// }

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

// *datasecurityloscapabilities = DataSecurityLoSCapabilities(t.temp)

// // Extract the links to other entities for later

// // This is a read/write object, so we need to save the raw object data for later
// datasecurityloscapabilities.rawData = b

// return nil
// }

// // Update commits updates to this object's properties to the running system.
// func (datasecurityloscapabilities *DataSecurityLoSCapabilities) Update() error {

// // Get a representation of the object's original state so we can find what
// // to update.
// original := new(DataSecurityLoSCapabilities)
// original.UnmarshalJSON(datasecurityloscapabilities.rawData)

// readWriteFields := []string{
// "SupportedAntivirusEngineProviders",
// "SupportedAntivirusScanPolicies",
// "SupportedChannelEncryptionStrengths",
// "SupportedDataSanitizationPolicies",
// "SupportedHostAuthenticationTypes",
// "SupportedLinesOfService",
// "SupportedMediaEncryptionStrengths",
// "SupportedSecureChannelProtocols",
// "SupportedUserAuthenticationTypes",
// }

// originalElement := reflect.ValueOf(original).Elem()
// currentElement := reflect.ValueOf(datasecurityloscapabilities).Elem()

// return datasecurityloscapabilities.Entity.Update(originalElement, currentElement, readWriteFields)
// }

// GetDataSecurityLoSCapabilities will get a DataSecurityLoSCapabilities instance from the service.
func GetDataSecurityLoSCapabilities(c common.Client, uri string) (*DataSecurityLoSCapabilities, error) {
resp, err := c.Get(uri)
Expand Down
48 changes: 48 additions & 0 deletions swordfish/datastorageloscapabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package swordfish

import (
"encoding/json"
"reflect"

"github.com/stmcginnis/gofish/common"
)
Expand Down Expand Up @@ -78,6 +79,53 @@ type DataStorageLoSCapabilities struct {
// SupportsSpaceEfficiency specifies whether storage compression or
// deduplication is supported. The default value for this property is false.
SupportsSpaceEfficiency bool
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
}

// UnmarshalJSON unmarshals a DataStorageLoSCapabilities object from the raw JSON.
func (datastorageloscapabilities *DataStorageLoSCapabilities) UnmarshalJSON(b []byte) error {
type temp DataStorageLoSCapabilities
var t struct {
temp
}

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

*datastorageloscapabilities = DataStorageLoSCapabilities(t.temp)

// Extract the links to other entities for later

// This is a read/write object, so we need to save the raw object data for later
datastorageloscapabilities.rawData = b

return nil
}

// Update commits updates to this object's properties to the running system.
func (datastorageloscapabilities *DataStorageLoSCapabilities) Update() error {

// Get a representation of the object's original state so we can find what
// to update.
original := new(DataStorageLoSCapabilities)
original.UnmarshalJSON(datastorageloscapabilities.rawData)

readWriteFields := []string{
"MaximumRecoverableCapacitySourceCount",
"SupportedAccessCapabilities",
"SupportedLinesOfService",
"SupportedProvisioningPolicies",
"SupportedRecoveryTimeObjectives",
"SupportsSpaceEfficiency",
}

originalElement := reflect.ValueOf(original).Elem()
currentElement := reflect.ValueOf(datastorageloscapabilities).Elem()

return datastorageloscapabilities.Entity.Update(originalElement, currentElement, readWriteFields)
}

// GetDataStorageLoSCapabilities will get a DataStorageLoSCapabilities instance from the service.
Expand Down
40 changes: 36 additions & 4 deletions swordfish/datastorageloscapabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"encoding/json"
"strings"
"testing"

"github.com/stmcginnis/gofish/common"
)

var dataStorageLoSCapabilitiesBody = strings.NewReader(
`{
var dataStorageLoSCapabilitiesBody = `{
"@odata.context": "/redfish/v1/$metadata#DataStorageLoSCapabilities.DataStorageLoSCapabilities",
"@odata.type": "#DataStorageLoSCapabilities.v1_2_0.DataStorageLoSCapabilities",
"@odata.id": "/redfish/v1/DataStorageLoSCapabilities",
Expand Down Expand Up @@ -44,12 +45,12 @@ var dataStorageLoSCapabilitiesBody = strings.NewReader(
"Offline"
],
"SupportsSpaceEfficiency": true
}`)
}`

// TestDataStorageLoSCapabilities tests the parsing of DataStorageLoSCapabilities objects.
func TestDataStorageLoSCapabilities(t *testing.T) {
var result DataStorageLoSCapabilities
err := json.NewDecoder(dataStorageLoSCapabilitiesBody).Decode(&result)
err := json.NewDecoder(strings.NewReader(dataStorageLoSCapabilitiesBody)).Decode(&result)

if err != nil {
t.Errorf("Error decoding JSON: %s", err)
Expand Down Expand Up @@ -80,3 +81,34 @@ func TestDataStorageLoSCapabilities(t *testing.T) {
t.Error("SupportsSpaceEfficiency should be true")
}
}

// TestDataStorageLoSCapabilitiesUpdate tests the Update call.
func TestDataStorageLoSCapabilitiesUpdate(t *testing.T) {
var result DataStorageLoSCapabilities
err := json.NewDecoder(strings.NewReader(dataStorageLoSCapabilitiesBody)).Decode(&result)

if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}

testClient := &common.TestClient{}
result.SetClient(testClient)

result.MaximumRecoverableCapacitySourceCount = 10
result.SupportsSpaceEfficiency = true
err = result.Update()

if err != nil {
t.Errorf("Error making Update call: %s", err)
}

calls := testClient.CapturedCalls()

if !strings.Contains(calls[0].Payload, "MaximumRecoverableCapacitySourceCount:10") {
t.Errorf("Unexpected MaximumRecoverableCapacitySourceCount update payload: %s", calls[0].Payload)
}

if strings.Contains(calls[0].Payload, "SupportsSpaceEfficiency") {
t.Errorf("Unexpected SupportsSpaceEfficiency update payload: %s", calls[0].Payload)
}
}
34 changes: 33 additions & 1 deletion swordfish/endpointgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package swordfish

import (
"encoding/json"
"reflect"

"github.com/stmcginnis/gofish/common"
"github.com/stmcginnis/gofish/redfish"
Expand Down Expand Up @@ -55,6 +56,8 @@ type EndpointGroup struct {
Description string
// endpoints shall reference an Endpoint resource.
endpoints string
// EndpointsCount is the number of Endpoints
EndpointsCount int
// GroupType contains only endpoints of a given type
// Client/Initiator or Server/Target. If this endpoint group represents
// a SCSI target group, the value of GroupType shall be Server.
Expand All @@ -73,14 +76,17 @@ type EndpointGroup struct {
// TARGET PORT GROUP field in an INQUIRY VPD page 85 response, type 5h
// identifier. See the INCITS SAM-5 specification.
TargetEndpointGroupIdentifier int
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
}

// UnmarshalJSON unmarshals a EndpointGroup object from the raw JSON.
func (endpointgroup *EndpointGroup) UnmarshalJSON(b []byte) error {
type temp EndpointGroup
var t struct {
temp
Endpoints common.Link
Endpoints common.Link
EndpointsCount int `json:"[email protected]"`
}

err := json.Unmarshal(b, &t)
Expand All @@ -92,10 +98,36 @@ func (endpointgroup *EndpointGroup) UnmarshalJSON(b []byte) error {

// Extract the links to other entities for later
endpointgroup.endpoints = string(t.Endpoints)
endpointgroup.EndpointsCount = t.EndpointsCount

// This is a read/write object, so we need to save the raw object data for later
endpointgroup.rawData = b

return nil
}

// Update commits updates to this object's properties to the running system.
func (endpointgroup *EndpointGroup) Update() error {

// Get a representation of the object's original state so we can find what
// to update.
original := new(EndpointGroup)
original.UnmarshalJSON(endpointgroup.rawData)

readWriteFields := []string{
"AccessState",
"Endpoints",
"GroupType",
"Preferred",
"TargetEndpointGroupIdentifier",
}

originalElement := reflect.ValueOf(original).Elem()
currentElement := reflect.ValueOf(endpointgroup).Elem()

return endpointgroup.Entity.Update(originalElement, currentElement, readWriteFields)
}

// GetEndpointGroup will get a EndpointGroup instance from the service.
func GetEndpointGroup(c common.Client, uri string) (*EndpointGroup, error) {
resp, err := c.Get(uri)
Expand Down
Loading

0 comments on commit de6aaee

Please sign in to comment.