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