github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/cluster_migrations_client.go (about) 1 /* 2 Copyright (c) 2020 Red Hat, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // IMPORTANT: This file has been generated automatically, refrain from modifying it manually as all 18 // your changes will be lost when the file is generated again. 19 20 package v1 // github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1 21 22 import ( 23 "bufio" 24 "bytes" 25 "context" 26 "io" 27 "net/http" 28 "net/url" 29 "path" 30 31 "github.com/openshift-online/ocm-sdk-go/errors" 32 "github.com/openshift-online/ocm-sdk-go/helpers" 33 ) 34 35 // ClusterMigrationsClient is the client of the 'cluster_migrations' resource. 36 // 37 // Manages the collection of cluster migrations of a cluster. 38 type ClusterMigrationsClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewClusterMigrationsClient creates a new client for the 'cluster_migrations' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewClusterMigrationsClient(transport http.RoundTripper, path string) *ClusterMigrationsClient { 47 return &ClusterMigrationsClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // Add creates a request for the 'add' method. 54 // 55 // Adds a cluster migration to the database. 56 func (c *ClusterMigrationsClient) Add() *ClusterMigrationsAddRequest { 57 return &ClusterMigrationsAddRequest{ 58 transport: c.transport, 59 path: c.path, 60 } 61 } 62 63 // List creates a request for the 'list' method. 64 func (c *ClusterMigrationsClient) List() *ClusterMigrationsListRequest { 65 return &ClusterMigrationsListRequest{ 66 transport: c.transport, 67 path: c.path, 68 } 69 } 70 71 // Migration returns the target 'cluster_migration' resource for the given identifier. 72 // 73 // Returns a reference to the service that manages a specific cluster migration. 74 func (c *ClusterMigrationsClient) Migration(id string) *ClusterMigrationClient { 75 return NewClusterMigrationClient( 76 c.transport, 77 path.Join(c.path, id), 78 ) 79 } 80 81 // ClusterMigrationsAddRequest is the request for the 'add' method. 82 type ClusterMigrationsAddRequest struct { 83 transport http.RoundTripper 84 path string 85 query url.Values 86 header http.Header 87 body *ClusterMigration 88 } 89 90 // Parameter adds a query parameter. 91 func (r *ClusterMigrationsAddRequest) Parameter(name string, value interface{}) *ClusterMigrationsAddRequest { 92 helpers.AddValue(&r.query, name, value) 93 return r 94 } 95 96 // Header adds a request header. 97 func (r *ClusterMigrationsAddRequest) Header(name string, value interface{}) *ClusterMigrationsAddRequest { 98 helpers.AddHeader(&r.header, name, value) 99 return r 100 } 101 102 // Impersonate wraps requests on behalf of another user. 103 // Note: Services that do not support this feature may silently ignore this call. 104 func (r *ClusterMigrationsAddRequest) Impersonate(user string) *ClusterMigrationsAddRequest { 105 helpers.AddImpersonationHeader(&r.header, user) 106 return r 107 } 108 109 // Body sets the value of the 'body' parameter. 110 // 111 // Description of the cluster migration. 112 func (r *ClusterMigrationsAddRequest) Body(value *ClusterMigration) *ClusterMigrationsAddRequest { 113 r.body = value 114 return r 115 } 116 117 // Send sends this request, waits for the response, and returns it. 118 // 119 // This is a potentially lengthy operation, as it requires network communication. 120 // Consider using a context and the SendContext method. 121 func (r *ClusterMigrationsAddRequest) Send() (result *ClusterMigrationsAddResponse, err error) { 122 return r.SendContext(context.Background()) 123 } 124 125 // SendContext sends this request, waits for the response, and returns it. 126 func (r *ClusterMigrationsAddRequest) SendContext(ctx context.Context) (result *ClusterMigrationsAddResponse, err error) { 127 query := helpers.CopyQuery(r.query) 128 header := helpers.CopyHeader(r.header) 129 buffer := &bytes.Buffer{} 130 err = writeClusterMigrationsAddRequest(r, buffer) 131 if err != nil { 132 return 133 } 134 uri := &url.URL{ 135 Path: r.path, 136 RawQuery: query.Encode(), 137 } 138 request := &http.Request{ 139 Method: "POST", 140 URL: uri, 141 Header: header, 142 Body: io.NopCloser(buffer), 143 } 144 if ctx != nil { 145 request = request.WithContext(ctx) 146 } 147 response, err := r.transport.RoundTrip(request) 148 if err != nil { 149 return 150 } 151 defer response.Body.Close() 152 result = &ClusterMigrationsAddResponse{} 153 result.status = response.StatusCode 154 result.header = response.Header 155 reader := bufio.NewReader(response.Body) 156 _, err = reader.Peek(1) 157 if err == io.EOF { 158 err = nil 159 return 160 } 161 if result.status >= 400 { 162 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 163 if err != nil { 164 return 165 } 166 err = result.err 167 return 168 } 169 err = readClusterMigrationsAddResponse(result, reader) 170 if err != nil { 171 return 172 } 173 return 174 } 175 176 // ClusterMigrationsAddResponse is the response for the 'add' method. 177 type ClusterMigrationsAddResponse struct { 178 status int 179 header http.Header 180 err *errors.Error 181 body *ClusterMigration 182 } 183 184 // Status returns the response status code. 185 func (r *ClusterMigrationsAddResponse) Status() int { 186 if r == nil { 187 return 0 188 } 189 return r.status 190 } 191 192 // Header returns header of the response. 193 func (r *ClusterMigrationsAddResponse) Header() http.Header { 194 if r == nil { 195 return nil 196 } 197 return r.header 198 } 199 200 // Error returns the response error. 201 func (r *ClusterMigrationsAddResponse) Error() *errors.Error { 202 if r == nil { 203 return nil 204 } 205 return r.err 206 } 207 208 // Body returns the value of the 'body' parameter. 209 // 210 // Description of the cluster migration. 211 func (r *ClusterMigrationsAddResponse) Body() *ClusterMigration { 212 if r == nil { 213 return nil 214 } 215 return r.body 216 } 217 218 // GetBody returns the value of the 'body' parameter and 219 // a flag indicating if the parameter has a value. 220 // 221 // Description of the cluster migration. 222 func (r *ClusterMigrationsAddResponse) GetBody() (value *ClusterMigration, ok bool) { 223 ok = r != nil && r.body != nil 224 if ok { 225 value = r.body 226 } 227 return 228 } 229 230 // ClusterMigrationsListRequest is the request for the 'list' method. 231 type ClusterMigrationsListRequest struct { 232 transport http.RoundTripper 233 path string 234 query url.Values 235 header http.Header 236 page *int 237 size *int 238 } 239 240 // Parameter adds a query parameter. 241 func (r *ClusterMigrationsListRequest) Parameter(name string, value interface{}) *ClusterMigrationsListRequest { 242 helpers.AddValue(&r.query, name, value) 243 return r 244 } 245 246 // Header adds a request header. 247 func (r *ClusterMigrationsListRequest) Header(name string, value interface{}) *ClusterMigrationsListRequest { 248 helpers.AddHeader(&r.header, name, value) 249 return r 250 } 251 252 // Impersonate wraps requests on behalf of another user. 253 // Note: Services that do not support this feature may silently ignore this call. 254 func (r *ClusterMigrationsListRequest) Impersonate(user string) *ClusterMigrationsListRequest { 255 helpers.AddImpersonationHeader(&r.header, user) 256 return r 257 } 258 259 // Page sets the value of the 'page' parameter. 260 // 261 // Index of the returned page, where one corresponds to the first page. 262 func (r *ClusterMigrationsListRequest) Page(value int) *ClusterMigrationsListRequest { 263 r.page = &value 264 return r 265 } 266 267 // Size sets the value of the 'size' parameter. 268 // 269 // Number of items that will be contained in the returned page. 270 func (r *ClusterMigrationsListRequest) Size(value int) *ClusterMigrationsListRequest { 271 r.size = &value 272 return r 273 } 274 275 // Send sends this request, waits for the response, and returns it. 276 // 277 // This is a potentially lengthy operation, as it requires network communication. 278 // Consider using a context and the SendContext method. 279 func (r *ClusterMigrationsListRequest) Send() (result *ClusterMigrationsListResponse, err error) { 280 return r.SendContext(context.Background()) 281 } 282 283 // SendContext sends this request, waits for the response, and returns it. 284 func (r *ClusterMigrationsListRequest) SendContext(ctx context.Context) (result *ClusterMigrationsListResponse, err error) { 285 query := helpers.CopyQuery(r.query) 286 if r.page != nil { 287 helpers.AddValue(&query, "page", *r.page) 288 } 289 if r.size != nil { 290 helpers.AddValue(&query, "size", *r.size) 291 } 292 header := helpers.CopyHeader(r.header) 293 uri := &url.URL{ 294 Path: r.path, 295 RawQuery: query.Encode(), 296 } 297 request := &http.Request{ 298 Method: "GET", 299 URL: uri, 300 Header: header, 301 } 302 if ctx != nil { 303 request = request.WithContext(ctx) 304 } 305 response, err := r.transport.RoundTrip(request) 306 if err != nil { 307 return 308 } 309 defer response.Body.Close() 310 result = &ClusterMigrationsListResponse{} 311 result.status = response.StatusCode 312 result.header = response.Header 313 reader := bufio.NewReader(response.Body) 314 _, err = reader.Peek(1) 315 if err == io.EOF { 316 err = nil 317 return 318 } 319 if result.status >= 400 { 320 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 321 if err != nil { 322 return 323 } 324 err = result.err 325 return 326 } 327 err = readClusterMigrationsListResponse(result, reader) 328 if err != nil { 329 return 330 } 331 return 332 } 333 334 // ClusterMigrationsListResponse is the response for the 'list' method. 335 type ClusterMigrationsListResponse struct { 336 status int 337 header http.Header 338 err *errors.Error 339 items *ClusterMigrationList 340 page *int 341 size *int 342 total *int 343 } 344 345 // Status returns the response status code. 346 func (r *ClusterMigrationsListResponse) Status() int { 347 if r == nil { 348 return 0 349 } 350 return r.status 351 } 352 353 // Header returns header of the response. 354 func (r *ClusterMigrationsListResponse) Header() http.Header { 355 if r == nil { 356 return nil 357 } 358 return r.header 359 } 360 361 // Error returns the response error. 362 func (r *ClusterMigrationsListResponse) Error() *errors.Error { 363 if r == nil { 364 return nil 365 } 366 return r.err 367 } 368 369 // Items returns the value of the 'items' parameter. 370 // 371 // Retrieved list of cluster migrations. 372 func (r *ClusterMigrationsListResponse) Items() *ClusterMigrationList { 373 if r == nil { 374 return nil 375 } 376 return r.items 377 } 378 379 // GetItems returns the value of the 'items' parameter and 380 // a flag indicating if the parameter has a value. 381 // 382 // Retrieved list of cluster migrations. 383 func (r *ClusterMigrationsListResponse) GetItems() (value *ClusterMigrationList, ok bool) { 384 ok = r != nil && r.items != nil 385 if ok { 386 value = r.items 387 } 388 return 389 } 390 391 // Page returns the value of the 'page' parameter. 392 // 393 // Index of the returned page, where one corresponds to the first page. 394 func (r *ClusterMigrationsListResponse) Page() int { 395 if r != nil && r.page != nil { 396 return *r.page 397 } 398 return 0 399 } 400 401 // GetPage returns the value of the 'page' parameter and 402 // a flag indicating if the parameter has a value. 403 // 404 // Index of the returned page, where one corresponds to the first page. 405 func (r *ClusterMigrationsListResponse) GetPage() (value int, ok bool) { 406 ok = r != nil && r.page != nil 407 if ok { 408 value = *r.page 409 } 410 return 411 } 412 413 // Size returns the value of the 'size' parameter. 414 // 415 // Number of items that will be contained in the returned page. 416 func (r *ClusterMigrationsListResponse) Size() int { 417 if r != nil && r.size != nil { 418 return *r.size 419 } 420 return 0 421 } 422 423 // GetSize returns the value of the 'size' parameter and 424 // a flag indicating if the parameter has a value. 425 // 426 // Number of items that will be contained in the returned page. 427 func (r *ClusterMigrationsListResponse) GetSize() (value int, ok bool) { 428 ok = r != nil && r.size != nil 429 if ok { 430 value = *r.size 431 } 432 return 433 } 434 435 // Total returns the value of the 'total' parameter. 436 // 437 // Total number of items of the collection that match the search criteria, 438 // regardless of the size of the page. As this collection doesn't support paging or 439 // searching the result will always be the total number of migrations of the cluster. 440 func (r *ClusterMigrationsListResponse) Total() int { 441 if r != nil && r.total != nil { 442 return *r.total 443 } 444 return 0 445 } 446 447 // GetTotal returns the value of the 'total' parameter and 448 // a flag indicating if the parameter has a value. 449 // 450 // Total number of items of the collection that match the search criteria, 451 // regardless of the size of the page. As this collection doesn't support paging or 452 // searching the result will always be the total number of migrations of the cluster. 453 func (r *ClusterMigrationsListResponse) GetTotal() (value int, ok bool) { 454 ok = r != nil && r.total != nil 455 if ok { 456 value = *r.total 457 } 458 return 459 }