...

Source file src/github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2016-05-15/dtl/virtualnetworks.go

Documentation: github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2016-05-15/dtl

     1  package dtl
     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/tracing"
    14  	"net/http"
    15  )
    16  
    17  // VirtualNetworksClient is the the DevTest Labs Client.
    18  type VirtualNetworksClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewVirtualNetworksClient creates an instance of the VirtualNetworksClient client.
    23  func NewVirtualNetworksClient(subscriptionID string) VirtualNetworksClient {
    24  	return NewVirtualNetworksClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewVirtualNetworksClientWithBaseURI creates an instance of the VirtualNetworksClient client using a custom endpoint.
    28  // Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewVirtualNetworksClientWithBaseURI(baseURI string, subscriptionID string) VirtualNetworksClient {
    30  	return VirtualNetworksClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // CreateOrUpdate create or replace an existing virtual network. This operation can take a while to complete.
    34  // Parameters:
    35  // resourceGroupName - the name of the resource group.
    36  // labName - the name of the lab.
    37  // name - the name of the virtual network.
    38  // virtualNetwork - a virtual network.
    39  func (client VirtualNetworksClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, labName string, name string, virtualNetwork VirtualNetwork) (result VirtualNetworksCreateOrUpdateFuture, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworksClient.CreateOrUpdate")
    42  		defer func() {
    43  			sc := -1
    44  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    45  				sc = result.FutureAPI.Response().StatusCode
    46  			}
    47  			tracing.EndSpan(ctx, sc, err)
    48  		}()
    49  	}
    50  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, labName, name, virtualNetwork)
    51  	if err != nil {
    52  		err = autorest.NewErrorWithError(err, "dtl.VirtualNetworksClient", "CreateOrUpdate", nil, "Failure preparing request")
    53  		return
    54  	}
    55  
    56  	result, err = client.CreateOrUpdateSender(req)
    57  	if err != nil {
    58  		err = autorest.NewErrorWithError(err, "dtl.VirtualNetworksClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    59  		return
    60  	}
    61  
    62  	return
    63  }
    64  
    65  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    66  func (client VirtualNetworksClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, labName string, name string, virtualNetwork VirtualNetwork) (*http.Request, error) {
    67  	pathParameters := map[string]interface{}{
    68  		"labName":           autorest.Encode("path", labName),
    69  		"name":              autorest.Encode("path", name),
    70  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    71  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    72  	}
    73  
    74  	const APIVersion = "2016-05-15"
    75  	queryParameters := map[string]interface{}{
    76  		"api-version": APIVersion,
    77  	}
    78  
    79  	preparer := autorest.CreatePreparer(
    80  		autorest.AsContentType("application/json; charset=utf-8"),
    81  		autorest.AsPut(),
    82  		autorest.WithBaseURL(client.BaseURI),
    83  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks/{name}", pathParameters),
    84  		autorest.WithJSON(virtualNetwork),
    85  		autorest.WithQueryParameters(queryParameters))
    86  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    87  }
    88  
    89  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
    90  // http.Response Body if it receives an error.
    91  func (client VirtualNetworksClient) CreateOrUpdateSender(req *http.Request) (future VirtualNetworksCreateOrUpdateFuture, err error) {
    92  	var resp *http.Response
    93  	future.FutureAPI = &azure.Future{}
    94  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
    95  	if err != nil {
    96  		return
    97  	}
    98  	var azf azure.Future
    99  	azf, err = azure.NewFutureFromResponse(resp)
   100  	future.FutureAPI = &azf
   101  	future.Result = future.result
   102  	return
   103  }
   104  
   105  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   106  // closes the http.Response Body.
   107  func (client VirtualNetworksClient) CreateOrUpdateResponder(resp *http.Response) (result VirtualNetwork, err error) {
   108  	err = autorest.Respond(
   109  		resp,
   110  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   111  		autorest.ByUnmarshallingJSON(&result),
   112  		autorest.ByClosing())
   113  	result.Response = autorest.Response{Response: resp}
   114  	return
   115  }
   116  
   117  // Delete delete virtual network. This operation can take a while to complete.
   118  // Parameters:
   119  // resourceGroupName - the name of the resource group.
   120  // labName - the name of the lab.
   121  // name - the name of the virtual network.
   122  func (client VirtualNetworksClient) Delete(ctx context.Context, resourceGroupName string, labName string, name string) (result VirtualNetworksDeleteFuture, err error) {
   123  	if tracing.IsEnabled() {
   124  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworksClient.Delete")
   125  		defer func() {
   126  			sc := -1
   127  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   128  				sc = result.FutureAPI.Response().StatusCode
   129  			}
   130  			tracing.EndSpan(ctx, sc, err)
   131  		}()
   132  	}
   133  	req, err := client.DeletePreparer(ctx, resourceGroupName, labName, name)
   134  	if err != nil {
   135  		err = autorest.NewErrorWithError(err, "dtl.VirtualNetworksClient", "Delete", nil, "Failure preparing request")
   136  		return
   137  	}
   138  
   139  	result, err = client.DeleteSender(req)
   140  	if err != nil {
   141  		err = autorest.NewErrorWithError(err, "dtl.VirtualNetworksClient", "Delete", result.Response(), "Failure sending request")
   142  		return
   143  	}
   144  
   145  	return
   146  }
   147  
   148  // DeletePreparer prepares the Delete request.
   149  func (client VirtualNetworksClient) DeletePreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
   150  	pathParameters := map[string]interface{}{
   151  		"labName":           autorest.Encode("path", labName),
   152  		"name":              autorest.Encode("path", name),
   153  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   154  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   155  	}
   156  
   157  	const APIVersion = "2016-05-15"
   158  	queryParameters := map[string]interface{}{
   159  		"api-version": APIVersion,
   160  	}
   161  
   162  	preparer := autorest.CreatePreparer(
   163  		autorest.AsDelete(),
   164  		autorest.WithBaseURL(client.BaseURI),
   165  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks/{name}", pathParameters),
   166  		autorest.WithQueryParameters(queryParameters))
   167  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   168  }
   169  
   170  // DeleteSender sends the Delete request. The method will close the
   171  // http.Response Body if it receives an error.
   172  func (client VirtualNetworksClient) DeleteSender(req *http.Request) (future VirtualNetworksDeleteFuture, err error) {
   173  	var resp *http.Response
   174  	future.FutureAPI = &azure.Future{}
   175  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   176  	if err != nil {
   177  		return
   178  	}
   179  	var azf azure.Future
   180  	azf, err = azure.NewFutureFromResponse(resp)
   181  	future.FutureAPI = &azf
   182  	future.Result = future.result
   183  	return
   184  }
   185  
   186  // DeleteResponder handles the response to the Delete request. The method always
   187  // closes the http.Response Body.
   188  func (client VirtualNetworksClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   189  	err = autorest.Respond(
   190  		resp,
   191  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   192  		autorest.ByClosing())
   193  	result.Response = resp
   194  	return
   195  }
   196  
   197  // Get get virtual network.
   198  // Parameters:
   199  // resourceGroupName - the name of the resource group.
   200  // labName - the name of the lab.
   201  // name - the name of the virtual network.
   202  // expand - specify the $expand query. Example: 'properties($expand=externalSubnets)'
   203  func (client VirtualNetworksClient) Get(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (result VirtualNetwork, err error) {
   204  	if tracing.IsEnabled() {
   205  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworksClient.Get")
   206  		defer func() {
   207  			sc := -1
   208  			if result.Response.Response != nil {
   209  				sc = result.Response.Response.StatusCode
   210  			}
   211  			tracing.EndSpan(ctx, sc, err)
   212  		}()
   213  	}
   214  	req, err := client.GetPreparer(ctx, resourceGroupName, labName, name, expand)
   215  	if err != nil {
   216  		err = autorest.NewErrorWithError(err, "dtl.VirtualNetworksClient", "Get", nil, "Failure preparing request")
   217  		return
   218  	}
   219  
   220  	resp, err := client.GetSender(req)
   221  	if err != nil {
   222  		result.Response = autorest.Response{Response: resp}
   223  		err = autorest.NewErrorWithError(err, "dtl.VirtualNetworksClient", "Get", resp, "Failure sending request")
   224  		return
   225  	}
   226  
   227  	result, err = client.GetResponder(resp)
   228  	if err != nil {
   229  		err = autorest.NewErrorWithError(err, "dtl.VirtualNetworksClient", "Get", resp, "Failure responding to request")
   230  		return
   231  	}
   232  
   233  	return
   234  }
   235  
   236  // GetPreparer prepares the Get request.
   237  func (client VirtualNetworksClient) GetPreparer(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (*http.Request, error) {
   238  	pathParameters := map[string]interface{}{
   239  		"labName":           autorest.Encode("path", labName),
   240  		"name":              autorest.Encode("path", name),
   241  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   242  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   243  	}
   244  
   245  	const APIVersion = "2016-05-15"
   246  	queryParameters := map[string]interface{}{
   247  		"api-version": APIVersion,
   248  	}
   249  	if len(expand) > 0 {
   250  		queryParameters["$expand"] = autorest.Encode("query", expand)
   251  	}
   252  
   253  	preparer := autorest.CreatePreparer(
   254  		autorest.AsGet(),
   255  		autorest.WithBaseURL(client.BaseURI),
   256  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks/{name}", pathParameters),
   257  		autorest.WithQueryParameters(queryParameters))
   258  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   259  }
   260  
   261  // GetSender sends the Get request. The method will close the
   262  // http.Response Body if it receives an error.
   263  func (client VirtualNetworksClient) GetSender(req *http.Request) (*http.Response, error) {
   264  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   265  }
   266  
   267  // GetResponder handles the response to the Get request. The method always
   268  // closes the http.Response Body.
   269  func (client VirtualNetworksClient) GetResponder(resp *http.Response) (result VirtualNetwork, err error) {
   270  	err = autorest.Respond(
   271  		resp,
   272  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   273  		autorest.ByUnmarshallingJSON(&result),
   274  		autorest.ByClosing())
   275  	result.Response = autorest.Response{Response: resp}
   276  	return
   277  }
   278  
   279  // List list virtual networks in a given lab.
   280  // Parameters:
   281  // resourceGroupName - the name of the resource group.
   282  // labName - the name of the lab.
   283  // expand - specify the $expand query. Example: 'properties($expand=externalSubnets)'
   284  // filter - the filter to apply to the operation.
   285  // top - the maximum number of resources to return from the operation.
   286  // orderby - the ordering expression for the results, using OData notation.
   287  func (client VirtualNetworksClient) List(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationVirtualNetworkPage, err error) {
   288  	if tracing.IsEnabled() {
   289  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworksClient.List")
   290  		defer func() {
   291  			sc := -1
   292  			if result.rwcvn.Response.Response != nil {
   293  				sc = result.rwcvn.Response.Response.StatusCode
   294  			}
   295  			tracing.EndSpan(ctx, sc, err)
   296  		}()
   297  	}
   298  	result.fn = client.listNextResults
   299  	req, err := client.ListPreparer(ctx, resourceGroupName, labName, expand, filter, top, orderby)
   300  	if err != nil {
   301  		err = autorest.NewErrorWithError(err, "dtl.VirtualNetworksClient", "List", nil, "Failure preparing request")
   302  		return
   303  	}
   304  
   305  	resp, err := client.ListSender(req)
   306  	if err != nil {
   307  		result.rwcvn.Response = autorest.Response{Response: resp}
   308  		err = autorest.NewErrorWithError(err, "dtl.VirtualNetworksClient", "List", resp, "Failure sending request")
   309  		return
   310  	}
   311  
   312  	result.rwcvn, err = client.ListResponder(resp)
   313  	if err != nil {
   314  		err = autorest.NewErrorWithError(err, "dtl.VirtualNetworksClient", "List", resp, "Failure responding to request")
   315  		return
   316  	}
   317  	if result.rwcvn.hasNextLink() && result.rwcvn.IsEmpty() {
   318  		err = result.NextWithContext(ctx)
   319  		return
   320  	}
   321  
   322  	return
   323  }
   324  
   325  // ListPreparer prepares the List request.
   326  func (client VirtualNetworksClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (*http.Request, error) {
   327  	pathParameters := map[string]interface{}{
   328  		"labName":           autorest.Encode("path", labName),
   329  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   330  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   331  	}
   332  
   333  	const APIVersion = "2016-05-15"
   334  	queryParameters := map[string]interface{}{
   335  		"api-version": APIVersion,
   336  	}
   337  	if len(expand) > 0 {
   338  		queryParameters["$expand"] = autorest.Encode("query", expand)
   339  	}
   340  	if len(filter) > 0 {
   341  		queryParameters["$filter"] = autorest.Encode("query", filter)
   342  	}
   343  	if top != nil {
   344  		queryParameters["$top"] = autorest.Encode("query", *top)
   345  	}
   346  	if len(orderby) > 0 {
   347  		queryParameters["$orderby"] = autorest.Encode("query", orderby)
   348  	}
   349  
   350  	preparer := autorest.CreatePreparer(
   351  		autorest.AsGet(),
   352  		autorest.WithBaseURL(client.BaseURI),
   353  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks", pathParameters),
   354  		autorest.WithQueryParameters(queryParameters))
   355  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   356  }
   357  
   358  // ListSender sends the List request. The method will close the
   359  // http.Response Body if it receives an error.
   360  func (client VirtualNetworksClient) ListSender(req *http.Request) (*http.Response, error) {
   361  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   362  }
   363  
   364  // ListResponder handles the response to the List request. The method always
   365  // closes the http.Response Body.
   366  func (client VirtualNetworksClient) ListResponder(resp *http.Response) (result ResponseWithContinuationVirtualNetwork, err error) {
   367  	err = autorest.Respond(
   368  		resp,
   369  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   370  		autorest.ByUnmarshallingJSON(&result),
   371  		autorest.ByClosing())
   372  	result.Response = autorest.Response{Response: resp}
   373  	return
   374  }
   375  
   376  // listNextResults retrieves the next set of results, if any.
   377  func (client VirtualNetworksClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationVirtualNetwork) (result ResponseWithContinuationVirtualNetwork, err error) {
   378  	req, err := lastResults.responseWithContinuationVirtualNetworkPreparer(ctx)
   379  	if err != nil {
   380  		return result, autorest.NewErrorWithError(err, "dtl.VirtualNetworksClient", "listNextResults", nil, "Failure preparing next results request")
   381  	}
   382  	if req == nil {
   383  		return
   384  	}
   385  	resp, err := client.ListSender(req)
   386  	if err != nil {
   387  		result.Response = autorest.Response{Response: resp}
   388  		return result, autorest.NewErrorWithError(err, "dtl.VirtualNetworksClient", "listNextResults", resp, "Failure sending next results request")
   389  	}
   390  	result, err = client.ListResponder(resp)
   391  	if err != nil {
   392  		err = autorest.NewErrorWithError(err, "dtl.VirtualNetworksClient", "listNextResults", resp, "Failure responding to next results request")
   393  	}
   394  	return
   395  }
   396  
   397  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   398  func (client VirtualNetworksClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationVirtualNetworkIterator, err error) {
   399  	if tracing.IsEnabled() {
   400  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworksClient.List")
   401  		defer func() {
   402  			sc := -1
   403  			if result.Response().Response.Response != nil {
   404  				sc = result.page.Response().Response.Response.StatusCode
   405  			}
   406  			tracing.EndSpan(ctx, sc, err)
   407  		}()
   408  	}
   409  	result.page, err = client.List(ctx, resourceGroupName, labName, expand, filter, top, orderby)
   410  	return
   411  }
   412  
   413  // Update modify properties of virtual networks.
   414  // Parameters:
   415  // resourceGroupName - the name of the resource group.
   416  // labName - the name of the lab.
   417  // name - the name of the virtual network.
   418  // virtualNetwork - a virtual network.
   419  func (client VirtualNetworksClient) Update(ctx context.Context, resourceGroupName string, labName string, name string, virtualNetwork VirtualNetworkFragment) (result VirtualNetwork, err error) {
   420  	if tracing.IsEnabled() {
   421  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualNetworksClient.Update")
   422  		defer func() {
   423  			sc := -1
   424  			if result.Response.Response != nil {
   425  				sc = result.Response.Response.StatusCode
   426  			}
   427  			tracing.EndSpan(ctx, sc, err)
   428  		}()
   429  	}
   430  	req, err := client.UpdatePreparer(ctx, resourceGroupName, labName, name, virtualNetwork)
   431  	if err != nil {
   432  		err = autorest.NewErrorWithError(err, "dtl.VirtualNetworksClient", "Update", nil, "Failure preparing request")
   433  		return
   434  	}
   435  
   436  	resp, err := client.UpdateSender(req)
   437  	if err != nil {
   438  		result.Response = autorest.Response{Response: resp}
   439  		err = autorest.NewErrorWithError(err, "dtl.VirtualNetworksClient", "Update", resp, "Failure sending request")
   440  		return
   441  	}
   442  
   443  	result, err = client.UpdateResponder(resp)
   444  	if err != nil {
   445  		err = autorest.NewErrorWithError(err, "dtl.VirtualNetworksClient", "Update", resp, "Failure responding to request")
   446  		return
   447  	}
   448  
   449  	return
   450  }
   451  
   452  // UpdatePreparer prepares the Update request.
   453  func (client VirtualNetworksClient) UpdatePreparer(ctx context.Context, resourceGroupName string, labName string, name string, virtualNetwork VirtualNetworkFragment) (*http.Request, error) {
   454  	pathParameters := map[string]interface{}{
   455  		"labName":           autorest.Encode("path", labName),
   456  		"name":              autorest.Encode("path", name),
   457  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   458  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   459  	}
   460  
   461  	const APIVersion = "2016-05-15"
   462  	queryParameters := map[string]interface{}{
   463  		"api-version": APIVersion,
   464  	}
   465  
   466  	preparer := autorest.CreatePreparer(
   467  		autorest.AsContentType("application/json; charset=utf-8"),
   468  		autorest.AsPatch(),
   469  		autorest.WithBaseURL(client.BaseURI),
   470  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks/{name}", pathParameters),
   471  		autorest.WithJSON(virtualNetwork),
   472  		autorest.WithQueryParameters(queryParameters))
   473  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   474  }
   475  
   476  // UpdateSender sends the Update request. The method will close the
   477  // http.Response Body if it receives an error.
   478  func (client VirtualNetworksClient) UpdateSender(req *http.Request) (*http.Response, error) {
   479  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   480  }
   481  
   482  // UpdateResponder handles the response to the Update request. The method always
   483  // closes the http.Response Body.
   484  func (client VirtualNetworksClient) UpdateResponder(resp *http.Response) (result VirtualNetwork, err error) {
   485  	err = autorest.Respond(
   486  		resp,
   487  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   488  		autorest.ByUnmarshallingJSON(&result),
   489  		autorest.ByClosing())
   490  	result.Response = autorest.Response{Response: resp}
   491  	return
   492  }
   493  

View as plain text