github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/sfs/v2/shares/results.go (about) 1 package shares 2 3 import ( 4 "encoding/json" 5 "time" 6 7 "github.com/huaweicloud/golangsdk" 8 "github.com/huaweicloud/golangsdk/pagination" 9 ) 10 11 // Share contains all information associated with an OpenStack Share 12 type Share struct { 13 // The availability zone of the share 14 AvailabilityZone string `json:"availability_zone"` 15 // A description of the share 16 Description string `json:"description"` 17 // The host name of the share 18 Host string `json:"host"` 19 // The UUID of the share 20 ID string `json:"id"` 21 // Indicates the visibility of the share 22 IsPublic bool `json:"is_public"` 23 // Share links for pagination 24 Links []map[string]string `json:"links"` 25 // Key, value -pairs of custom metadata 26 Metadata map[string]string `json:"metadata"` 27 // The name of the share 28 Name string `json:"name"` 29 // The UUID of the project to which this share belongs to 30 ProjectID string `json:"project_id"` 31 // The UUID of the share network 32 ShareNetworkID string `json:"share_network_id"` 33 // The shared file system protocol 34 ShareProto string `json:"share_proto"` 35 // The UUID of the share type. 36 ShareType string `json:"share_type"` 37 // Size of the share in GB 38 Size int `json:"size"` 39 // UUID of the snapshot from which to create the share 40 SnapshotID string `json:"snapshot_id"` 41 // The share status 42 Status string `json:"status"` 43 // The type of the volume 44 VolumeType string `json:"volume_type"` 45 // Timestamp when the share was created 46 CreatedAt time.Time `json:"-"` 47 //Specifies the mount location. 48 ExportLocation string `json:"export_location"` 49 //Lists the mount locations. 50 ExportLocations []string `json:"export_locations"` 51 } 52 53 // AccessRight contains all information associated with an OpenStack share 54 // Grant Access Response 55 type AccessRight struct { 56 // The access rule type that can be "ip", "cert" or "user". 57 AccessType string `json:"access_type"` 58 // The value that defines the access that can be a valid format of IP, cert or user. 59 AccessTo string `json:"access_to"` 60 // The access level to the share is either "rw" or "ro". 61 AccessLevel string `json:"access_level"` 62 // The state of the access rule 63 State string `json:"state"` 64 // The access rule ID. 65 ID string `json:"id"` 66 } 67 68 // ExportLocation contains all information associated with a share export location 69 type ExportLocation struct { 70 // The export location path that should be used for mount operation. 71 Path string `json:"path"` 72 // The UUID of the share instance that this export location belongs to. 73 ShareInstanceID string `json:"share_instance_id"` 74 // Defines purpose of an export location. 75 // If set to true, then it is expected to be used for service needs 76 // and by administrators only. 77 // If it is set to false, then this export location can be used by end users. 78 IsAdminOnly bool `json:"is_admin_only"` 79 // The share export location UUID. 80 ID string `json:"id"` 81 Preferred bool `json:"preferred"` 82 } 83 84 // SharePage is the page returned by a pager when traversing over a 85 // collection of Shares. 86 type SharePage struct { 87 pagination.LinkedPageBase 88 } 89 90 // Extract will get the GrantAccess object from the commonResult 91 func (r GrantAccessResult) ExtractAccess() (*AccessRight, error) { 92 var s struct { 93 AccessRight *AccessRight `json:"access"` 94 } 95 err := r.ExtractInto(&s) 96 return s.AccessRight, err 97 } 98 99 // Extract will get a slice of AccessRight objects from the AccessRightsResult 100 func (r AccessRightsResult) ExtractAccessRights() ([]AccessRight, error) { 101 var s struct { 102 AccessRights []AccessRight `json:"access_list"` 103 } 104 err := r.ExtractInto(&s) 105 return s.AccessRights, err 106 } 107 108 // Extract will get the Share object from the commonResult 109 func (r commonResult) Extract() (*Share, error) { 110 var s struct { 111 Share *Share `json:"share"` 112 } 113 err := r.ExtractInto(&s) 114 return s.Share, err 115 } 116 117 // ExtractShares accepts a Page struct, specifically a SharePage struct, 118 // and extracts the elements into a slice of share structs. In other words, 119 // a generic collection is mapped into a relevant slice. 120 func ExtractShares(r pagination.Page) ([]Share, error) { 121 var s struct { 122 ListedShares []Share `json:"shares"` 123 } 124 err := (r.(SharePage)).ExtractInto(&s) 125 return s.ListedShares, err 126 } 127 128 // Extract will get the Export Locations from the commonResult 129 func (r GetExportLocationsResult) ExtractExportLocations() ([]ExportLocation, error) { 130 var s struct { 131 ExportLocations []ExportLocation `json:"export_locations"` 132 } 133 err := r.ExtractInto(&s) 134 return s.ExportLocations, err 135 } 136 137 func (r *Share) UnmarshalJSON(b []byte) error { 138 type tmp Share 139 var s struct { 140 tmp 141 CreatedAt golangsdk.JSONRFC3339MilliNoZ `json:"created_at"` 142 } 143 err := json.Unmarshal(b, &s) 144 if err != nil { 145 return err 146 } 147 *r = Share(s.tmp) 148 149 r.CreatedAt = time.Time(s.CreatedAt) 150 151 return nil 152 } 153 154 // IsEmpty returns true if a ListResult contains no Shares. 155 func (r SharePage) IsEmpty() (bool, error) { 156 shares, err := ExtractShares(r) 157 return len(shares) == 0, err 158 } 159 160 // NextPageURL is invoked when a paginated collection of shares has reached 161 // the end of a page and the pager seeks to traverse over a new one. In order 162 // to do this, it needs to construct the next page's URL. 163 func (r SharePage) NextPageURL() (string, error) { 164 var s struct { 165 Links []golangsdk.Link `json:"shares_links"` 166 } 167 err := r.ExtractInto(&s) 168 if err != nil { 169 return "", err 170 } 171 return golangsdk.ExtractNextURL(s.Links) 172 } 173 174 // GrantAccessResult contains the result body and error from an GrantAccess request. 175 type GrantAccessResult struct { 176 commonResult 177 } 178 179 // AccessRightsResult contains the result body and error from a AccessRight request. 180 type AccessRightsResult struct { 181 golangsdk.Result 182 } 183 184 //DeleteAccessResult contains the response body from DeleteAccess rights 185 type DeleteAccessResult struct { 186 golangsdk.Result 187 } 188 189 //GetExportLocationsResult contains the response body from GetExportLocations 190 type GetExportLocationsResult struct { 191 golangsdk.Result 192 } 193 194 type commonResult struct { 195 golangsdk.Result 196 } 197 198 // CreateResult contains the response body and error from a Create request. 199 type CreateResult struct { 200 commonResult 201 } 202 203 // DeleteResult contains the response body and error from a Delete request. 204 type DeleteResult struct { 205 golangsdk.ErrResult 206 } 207 208 // UpdateResult contains the response body and error from a update request. 209 type UpdateResult struct { 210 commonResult 211 } 212 213 // GetResult contains the response body and error from a Get request. 214 type GetResult struct { 215 commonResult 216 } 217 218 // ExpandResult contains the response body and error from a Expand request. 219 type ExpandResult struct { 220 golangsdk.ErrResult 221 } 222 223 // ShrinkResult contains the response body and error from a Shrink request. 224 type ShrinkResult struct { 225 golangsdk.ErrResult 226 }