github.com/gophercloud/gophercloud@v1.11.0/openstack/sharedfilesystems/v2/replicas/requests.go (about) 1 package replicas 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 // CreateOptsBuilder allows extensions to add additional parameters to the 9 // Create request. 10 type CreateOptsBuilder interface { 11 ToReplicaCreateMap() (map[string]interface{}, error) 12 } 13 14 // CreateOpts contains the options for create a Share Replica. This object is 15 // passed to replicas.Create function. For more information about these parameters, 16 // please refer to the Replica object, or the shared file systems API v2 17 // documentation. 18 type CreateOpts struct { 19 // The UUID of the share from which to create a share replica. 20 ShareID string `json:"share_id" required:"true"` 21 // The UUID of the share network to which the share replica should 22 // belong to. 23 ShareNetworkID string `json:"share_network_id,omitempty"` 24 // The availability zone of the share replica. 25 AvailabilityZone string `json:"availability_zone,omitempty"` 26 // One or more scheduler hints key and value pairs as a dictionary of 27 // strings. Minimum supported microversion for SchedulerHints is 2.67. 28 SchedulerHints map[string]string `json:"scheduler_hints,omitempty"` 29 } 30 31 // ToReplicaCreateMap assembles a request body based on the contents of a 32 // CreateOpts. 33 func (opts CreateOpts) ToReplicaCreateMap() (map[string]interface{}, error) { 34 return gophercloud.BuildRequestBody(opts, "share_replica") 35 } 36 37 // Create will create a new Share Replica based on the values in CreateOpts. To extract 38 // the Replica object from the response, call the Extract method on the 39 // CreateResult. 40 func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 41 b, err := opts.ToReplicaCreateMap() 42 if err != nil { 43 r.Err = err 44 return 45 } 46 resp, err := client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{ 47 OkCodes: []int{202}, 48 }) 49 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 50 return 51 } 52 53 // ListOpts holds options for listing Share Replicas. This object is passed to the 54 // replicas.List or replicas.ListDetail functions. 55 type ListOpts struct { 56 // The UUID of the share. 57 ShareID string `q:"share_id"` 58 // Per page limit for share replicas 59 Limit int `q:"limit"` 60 // Used in conjunction with limit to return a slice of items. 61 Offset int `q:"offset"` 62 // The ID of the last-seen item. 63 Marker string `q:"marker"` 64 } 65 66 // ListOptsBuilder allows extensions to add additional parameters to the List 67 // request. 68 type ListOptsBuilder interface { 69 ToReplicaListQuery() (string, error) 70 } 71 72 // ToReplicaListQuery formats a ListOpts into a query string. 73 func (opts ListOpts) ToReplicaListQuery() (string, error) { 74 q, err := gophercloud.BuildQueryString(opts) 75 return q.String(), err 76 } 77 78 // List returns []Replica optionally limited by the conditions provided in ListOpts. 79 func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { 80 url := listURL(client) 81 if opts != nil { 82 query, err := opts.ToReplicaListQuery() 83 if err != nil { 84 return pagination.Pager{Err: err} 85 } 86 url += query 87 } 88 89 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 90 p := ReplicaPage{pagination.MarkerPageBase{PageResult: r}} 91 p.MarkerPageBase.Owner = p 92 return p 93 }) 94 } 95 96 // ListDetail returns []Replica optionally limited by the conditions provided in ListOpts. 97 func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { 98 url := listDetailURL(client) 99 if opts != nil { 100 query, err := opts.ToReplicaListQuery() 101 if err != nil { 102 return pagination.Pager{Err: err} 103 } 104 url += query 105 } 106 107 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 108 p := ReplicaPage{pagination.MarkerPageBase{PageResult: r}} 109 p.MarkerPageBase.Owner = p 110 return p 111 }) 112 } 113 114 // Delete will delete an existing Replica with the given UUID. 115 func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) { 116 resp, err := client.Delete(deleteURL(client, id), nil) 117 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 118 return 119 } 120 121 // Get will get a single share with given UUID 122 func Get(client *gophercloud.ServiceClient, id string) (r GetResult) { 123 resp, err := client.Get(getURL(client, id), &r.Body, nil) 124 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 125 return 126 } 127 128 // ListExportLocations will list replicaID's export locations. 129 // Minimum supported microversion for ListExportLocations is 2.47. 130 func ListExportLocations(client *gophercloud.ServiceClient, id string) (r ListExportLocationsResult) { 131 resp, err := client.Get(listExportLocationsURL(client, id), &r.Body, nil) 132 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 133 return 134 } 135 136 // GetExportLocation will get replicaID's export location by an ID. 137 // Minimum supported microversion for GetExportLocation is 2.47. 138 func GetExportLocation(client *gophercloud.ServiceClient, replicaID string, id string) (r GetExportLocationResult) { 139 resp, err := client.Get(getExportLocationURL(client, replicaID, id), &r.Body, nil) 140 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 141 return 142 } 143 144 // PromoteOptsBuilder allows extensions to add additional parameters to the 145 // Promote request. 146 type PromoteOptsBuilder interface { 147 ToReplicaPromoteMap() (map[string]interface{}, error) 148 } 149 150 // PromoteOpts contains options for promoteing a Replica to active replica state. 151 // This object is passed to the replicas.Promote function. 152 type PromoteOpts struct { 153 // The quiesce wait time in seconds used during replica promote. 154 // Minimum supported microversion for QuiesceWaitTime is 2.75. 155 QuiesceWaitTime int `json:"quiesce_wait_time,omitempty"` 156 } 157 158 // ToReplicaPromoteMap assembles a request body based on the contents of a 159 // PromoteOpts. 160 func (opts PromoteOpts) ToReplicaPromoteMap() (map[string]interface{}, error) { 161 return gophercloud.BuildRequestBody(opts, "promote") 162 } 163 164 // Promote will promote an existing Replica to active state. PromoteResult contains only the error. 165 // To extract it, call the ExtractErr method on the PromoteResult. 166 func Promote(client *gophercloud.ServiceClient, id string, opts PromoteOptsBuilder) (r PromoteResult) { 167 b, err := opts.ToReplicaPromoteMap() 168 if err != nil { 169 r.Err = err 170 return 171 } 172 173 resp, err := client.Post(actionURL(client, id), b, nil, &gophercloud.RequestOpts{ 174 OkCodes: []int{202}, 175 }) 176 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 177 return 178 } 179 180 // Resync a replica with its active mirror. ResyncResult contains only the error. 181 // To extract it, call the ExtractErr method on the ResyncResult. 182 func Resync(client *gophercloud.ServiceClient, id string) (r ResyncResult) { 183 resp, err := client.Post(actionURL(client, id), map[string]interface{}{"resync": nil}, nil, &gophercloud.RequestOpts{ 184 OkCodes: []int{202}, 185 }) 186 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 187 return 188 } 189 190 // ResetStatusOptsBuilder allows extensions to add additional parameters to the 191 // ResetStatus request. 192 type ResetStatusOptsBuilder interface { 193 ToReplicaResetStatusMap() (map[string]interface{}, error) 194 } 195 196 // ResetStatusOpts contain options for updating a Share Replica status. This object is passed 197 // to the replicas.ResetStatus function. Administrator only. 198 type ResetStatusOpts struct { 199 // The status of a share replica. List of possible values: "available", 200 // "error", "creating", "deleting" or "error_deleting". 201 Status string `json:"status" required:"true"` 202 } 203 204 // ToReplicaResetStatusMap assembles a request body based on the contents of an 205 // ResetStatusOpts. 206 func (opts ResetStatusOpts) ToReplicaResetStatusMap() (map[string]interface{}, error) { 207 return gophercloud.BuildRequestBody(opts, "reset_status") 208 } 209 210 // ResetStatus will reset the Share Replica status with provided information. 211 // ResetStatusResult contains only the error. To extract it, call the ExtractErr 212 // method on the ResetStatusResult. 213 func ResetStatus(client *gophercloud.ServiceClient, id string, opts ResetStatusOptsBuilder) (r ResetStatusResult) { 214 b, err := opts.ToReplicaResetStatusMap() 215 if err != nil { 216 r.Err = err 217 return 218 } 219 resp, err := client.Post(actionURL(client, id), b, nil, &gophercloud.RequestOpts{ 220 OkCodes: []int{202}, 221 }) 222 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 223 return 224 } 225 226 // ResetStateOptsBuilder allows extensions to add additional parameters to the 227 // ResetState request. 228 type ResetStateOptsBuilder interface { 229 ToReplicaResetStateMap() (map[string]interface{}, error) 230 } 231 232 // ResetStateOpts contain options for updating a Share Replica state. This object is passed 233 // to the replicas.ResetState function. Administrator only. 234 type ResetStateOpts struct { 235 // The state of a share replica. List of possible values: "active", 236 // "in_sync", "out_of_sync" or "error". 237 State string `json:"replica_state" required:"true"` 238 } 239 240 // ToReplicaResetStateMap assembles a request body based on the contents of an 241 // ResetStateOpts. 242 func (opts ResetStateOpts) ToReplicaResetStateMap() (map[string]interface{}, error) { 243 return gophercloud.BuildRequestBody(opts, "reset_replica_state") 244 } 245 246 // ResetState will reset the Share Replica state with provided information. 247 // ResetStateResult contains only the error. To extract it, call the ExtractErr 248 // method on the ResetStateResult. 249 func ResetState(client *gophercloud.ServiceClient, id string, opts ResetStateOptsBuilder) (r ResetStateResult) { 250 b, err := opts.ToReplicaResetStateMap() 251 if err != nil { 252 r.Err = err 253 return 254 } 255 resp, err := client.Post(actionURL(client, id), b, nil, &gophercloud.RequestOpts{ 256 OkCodes: []int{202}, 257 }) 258 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 259 return 260 } 261 262 // ForceDelete force-deletes a Share Replica in any state. ForceDeleteResult 263 // contains only the error. To extract it, call the ExtractErr method on the 264 // ForceDeleteResult. Administrator only. 265 func ForceDelete(client *gophercloud.ServiceClient, id string) (r ForceDeleteResult) { 266 resp, err := client.Post(actionURL(client, id), map[string]interface{}{"force_delete": nil}, nil, &gophercloud.RequestOpts{ 267 OkCodes: []int{202}, 268 }) 269 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 270 return 271 }