1// Package serialconsole implements the Azure ARM Serialconsole service API version 2018-05-01.
2//
3// The Azure Serial Console allows you to access the serial console of a Virtual Machine or VM scale set instance
4package serialconsole
5
6// Copyright (c) Microsoft and contributors.  All rights reserved.
7//
8// Licensed under the Apache License, Version 2.0 (the "License");
9// you may not use this file except in compliance with the License.
10// You may obtain a copy of the License at
11// http://www.apache.org/licenses/LICENSE-2.0
12//
13// Unless required by applicable law or agreed to in writing, software
14// distributed under the License is distributed on an "AS IS" BASIS,
15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16//
17// See the License for the specific language governing permissions and
18// limitations under the License.
19//
20// Code generated by Microsoft (R) AutoRest Code Generator.
21// Changes may cause incorrect behavior and will be lost if the code is regenerated.
22
23import (
24	"context"
25	"github.com/Azure/go-autorest/autorest"
26	"github.com/Azure/go-autorest/autorest/azure"
27	"github.com/Azure/go-autorest/tracing"
28	"net/http"
29)
30
31const (
32	// DefaultBaseURI is the default URI used for the service Serialconsole
33	DefaultBaseURI = "https://management.azure.com"
34)
35
36// BaseClient is the base client for Serialconsole.
37type BaseClient struct {
38	autorest.Client
39	BaseURI        string
40	SubscriptionID string
41}
42
43// New creates an instance of the BaseClient client.
44func New(subscriptionID string) BaseClient {
45	return NewWithBaseURI(DefaultBaseURI, subscriptionID)
46}
47
48// NewWithBaseURI creates an instance of the BaseClient client.
49func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient {
50	return BaseClient{
51		Client:         autorest.NewClientWithUserAgent(UserAgent()),
52		BaseURI:        baseURI,
53		SubscriptionID: subscriptionID,
54	}
55}
56
57// DisableConsole disables the Serial Console service for all VMs and VM scale sets in the provided subscription
58// Parameters:
59// defaultParameter - default parameter. Leave the value as "default".
60func (client BaseClient) DisableConsole(ctx context.Context, defaultParameter string) (result SetObject, err error) {
61	if tracing.IsEnabled() {
62		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.DisableConsole")
63		defer func() {
64			sc := -1
65			if result.Response.Response != nil {
66				sc = result.Response.Response.StatusCode
67			}
68			tracing.EndSpan(ctx, sc, err)
69		}()
70	}
71	req, err := client.DisableConsolePreparer(ctx, defaultParameter)
72	if err != nil {
73		err = autorest.NewErrorWithError(err, "serialconsole.BaseClient", "DisableConsole", nil, "Failure preparing request")
74		return
75	}
76
77	resp, err := client.DisableConsoleSender(req)
78	if err != nil {
79		result.Response = autorest.Response{Response: resp}
80		err = autorest.NewErrorWithError(err, "serialconsole.BaseClient", "DisableConsole", resp, "Failure sending request")
81		return
82	}
83
84	result, err = client.DisableConsoleResponder(resp)
85	if err != nil {
86		err = autorest.NewErrorWithError(err, "serialconsole.BaseClient", "DisableConsole", resp, "Failure responding to request")
87	}
88
89	return
90}
91
92// DisableConsolePreparer prepares the DisableConsole request.
93func (client BaseClient) DisableConsolePreparer(ctx context.Context, defaultParameter string) (*http.Request, error) {
94	pathParameters := map[string]interface{}{
95		"default":        autorest.Encode("path", defaultParameter),
96		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
97	}
98
99	const APIVersion = "2018-05-01"
100	queryParameters := map[string]interface{}{
101		"api-version": APIVersion,
102	}
103
104	preparer := autorest.CreatePreparer(
105		autorest.AsPost(),
106		autorest.WithBaseURL(client.BaseURI),
107		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.SerialConsole/consoleServices/{default}/disableConsole", pathParameters),
108		autorest.WithQueryParameters(queryParameters))
109	return preparer.Prepare((&http.Request{}).WithContext(ctx))
110}
111
112// DisableConsoleSender sends the DisableConsole request. The method will close the
113// http.Response Body if it receives an error.
114func (client BaseClient) DisableConsoleSender(req *http.Request) (*http.Response, error) {
115	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
116	return autorest.SendWithSender(client, req, sd...)
117}
118
119// DisableConsoleResponder handles the response to the DisableConsole request. The method always
120// closes the http.Response Body.
121func (client BaseClient) DisableConsoleResponder(resp *http.Response) (result SetObject, err error) {
122	err = autorest.Respond(
123		resp,
124		client.ByInspecting(),
125		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNotFound),
126		autorest.ByUnmarshallingJSON(&result.Value),
127		autorest.ByClosing())
128	result.Response = autorest.Response{Response: resp}
129	return
130}
131
132// EnableConsole enables the Serial Console service for all VMs and VM scale sets in the provided subscription
133// Parameters:
134// defaultParameter - default parameter. Leave the value as "default".
135func (client BaseClient) EnableConsole(ctx context.Context, defaultParameter string) (result SetObject, err error) {
136	if tracing.IsEnabled() {
137		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.EnableConsole")
138		defer func() {
139			sc := -1
140			if result.Response.Response != nil {
141				sc = result.Response.Response.StatusCode
142			}
143			tracing.EndSpan(ctx, sc, err)
144		}()
145	}
146	req, err := client.EnableConsolePreparer(ctx, defaultParameter)
147	if err != nil {
148		err = autorest.NewErrorWithError(err, "serialconsole.BaseClient", "EnableConsole", nil, "Failure preparing request")
149		return
150	}
151
152	resp, err := client.EnableConsoleSender(req)
153	if err != nil {
154		result.Response = autorest.Response{Response: resp}
155		err = autorest.NewErrorWithError(err, "serialconsole.BaseClient", "EnableConsole", resp, "Failure sending request")
156		return
157	}
158
159	result, err = client.EnableConsoleResponder(resp)
160	if err != nil {
161		err = autorest.NewErrorWithError(err, "serialconsole.BaseClient", "EnableConsole", resp, "Failure responding to request")
162	}
163
164	return
165}
166
167// EnableConsolePreparer prepares the EnableConsole request.
168func (client BaseClient) EnableConsolePreparer(ctx context.Context, defaultParameter string) (*http.Request, error) {
169	pathParameters := map[string]interface{}{
170		"default":        autorest.Encode("path", defaultParameter),
171		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
172	}
173
174	const APIVersion = "2018-05-01"
175	queryParameters := map[string]interface{}{
176		"api-version": APIVersion,
177	}
178
179	preparer := autorest.CreatePreparer(
180		autorest.AsPost(),
181		autorest.WithBaseURL(client.BaseURI),
182		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.SerialConsole/consoleServices/{default}/enableConsole", pathParameters),
183		autorest.WithQueryParameters(queryParameters))
184	return preparer.Prepare((&http.Request{}).WithContext(ctx))
185}
186
187// EnableConsoleSender sends the EnableConsole request. The method will close the
188// http.Response Body if it receives an error.
189func (client BaseClient) EnableConsoleSender(req *http.Request) (*http.Response, error) {
190	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
191	return autorest.SendWithSender(client, req, sd...)
192}
193
194// EnableConsoleResponder handles the response to the EnableConsole request. The method always
195// closes the http.Response Body.
196func (client BaseClient) EnableConsoleResponder(resp *http.Response) (result SetObject, err error) {
197	err = autorest.Respond(
198		resp,
199		client.ByInspecting(),
200		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNotFound),
201		autorest.ByUnmarshallingJSON(&result.Value),
202		autorest.ByClosing())
203	result.Response = autorest.Response{Response: resp}
204	return
205}
206
207// GetConsoleStatus gets whether or not Serial Console is disabled for a given subscription
208// Parameters:
209// defaultParameter - default parameter. Leave the value as "default".
210func (client BaseClient) GetConsoleStatus(ctx context.Context, defaultParameter string) (result SetObject, err error) {
211	if tracing.IsEnabled() {
212		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetConsoleStatus")
213		defer func() {
214			sc := -1
215			if result.Response.Response != nil {
216				sc = result.Response.Response.StatusCode
217			}
218			tracing.EndSpan(ctx, sc, err)
219		}()
220	}
221	req, err := client.GetConsoleStatusPreparer(ctx, defaultParameter)
222	if err != nil {
223		err = autorest.NewErrorWithError(err, "serialconsole.BaseClient", "GetConsoleStatus", nil, "Failure preparing request")
224		return
225	}
226
227	resp, err := client.GetConsoleStatusSender(req)
228	if err != nil {
229		result.Response = autorest.Response{Response: resp}
230		err = autorest.NewErrorWithError(err, "serialconsole.BaseClient", "GetConsoleStatus", resp, "Failure sending request")
231		return
232	}
233
234	result, err = client.GetConsoleStatusResponder(resp)
235	if err != nil {
236		err = autorest.NewErrorWithError(err, "serialconsole.BaseClient", "GetConsoleStatus", resp, "Failure responding to request")
237	}
238
239	return
240}
241
242// GetConsoleStatusPreparer prepares the GetConsoleStatus request.
243func (client BaseClient) GetConsoleStatusPreparer(ctx context.Context, defaultParameter string) (*http.Request, error) {
244	pathParameters := map[string]interface{}{
245		"default":        autorest.Encode("path", defaultParameter),
246		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
247	}
248
249	const APIVersion = "2018-05-01"
250	queryParameters := map[string]interface{}{
251		"api-version": APIVersion,
252	}
253
254	preparer := autorest.CreatePreparer(
255		autorest.AsGet(),
256		autorest.WithBaseURL(client.BaseURI),
257		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.SerialConsole/consoleServices/{default}", pathParameters),
258		autorest.WithQueryParameters(queryParameters))
259	return preparer.Prepare((&http.Request{}).WithContext(ctx))
260}
261
262// GetConsoleStatusSender sends the GetConsoleStatus request. The method will close the
263// http.Response Body if it receives an error.
264func (client BaseClient) GetConsoleStatusSender(req *http.Request) (*http.Response, error) {
265	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
266	return autorest.SendWithSender(client, req, sd...)
267}
268
269// GetConsoleStatusResponder handles the response to the GetConsoleStatus request. The method always
270// closes the http.Response Body.
271func (client BaseClient) GetConsoleStatusResponder(resp *http.Response) (result SetObject, err error) {
272	err = autorest.Respond(
273		resp,
274		client.ByInspecting(),
275		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNotFound),
276		autorest.ByUnmarshallingJSON(&result.Value),
277		autorest.ByClosing())
278	result.Response = autorest.Response{Response: resp}
279	return
280}
281
282// ListOperations gets a list of Serial Console API operations.
283func (client BaseClient) ListOperations(ctx context.Context) (result Operations, err error) {
284	if tracing.IsEnabled() {
285		ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.ListOperations")
286		defer func() {
287			sc := -1
288			if result.Response.Response != nil {
289				sc = result.Response.Response.StatusCode
290			}
291			tracing.EndSpan(ctx, sc, err)
292		}()
293	}
294	req, err := client.ListOperationsPreparer(ctx)
295	if err != nil {
296		err = autorest.NewErrorWithError(err, "serialconsole.BaseClient", "ListOperations", nil, "Failure preparing request")
297		return
298	}
299
300	resp, err := client.ListOperationsSender(req)
301	if err != nil {
302		result.Response = autorest.Response{Response: resp}
303		err = autorest.NewErrorWithError(err, "serialconsole.BaseClient", "ListOperations", resp, "Failure sending request")
304		return
305	}
306
307	result, err = client.ListOperationsResponder(resp)
308	if err != nil {
309		err = autorest.NewErrorWithError(err, "serialconsole.BaseClient", "ListOperations", resp, "Failure responding to request")
310	}
311
312	return
313}
314
315// ListOperationsPreparer prepares the ListOperations request.
316func (client BaseClient) ListOperationsPreparer(ctx context.Context) (*http.Request, error) {
317	const APIVersion = "2018-05-01"
318	queryParameters := map[string]interface{}{
319		"api-version": APIVersion,
320	}
321
322	preparer := autorest.CreatePreparer(
323		autorest.AsGet(),
324		autorest.WithBaseURL(client.BaseURI),
325		autorest.WithPath("/providers/Microsoft.SerialConsole/operations"),
326		autorest.WithQueryParameters(queryParameters))
327	return preparer.Prepare((&http.Request{}).WithContext(ctx))
328}
329
330// ListOperationsSender sends the ListOperations request. The method will close the
331// http.Response Body if it receives an error.
332func (client BaseClient) ListOperationsSender(req *http.Request) (*http.Response, error) {
333	sd := autorest.GetSendDecorators(req.Context(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
334	return autorest.SendWithSender(client, req, sd...)
335}
336
337// ListOperationsResponder handles the response to the ListOperations request. The method always
338// closes the http.Response Body.
339func (client BaseClient) ListOperationsResponder(resp *http.Response) (result Operations, err error) {
340	err = autorest.Respond(
341		resp,
342		client.ByInspecting(),
343		azure.WithErrorUnlessStatusCode(http.StatusOK),
344		autorest.ByUnmarshallingJSON(&result),
345		autorest.ByClosing())
346	result.Response = autorest.Response{Response: resp}
347	return
348}
349