...

Source file src/github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-08-01/network/connectionmonitors.go

Documentation: github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-08-01/network

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

View as plain text