1package migrate
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/tracing"
14	"net/http"
15)
16
17// HyperVMachinesClient is the discover your workloads for Azure.
18type HyperVMachinesClient struct {
19	BaseClient
20}
21
22// NewHyperVMachinesClient creates an instance of the HyperVMachinesClient client.
23func NewHyperVMachinesClient() HyperVMachinesClient {
24	return NewHyperVMachinesClientWithBaseURI(DefaultBaseURI)
25}
26
27// NewHyperVMachinesClientWithBaseURI creates an instance of the HyperVMachinesClient client using a custom endpoint.
28// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
29func NewHyperVMachinesClientWithBaseURI(baseURI string) HyperVMachinesClient {
30	return HyperVMachinesClient{NewWithBaseURI(baseURI)}
31}
32
33// GetAllMachinesInSite sends the get all machines in site request.
34// Parameters:
35// subscriptionID - the ID of the target subscription.
36// resourceGroupName - the name of the resource group. The name is case insensitive.
37// siteName - site name.
38// APIVersion - the API version to use for this operation.
39// continuationToken - optional parameter for continuation token.
40// totalRecordCount - total count of machines in the given site.
41func (client HyperVMachinesClient) GetAllMachinesInSite(ctx context.Context, subscriptionID string, resourceGroupName string, siteName string, APIVersion string, filter string, top *int32, continuationToken string, totalRecordCount *int32) (result HyperVMachineCollectionPage, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/HyperVMachinesClient.GetAllMachinesInSite")
44		defer func() {
45			sc := -1
46			if result.hvmc.Response.Response != nil {
47				sc = result.hvmc.Response.Response.StatusCode
48			}
49			tracing.EndSpan(ctx, sc, err)
50		}()
51	}
52	result.fn = client.getAllMachinesInSiteNextResults
53	req, err := client.GetAllMachinesInSitePreparer(ctx, subscriptionID, resourceGroupName, siteName, APIVersion, filter, top, continuationToken, totalRecordCount)
54	if err != nil {
55		err = autorest.NewErrorWithError(err, "migrate.HyperVMachinesClient", "GetAllMachinesInSite", nil, "Failure preparing request")
56		return
57	}
58
59	resp, err := client.GetAllMachinesInSiteSender(req)
60	if err != nil {
61		result.hvmc.Response = autorest.Response{Response: resp}
62		err = autorest.NewErrorWithError(err, "migrate.HyperVMachinesClient", "GetAllMachinesInSite", resp, "Failure sending request")
63		return
64	}
65
66	result.hvmc, err = client.GetAllMachinesInSiteResponder(resp)
67	if err != nil {
68		err = autorest.NewErrorWithError(err, "migrate.HyperVMachinesClient", "GetAllMachinesInSite", resp, "Failure responding to request")
69		return
70	}
71	if result.hvmc.hasNextLink() && result.hvmc.IsEmpty() {
72		err = result.NextWithContext(ctx)
73		return
74	}
75
76	return
77}
78
79// GetAllMachinesInSitePreparer prepares the GetAllMachinesInSite request.
80func (client HyperVMachinesClient) GetAllMachinesInSitePreparer(ctx context.Context, subscriptionID string, resourceGroupName string, siteName string, APIVersion string, filter string, top *int32, continuationToken string, totalRecordCount *int32) (*http.Request, error) {
81	pathParameters := map[string]interface{}{
82		"resourceGroupName": autorest.Encode("path", resourceGroupName),
83		"siteName":          autorest.Encode("path", siteName),
84		"subscriptionId":    autorest.Encode("path", subscriptionID),
85	}
86
87	queryParameters := map[string]interface{}{
88		"api-version": APIVersion,
89	}
90	if len(filter) > 0 {
91		queryParameters["$filter"] = autorest.Encode("query", filter)
92	}
93	if top != nil {
94		queryParameters["$top"] = autorest.Encode("query", *top)
95	}
96	if len(continuationToken) > 0 {
97		queryParameters["continuationToken"] = autorest.Encode("query", continuationToken)
98	}
99	if totalRecordCount != nil {
100		queryParameters["totalRecordCount"] = autorest.Encode("query", *totalRecordCount)
101	}
102
103	preparer := autorest.CreatePreparer(
104		autorest.AsGet(),
105		autorest.WithBaseURL(client.BaseURI),
106		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OffAzure/HyperVSites/{siteName}/machines", pathParameters),
107		autorest.WithQueryParameters(queryParameters))
108	return preparer.Prepare((&http.Request{}).WithContext(ctx))
109}
110
111// GetAllMachinesInSiteSender sends the GetAllMachinesInSite request. The method will close the
112// http.Response Body if it receives an error.
113func (client HyperVMachinesClient) GetAllMachinesInSiteSender(req *http.Request) (*http.Response, error) {
114	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
115}
116
117// GetAllMachinesInSiteResponder handles the response to the GetAllMachinesInSite request. The method always
118// closes the http.Response Body.
119func (client HyperVMachinesClient) GetAllMachinesInSiteResponder(resp *http.Response) (result HyperVMachineCollection, err error) {
120	err = autorest.Respond(
121		resp,
122		azure.WithErrorUnlessStatusCode(http.StatusOK),
123		autorest.ByUnmarshallingJSON(&result),
124		autorest.ByClosing())
125	result.Response = autorest.Response{Response: resp}
126	return
127}
128
129// getAllMachinesInSiteNextResults retrieves the next set of results, if any.
130func (client HyperVMachinesClient) getAllMachinesInSiteNextResults(ctx context.Context, lastResults HyperVMachineCollection) (result HyperVMachineCollection, err error) {
131	req, err := lastResults.hyperVMachineCollectionPreparer(ctx)
132	if err != nil {
133		return result, autorest.NewErrorWithError(err, "migrate.HyperVMachinesClient", "getAllMachinesInSiteNextResults", nil, "Failure preparing next results request")
134	}
135	if req == nil {
136		return
137	}
138	resp, err := client.GetAllMachinesInSiteSender(req)
139	if err != nil {
140		result.Response = autorest.Response{Response: resp}
141		return result, autorest.NewErrorWithError(err, "migrate.HyperVMachinesClient", "getAllMachinesInSiteNextResults", resp, "Failure sending next results request")
142	}
143	result, err = client.GetAllMachinesInSiteResponder(resp)
144	if err != nil {
145		err = autorest.NewErrorWithError(err, "migrate.HyperVMachinesClient", "getAllMachinesInSiteNextResults", resp, "Failure responding to next results request")
146	}
147	return
148}
149
150// GetAllMachinesInSiteComplete enumerates all values, automatically crossing page boundaries as required.
151func (client HyperVMachinesClient) GetAllMachinesInSiteComplete(ctx context.Context, subscriptionID string, resourceGroupName string, siteName string, APIVersion string, filter string, top *int32, continuationToken string, totalRecordCount *int32) (result HyperVMachineCollectionIterator, err error) {
152	if tracing.IsEnabled() {
153		ctx = tracing.StartSpan(ctx, fqdn+"/HyperVMachinesClient.GetAllMachinesInSite")
154		defer func() {
155			sc := -1
156			if result.Response().Response.Response != nil {
157				sc = result.page.Response().Response.Response.StatusCode
158			}
159			tracing.EndSpan(ctx, sc, err)
160		}()
161	}
162	result.page, err = client.GetAllMachinesInSite(ctx, subscriptionID, resourceGroupName, siteName, APIVersion, filter, top, continuationToken, totalRecordCount)
163	return
164}
165
166// GetMachine sends the get machine request.
167// Parameters:
168// subscriptionID - the ID of the target subscription.
169// resourceGroupName - the name of the resource group. The name is case insensitive.
170// siteName - site name.
171// machineName - machine ARM name.
172// APIVersion - the API version to use for this operation.
173func (client HyperVMachinesClient) GetMachine(ctx context.Context, subscriptionID string, resourceGroupName string, siteName string, machineName string, APIVersion string) (result HyperVMachine, err error) {
174	if tracing.IsEnabled() {
175		ctx = tracing.StartSpan(ctx, fqdn+"/HyperVMachinesClient.GetMachine")
176		defer func() {
177			sc := -1
178			if result.Response.Response != nil {
179				sc = result.Response.Response.StatusCode
180			}
181			tracing.EndSpan(ctx, sc, err)
182		}()
183	}
184	req, err := client.GetMachinePreparer(ctx, subscriptionID, resourceGroupName, siteName, machineName, APIVersion)
185	if err != nil {
186		err = autorest.NewErrorWithError(err, "migrate.HyperVMachinesClient", "GetMachine", nil, "Failure preparing request")
187		return
188	}
189
190	resp, err := client.GetMachineSender(req)
191	if err != nil {
192		result.Response = autorest.Response{Response: resp}
193		err = autorest.NewErrorWithError(err, "migrate.HyperVMachinesClient", "GetMachine", resp, "Failure sending request")
194		return
195	}
196
197	result, err = client.GetMachineResponder(resp)
198	if err != nil {
199		err = autorest.NewErrorWithError(err, "migrate.HyperVMachinesClient", "GetMachine", resp, "Failure responding to request")
200		return
201	}
202
203	return
204}
205
206// GetMachinePreparer prepares the GetMachine request.
207func (client HyperVMachinesClient) GetMachinePreparer(ctx context.Context, subscriptionID string, resourceGroupName string, siteName string, machineName string, APIVersion string) (*http.Request, error) {
208	pathParameters := map[string]interface{}{
209		"machineName":       autorest.Encode("path", machineName),
210		"resourceGroupName": autorest.Encode("path", resourceGroupName),
211		"siteName":          autorest.Encode("path", siteName),
212		"subscriptionId":    autorest.Encode("path", subscriptionID),
213	}
214
215	queryParameters := map[string]interface{}{
216		"api-version": APIVersion,
217	}
218
219	preparer := autorest.CreatePreparer(
220		autorest.AsGet(),
221		autorest.WithBaseURL(client.BaseURI),
222		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OffAzure/HyperVSites/{siteName}/machines/{machineName}", pathParameters),
223		autorest.WithQueryParameters(queryParameters))
224	return preparer.Prepare((&http.Request{}).WithContext(ctx))
225}
226
227// GetMachineSender sends the GetMachine request. The method will close the
228// http.Response Body if it receives an error.
229func (client HyperVMachinesClient) GetMachineSender(req *http.Request) (*http.Response, error) {
230	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
231}
232
233// GetMachineResponder handles the response to the GetMachine request. The method always
234// closes the http.Response Body.
235func (client HyperVMachinesClient) GetMachineResponder(resp *http.Response) (result HyperVMachine, err error) {
236	err = autorest.Respond(
237		resp,
238		azure.WithErrorUnlessStatusCode(http.StatusOK),
239		autorest.ByUnmarshallingJSON(&result),
240		autorest.ByClosing())
241	result.Response = autorest.Response{Response: resp}
242	return
243}
244