From 186194bdda91e03144243cd76ff7ed040eec12bb Mon Sep 17 00:00:00 2001 From: hc-github-team-tf-azure <> Date: Thu, 15 Feb 2024 14:11:28 +0000 Subject: [PATCH] Updating based on 3b3c7b35 --- .../availabilitygrouplisteners/client.go | 22 ++- .../availabilitygrouplisteners/constants.go | 58 +++++- .../method_createorupdate.go | 75 +++++++ .../method_createorupdate_autorest.go | 80 -------- .../method_delete.go | 71 +++++++ .../method_delete_autorest.go | 78 -------- .../availabilitygrouplisteners/method_get.go | 80 ++++++++ .../method_get_autorest.go | 97 --------- .../method_listbygroup.go | 91 +++++++++ .../method_listbygroup_autorest.go | 186 ----------------- .../sqlvirtualmachine/2022-02-01/client.go | 39 ++-- .../sqlvirtualmachinegroups/client.go | 22 ++- .../sqlvirtualmachinegroups/constants.go | 71 ++++++- .../method_createorupdate.go | 75 +++++++ .../method_createorupdate_autorest.go | 80 -------- .../sqlvirtualmachinegroups/method_delete.go | 71 +++++++ .../method_delete_autorest.go | 78 -------- .../sqlvirtualmachinegroups/method_get.go | 51 +++++ .../method_get_autorest.go | 68 ------- .../sqlvirtualmachinegroups/method_list.go | 92 +++++++++ .../method_list_autorest.go | 187 ------------------ .../method_listbyresourcegroup.go | 92 +++++++++ .../method_listbyresourcegroup_autorest.go | 187 ------------------ .../sqlvirtualmachinegroups/method_update.go | 74 +++++++ .../method_update_autorest.go | 80 -------- .../2022-02-01/sqlvirtualmachines/client.go | 22 ++- .../sqlvirtualmachines/constants.go | 162 ++++++++++++++- .../method_createorupdate.go | 75 +++++++ .../method_createorupdate_autorest.go | 80 -------- .../sqlvirtualmachines/method_delete.go | 71 +++++++ .../method_delete_autorest.go | 78 -------- .../sqlvirtualmachines/method_get.go | 80 ++++++++ .../sqlvirtualmachines/method_get_autorest.go | 97 --------- .../sqlvirtualmachines/method_list.go | 92 +++++++++ .../method_list_autorest.go | 187 ------------------ .../method_listbyresourcegroup.go | 92 +++++++++ .../method_listbyresourcegroup_autorest.go | 187 ------------------ .../method_listbysqlvmgroup.go | 91 +++++++++ .../method_listbysqlvmgroup_autorest.go | 186 ----------------- .../sqlvirtualmachines/method_redeploy.go | 70 +++++++ .../method_redeploy_autorest.go | 78 -------- .../method_startassessment.go | 70 +++++++ .../method_startassessment_autorest.go | 78 -------- .../sqlvirtualmachines/method_update.go | 74 +++++++ .../method_update_autorest.go | 80 -------- 45 files changed, 1845 insertions(+), 2210 deletions(-) create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_createorupdate.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_createorupdate_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_delete.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_delete_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_get.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_get_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_listbygroup.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_listbygroup_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_createorupdate.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_createorupdate_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_delete.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_delete_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_get.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_get_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_list.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_list_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_listbyresourcegroup.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_listbyresourcegroup_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_update.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_update_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_createorupdate.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_createorupdate_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_delete.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_delete_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_get.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_get_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_list.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_list_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_listbyresourcegroup.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_listbyresourcegroup_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_listbysqlvmgroup.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_listbysqlvmgroup_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_redeploy.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_redeploy_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_startassessment.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_startassessment_autorest.go create mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_update.go delete mode 100644 resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_update_autorest.go diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/client.go b/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/client.go index 5bfcd62f8b6..dd5ea297a04 100644 --- a/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/client.go +++ b/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/client.go @@ -1,18 +1,26 @@ package availabilitygrouplisteners -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type AvailabilityGroupListenersClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewAvailabilityGroupListenersClientWithBaseURI(endpoint string) AvailabilityGroupListenersClient { - return AvailabilityGroupListenersClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewAvailabilityGroupListenersClientWithBaseURI(sdkApi sdkEnv.Api) (*AvailabilityGroupListenersClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "availabilitygrouplisteners", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AvailabilityGroupListenersClient: %+v", err) } + + return &AvailabilityGroupListenersClient{ + Client: client, + }, nil } diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/constants.go b/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/constants.go index 7e0f67d0f48..0a44c460cc5 100644 --- a/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/constants.go +++ b/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/constants.go @@ -1,6 +1,10 @@ package availabilitygrouplisteners -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -19,6 +23,19 @@ func PossibleValuesForCommit() []string { } } +func (s *Commit) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCommit(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCommit(input string) (*Commit, error) { vals := map[string]Commit{ "asynchronous_commit": CommitAsynchronousCommit, @@ -47,6 +64,19 @@ func PossibleValuesForFailover() []string { } } +func (s *Failover) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFailover(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseFailover(input string) (*Failover, error) { vals := map[string]Failover{ "automatic": FailoverAutomatic, @@ -77,6 +107,19 @@ func PossibleValuesForReadableSecondary() []string { } } +func (s *ReadableSecondary) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReadableSecondary(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseReadableSecondary(input string) (*ReadableSecondary, error) { vals := map[string]ReadableSecondary{ "all": ReadableSecondaryAll, @@ -106,6 +149,19 @@ func PossibleValuesForRole() []string { } } +func (s *Role) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRole(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRole(input string) (*Role, error) { vals := map[string]Role{ "primary": RolePrimary, diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_createorupdate.go b/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_createorupdate.go new file mode 100644 index 00000000000..e93dd63c0d4 --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_createorupdate.go @@ -0,0 +1,75 @@ +package availabilitygrouplisteners + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AvailabilityGroupListener +} + +// CreateOrUpdate ... +func (c AvailabilityGroupListenersClient) CreateOrUpdate(ctx context.Context, id AvailabilityGroupListenerId, input AvailabilityGroupListener) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c AvailabilityGroupListenersClient) CreateOrUpdateThenPoll(ctx context.Context, id AvailabilityGroupListenerId, input AvailabilityGroupListener) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_createorupdate_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_createorupdate_autorest.go deleted file mode 100644 index 7450964767f..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_createorupdate_autorest.go +++ /dev/null @@ -1,80 +0,0 @@ -package availabilitygrouplisteners - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *AvailabilityGroupListener -} - -// CreateOrUpdate ... -func (c AvailabilityGroupListenersClient) CreateOrUpdate(ctx context.Context, id AvailabilityGroupListenerId, input AvailabilityGroupListener) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "availabilitygrouplisteners.AvailabilityGroupListenersClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result, err = c.senderForCreateOrUpdate(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "availabilitygrouplisteners.AvailabilityGroupListenersClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed -func (c AvailabilityGroupListenersClient) CreateOrUpdateThenPoll(ctx context.Context, id AvailabilityGroupListenerId, input AvailabilityGroupListener) error { - result, err := c.CreateOrUpdate(ctx, id, input) - if err != nil { - return fmt.Errorf("performing CreateOrUpdate: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after CreateOrUpdate: %+v", err) - } - - return nil -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c AvailabilityGroupListenersClient) preparerForCreateOrUpdate(ctx context.Context, id AvailabilityGroupListenerId, input AvailabilityGroupListener) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForCreateOrUpdate sends the CreateOrUpdate request. The method will close the -// http.Response Body if it receives an error. -func (c AvailabilityGroupListenersClient) senderForCreateOrUpdate(ctx context.Context, req *http.Request) (future CreateOrUpdateOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_delete.go b/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_delete.go new file mode 100644 index 00000000000..bf3e8a5fc47 --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_delete.go @@ -0,0 +1,71 @@ +package availabilitygrouplisteners + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c AvailabilityGroupListenersClient) Delete(ctx context.Context, id AvailabilityGroupListenerId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c AvailabilityGroupListenersClient) DeleteThenPoll(ctx context.Context, id AvailabilityGroupListenerId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_delete_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_delete_autorest.go deleted file mode 100644 index 2a2ea7120cd..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_delete_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package availabilitygrouplisteners - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// Delete ... -func (c AvailabilityGroupListenersClient) Delete(ctx context.Context, id AvailabilityGroupListenerId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "availabilitygrouplisteners.AvailabilityGroupListenersClient", "Delete", nil, "Failure preparing request") - return - } - - result, err = c.senderForDelete(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "availabilitygrouplisteners.AvailabilityGroupListenersClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// DeleteThenPoll performs Delete then polls until it's completed -func (c AvailabilityGroupListenersClient) DeleteThenPoll(ctx context.Context, id AvailabilityGroupListenerId) error { - result, err := c.Delete(ctx, id) - if err != nil { - return fmt.Errorf("performing Delete: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Delete: %+v", err) - } - - return nil -} - -// preparerForDelete prepares the Delete request. -func (c AvailabilityGroupListenersClient) preparerForDelete(ctx context.Context, id AvailabilityGroupListenerId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForDelete sends the Delete request. The method will close the -// http.Response Body if it receives an error. -func (c AvailabilityGroupListenersClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_get.go b/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_get.go new file mode 100644 index 00000000000..9c8ba131a39 --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_get.go @@ -0,0 +1,80 @@ +package availabilitygrouplisteners + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AvailabilityGroupListener +} + +type GetOperationOptions struct { + Expand *string +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// Get ... +func (c AvailabilityGroupListenersClient) Get(ctx context.Context, id AvailabilityGroupListenerId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_get_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_get_autorest.go deleted file mode 100644 index bbe0b3326d3..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_get_autorest.go +++ /dev/null @@ -1,97 +0,0 @@ -package availabilitygrouplisteners - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *AvailabilityGroupListener -} - -type GetOperationOptions struct { - Expand *string -} - -func DefaultGetOperationOptions() GetOperationOptions { - return GetOperationOptions{} -} - -func (o GetOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o GetOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Expand != nil { - out["$expand"] = *o.Expand - } - - return out -} - -// Get ... -func (c AvailabilityGroupListenersClient) Get(ctx context.Context, id AvailabilityGroupListenerId, options GetOperationOptions) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "availabilitygrouplisteners.AvailabilityGroupListenersClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "availabilitygrouplisteners.AvailabilityGroupListenersClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "availabilitygrouplisteners.AvailabilityGroupListenersClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c AvailabilityGroupListenersClient) preparerForGet(ctx context.Context, id AvailabilityGroupListenerId, options GetOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c AvailabilityGroupListenersClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_listbygroup.go b/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_listbygroup.go new file mode 100644 index 00000000000..29571bc627a --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_listbygroup.go @@ -0,0 +1,91 @@ +package availabilitygrouplisteners + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AvailabilityGroupListener +} + +type ListByGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []AvailabilityGroupListener +} + +// ListByGroup ... +func (c AvailabilityGroupListenersClient) ListByGroup(ctx context.Context, id SqlVirtualMachineGroupId) (result ListByGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/availabilityGroupListeners", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AvailabilityGroupListener `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByGroupComplete retrieves all the results into a single object +func (c AvailabilityGroupListenersClient) ListByGroupComplete(ctx context.Context, id SqlVirtualMachineGroupId) (ListByGroupCompleteResult, error) { + return c.ListByGroupCompleteMatchingPredicate(ctx, id, AvailabilityGroupListenerOperationPredicate{}) +} + +// ListByGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AvailabilityGroupListenersClient) ListByGroupCompleteMatchingPredicate(ctx context.Context, id SqlVirtualMachineGroupId, predicate AvailabilityGroupListenerOperationPredicate) (result ListByGroupCompleteResult, err error) { + items := make([]AvailabilityGroupListener, 0) + + resp, err := c.ListByGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_listbygroup_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_listbygroup_autorest.go deleted file mode 100644 index 0c0ab85e2f8..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners/method_listbygroup_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package availabilitygrouplisteners - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListByGroupOperationResponse struct { - HttpResponse *http.Response - Model *[]AvailabilityGroupListener - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByGroupOperationResponse, error) -} - -type ListByGroupCompleteResult struct { - Items []AvailabilityGroupListener -} - -func (r ListByGroupOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByGroupOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListByGroup ... -func (c AvailabilityGroupListenersClient) ListByGroup(ctx context.Context, id SqlVirtualMachineGroupId) (resp ListByGroupOperationResponse, err error) { - req, err := c.preparerForListByGroup(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "availabilitygrouplisteners.AvailabilityGroupListenersClient", "ListByGroup", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "availabilitygrouplisteners.AvailabilityGroupListenersClient", "ListByGroup", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByGroup(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "availabilitygrouplisteners.AvailabilityGroupListenersClient", "ListByGroup", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByGroup prepares the ListByGroup request. -func (c AvailabilityGroupListenersClient) preparerForListByGroup(ctx context.Context, id SqlVirtualMachineGroupId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/availabilityGroupListeners", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByGroupWithNextLink prepares the ListByGroup request with the given nextLink token. -func (c AvailabilityGroupListenersClient) preparerForListByGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListByGroup handles the response to the ListByGroup request. The method always -// closes the http.Response Body. -func (c AvailabilityGroupListenersClient) responderForListByGroup(resp *http.Response) (result ListByGroupOperationResponse, err error) { - type page struct { - Values []AvailabilityGroupListener `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByGroupOperationResponse, err error) { - req, err := c.preparerForListByGroupWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "availabilitygrouplisteners.AvailabilityGroupListenersClient", "ListByGroup", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "availabilitygrouplisteners.AvailabilityGroupListenersClient", "ListByGroup", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByGroup(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "availabilitygrouplisteners.AvailabilityGroupListenersClient", "ListByGroup", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByGroupComplete retrieves all of the results into a single object -func (c AvailabilityGroupListenersClient) ListByGroupComplete(ctx context.Context, id SqlVirtualMachineGroupId) (ListByGroupCompleteResult, error) { - return c.ListByGroupCompleteMatchingPredicate(ctx, id, AvailabilityGroupListenerOperationPredicate{}) -} - -// ListByGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c AvailabilityGroupListenersClient) ListByGroupCompleteMatchingPredicate(ctx context.Context, id SqlVirtualMachineGroupId, predicate AvailabilityGroupListenerOperationPredicate) (resp ListByGroupCompleteResult, err error) { - items := make([]AvailabilityGroupListener, 0) - - page, err := c.ListByGroup(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListByGroupCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/client.go b/resource-manager/sqlvirtualmachine/2022-02-01/client.go index 0ca86cafd0c..280bf489e41 100644 --- a/resource-manager/sqlvirtualmachine/2022-02-01/client.go +++ b/resource-manager/sqlvirtualmachine/2022-02-01/client.go @@ -4,10 +4,13 @@ package v2022_02_01 // Licensed under the MIT License. See NOTICE.txt in the project root for license information. import ( - "github.com/Azure/go-autorest/autorest" + "fmt" + "github.com/hashicorp/go-azure-sdk/resource-manager/sqlvirtualmachine/2022-02-01/availabilitygrouplisteners" "github.com/hashicorp/go-azure-sdk/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups" "github.com/hashicorp/go-azure-sdk/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" ) type Client struct { @@ -16,20 +19,28 @@ type Client struct { SqlVirtualMachines *sqlvirtualmachines.SqlVirtualMachinesClient } -func NewClientWithBaseURI(endpoint string, configureAuthFunc func(c *autorest.Client)) Client { - - availabilityGroupListenersClient := availabilitygrouplisteners.NewAvailabilityGroupListenersClientWithBaseURI(endpoint) - configureAuthFunc(&availabilityGroupListenersClient.Client) - - sqlVirtualMachineGroupsClient := sqlvirtualmachinegroups.NewSqlVirtualMachineGroupsClientWithBaseURI(endpoint) - configureAuthFunc(&sqlVirtualMachineGroupsClient.Client) +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + availabilityGroupListenersClient, err := availabilitygrouplisteners.NewAvailabilityGroupListenersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AvailabilityGroupListeners client: %+v", err) + } + configureFunc(availabilityGroupListenersClient.Client) - sqlVirtualMachinesClient := sqlvirtualmachines.NewSqlVirtualMachinesClientWithBaseURI(endpoint) - configureAuthFunc(&sqlVirtualMachinesClient.Client) + sqlVirtualMachineGroupsClient, err := sqlvirtualmachinegroups.NewSqlVirtualMachineGroupsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlVirtualMachineGroups client: %+v", err) + } + configureFunc(sqlVirtualMachineGroupsClient.Client) - return Client{ - AvailabilityGroupListeners: &availabilityGroupListenersClient, - SqlVirtualMachineGroups: &sqlVirtualMachineGroupsClient, - SqlVirtualMachines: &sqlVirtualMachinesClient, + sqlVirtualMachinesClient, err := sqlvirtualmachines.NewSqlVirtualMachinesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlVirtualMachines client: %+v", err) } + configureFunc(sqlVirtualMachinesClient.Client) + + return &Client{ + AvailabilityGroupListeners: availabilityGroupListenersClient, + SqlVirtualMachineGroups: sqlVirtualMachineGroupsClient, + SqlVirtualMachines: sqlVirtualMachinesClient, + }, nil } diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/client.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/client.go index 1ca4860d732..1bf6a0b88a7 100644 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/client.go +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/client.go @@ -1,18 +1,26 @@ package sqlvirtualmachinegroups -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SqlVirtualMachineGroupsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSqlVirtualMachineGroupsClientWithBaseURI(endpoint string) SqlVirtualMachineGroupsClient { - return SqlVirtualMachineGroupsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSqlVirtualMachineGroupsClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlVirtualMachineGroupsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlvirtualmachinegroups", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlVirtualMachineGroupsClient: %+v", err) } + + return &SqlVirtualMachineGroupsClient{ + Client: client, + }, nil } diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/constants.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/constants.go index be4233d3cfa..71b3473b0a0 100644 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/constants.go +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/constants.go @@ -1,6 +1,10 @@ package sqlvirtualmachinegroups -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -17,6 +21,19 @@ func PossibleValuesForClusterConfiguration() []string { } } +func (s *ClusterConfiguration) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClusterConfiguration(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseClusterConfiguration(input string) (*ClusterConfiguration, error) { vals := map[string]ClusterConfiguration{ "domainful": ClusterConfigurationDomainful, @@ -42,6 +59,19 @@ func PossibleValuesForClusterManagerType() []string { } } +func (s *ClusterManagerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClusterManagerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseClusterManagerType(input string) (*ClusterManagerType, error) { vals := map[string]ClusterManagerType{ "wsfc": ClusterManagerTypeWSFC, @@ -69,6 +99,19 @@ func PossibleValuesForClusterSubnetType() []string { } } +func (s *ClusterSubnetType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClusterSubnetType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseClusterSubnetType(input string) (*ClusterSubnetType, error) { vals := map[string]ClusterSubnetType{ "multisubnet": ClusterSubnetTypeMultiSubnet, @@ -95,6 +138,19 @@ func PossibleValuesForScaleType() []string { } } +func (s *ScaleType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScaleType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseScaleType(input string) (*ScaleType, error) { vals := map[string]ScaleType{ "ha": ScaleTypeHA, @@ -122,6 +178,19 @@ func PossibleValuesForSqlVMGroupImageSku() []string { } } +func (s *SqlVMGroupImageSku) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSqlVMGroupImageSku(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSqlVMGroupImageSku(input string) (*SqlVMGroupImageSku, error) { vals := map[string]SqlVMGroupImageSku{ "developer": SqlVMGroupImageSkuDeveloper, diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_createorupdate.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_createorupdate.go new file mode 100644 index 00000000000..dd280e37f5e --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_createorupdate.go @@ -0,0 +1,75 @@ +package sqlvirtualmachinegroups + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SqlVirtualMachineGroup +} + +// CreateOrUpdate ... +func (c SqlVirtualMachineGroupsClient) CreateOrUpdate(ctx context.Context, id SqlVirtualMachineGroupId, input SqlVirtualMachineGroup) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c SqlVirtualMachineGroupsClient) CreateOrUpdateThenPoll(ctx context.Context, id SqlVirtualMachineGroupId, input SqlVirtualMachineGroup) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_createorupdate_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_createorupdate_autorest.go deleted file mode 100644 index 13328620f1c..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_createorupdate_autorest.go +++ /dev/null @@ -1,80 +0,0 @@ -package sqlvirtualmachinegroups - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *SqlVirtualMachineGroup -} - -// CreateOrUpdate ... -func (c SqlVirtualMachineGroupsClient) CreateOrUpdate(ctx context.Context, id SqlVirtualMachineGroupId, input SqlVirtualMachineGroup) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result, err = c.senderForCreateOrUpdate(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed -func (c SqlVirtualMachineGroupsClient) CreateOrUpdateThenPoll(ctx context.Context, id SqlVirtualMachineGroupId, input SqlVirtualMachineGroup) error { - result, err := c.CreateOrUpdate(ctx, id, input) - if err != nil { - return fmt.Errorf("performing CreateOrUpdate: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after CreateOrUpdate: %+v", err) - } - - return nil -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c SqlVirtualMachineGroupsClient) preparerForCreateOrUpdate(ctx context.Context, id SqlVirtualMachineGroupId, input SqlVirtualMachineGroup) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForCreateOrUpdate sends the CreateOrUpdate request. The method will close the -// http.Response Body if it receives an error. -func (c SqlVirtualMachineGroupsClient) senderForCreateOrUpdate(ctx context.Context, req *http.Request) (future CreateOrUpdateOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_delete.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_delete.go new file mode 100644 index 00000000000..e1b974dd763 --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_delete.go @@ -0,0 +1,71 @@ +package sqlvirtualmachinegroups + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SqlVirtualMachineGroupsClient) Delete(ctx context.Context, id SqlVirtualMachineGroupId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c SqlVirtualMachineGroupsClient) DeleteThenPoll(ctx context.Context, id SqlVirtualMachineGroupId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_delete_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_delete_autorest.go deleted file mode 100644 index caefd663e7e..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_delete_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package sqlvirtualmachinegroups - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// Delete ... -func (c SqlVirtualMachineGroupsClient) Delete(ctx context.Context, id SqlVirtualMachineGroupId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "Delete", nil, "Failure preparing request") - return - } - - result, err = c.senderForDelete(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// DeleteThenPoll performs Delete then polls until it's completed -func (c SqlVirtualMachineGroupsClient) DeleteThenPoll(ctx context.Context, id SqlVirtualMachineGroupId) error { - result, err := c.Delete(ctx, id) - if err != nil { - return fmt.Errorf("performing Delete: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Delete: %+v", err) - } - - return nil -} - -// preparerForDelete prepares the Delete request. -func (c SqlVirtualMachineGroupsClient) preparerForDelete(ctx context.Context, id SqlVirtualMachineGroupId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForDelete sends the Delete request. The method will close the -// http.Response Body if it receives an error. -func (c SqlVirtualMachineGroupsClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_get.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_get.go new file mode 100644 index 00000000000..00f404705d0 --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_get.go @@ -0,0 +1,51 @@ +package sqlvirtualmachinegroups + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SqlVirtualMachineGroup +} + +// Get ... +func (c SqlVirtualMachineGroupsClient) Get(ctx context.Context, id SqlVirtualMachineGroupId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_get_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_get_autorest.go deleted file mode 100644 index d707530815b..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package sqlvirtualmachinegroups - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SqlVirtualMachineGroup -} - -// Get ... -func (c SqlVirtualMachineGroupsClient) Get(ctx context.Context, id SqlVirtualMachineGroupId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SqlVirtualMachineGroupsClient) preparerForGet(ctx context.Context, id SqlVirtualMachineGroupId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SqlVirtualMachineGroupsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_list.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_list.go new file mode 100644 index 00000000000..82ea19db0e0 --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_list.go @@ -0,0 +1,92 @@ +package sqlvirtualmachinegroups + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SqlVirtualMachineGroup +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SqlVirtualMachineGroup +} + +// List ... +func (c SqlVirtualMachineGroupsClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SqlVirtualMachine/sqlVirtualMachineGroups", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SqlVirtualMachineGroup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c SqlVirtualMachineGroupsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SqlVirtualMachineGroupOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlVirtualMachineGroupsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate SqlVirtualMachineGroupOperationPredicate) (result ListCompleteResult, err error) { + items := make([]SqlVirtualMachineGroup, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_list_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_list_autorest.go deleted file mode 100644 index 83352a68ed4..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_list_autorest.go +++ /dev/null @@ -1,187 +0,0 @@ -package sqlvirtualmachinegroups - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]SqlVirtualMachineGroup - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []SqlVirtualMachineGroup -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c SqlVirtualMachineGroupsClient) List(ctx context.Context, id commonids.SubscriptionId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c SqlVirtualMachineGroupsClient) preparerForList(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SqlVirtualMachine/sqlVirtualMachineGroups", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c SqlVirtualMachineGroupsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SqlVirtualMachineGroupsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []SqlVirtualMachineGroup `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c SqlVirtualMachineGroupsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, SqlVirtualMachineGroupOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c SqlVirtualMachineGroupsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate SqlVirtualMachineGroupOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]SqlVirtualMachineGroup, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_listbyresourcegroup.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_listbyresourcegroup.go new file mode 100644 index 00000000000..07d0cdfd384 --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_listbyresourcegroup.go @@ -0,0 +1,92 @@ +package sqlvirtualmachinegroups + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SqlVirtualMachineGroup +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []SqlVirtualMachineGroup +} + +// ListByResourceGroup ... +func (c SqlVirtualMachineGroupsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SqlVirtualMachine/sqlVirtualMachineGroups", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SqlVirtualMachineGroup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c SqlVirtualMachineGroupsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, SqlVirtualMachineGroupOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlVirtualMachineGroupsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate SqlVirtualMachineGroupOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]SqlVirtualMachineGroup, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_listbyresourcegroup_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_listbyresourcegroup_autorest.go deleted file mode 100644 index 3a062e4084b..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_listbyresourcegroup_autorest.go +++ /dev/null @@ -1,187 +0,0 @@ -package sqlvirtualmachinegroups - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListByResourceGroupOperationResponse struct { - HttpResponse *http.Response - Model *[]SqlVirtualMachineGroup - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) -} - -type ListByResourceGroupCompleteResult struct { - Items []SqlVirtualMachineGroup -} - -func (r ListByResourceGroupOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListByResourceGroup ... -func (c SqlVirtualMachineGroupsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ListByResourceGroupOperationResponse, err error) { - req, err := c.preparerForListByResourceGroup(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "ListByResourceGroup", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByResourceGroup(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByResourceGroup prepares the ListByResourceGroup request. -func (c SqlVirtualMachineGroupsClient) preparerForListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SqlVirtualMachine/sqlVirtualMachineGroups", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. -func (c SqlVirtualMachineGroupsClient) preparerForListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always -// closes the http.Response Body. -func (c SqlVirtualMachineGroupsClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { - type page struct { - Values []SqlVirtualMachineGroup `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByResourceGroupOperationResponse, err error) { - req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "ListByResourceGroup", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByResourceGroup(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByResourceGroupComplete retrieves all of the results into a single object -func (c SqlVirtualMachineGroupsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { - return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, SqlVirtualMachineGroupOperationPredicate{}) -} - -// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c SqlVirtualMachineGroupsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate SqlVirtualMachineGroupOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { - items := make([]SqlVirtualMachineGroup, 0) - - page, err := c.ListByResourceGroup(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListByResourceGroupCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_update.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_update.go new file mode 100644 index 00000000000..6567ee1e501 --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_update.go @@ -0,0 +1,74 @@ +package sqlvirtualmachinegroups + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SqlVirtualMachineGroup +} + +// Update ... +func (c SqlVirtualMachineGroupsClient) Update(ctx context.Context, id SqlVirtualMachineGroupId, input SqlVirtualMachineGroupUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c SqlVirtualMachineGroupsClient) UpdateThenPoll(ctx context.Context, id SqlVirtualMachineGroupId, input SqlVirtualMachineGroupUpdate) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_update_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_update_autorest.go deleted file mode 100644 index 387579f2dd2..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachinegroups/method_update_autorest.go +++ /dev/null @@ -1,80 +0,0 @@ -package sqlvirtualmachinegroups - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type UpdateOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *SqlVirtualMachineGroup -} - -// Update ... -func (c SqlVirtualMachineGroupsClient) Update(ctx context.Context, id SqlVirtualMachineGroupId, input SqlVirtualMachineGroupUpdate) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "Update", nil, "Failure preparing request") - return - } - - result, err = c.senderForUpdate(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachinegroups.SqlVirtualMachineGroupsClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// UpdateThenPoll performs Update then polls until it's completed -func (c SqlVirtualMachineGroupsClient) UpdateThenPoll(ctx context.Context, id SqlVirtualMachineGroupId, input SqlVirtualMachineGroupUpdate) error { - result, err := c.Update(ctx, id, input) - if err != nil { - return fmt.Errorf("performing Update: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Update: %+v", err) - } - - return nil -} - -// preparerForUpdate prepares the Update request. -func (c SqlVirtualMachineGroupsClient) preparerForUpdate(ctx context.Context, id SqlVirtualMachineGroupId, input SqlVirtualMachineGroupUpdate) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForUpdate sends the Update request. The method will close the -// http.Response Body if it receives an error. -func (c SqlVirtualMachineGroupsClient) senderForUpdate(ctx context.Context, req *http.Request) (future UpdateOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/client.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/client.go index 3ef65baa033..d3578ee4c55 100644 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/client.go +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/client.go @@ -1,18 +1,26 @@ package sqlvirtualmachines -import "github.com/Azure/go-autorest/autorest" +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type SqlVirtualMachinesClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSqlVirtualMachinesClientWithBaseURI(endpoint string) SqlVirtualMachinesClient { - return SqlVirtualMachinesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSqlVirtualMachinesClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlVirtualMachinesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlvirtualmachines", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlVirtualMachinesClient: %+v", err) } + + return &SqlVirtualMachinesClient{ + Client: client, + }, nil } diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/constants.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/constants.go index 8d1f12b1d9f..f1b55c97705 100644 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/constants.go +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/constants.go @@ -1,6 +1,10 @@ package sqlvirtualmachines -import "strings" +import ( + "encoding/json" + "fmt" + "strings" +) // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. @@ -29,6 +33,19 @@ func PossibleValuesForAssessmentDayOfWeek() []string { } } +func (s *AssessmentDayOfWeek) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAssessmentDayOfWeek(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAssessmentDayOfWeek(input string) (*AssessmentDayOfWeek, error) { vals := map[string]AssessmentDayOfWeek{ "friday": AssessmentDayOfWeekFriday, @@ -72,6 +89,19 @@ func PossibleValuesForAutoBackupDaysOfWeek() []string { } } +func (s *AutoBackupDaysOfWeek) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutoBackupDaysOfWeek(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAutoBackupDaysOfWeek(input string) (*AutoBackupDaysOfWeek, error) { vals := map[string]AutoBackupDaysOfWeek{ "friday": AutoBackupDaysOfWeekFriday, @@ -105,6 +135,19 @@ func PossibleValuesForBackupScheduleType() []string { } } +func (s *BackupScheduleType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBackupScheduleType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseBackupScheduleType(input string) (*BackupScheduleType, error) { vals := map[string]BackupScheduleType{ "automated": BackupScheduleTypeAutomated, @@ -135,6 +178,19 @@ func PossibleValuesForConnectivityType() []string { } } +func (s *ConnectivityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConnectivityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseConnectivityType(input string) (*ConnectivityType, error) { vals := map[string]ConnectivityType{ "local": ConnectivityTypeLOCAL, @@ -176,6 +232,19 @@ func PossibleValuesForDayOfWeek() []string { } } +func (s *DayOfWeek) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDayOfWeek(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDayOfWeek(input string) (*DayOfWeek, error) { vals := map[string]DayOfWeek{ "everyday": DayOfWeekEveryday, @@ -212,6 +281,19 @@ func PossibleValuesForDiskConfigurationType() []string { } } +func (s *DiskConfigurationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDiskConfigurationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseDiskConfigurationType(input string) (*DiskConfigurationType, error) { vals := map[string]DiskConfigurationType{ "add": DiskConfigurationTypeADD, @@ -241,6 +323,19 @@ func PossibleValuesForFullBackupFrequencyType() []string { } } +func (s *FullBackupFrequencyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFullBackupFrequencyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseFullBackupFrequencyType(input string) (*FullBackupFrequencyType, error) { vals := map[string]FullBackupFrequencyType{ "daily": FullBackupFrequencyTypeDaily, @@ -275,6 +370,19 @@ func PossibleValuesForSqlImageSku() []string { } } +func (s *SqlImageSku) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSqlImageSku(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSqlImageSku(input string) (*SqlImageSku, error) { vals := map[string]SqlImageSku{ "developer": SqlImageSkuDeveloper, @@ -308,6 +416,19 @@ func PossibleValuesForSqlManagementMode() []string { } } +func (s *SqlManagementMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSqlManagementMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSqlManagementMode(input string) (*SqlManagementMode, error) { vals := map[string]SqlManagementMode{ "full": SqlManagementModeFull, @@ -339,6 +460,19 @@ func PossibleValuesForSqlServerLicenseType() []string { } } +func (s *SqlServerLicenseType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSqlServerLicenseType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSqlServerLicenseType(input string) (*SqlServerLicenseType, error) { vals := map[string]SqlServerLicenseType{ "ahub": SqlServerLicenseTypeAHUB, @@ -370,6 +504,19 @@ func PossibleValuesForSqlWorkloadType() []string { } } +func (s *SqlWorkloadType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSqlWorkloadType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSqlWorkloadType(input string) (*SqlWorkloadType, error) { vals := map[string]SqlWorkloadType{ "dw": SqlWorkloadTypeDW, @@ -401,6 +548,19 @@ func PossibleValuesForStorageWorkloadType() []string { } } +func (s *StorageWorkloadType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStorageWorkloadType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseStorageWorkloadType(input string) (*StorageWorkloadType, error) { vals := map[string]StorageWorkloadType{ "dw": StorageWorkloadTypeDW, diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_createorupdate.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_createorupdate.go new file mode 100644 index 00000000000..935e5a46777 --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_createorupdate.go @@ -0,0 +1,75 @@ +package sqlvirtualmachines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SqlVirtualMachine +} + +// CreateOrUpdate ... +func (c SqlVirtualMachinesClient) CreateOrUpdate(ctx context.Context, id SqlVirtualMachineId, input SqlVirtualMachine) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c SqlVirtualMachinesClient) CreateOrUpdateThenPoll(ctx context.Context, id SqlVirtualMachineId, input SqlVirtualMachine) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_createorupdate_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_createorupdate_autorest.go deleted file mode 100644 index ec256318387..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_createorupdate_autorest.go +++ /dev/null @@ -1,80 +0,0 @@ -package sqlvirtualmachines - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrUpdateOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *SqlVirtualMachine -} - -// CreateOrUpdate ... -func (c SqlVirtualMachinesClient) CreateOrUpdate(ctx context.Context, id SqlVirtualMachineId, input SqlVirtualMachine) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result, err = c.senderForCreateOrUpdate(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed -func (c SqlVirtualMachinesClient) CreateOrUpdateThenPoll(ctx context.Context, id SqlVirtualMachineId, input SqlVirtualMachine) error { - result, err := c.CreateOrUpdate(ctx, id, input) - if err != nil { - return fmt.Errorf("performing CreateOrUpdate: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after CreateOrUpdate: %+v", err) - } - - return nil -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c SqlVirtualMachinesClient) preparerForCreateOrUpdate(ctx context.Context, id SqlVirtualMachineId, input SqlVirtualMachine) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForCreateOrUpdate sends the CreateOrUpdate request. The method will close the -// http.Response Body if it receives an error. -func (c SqlVirtualMachinesClient) senderForCreateOrUpdate(ctx context.Context, req *http.Request) (future CreateOrUpdateOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_delete.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_delete.go new file mode 100644 index 00000000000..59cff7cdba6 --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_delete.go @@ -0,0 +1,71 @@ +package sqlvirtualmachines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SqlVirtualMachinesClient) Delete(ctx context.Context, id SqlVirtualMachineId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c SqlVirtualMachinesClient) DeleteThenPoll(ctx context.Context, id SqlVirtualMachineId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_delete_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_delete_autorest.go deleted file mode 100644 index 2d92155074c..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_delete_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package sqlvirtualmachines - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type DeleteOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// Delete ... -func (c SqlVirtualMachinesClient) Delete(ctx context.Context, id SqlVirtualMachineId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "Delete", nil, "Failure preparing request") - return - } - - result, err = c.senderForDelete(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// DeleteThenPoll performs Delete then polls until it's completed -func (c SqlVirtualMachinesClient) DeleteThenPoll(ctx context.Context, id SqlVirtualMachineId) error { - result, err := c.Delete(ctx, id) - if err != nil { - return fmt.Errorf("performing Delete: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Delete: %+v", err) - } - - return nil -} - -// preparerForDelete prepares the Delete request. -func (c SqlVirtualMachinesClient) preparerForDelete(ctx context.Context, id SqlVirtualMachineId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForDelete sends the Delete request. The method will close the -// http.Response Body if it receives an error. -func (c SqlVirtualMachinesClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_get.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_get.go new file mode 100644 index 00000000000..421aae1d80f --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_get.go @@ -0,0 +1,80 @@ +package sqlvirtualmachines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SqlVirtualMachine +} + +type GetOperationOptions struct { + Expand *string +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// Get ... +func (c SqlVirtualMachinesClient) Get(ctx context.Context, id SqlVirtualMachineId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_get_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_get_autorest.go deleted file mode 100644 index e0beb4ed54a..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_get_autorest.go +++ /dev/null @@ -1,97 +0,0 @@ -package sqlvirtualmachines - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type GetOperationResponse struct { - HttpResponse *http.Response - Model *SqlVirtualMachine -} - -type GetOperationOptions struct { - Expand *string -} - -func DefaultGetOperationOptions() GetOperationOptions { - return GetOperationOptions{} -} - -func (o GetOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o GetOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Expand != nil { - out["$expand"] = *o.Expand - } - - return out -} - -// Get ... -func (c SqlVirtualMachinesClient) Get(ctx context.Context, id SqlVirtualMachineId, options GetOperationOptions) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c SqlVirtualMachinesClient) preparerForGet(ctx context.Context, id SqlVirtualMachineId, options GetOperationOptions) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - for k, v := range options.toQueryString() { - queryParameters[k] = autorest.Encode("query", v) - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForGet handles the response to the Get request. The method always -// closes the http.Response Body. -func (c SqlVirtualMachinesClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - - return -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_list.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_list.go new file mode 100644 index 00000000000..04b5e1f8ca0 --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_list.go @@ -0,0 +1,92 @@ +package sqlvirtualmachines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SqlVirtualMachine +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SqlVirtualMachine +} + +// List ... +func (c SqlVirtualMachinesClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SqlVirtualMachine/sqlVirtualMachines", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SqlVirtualMachine `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c SqlVirtualMachinesClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SqlVirtualMachineOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlVirtualMachinesClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate SqlVirtualMachineOperationPredicate) (result ListCompleteResult, err error) { + items := make([]SqlVirtualMachine, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_list_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_list_autorest.go deleted file mode 100644 index a765feeab37..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_list_autorest.go +++ /dev/null @@ -1,187 +0,0 @@ -package sqlvirtualmachines - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListOperationResponse struct { - HttpResponse *http.Response - Model *[]SqlVirtualMachine - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []SqlVirtualMachine -} - -func (r ListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// List ... -func (c SqlVirtualMachinesClient) List(ctx context.Context, id commonids.SubscriptionId) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c SqlVirtualMachinesClient) preparerForList(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SqlVirtualMachine/sqlVirtualMachines", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c SqlVirtualMachinesClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForList handles the response to the List request. The method always -// closes the http.Response Body. -func (c SqlVirtualMachinesClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []SqlVirtualMachine `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { - req, err := c.preparerForListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c SqlVirtualMachinesClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, SqlVirtualMachineOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c SqlVirtualMachinesClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate SqlVirtualMachineOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]SqlVirtualMachine, 0) - - page, err := c.List(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_listbyresourcegroup.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_listbyresourcegroup.go new file mode 100644 index 00000000000..033be33aa2d --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_listbyresourcegroup.go @@ -0,0 +1,92 @@ +package sqlvirtualmachines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SqlVirtualMachine +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []SqlVirtualMachine +} + +// ListByResourceGroup ... +func (c SqlVirtualMachinesClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SqlVirtualMachine/sqlVirtualMachines", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SqlVirtualMachine `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c SqlVirtualMachinesClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, SqlVirtualMachineOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlVirtualMachinesClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate SqlVirtualMachineOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]SqlVirtualMachine, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_listbyresourcegroup_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_listbyresourcegroup_autorest.go deleted file mode 100644 index d500636c970..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_listbyresourcegroup_autorest.go +++ /dev/null @@ -1,187 +0,0 @@ -package sqlvirtualmachines - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListByResourceGroupOperationResponse struct { - HttpResponse *http.Response - Model *[]SqlVirtualMachine - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) -} - -type ListByResourceGroupCompleteResult struct { - Items []SqlVirtualMachine -} - -func (r ListByResourceGroupOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListByResourceGroup ... -func (c SqlVirtualMachinesClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ListByResourceGroupOperationResponse, err error) { - req, err := c.preparerForListByResourceGroup(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "ListByResourceGroup", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByResourceGroup(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByResourceGroup prepares the ListByResourceGroup request. -func (c SqlVirtualMachinesClient) preparerForListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SqlVirtualMachine/sqlVirtualMachines", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. -func (c SqlVirtualMachinesClient) preparerForListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always -// closes the http.Response Body. -func (c SqlVirtualMachinesClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { - type page struct { - Values []SqlVirtualMachine `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByResourceGroupOperationResponse, err error) { - req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "ListByResourceGroup", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByResourceGroup(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByResourceGroupComplete retrieves all of the results into a single object -func (c SqlVirtualMachinesClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { - return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, SqlVirtualMachineOperationPredicate{}) -} - -// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c SqlVirtualMachinesClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate SqlVirtualMachineOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { - items := make([]SqlVirtualMachine, 0) - - page, err := c.ListByResourceGroup(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListByResourceGroupCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_listbysqlvmgroup.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_listbysqlvmgroup.go new file mode 100644 index 00000000000..c2f01089b12 --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_listbysqlvmgroup.go @@ -0,0 +1,91 @@ +package sqlvirtualmachines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySqlVMGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SqlVirtualMachine +} + +type ListBySqlVMGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []SqlVirtualMachine +} + +// ListBySqlVMGroup ... +func (c SqlVirtualMachinesClient) ListBySqlVMGroup(ctx context.Context, id SqlVirtualMachineGroupId) (result ListBySqlVMGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/sqlVirtualMachines", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SqlVirtualMachine `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySqlVMGroupComplete retrieves all the results into a single object +func (c SqlVirtualMachinesClient) ListBySqlVMGroupComplete(ctx context.Context, id SqlVirtualMachineGroupId) (ListBySqlVMGroupCompleteResult, error) { + return c.ListBySqlVMGroupCompleteMatchingPredicate(ctx, id, SqlVirtualMachineOperationPredicate{}) +} + +// ListBySqlVMGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlVirtualMachinesClient) ListBySqlVMGroupCompleteMatchingPredicate(ctx context.Context, id SqlVirtualMachineGroupId, predicate SqlVirtualMachineOperationPredicate) (result ListBySqlVMGroupCompleteResult, err error) { + items := make([]SqlVirtualMachine, 0) + + resp, err := c.ListBySqlVMGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySqlVMGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_listbysqlvmgroup_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_listbysqlvmgroup_autorest.go deleted file mode 100644 index 381a1aecbce..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_listbysqlvmgroup_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package sqlvirtualmachines - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ListBySqlVMGroupOperationResponse struct { - HttpResponse *http.Response - Model *[]SqlVirtualMachine - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListBySqlVMGroupOperationResponse, error) -} - -type ListBySqlVMGroupCompleteResult struct { - Items []SqlVirtualMachine -} - -func (r ListBySqlVMGroupOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListBySqlVMGroupOperationResponse) LoadMore(ctx context.Context) (resp ListBySqlVMGroupOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListBySqlVMGroup ... -func (c SqlVirtualMachinesClient) ListBySqlVMGroup(ctx context.Context, id SqlVirtualMachineGroupId) (resp ListBySqlVMGroupOperationResponse, err error) { - req, err := c.preparerForListBySqlVMGroup(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "ListBySqlVMGroup", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "ListBySqlVMGroup", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListBySqlVMGroup(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "ListBySqlVMGroup", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListBySqlVMGroup prepares the ListBySqlVMGroup request. -func (c SqlVirtualMachinesClient) preparerForListBySqlVMGroup(ctx context.Context, id SqlVirtualMachineGroupId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/sqlVirtualMachines", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListBySqlVMGroupWithNextLink prepares the ListBySqlVMGroup request with the given nextLink token. -func (c SqlVirtualMachinesClient) preparerForListBySqlVMGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListBySqlVMGroup handles the response to the ListBySqlVMGroup request. The method always -// closes the http.Response Body. -func (c SqlVirtualMachinesClient) responderForListBySqlVMGroup(resp *http.Response) (result ListBySqlVMGroupOperationResponse, err error) { - type page struct { - Values []SqlVirtualMachine `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListBySqlVMGroupOperationResponse, err error) { - req, err := c.preparerForListBySqlVMGroupWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "ListBySqlVMGroup", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "ListBySqlVMGroup", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListBySqlVMGroup(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "ListBySqlVMGroup", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListBySqlVMGroupComplete retrieves all of the results into a single object -func (c SqlVirtualMachinesClient) ListBySqlVMGroupComplete(ctx context.Context, id SqlVirtualMachineGroupId) (ListBySqlVMGroupCompleteResult, error) { - return c.ListBySqlVMGroupCompleteMatchingPredicate(ctx, id, SqlVirtualMachineOperationPredicate{}) -} - -// ListBySqlVMGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c SqlVirtualMachinesClient) ListBySqlVMGroupCompleteMatchingPredicate(ctx context.Context, id SqlVirtualMachineGroupId, predicate SqlVirtualMachineOperationPredicate) (resp ListBySqlVMGroupCompleteResult, err error) { - items := make([]SqlVirtualMachine, 0) - - page, err := c.ListBySqlVMGroup(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ListBySqlVMGroupCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_redeploy.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_redeploy.go new file mode 100644 index 00000000000..ff343c7b680 --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_redeploy.go @@ -0,0 +1,70 @@ +package sqlvirtualmachines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedeployOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Redeploy ... +func (c SqlVirtualMachinesClient) Redeploy(ctx context.Context, id SqlVirtualMachineId) (result RedeployOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/redeploy", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// RedeployThenPoll performs Redeploy then polls until it's completed +func (c SqlVirtualMachinesClient) RedeployThenPoll(ctx context.Context, id SqlVirtualMachineId) error { + result, err := c.Redeploy(ctx, id) + if err != nil { + return fmt.Errorf("performing Redeploy: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Redeploy: %+v", err) + } + + return nil +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_redeploy_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_redeploy_autorest.go deleted file mode 100644 index 742e4a8c959..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_redeploy_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package sqlvirtualmachines - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type RedeployOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// Redeploy ... -func (c SqlVirtualMachinesClient) Redeploy(ctx context.Context, id SqlVirtualMachineId) (result RedeployOperationResponse, err error) { - req, err := c.preparerForRedeploy(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "Redeploy", nil, "Failure preparing request") - return - } - - result, err = c.senderForRedeploy(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "Redeploy", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// RedeployThenPoll performs Redeploy then polls until it's completed -func (c SqlVirtualMachinesClient) RedeployThenPoll(ctx context.Context, id SqlVirtualMachineId) error { - result, err := c.Redeploy(ctx, id) - if err != nil { - return fmt.Errorf("performing Redeploy: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Redeploy: %+v", err) - } - - return nil -} - -// preparerForRedeploy prepares the Redeploy request. -func (c SqlVirtualMachinesClient) preparerForRedeploy(ctx context.Context, id SqlVirtualMachineId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/redeploy", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForRedeploy sends the Redeploy request. The method will close the -// http.Response Body if it receives an error. -func (c SqlVirtualMachinesClient) senderForRedeploy(ctx context.Context, req *http.Request) (future RedeployOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_startassessment.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_startassessment.go new file mode 100644 index 00000000000..6727c17a34f --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_startassessment.go @@ -0,0 +1,70 @@ +package sqlvirtualmachines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StartAssessmentOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// StartAssessment ... +func (c SqlVirtualMachinesClient) StartAssessment(ctx context.Context, id SqlVirtualMachineId) (result StartAssessmentOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/startAssessment", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// StartAssessmentThenPoll performs StartAssessment then polls until it's completed +func (c SqlVirtualMachinesClient) StartAssessmentThenPoll(ctx context.Context, id SqlVirtualMachineId) error { + result, err := c.StartAssessment(ctx, id) + if err != nil { + return fmt.Errorf("performing StartAssessment: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after StartAssessment: %+v", err) + } + + return nil +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_startassessment_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_startassessment_autorest.go deleted file mode 100644 index aa095cd8f6b..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_startassessment_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package sqlvirtualmachines - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type StartAssessmentOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// StartAssessment ... -func (c SqlVirtualMachinesClient) StartAssessment(ctx context.Context, id SqlVirtualMachineId) (result StartAssessmentOperationResponse, err error) { - req, err := c.preparerForStartAssessment(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "StartAssessment", nil, "Failure preparing request") - return - } - - result, err = c.senderForStartAssessment(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "StartAssessment", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// StartAssessmentThenPoll performs StartAssessment then polls until it's completed -func (c SqlVirtualMachinesClient) StartAssessmentThenPoll(ctx context.Context, id SqlVirtualMachineId) error { - result, err := c.StartAssessment(ctx, id) - if err != nil { - return fmt.Errorf("performing StartAssessment: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after StartAssessment: %+v", err) - } - - return nil -} - -// preparerForStartAssessment prepares the StartAssessment request. -func (c SqlVirtualMachinesClient) preparerForStartAssessment(ctx context.Context, id SqlVirtualMachineId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/startAssessment", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForStartAssessment sends the StartAssessment request. The method will close the -// http.Response Body if it receives an error. -func (c SqlVirtualMachinesClient) senderForStartAssessment(ctx context.Context, req *http.Request) (future StartAssessmentOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_update.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_update.go new file mode 100644 index 00000000000..413762cb84c --- /dev/null +++ b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_update.go @@ -0,0 +1,74 @@ +package sqlvirtualmachines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SqlVirtualMachine +} + +// Update ... +func (c SqlVirtualMachinesClient) Update(ctx context.Context, id SqlVirtualMachineId, input SqlVirtualMachineUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c SqlVirtualMachinesClient) UpdateThenPoll(ctx context.Context, id SqlVirtualMachineId, input SqlVirtualMachineUpdate) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_update_autorest.go b/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_update_autorest.go deleted file mode 100644 index a839bf35517..00000000000 --- a/resource-manager/sqlvirtualmachine/2022-02-01/sqlvirtualmachines/method_update_autorest.go +++ /dev/null @@ -1,80 +0,0 @@ -package sqlvirtualmachines - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type UpdateOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *SqlVirtualMachine -} - -// Update ... -func (c SqlVirtualMachinesClient) Update(ctx context.Context, id SqlVirtualMachineId, input SqlVirtualMachineUpdate) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "Update", nil, "Failure preparing request") - return - } - - result, err = c.senderForUpdate(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "sqlvirtualmachines.SqlVirtualMachinesClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// UpdateThenPoll performs Update then polls until it's completed -func (c SqlVirtualMachinesClient) UpdateThenPoll(ctx context.Context, id SqlVirtualMachineId, input SqlVirtualMachineUpdate) error { - result, err := c.Update(ctx, id, input) - if err != nil { - return fmt.Errorf("performing Update: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Update: %+v", err) - } - - return nil -} - -// preparerForUpdate prepares the Update request. -func (c SqlVirtualMachinesClient) preparerForUpdate(ctx context.Context, id SqlVirtualMachineId, input SqlVirtualMachineUpdate) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForUpdate sends the Update request. The method will close the -// http.Response Body if it receives an error. -func (c SqlVirtualMachinesClient) senderForUpdate(ctx context.Context, req *http.Request) (future UpdateOperationResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - - future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) - return -}