/
datastorageloscapabilities.go
179 lines (152 loc) · 6.04 KB
/
datastorageloscapabilities.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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package swordfish
import (
"encoding/json"
"reflect"
"github.com/stmcginnis/gofish/common"
)
// ProvisioningPolicy is used to specify space provisioning policy.
type ProvisioningPolicy string
const (
// FixedProvisioningPolicy shall be fully allocated.
FixedProvisioningPolicy ProvisioningPolicy = "Fixed"
// ThinProvisioningPolicy specifies storage may be over allocated.
ThinProvisioningPolicy ProvisioningPolicy = "Thin"
)
// StorageAccessCapability is used to describe abilities to read or write
// storage.
type StorageAccessCapability string
const (
// ReadStorageAccessCapability shall indicate that the storage may be
// read.
ReadStorageAccessCapability StorageAccessCapability = "Read"
// WriteStorageAccessCapability shall indicate that the storage may be
// written multiple times.
WriteStorageAccessCapability StorageAccessCapability = "Write"
// WriteOnceStorageAccessCapability shall indicate that the storage may
// be written only once.
WriteOnceStorageAccessCapability StorageAccessCapability = "WriteOnce"
// AppendStorageAccessCapability shall indicate that the storage may be
// written only to append.
AppendStorageAccessCapability StorageAccessCapability = "Append"
// StreamingStorageAccessCapability shall indicate that the storage may
// be read sequentially.
StreamingStorageAccessCapability StorageAccessCapability = "Streaming"
// ExecuteStorageAccessCapability shall indicate that Execute access is
// allowed by the file share.
ExecuteStorageAccessCapability StorageAccessCapability = "Execute"
)
// DataStorageLoSCapabilities describes capabilities of the system to
// support various data storage service options.
type DataStorageLoSCapabilities struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// Description provides a description of this resource.
Description string
// Identifier shall be unique within the managed ecosystem.
Identifier common.Identifier
// MaximumRecoverableCapacitySourceCount is the maximum number of capacity
// source resources that can be supported for the purpose of recovery when
// in the event that an equivalent capacity source resource fails.
MaximumRecoverableCapacitySourceCount int
// SupportedAccessCapabilities specifies a storage access capabilities.
SupportedAccessCapabilities []StorageAccessCapability
// SupportedLinesOfService shall contain known and supported DataStorageLinesOfService.
SupportedLinesOfService []DataStorageLineOfService
// SupportedLinesOfServiceCount is
SupportedLinesOfServiceCount int `json:"SupportedLinesOfService@odata.count"`
// SupportedProvisioningPolicies specifies supported storage allocation policies.
SupportedProvisioningPolicies []ProvisioningPolicy
// SupportedRecoveryTimeObjectives specifies supported expectations for time
// to access the primary store after recovery.
SupportedRecoveryTimeObjectives []RecoveryAccessScope
// 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)
err := original.UnmarshalJSON(datastorageloscapabilities.rawData)
if err != nil {
return err
}
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.
func GetDataStorageLoSCapabilities(c common.Client, uri string) (*DataStorageLoSCapabilities, error) {
var dataStorageLoSCapabilities DataStorageLoSCapabilities
return &dataStorageLoSCapabilities, dataStorageLoSCapabilities.Get(c, uri, &dataStorageLoSCapabilities)
}
// ListReferencedDataStorageLoSCapabilities gets the collection of DataStorageLoSCapabilities from
// a provided reference.
func ListReferencedDataStorageLoSCapabilities(c common.Client, link string) ([]*DataStorageLoSCapabilities, error) { //nolint:dupl
var result []*DataStorageLoSCapabilities
if link == "" {
return result, nil
}
type GetResult struct {
Item *DataStorageLoSCapabilities
Link string
Error error
}
ch := make(chan GetResult)
collectionError := common.NewCollectionError()
get := func(link string) {
datastorageloscapabilities, err := GetDataStorageLoSCapabilities(c, link)
ch <- GetResult{Item: datastorageloscapabilities, 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
}