1package network
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// ConnectionMonitorsClient is the network Client
19type ConnectionMonitorsClient struct {
20	BaseClient
21}
22
23// NewConnectionMonitorsClient creates an instance of the ConnectionMonitorsClient client.
24func NewConnectionMonitorsClient(subscriptionID string) ConnectionMonitorsClient {
25	return NewConnectionMonitorsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewConnectionMonitorsClientWithBaseURI creates an instance of the ConnectionMonitorsClient 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 NewConnectionMonitorsClientWithBaseURI(baseURI string, subscriptionID string) ConnectionMonitorsClient {
32	return ConnectionMonitorsClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// CreateOrUpdate create or update a connection monitor.
36// Parameters:
37// resourceGroupName - the name of the resource group containing Network Watcher.
38// networkWatcherName - the name of the Network Watcher resource.
39// connectionMonitorName - the name of the connection monitor.
40// parameters - parameters that define the operation to create a connection monitor.
41// migrate - value indicating whether connection monitor V1 should be migrated to V2 format.
42func (client ConnectionMonitorsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, parameters ConnectionMonitor, migrate string) (result ConnectionMonitorsCreateOrUpdateFuture, err error) {
43	if tracing.IsEnabled() {
44		ctx = tracing.StartSpan(ctx, fqdn+"/ConnectionMonitorsClient.CreateOrUpdate")
45		defer func() {
46			sc := -1
47			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
48				sc = result.FutureAPI.Response().StatusCode
49			}
50			tracing.EndSpan(ctx, sc, err)
51		}()
52	}
53	if err := validation.Validate([]validation.Validation{
54		{TargetValue: parameters,
55			Constraints: []validation.Constraint{{Target: "parameters.ConnectionMonitorParameters", Name: validation.Null, Rule: true,
56				Chain: []validation.Constraint{{Target: "parameters.ConnectionMonitorParameters.Source", Name: validation.Null, Rule: false,
57					Chain: []validation.Constraint{{Target: "parameters.ConnectionMonitorParameters.Source.ResourceID", Name: validation.Null, Rule: true, Chain: nil},
58						{Target: "parameters.ConnectionMonitorParameters.Source.Port", Name: validation.Null, Rule: false,
59							Chain: []validation.Constraint{{Target: "parameters.ConnectionMonitorParameters.Source.Port", Name: validation.InclusiveMaximum, Rule: int64(65535), Chain: nil},
60								{Target: "parameters.ConnectionMonitorParameters.Source.Port", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil},
61							}},
62					}},
63					{Target: "parameters.ConnectionMonitorParameters.Destination", Name: validation.Null, Rule: false,
64						Chain: []validation.Constraint{{Target: "parameters.ConnectionMonitorParameters.Destination.Port", Name: validation.Null, Rule: false,
65							Chain: []validation.Constraint{{Target: "parameters.ConnectionMonitorParameters.Destination.Port", Name: validation.InclusiveMaximum, Rule: int64(65535), Chain: nil},
66								{Target: "parameters.ConnectionMonitorParameters.Destination.Port", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil},
67							}},
68						}},
69					{Target: "parameters.ConnectionMonitorParameters.MonitoringIntervalInSeconds", Name: validation.Null, Rule: false,
70						Chain: []validation.Constraint{{Target: "parameters.ConnectionMonitorParameters.MonitoringIntervalInSeconds", Name: validation.InclusiveMaximum, Rule: int64(1800), Chain: nil},
71							{Target: "parameters.ConnectionMonitorParameters.MonitoringIntervalInSeconds", Name: validation.InclusiveMinimum, Rule: int64(30), Chain: nil},
72						}},
73				}}}}}); err != nil {
74		return result, validation.NewError("network.ConnectionMonitorsClient", "CreateOrUpdate", err.Error())
75	}
76
77	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, networkWatcherName, connectionMonitorName, parameters, migrate)
78	if err != nil {
79		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "CreateOrUpdate", nil, "Failure preparing request")
80		return
81	}
82
83	result, err = client.CreateOrUpdateSender(req)
84	if err != nil {
85		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "CreateOrUpdate", nil, "Failure sending request")
86		return
87	}
88
89	return
90}
91
92// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
93func (client ConnectionMonitorsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, parameters ConnectionMonitor, migrate string) (*http.Request, error) {
94	pathParameters := map[string]interface{}{
95		"connectionMonitorName": autorest.Encode("path", connectionMonitorName),
96		"networkWatcherName":    autorest.Encode("path", networkWatcherName),
97		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
98		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
99	}
100
101	const APIVersion = "2020-07-01"
102	queryParameters := map[string]interface{}{
103		"api-version": APIVersion,
104	}
105	if len(migrate) > 0 {
106		queryParameters["migrate"] = autorest.Encode("query", migrate)
107	}
108
109	preparer := autorest.CreatePreparer(
110		autorest.AsContentType("application/json; charset=utf-8"),
111		autorest.AsPut(),
112		autorest.WithBaseURL(client.BaseURI),
113		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectionMonitors/{connectionMonitorName}", pathParameters),
114		autorest.WithJSON(parameters),
115		autorest.WithQueryParameters(queryParameters))
116	return preparer.Prepare((&http.Request{}).WithContext(ctx))
117}
118
119// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
120// http.Response Body if it receives an error.
121func (client ConnectionMonitorsClient) CreateOrUpdateSender(req *http.Request) (future ConnectionMonitorsCreateOrUpdateFuture, err error) {
122	var resp *http.Response
123	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
124	if err != nil {
125		return
126	}
127	var azf azure.Future
128	azf, err = azure.NewFutureFromResponse(resp)
129	future.FutureAPI = &azf
130	future.Result = future.result
131	return
132}
133
134// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
135// closes the http.Response Body.
136func (client ConnectionMonitorsClient) CreateOrUpdateResponder(resp *http.Response) (result ConnectionMonitorResult, err error) {
137	err = autorest.Respond(
138		resp,
139		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
140		autorest.ByUnmarshallingJSON(&result),
141		autorest.ByClosing())
142	result.Response = autorest.Response{Response: resp}
143	return
144}
145
146// Delete deletes the specified connection monitor.
147// Parameters:
148// resourceGroupName - the name of the resource group containing Network Watcher.
149// networkWatcherName - the name of the Network Watcher resource.
150// connectionMonitorName - the name of the connection monitor.
151func (client ConnectionMonitorsClient) Delete(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string) (result ConnectionMonitorsDeleteFuture, err error) {
152	if tracing.IsEnabled() {
153		ctx = tracing.StartSpan(ctx, fqdn+"/ConnectionMonitorsClient.Delete")
154		defer func() {
155			sc := -1
156			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
157				sc = result.FutureAPI.Response().StatusCode
158			}
159			tracing.EndSpan(ctx, sc, err)
160		}()
161	}
162	req, err := client.DeletePreparer(ctx, resourceGroupName, networkWatcherName, connectionMonitorName)
163	if err != nil {
164		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "Delete", nil, "Failure preparing request")
165		return
166	}
167
168	result, err = client.DeleteSender(req)
169	if err != nil {
170		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "Delete", nil, "Failure sending request")
171		return
172	}
173
174	return
175}
176
177// DeletePreparer prepares the Delete request.
178func (client ConnectionMonitorsClient) DeletePreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string) (*http.Request, error) {
179	pathParameters := map[string]interface{}{
180		"connectionMonitorName": autorest.Encode("path", connectionMonitorName),
181		"networkWatcherName":    autorest.Encode("path", networkWatcherName),
182		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
183		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
184	}
185
186	const APIVersion = "2020-07-01"
187	queryParameters := map[string]interface{}{
188		"api-version": APIVersion,
189	}
190
191	preparer := autorest.CreatePreparer(
192		autorest.AsDelete(),
193		autorest.WithBaseURL(client.BaseURI),
194		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectionMonitors/{connectionMonitorName}", pathParameters),
195		autorest.WithQueryParameters(queryParameters))
196	return preparer.Prepare((&http.Request{}).WithContext(ctx))
197}
198
199// DeleteSender sends the Delete request. The method will close the
200// http.Response Body if it receives an error.
201func (client ConnectionMonitorsClient) DeleteSender(req *http.Request) (future ConnectionMonitorsDeleteFuture, err error) {
202	var resp *http.Response
203	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
204	if err != nil {
205		return
206	}
207	var azf azure.Future
208	azf, err = azure.NewFutureFromResponse(resp)
209	future.FutureAPI = &azf
210	future.Result = future.result
211	return
212}
213
214// DeleteResponder handles the response to the Delete request. The method always
215// closes the http.Response Body.
216func (client ConnectionMonitorsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
217	err = autorest.Respond(
218		resp,
219		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
220		autorest.ByClosing())
221	result.Response = resp
222	return
223}
224
225// Get gets a connection monitor by name.
226// Parameters:
227// resourceGroupName - the name of the resource group containing Network Watcher.
228// networkWatcherName - the name of the Network Watcher resource.
229// connectionMonitorName - the name of the connection monitor.
230func (client ConnectionMonitorsClient) Get(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string) (result ConnectionMonitorResult, err error) {
231	if tracing.IsEnabled() {
232		ctx = tracing.StartSpan(ctx, fqdn+"/ConnectionMonitorsClient.Get")
233		defer func() {
234			sc := -1
235			if result.Response.Response != nil {
236				sc = result.Response.Response.StatusCode
237			}
238			tracing.EndSpan(ctx, sc, err)
239		}()
240	}
241	req, err := client.GetPreparer(ctx, resourceGroupName, networkWatcherName, connectionMonitorName)
242	if err != nil {
243		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "Get", nil, "Failure preparing request")
244		return
245	}
246
247	resp, err := client.GetSender(req)
248	if err != nil {
249		result.Response = autorest.Response{Response: resp}
250		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "Get", resp, "Failure sending request")
251		return
252	}
253
254	result, err = client.GetResponder(resp)
255	if err != nil {
256		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "Get", resp, "Failure responding to request")
257		return
258	}
259
260	return
261}
262
263// GetPreparer prepares the Get request.
264func (client ConnectionMonitorsClient) GetPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string) (*http.Request, error) {
265	pathParameters := map[string]interface{}{
266		"connectionMonitorName": autorest.Encode("path", connectionMonitorName),
267		"networkWatcherName":    autorest.Encode("path", networkWatcherName),
268		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
269		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
270	}
271
272	const APIVersion = "2020-07-01"
273	queryParameters := map[string]interface{}{
274		"api-version": APIVersion,
275	}
276
277	preparer := autorest.CreatePreparer(
278		autorest.AsGet(),
279		autorest.WithBaseURL(client.BaseURI),
280		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectionMonitors/{connectionMonitorName}", pathParameters),
281		autorest.WithQueryParameters(queryParameters))
282	return preparer.Prepare((&http.Request{}).WithContext(ctx))
283}
284
285// GetSender sends the Get request. The method will close the
286// http.Response Body if it receives an error.
287func (client ConnectionMonitorsClient) GetSender(req *http.Request) (*http.Response, error) {
288	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
289}
290
291// GetResponder handles the response to the Get request. The method always
292// closes the http.Response Body.
293func (client ConnectionMonitorsClient) GetResponder(resp *http.Response) (result ConnectionMonitorResult, err error) {
294	err = autorest.Respond(
295		resp,
296		azure.WithErrorUnlessStatusCode(http.StatusOK),
297		autorest.ByUnmarshallingJSON(&result),
298		autorest.ByClosing())
299	result.Response = autorest.Response{Response: resp}
300	return
301}
302
303// List lists all connection monitors for the specified Network Watcher.
304// Parameters:
305// resourceGroupName - the name of the resource group containing Network Watcher.
306// networkWatcherName - the name of the Network Watcher resource.
307func (client ConnectionMonitorsClient) List(ctx context.Context, resourceGroupName string, networkWatcherName string) (result ConnectionMonitorListResult, err error) {
308	if tracing.IsEnabled() {
309		ctx = tracing.StartSpan(ctx, fqdn+"/ConnectionMonitorsClient.List")
310		defer func() {
311			sc := -1
312			if result.Response.Response != nil {
313				sc = result.Response.Response.StatusCode
314			}
315			tracing.EndSpan(ctx, sc, err)
316		}()
317	}
318	req, err := client.ListPreparer(ctx, resourceGroupName, networkWatcherName)
319	if err != nil {
320		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "List", nil, "Failure preparing request")
321		return
322	}
323
324	resp, err := client.ListSender(req)
325	if err != nil {
326		result.Response = autorest.Response{Response: resp}
327		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "List", resp, "Failure sending request")
328		return
329	}
330
331	result, err = client.ListResponder(resp)
332	if err != nil {
333		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "List", resp, "Failure responding to request")
334		return
335	}
336
337	return
338}
339
340// ListPreparer prepares the List request.
341func (client ConnectionMonitorsClient) ListPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string) (*http.Request, error) {
342	pathParameters := map[string]interface{}{
343		"networkWatcherName": autorest.Encode("path", networkWatcherName),
344		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
345		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
346	}
347
348	const APIVersion = "2020-07-01"
349	queryParameters := map[string]interface{}{
350		"api-version": APIVersion,
351	}
352
353	preparer := autorest.CreatePreparer(
354		autorest.AsGet(),
355		autorest.WithBaseURL(client.BaseURI),
356		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectionMonitors", pathParameters),
357		autorest.WithQueryParameters(queryParameters))
358	return preparer.Prepare((&http.Request{}).WithContext(ctx))
359}
360
361// ListSender sends the List request. The method will close the
362// http.Response Body if it receives an error.
363func (client ConnectionMonitorsClient) ListSender(req *http.Request) (*http.Response, error) {
364	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
365}
366
367// ListResponder handles the response to the List request. The method always
368// closes the http.Response Body.
369func (client ConnectionMonitorsClient) ListResponder(resp *http.Response) (result ConnectionMonitorListResult, err error) {
370	err = autorest.Respond(
371		resp,
372		azure.WithErrorUnlessStatusCode(http.StatusOK),
373		autorest.ByUnmarshallingJSON(&result),
374		autorest.ByClosing())
375	result.Response = autorest.Response{Response: resp}
376	return
377}
378
379// Query query a snapshot of the most recent connection states.
380// Parameters:
381// resourceGroupName - the name of the resource group containing Network Watcher.
382// networkWatcherName - the name of the Network Watcher resource.
383// connectionMonitorName - the name given to the connection monitor.
384func (client ConnectionMonitorsClient) Query(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string) (result ConnectionMonitorsQueryFuture, err error) {
385	if tracing.IsEnabled() {
386		ctx = tracing.StartSpan(ctx, fqdn+"/ConnectionMonitorsClient.Query")
387		defer func() {
388			sc := -1
389			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
390				sc = result.FutureAPI.Response().StatusCode
391			}
392			tracing.EndSpan(ctx, sc, err)
393		}()
394	}
395	req, err := client.QueryPreparer(ctx, resourceGroupName, networkWatcherName, connectionMonitorName)
396	if err != nil {
397		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "Query", nil, "Failure preparing request")
398		return
399	}
400
401	result, err = client.QuerySender(req)
402	if err != nil {
403		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "Query", nil, "Failure sending request")
404		return
405	}
406
407	return
408}
409
410// QueryPreparer prepares the Query request.
411func (client ConnectionMonitorsClient) QueryPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string) (*http.Request, error) {
412	pathParameters := map[string]interface{}{
413		"connectionMonitorName": autorest.Encode("path", connectionMonitorName),
414		"networkWatcherName":    autorest.Encode("path", networkWatcherName),
415		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
416		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
417	}
418
419	const APIVersion = "2020-07-01"
420	queryParameters := map[string]interface{}{
421		"api-version": APIVersion,
422	}
423
424	preparer := autorest.CreatePreparer(
425		autorest.AsPost(),
426		autorest.WithBaseURL(client.BaseURI),
427		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectionMonitors/{connectionMonitorName}/query", pathParameters),
428		autorest.WithQueryParameters(queryParameters))
429	return preparer.Prepare((&http.Request{}).WithContext(ctx))
430}
431
432// QuerySender sends the Query request. The method will close the
433// http.Response Body if it receives an error.
434func (client ConnectionMonitorsClient) QuerySender(req *http.Request) (future ConnectionMonitorsQueryFuture, err error) {
435	var resp *http.Response
436	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
437	if err != nil {
438		return
439	}
440	var azf azure.Future
441	azf, err = azure.NewFutureFromResponse(resp)
442	future.FutureAPI = &azf
443	future.Result = future.result
444	return
445}
446
447// QueryResponder handles the response to the Query request. The method always
448// closes the http.Response Body.
449func (client ConnectionMonitorsClient) QueryResponder(resp *http.Response) (result ConnectionMonitorQueryResult, err error) {
450	err = autorest.Respond(
451		resp,
452		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
453		autorest.ByUnmarshallingJSON(&result),
454		autorest.ByClosing())
455	result.Response = autorest.Response{Response: resp}
456	return
457}
458
459// Start starts the specified connection monitor.
460// Parameters:
461// resourceGroupName - the name of the resource group containing Network Watcher.
462// networkWatcherName - the name of the Network Watcher resource.
463// connectionMonitorName - the name of the connection monitor.
464func (client ConnectionMonitorsClient) Start(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string) (result ConnectionMonitorsStartFuture, err error) {
465	if tracing.IsEnabled() {
466		ctx = tracing.StartSpan(ctx, fqdn+"/ConnectionMonitorsClient.Start")
467		defer func() {
468			sc := -1
469			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
470				sc = result.FutureAPI.Response().StatusCode
471			}
472			tracing.EndSpan(ctx, sc, err)
473		}()
474	}
475	req, err := client.StartPreparer(ctx, resourceGroupName, networkWatcherName, connectionMonitorName)
476	if err != nil {
477		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "Start", nil, "Failure preparing request")
478		return
479	}
480
481	result, err = client.StartSender(req)
482	if err != nil {
483		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "Start", nil, "Failure sending request")
484		return
485	}
486
487	return
488}
489
490// StartPreparer prepares the Start request.
491func (client ConnectionMonitorsClient) StartPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string) (*http.Request, error) {
492	pathParameters := map[string]interface{}{
493		"connectionMonitorName": autorest.Encode("path", connectionMonitorName),
494		"networkWatcherName":    autorest.Encode("path", networkWatcherName),
495		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
496		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
497	}
498
499	const APIVersion = "2020-07-01"
500	queryParameters := map[string]interface{}{
501		"api-version": APIVersion,
502	}
503
504	preparer := autorest.CreatePreparer(
505		autorest.AsPost(),
506		autorest.WithBaseURL(client.BaseURI),
507		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectionMonitors/{connectionMonitorName}/start", pathParameters),
508		autorest.WithQueryParameters(queryParameters))
509	return preparer.Prepare((&http.Request{}).WithContext(ctx))
510}
511
512// StartSender sends the Start request. The method will close the
513// http.Response Body if it receives an error.
514func (client ConnectionMonitorsClient) StartSender(req *http.Request) (future ConnectionMonitorsStartFuture, err error) {
515	var resp *http.Response
516	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
517	if err != nil {
518		return
519	}
520	var azf azure.Future
521	azf, err = azure.NewFutureFromResponse(resp)
522	future.FutureAPI = &azf
523	future.Result = future.result
524	return
525}
526
527// StartResponder handles the response to the Start request. The method always
528// closes the http.Response Body.
529func (client ConnectionMonitorsClient) StartResponder(resp *http.Response) (result autorest.Response, err error) {
530	err = autorest.Respond(
531		resp,
532		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
533		autorest.ByClosing())
534	result.Response = resp
535	return
536}
537
538// Stop stops the specified connection monitor.
539// Parameters:
540// resourceGroupName - the name of the resource group containing Network Watcher.
541// networkWatcherName - the name of the Network Watcher resource.
542// connectionMonitorName - the name of the connection monitor.
543func (client ConnectionMonitorsClient) Stop(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string) (result ConnectionMonitorsStopFuture, err error) {
544	if tracing.IsEnabled() {
545		ctx = tracing.StartSpan(ctx, fqdn+"/ConnectionMonitorsClient.Stop")
546		defer func() {
547			sc := -1
548			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
549				sc = result.FutureAPI.Response().StatusCode
550			}
551			tracing.EndSpan(ctx, sc, err)
552		}()
553	}
554	req, err := client.StopPreparer(ctx, resourceGroupName, networkWatcherName, connectionMonitorName)
555	if err != nil {
556		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "Stop", nil, "Failure preparing request")
557		return
558	}
559
560	result, err = client.StopSender(req)
561	if err != nil {
562		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "Stop", nil, "Failure sending request")
563		return
564	}
565
566	return
567}
568
569// StopPreparer prepares the Stop request.
570func (client ConnectionMonitorsClient) StopPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string) (*http.Request, error) {
571	pathParameters := map[string]interface{}{
572		"connectionMonitorName": autorest.Encode("path", connectionMonitorName),
573		"networkWatcherName":    autorest.Encode("path", networkWatcherName),
574		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
575		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
576	}
577
578	const APIVersion = "2020-07-01"
579	queryParameters := map[string]interface{}{
580		"api-version": APIVersion,
581	}
582
583	preparer := autorest.CreatePreparer(
584		autorest.AsPost(),
585		autorest.WithBaseURL(client.BaseURI),
586		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectionMonitors/{connectionMonitorName}/stop", pathParameters),
587		autorest.WithQueryParameters(queryParameters))
588	return preparer.Prepare((&http.Request{}).WithContext(ctx))
589}
590
591// StopSender sends the Stop request. The method will close the
592// http.Response Body if it receives an error.
593func (client ConnectionMonitorsClient) StopSender(req *http.Request) (future ConnectionMonitorsStopFuture, err error) {
594	var resp *http.Response
595	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
596	if err != nil {
597		return
598	}
599	var azf azure.Future
600	azf, err = azure.NewFutureFromResponse(resp)
601	future.FutureAPI = &azf
602	future.Result = future.result
603	return
604}
605
606// StopResponder handles the response to the Stop request. The method always
607// closes the http.Response Body.
608func (client ConnectionMonitorsClient) StopResponder(resp *http.Response) (result autorest.Response, err error) {
609	err = autorest.Respond(
610		resp,
611		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
612		autorest.ByClosing())
613	result.Response = resp
614	return
615}
616
617// UpdateTags update tags of the specified connection monitor.
618// Parameters:
619// resourceGroupName - the name of the resource group.
620// networkWatcherName - the name of the network watcher.
621// connectionMonitorName - the name of the connection monitor.
622// parameters - parameters supplied to update connection monitor tags.
623func (client ConnectionMonitorsClient) UpdateTags(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, parameters TagsObject) (result ConnectionMonitorResult, err error) {
624	if tracing.IsEnabled() {
625		ctx = tracing.StartSpan(ctx, fqdn+"/ConnectionMonitorsClient.UpdateTags")
626		defer func() {
627			sc := -1
628			if result.Response.Response != nil {
629				sc = result.Response.Response.StatusCode
630			}
631			tracing.EndSpan(ctx, sc, err)
632		}()
633	}
634	req, err := client.UpdateTagsPreparer(ctx, resourceGroupName, networkWatcherName, connectionMonitorName, parameters)
635	if err != nil {
636		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "UpdateTags", nil, "Failure preparing request")
637		return
638	}
639
640	resp, err := client.UpdateTagsSender(req)
641	if err != nil {
642		result.Response = autorest.Response{Response: resp}
643		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "UpdateTags", resp, "Failure sending request")
644		return
645	}
646
647	result, err = client.UpdateTagsResponder(resp)
648	if err != nil {
649		err = autorest.NewErrorWithError(err, "network.ConnectionMonitorsClient", "UpdateTags", resp, "Failure responding to request")
650		return
651	}
652
653	return
654}
655
656// UpdateTagsPreparer prepares the UpdateTags request.
657func (client ConnectionMonitorsClient) UpdateTagsPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, connectionMonitorName string, parameters TagsObject) (*http.Request, error) {
658	pathParameters := map[string]interface{}{
659		"connectionMonitorName": autorest.Encode("path", connectionMonitorName),
660		"networkWatcherName":    autorest.Encode("path", networkWatcherName),
661		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
662		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
663	}
664
665	const APIVersion = "2020-07-01"
666	queryParameters := map[string]interface{}{
667		"api-version": APIVersion,
668	}
669
670	preparer := autorest.CreatePreparer(
671		autorest.AsContentType("application/json; charset=utf-8"),
672		autorest.AsPatch(),
673		autorest.WithBaseURL(client.BaseURI),
674		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectionMonitors/{connectionMonitorName}", pathParameters),
675		autorest.WithJSON(parameters),
676		autorest.WithQueryParameters(queryParameters))
677	return preparer.Prepare((&http.Request{}).WithContext(ctx))
678}
679
680// UpdateTagsSender sends the UpdateTags request. The method will close the
681// http.Response Body if it receives an error.
682func (client ConnectionMonitorsClient) UpdateTagsSender(req *http.Request) (*http.Response, error) {
683	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
684}
685
686// UpdateTagsResponder handles the response to the UpdateTags request. The method always
687// closes the http.Response Body.
688func (client ConnectionMonitorsClient) UpdateTagsResponder(resp *http.Response) (result ConnectionMonitorResult, err error) {
689	err = autorest.Respond(
690		resp,
691		azure.WithErrorUnlessStatusCode(http.StatusOK),
692		autorest.ByUnmarshallingJSON(&result),
693		autorest.ByClosing())
694	result.Response = autorest.Response{Response: resp}
695	return
696}
697