1package compute
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/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// VirtualMachineSizesClient is the compute Client
19type VirtualMachineSizesClient struct {
20	BaseClient
21}
22
23// NewVirtualMachineSizesClient creates an instance of the VirtualMachineSizesClient client.
24func NewVirtualMachineSizesClient(subscriptionID string) VirtualMachineSizesClient {
25	return NewVirtualMachineSizesClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewVirtualMachineSizesClientWithBaseURI creates an instance of the VirtualMachineSizesClient client using a custom
29// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
30// stack).
31func NewVirtualMachineSizesClientWithBaseURI(baseURI string, subscriptionID string) VirtualMachineSizesClient {
32	return VirtualMachineSizesClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// List lists all available virtual machine sizes for a subscription in a location.
36// Parameters:
37// location - the location upon which virtual-machine-sizes is queried.
38func (client VirtualMachineSizesClient) List(ctx context.Context, location string) (result VirtualMachineSizeListResult, err error) {
39	if tracing.IsEnabled() {
40		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineSizesClient.List")
41		defer func() {
42			sc := -1
43			if result.Response.Response != nil {
44				sc = result.Response.Response.StatusCode
45			}
46			tracing.EndSpan(ctx, sc, err)
47		}()
48	}
49	if err := validation.Validate([]validation.Validation{
50		{TargetValue: location,
51			Constraints: []validation.Constraint{{Target: "location", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
52		return result, validation.NewError("compute.VirtualMachineSizesClient", "List", err.Error())
53	}
54
55	req, err := client.ListPreparer(ctx, location)
56	if err != nil {
57		err = autorest.NewErrorWithError(err, "compute.VirtualMachineSizesClient", "List", nil, "Failure preparing request")
58		return
59	}
60
61	resp, err := client.ListSender(req)
62	if err != nil {
63		result.Response = autorest.Response{Response: resp}
64		err = autorest.NewErrorWithError(err, "compute.VirtualMachineSizesClient", "List", resp, "Failure sending request")
65		return
66	}
67
68	result, err = client.ListResponder(resp)
69	if err != nil {
70		err = autorest.NewErrorWithError(err, "compute.VirtualMachineSizesClient", "List", resp, "Failure responding to request")
71		return
72	}
73
74	return
75}
76
77// ListPreparer prepares the List request.
78func (client VirtualMachineSizesClient) ListPreparer(ctx context.Context, location string) (*http.Request, error) {
79	pathParameters := map[string]interface{}{
80		"location":       autorest.Encode("path", location),
81		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
82	}
83
84	const APIVersion = "2015-06-15"
85	queryParameters := map[string]interface{}{
86		"api-version": APIVersion,
87	}
88
89	preparer := autorest.CreatePreparer(
90		autorest.AsGet(),
91		autorest.WithBaseURL(client.BaseURI),
92		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/vmSizes", pathParameters),
93		autorest.WithQueryParameters(queryParameters))
94	return preparer.Prepare((&http.Request{}).WithContext(ctx))
95}
96
97// ListSender sends the List request. The method will close the
98// http.Response Body if it receives an error.
99func (client VirtualMachineSizesClient) ListSender(req *http.Request) (*http.Response, error) {
100	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
101}
102
103// ListResponder handles the response to the List request. The method always
104// closes the http.Response Body.
105func (client VirtualMachineSizesClient) ListResponder(resp *http.Response) (result VirtualMachineSizeListResult, err error) {
106	err = autorest.Respond(
107		resp,
108		azure.WithErrorUnlessStatusCode(http.StatusOK),
109		autorest.ByUnmarshallingJSON(&result),
110		autorest.ByClosing())
111	result.Response = autorest.Response{Response: resp}
112	return
113}
114