1package vmwarecloudsimple
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/tracing"
25	"net/http"
26)
27
28// PrivateCloudsClient is the description of the new service
29type PrivateCloudsClient struct {
30	BaseClient
31}
32
33// NewPrivateCloudsClient creates an instance of the PrivateCloudsClient client.
34func NewPrivateCloudsClient(subscriptionID string, referer string) PrivateCloudsClient {
35	return NewPrivateCloudsClientWithBaseURI(DefaultBaseURI, subscriptionID, referer)
36}
37
38// NewPrivateCloudsClientWithBaseURI creates an instance of the PrivateCloudsClient client using a custom endpoint.
39// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
40func NewPrivateCloudsClientWithBaseURI(baseURI string, subscriptionID string, referer string) PrivateCloudsClient {
41	return PrivateCloudsClient{NewWithBaseURI(baseURI, subscriptionID, referer)}
42}
43
44// Get returns private cloud by its name
45// Parameters:
46// pcName - the private cloud name
47// regionID - the region Id (westus, eastus)
48func (client PrivateCloudsClient) Get(ctx context.Context, pcName string, regionID string) (result PrivateCloud, err error) {
49	if tracing.IsEnabled() {
50		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateCloudsClient.Get")
51		defer func() {
52			sc := -1
53			if result.Response.Response != nil {
54				sc = result.Response.Response.StatusCode
55			}
56			tracing.EndSpan(ctx, sc, err)
57		}()
58	}
59	req, err := client.GetPreparer(ctx, pcName, regionID)
60	if err != nil {
61		err = autorest.NewErrorWithError(err, "vmwarecloudsimple.PrivateCloudsClient", "Get", nil, "Failure preparing request")
62		return
63	}
64
65	resp, err := client.GetSender(req)
66	if err != nil {
67		result.Response = autorest.Response{Response: resp}
68		err = autorest.NewErrorWithError(err, "vmwarecloudsimple.PrivateCloudsClient", "Get", resp, "Failure sending request")
69		return
70	}
71
72	result, err = client.GetResponder(resp)
73	if err != nil {
74		err = autorest.NewErrorWithError(err, "vmwarecloudsimple.PrivateCloudsClient", "Get", resp, "Failure responding to request")
75	}
76
77	return
78}
79
80// GetPreparer prepares the Get request.
81func (client PrivateCloudsClient) GetPreparer(ctx context.Context, pcName string, regionID string) (*http.Request, error) {
82	pathParameters := map[string]interface{}{
83		"pcName":         autorest.Encode("path", pcName),
84		"regionId":       autorest.Encode("path", regionID),
85		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
86	}
87
88	const APIVersion = "2019-04-01"
89	queryParameters := map[string]interface{}{
90		"api-version": APIVersion,
91	}
92
93	preparer := autorest.CreatePreparer(
94		autorest.AsGet(),
95		autorest.WithBaseURL(client.BaseURI),
96		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.VMwareCloudSimple/locations/{regionId}/privateClouds/{pcName}", pathParameters),
97		autorest.WithQueryParameters(queryParameters))
98	return preparer.Prepare((&http.Request{}).WithContext(ctx))
99}
100
101// GetSender sends the Get request. The method will close the
102// http.Response Body if it receives an error.
103func (client PrivateCloudsClient) GetSender(req *http.Request) (*http.Response, error) {
104	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
105}
106
107// GetResponder handles the response to the Get request. The method always
108// closes the http.Response Body.
109func (client PrivateCloudsClient) GetResponder(resp *http.Response) (result PrivateCloud, err error) {
110	err = autorest.Respond(
111		resp,
112		client.ByInspecting(),
113		azure.WithErrorUnlessStatusCode(http.StatusOK),
114		autorest.ByUnmarshallingJSON(&result),
115		autorest.ByClosing())
116	result.Response = autorest.Response{Response: resp}
117	return
118}
119
120// List returns list of private clouds in particular region
121// Parameters:
122// regionID - the region Id (westus, eastus)
123func (client PrivateCloudsClient) List(ctx context.Context, regionID string) (result PrivateCloudListPage, err error) {
124	if tracing.IsEnabled() {
125		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateCloudsClient.List")
126		defer func() {
127			sc := -1
128			if result.pcl.Response.Response != nil {
129				sc = result.pcl.Response.Response.StatusCode
130			}
131			tracing.EndSpan(ctx, sc, err)
132		}()
133	}
134	result.fn = client.listNextResults
135	req, err := client.ListPreparer(ctx, regionID)
136	if err != nil {
137		err = autorest.NewErrorWithError(err, "vmwarecloudsimple.PrivateCloudsClient", "List", nil, "Failure preparing request")
138		return
139	}
140
141	resp, err := client.ListSender(req)
142	if err != nil {
143		result.pcl.Response = autorest.Response{Response: resp}
144		err = autorest.NewErrorWithError(err, "vmwarecloudsimple.PrivateCloudsClient", "List", resp, "Failure sending request")
145		return
146	}
147
148	result.pcl, err = client.ListResponder(resp)
149	if err != nil {
150		err = autorest.NewErrorWithError(err, "vmwarecloudsimple.PrivateCloudsClient", "List", resp, "Failure responding to request")
151	}
152
153	return
154}
155
156// ListPreparer prepares the List request.
157func (client PrivateCloudsClient) ListPreparer(ctx context.Context, regionID string) (*http.Request, error) {
158	pathParameters := map[string]interface{}{
159		"regionId":       autorest.Encode("path", regionID),
160		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
161	}
162
163	const APIVersion = "2019-04-01"
164	queryParameters := map[string]interface{}{
165		"api-version": APIVersion,
166	}
167
168	preparer := autorest.CreatePreparer(
169		autorest.AsGet(),
170		autorest.WithBaseURL(client.BaseURI),
171		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.VMwareCloudSimple/locations/{regionId}/privateClouds", pathParameters),
172		autorest.WithQueryParameters(queryParameters))
173	return preparer.Prepare((&http.Request{}).WithContext(ctx))
174}
175
176// ListSender sends the List request. The method will close the
177// http.Response Body if it receives an error.
178func (client PrivateCloudsClient) ListSender(req *http.Request) (*http.Response, error) {
179	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
180}
181
182// ListResponder handles the response to the List request. The method always
183// closes the http.Response Body.
184func (client PrivateCloudsClient) ListResponder(resp *http.Response) (result PrivateCloudList, err error) {
185	err = autorest.Respond(
186		resp,
187		client.ByInspecting(),
188		azure.WithErrorUnlessStatusCode(http.StatusOK),
189		autorest.ByUnmarshallingJSON(&result),
190		autorest.ByClosing())
191	result.Response = autorest.Response{Response: resp}
192	return
193}
194
195// listNextResults retrieves the next set of results, if any.
196func (client PrivateCloudsClient) listNextResults(ctx context.Context, lastResults PrivateCloudList) (result PrivateCloudList, err error) {
197	req, err := lastResults.privateCloudListPreparer(ctx)
198	if err != nil {
199		return result, autorest.NewErrorWithError(err, "vmwarecloudsimple.PrivateCloudsClient", "listNextResults", nil, "Failure preparing next results request")
200	}
201	if req == nil {
202		return
203	}
204	resp, err := client.ListSender(req)
205	if err != nil {
206		result.Response = autorest.Response{Response: resp}
207		return result, autorest.NewErrorWithError(err, "vmwarecloudsimple.PrivateCloudsClient", "listNextResults", resp, "Failure sending next results request")
208	}
209	result, err = client.ListResponder(resp)
210	if err != nil {
211		err = autorest.NewErrorWithError(err, "vmwarecloudsimple.PrivateCloudsClient", "listNextResults", resp, "Failure responding to next results request")
212	}
213	return
214}
215
216// ListComplete enumerates all values, automatically crossing page boundaries as required.
217func (client PrivateCloudsClient) ListComplete(ctx context.Context, regionID string) (result PrivateCloudListIterator, err error) {
218	if tracing.IsEnabled() {
219		ctx = tracing.StartSpan(ctx, fqdn+"/PrivateCloudsClient.List")
220		defer func() {
221			sc := -1
222			if result.Response().Response.Response != nil {
223				sc = result.page.Response().Response.Response.StatusCode
224			}
225			tracing.EndSpan(ctx, sc, err)
226		}()
227	}
228	result.page, err = client.List(ctx, regionID)
229	return
230}
231