github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/virtualnetworks_client.go (about)

     1  //go:build go1.18
     2  // +build go1.18
     3  
     4  // Copyright (c) Microsoft Corporation. All rights reserved.
     5  // Licensed under the MIT License. See License.txt in the project root for license information.
     6  // Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT.
     7  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
     8  
     9  package armnetwork
    10  
    11  import (
    12  	"context"
    13  	"errors"
    14  	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
    15  	"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
    16  	"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
    17  	"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
    18  	"net/http"
    19  	"net/url"
    20  	"strconv"
    21  	"strings"
    22  )
    23  
    24  // VirtualNetworksClient contains the methods for the VirtualNetworks group.
    25  // Don't use this type directly, use NewVirtualNetworksClient() instead.
    26  type VirtualNetworksClient struct {
    27  	internal       *arm.Client
    28  	subscriptionID string
    29  }
    30  
    31  // NewVirtualNetworksClient creates a new instance of VirtualNetworksClient with the specified values.
    32  //   - subscriptionID - The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription
    33  //     ID forms part of the URI for every service call.
    34  //   - credential - used to authorize requests. Usually a credential from azidentity.
    35  //   - options - pass nil to accept the default values.
    36  func NewVirtualNetworksClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*VirtualNetworksClient, error) {
    37  	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  	client := &VirtualNetworksClient{
    42  		subscriptionID: subscriptionID,
    43  		internal:       cl,
    44  	}
    45  	return client, nil
    46  }
    47  
    48  // CheckIPAddressAvailability - Checks whether a private IP address is available for use.
    49  // If the operation fails it returns an *azcore.ResponseError type.
    50  //
    51  // Generated from API version 2024-05-01
    52  //   - resourceGroupName - The name of the resource group.
    53  //   - virtualNetworkName - The name of the virtual network.
    54  //   - ipAddress - The private IP address to be verified.
    55  //   - options - VirtualNetworksClientCheckIPAddressAvailabilityOptions contains the optional parameters for the VirtualNetworksClient.CheckIPAddressAvailability
    56  //     method.
    57  func (client *VirtualNetworksClient) CheckIPAddressAvailability(ctx context.Context, resourceGroupName string, virtualNetworkName string, ipAddress string, options *VirtualNetworksClientCheckIPAddressAvailabilityOptions) (VirtualNetworksClientCheckIPAddressAvailabilityResponse, error) {
    58  	var err error
    59  	const operationName = "VirtualNetworksClient.CheckIPAddressAvailability"
    60  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
    61  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
    62  	defer func() { endSpan(err) }()
    63  	req, err := client.checkIPAddressAvailabilityCreateRequest(ctx, resourceGroupName, virtualNetworkName, ipAddress, options)
    64  	if err != nil {
    65  		return VirtualNetworksClientCheckIPAddressAvailabilityResponse{}, err
    66  	}
    67  	httpResp, err := client.internal.Pipeline().Do(req)
    68  	if err != nil {
    69  		return VirtualNetworksClientCheckIPAddressAvailabilityResponse{}, err
    70  	}
    71  	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
    72  		err = runtime.NewResponseError(httpResp)
    73  		return VirtualNetworksClientCheckIPAddressAvailabilityResponse{}, err
    74  	}
    75  	resp, err := client.checkIPAddressAvailabilityHandleResponse(httpResp)
    76  	return resp, err
    77  }
    78  
    79  // checkIPAddressAvailabilityCreateRequest creates the CheckIPAddressAvailability request.
    80  func (client *VirtualNetworksClient) checkIPAddressAvailabilityCreateRequest(ctx context.Context, resourceGroupName string, virtualNetworkName string, ipAddress string, options *VirtualNetworksClientCheckIPAddressAvailabilityOptions) (*policy.Request, error) {
    81  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/CheckIPAddressAvailability"
    82  	if resourceGroupName == "" {
    83  		return nil, errors.New("parameter resourceGroupName cannot be empty")
    84  	}
    85  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
    86  	if virtualNetworkName == "" {
    87  		return nil, errors.New("parameter virtualNetworkName cannot be empty")
    88  	}
    89  	urlPath = strings.ReplaceAll(urlPath, "{virtualNetworkName}", url.PathEscape(virtualNetworkName))
    90  	if client.subscriptionID == "" {
    91  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
    92  	}
    93  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
    94  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
    95  	if err != nil {
    96  		return nil, err
    97  	}
    98  	reqQP := req.Raw().URL.Query()
    99  	reqQP.Set("api-version", "2024-05-01")
   100  	reqQP.Set("ipAddress", ipAddress)
   101  	req.Raw().URL.RawQuery = reqQP.Encode()
   102  	req.Raw().Header["Accept"] = []string{"application/json"}
   103  	return req, nil
   104  }
   105  
   106  // checkIPAddressAvailabilityHandleResponse handles the CheckIPAddressAvailability response.
   107  func (client *VirtualNetworksClient) checkIPAddressAvailabilityHandleResponse(resp *http.Response) (VirtualNetworksClientCheckIPAddressAvailabilityResponse, error) {
   108  	result := VirtualNetworksClientCheckIPAddressAvailabilityResponse{}
   109  	if err := runtime.UnmarshalAsJSON(resp, &result.IPAddressAvailabilityResult); err != nil {
   110  		return VirtualNetworksClientCheckIPAddressAvailabilityResponse{}, err
   111  	}
   112  	return result, nil
   113  }
   114  
   115  // BeginCreateOrUpdate - Creates or updates a virtual network in the specified resource group.
   116  // If the operation fails it returns an *azcore.ResponseError type.
   117  //
   118  // Generated from API version 2024-05-01
   119  //   - resourceGroupName - The name of the resource group.
   120  //   - virtualNetworkName - The name of the virtual network.
   121  //   - parameters - Parameters supplied to the create or update virtual network operation.
   122  //   - options - VirtualNetworksClientBeginCreateOrUpdateOptions contains the optional parameters for the VirtualNetworksClient.BeginCreateOrUpdate
   123  //     method.
   124  func (client *VirtualNetworksClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, virtualNetworkName string, parameters VirtualNetwork, options *VirtualNetworksClientBeginCreateOrUpdateOptions) (*runtime.Poller[VirtualNetworksClientCreateOrUpdateResponse], error) {
   125  	if options == nil || options.ResumeToken == "" {
   126  		resp, err := client.createOrUpdate(ctx, resourceGroupName, virtualNetworkName, parameters, options)
   127  		if err != nil {
   128  			return nil, err
   129  		}
   130  		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworksClientCreateOrUpdateResponse]{
   131  			FinalStateVia: runtime.FinalStateViaAzureAsyncOp,
   132  			Tracer:        client.internal.Tracer(),
   133  		})
   134  		return poller, err
   135  	} else {
   136  		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[VirtualNetworksClientCreateOrUpdateResponse]{
   137  			Tracer: client.internal.Tracer(),
   138  		})
   139  	}
   140  }
   141  
   142  // CreateOrUpdate - Creates or updates a virtual network in the specified resource group.
   143  // If the operation fails it returns an *azcore.ResponseError type.
   144  //
   145  // Generated from API version 2024-05-01
   146  func (client *VirtualNetworksClient) createOrUpdate(ctx context.Context, resourceGroupName string, virtualNetworkName string, parameters VirtualNetwork, options *VirtualNetworksClientBeginCreateOrUpdateOptions) (*http.Response, error) {
   147  	var err error
   148  	const operationName = "VirtualNetworksClient.BeginCreateOrUpdate"
   149  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
   150  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
   151  	defer func() { endSpan(err) }()
   152  	req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, virtualNetworkName, parameters, options)
   153  	if err != nil {
   154  		return nil, err
   155  	}
   156  	httpResp, err := client.internal.Pipeline().Do(req)
   157  	if err != nil {
   158  		return nil, err
   159  	}
   160  	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) {
   161  		err = runtime.NewResponseError(httpResp)
   162  		return nil, err
   163  	}
   164  	return httpResp, nil
   165  }
   166  
   167  // createOrUpdateCreateRequest creates the CreateOrUpdate request.
   168  func (client *VirtualNetworksClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, virtualNetworkName string, parameters VirtualNetwork, options *VirtualNetworksClientBeginCreateOrUpdateOptions) (*policy.Request, error) {
   169  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}"
   170  	if resourceGroupName == "" {
   171  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   172  	}
   173  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   174  	if virtualNetworkName == "" {
   175  		return nil, errors.New("parameter virtualNetworkName cannot be empty")
   176  	}
   177  	urlPath = strings.ReplaceAll(urlPath, "{virtualNetworkName}", url.PathEscape(virtualNetworkName))
   178  	if client.subscriptionID == "" {
   179  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   180  	}
   181  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   182  	req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   183  	if err != nil {
   184  		return nil, err
   185  	}
   186  	reqQP := req.Raw().URL.Query()
   187  	reqQP.Set("api-version", "2024-05-01")
   188  	req.Raw().URL.RawQuery = reqQP.Encode()
   189  	req.Raw().Header["Accept"] = []string{"application/json"}
   190  	if err := runtime.MarshalAsJSON(req, parameters); err != nil {
   191  		return nil, err
   192  	}
   193  	return req, nil
   194  }
   195  
   196  // BeginDelete - Deletes the specified virtual network.
   197  // If the operation fails it returns an *azcore.ResponseError type.
   198  //
   199  // Generated from API version 2024-05-01
   200  //   - resourceGroupName - The name of the resource group.
   201  //   - virtualNetworkName - The name of the virtual network.
   202  //   - options - VirtualNetworksClientBeginDeleteOptions contains the optional parameters for the VirtualNetworksClient.BeginDelete
   203  //     method.
   204  func (client *VirtualNetworksClient) BeginDelete(ctx context.Context, resourceGroupName string, virtualNetworkName string, options *VirtualNetworksClientBeginDeleteOptions) (*runtime.Poller[VirtualNetworksClientDeleteResponse], error) {
   205  	if options == nil || options.ResumeToken == "" {
   206  		resp, err := client.deleteOperation(ctx, resourceGroupName, virtualNetworkName, options)
   207  		if err != nil {
   208  			return nil, err
   209  		}
   210  		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VirtualNetworksClientDeleteResponse]{
   211  			FinalStateVia: runtime.FinalStateViaLocation,
   212  			Tracer:        client.internal.Tracer(),
   213  		})
   214  		return poller, err
   215  	} else {
   216  		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[VirtualNetworksClientDeleteResponse]{
   217  			Tracer: client.internal.Tracer(),
   218  		})
   219  	}
   220  }
   221  
   222  // Delete - Deletes the specified virtual network.
   223  // If the operation fails it returns an *azcore.ResponseError type.
   224  //
   225  // Generated from API version 2024-05-01
   226  func (client *VirtualNetworksClient) deleteOperation(ctx context.Context, resourceGroupName string, virtualNetworkName string, options *VirtualNetworksClientBeginDeleteOptions) (*http.Response, error) {
   227  	var err error
   228  	const operationName = "VirtualNetworksClient.BeginDelete"
   229  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
   230  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
   231  	defer func() { endSpan(err) }()
   232  	req, err := client.deleteCreateRequest(ctx, resourceGroupName, virtualNetworkName, options)
   233  	if err != nil {
   234  		return nil, err
   235  	}
   236  	httpResp, err := client.internal.Pipeline().Do(req)
   237  	if err != nil {
   238  		return nil, err
   239  	}
   240  	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) {
   241  		err = runtime.NewResponseError(httpResp)
   242  		return nil, err
   243  	}
   244  	return httpResp, nil
   245  }
   246  
   247  // deleteCreateRequest creates the Delete request.
   248  func (client *VirtualNetworksClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, virtualNetworkName string, options *VirtualNetworksClientBeginDeleteOptions) (*policy.Request, error) {
   249  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}"
   250  	if resourceGroupName == "" {
   251  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   252  	}
   253  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   254  	if virtualNetworkName == "" {
   255  		return nil, errors.New("parameter virtualNetworkName cannot be empty")
   256  	}
   257  	urlPath = strings.ReplaceAll(urlPath, "{virtualNetworkName}", url.PathEscape(virtualNetworkName))
   258  	if client.subscriptionID == "" {
   259  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   260  	}
   261  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   262  	req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   263  	if err != nil {
   264  		return nil, err
   265  	}
   266  	reqQP := req.Raw().URL.Query()
   267  	reqQP.Set("api-version", "2024-05-01")
   268  	req.Raw().URL.RawQuery = reqQP.Encode()
   269  	req.Raw().Header["Accept"] = []string{"application/json"}
   270  	return req, nil
   271  }
   272  
   273  // Get - Gets the specified virtual network by resource group.
   274  // If the operation fails it returns an *azcore.ResponseError type.
   275  //
   276  // Generated from API version 2024-05-01
   277  //   - resourceGroupName - The name of the resource group.
   278  //   - virtualNetworkName - The name of the virtual network.
   279  //   - options - VirtualNetworksClientGetOptions contains the optional parameters for the VirtualNetworksClient.Get method.
   280  func (client *VirtualNetworksClient) Get(ctx context.Context, resourceGroupName string, virtualNetworkName string, options *VirtualNetworksClientGetOptions) (VirtualNetworksClientGetResponse, error) {
   281  	var err error
   282  	const operationName = "VirtualNetworksClient.Get"
   283  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
   284  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
   285  	defer func() { endSpan(err) }()
   286  	req, err := client.getCreateRequest(ctx, resourceGroupName, virtualNetworkName, options)
   287  	if err != nil {
   288  		return VirtualNetworksClientGetResponse{}, err
   289  	}
   290  	httpResp, err := client.internal.Pipeline().Do(req)
   291  	if err != nil {
   292  		return VirtualNetworksClientGetResponse{}, err
   293  	}
   294  	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
   295  		err = runtime.NewResponseError(httpResp)
   296  		return VirtualNetworksClientGetResponse{}, err
   297  	}
   298  	resp, err := client.getHandleResponse(httpResp)
   299  	return resp, err
   300  }
   301  
   302  // getCreateRequest creates the Get request.
   303  func (client *VirtualNetworksClient) getCreateRequest(ctx context.Context, resourceGroupName string, virtualNetworkName string, options *VirtualNetworksClientGetOptions) (*policy.Request, error) {
   304  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}"
   305  	if resourceGroupName == "" {
   306  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   307  	}
   308  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   309  	if virtualNetworkName == "" {
   310  		return nil, errors.New("parameter virtualNetworkName cannot be empty")
   311  	}
   312  	urlPath = strings.ReplaceAll(urlPath, "{virtualNetworkName}", url.PathEscape(virtualNetworkName))
   313  	if client.subscriptionID == "" {
   314  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   315  	}
   316  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   317  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   318  	if err != nil {
   319  		return nil, err
   320  	}
   321  	reqQP := req.Raw().URL.Query()
   322  	if options != nil && options.Expand != nil {
   323  		reqQP.Set("$expand", *options.Expand)
   324  	}
   325  	reqQP.Set("api-version", "2024-05-01")
   326  	req.Raw().URL.RawQuery = reqQP.Encode()
   327  	req.Raw().Header["Accept"] = []string{"application/json"}
   328  	return req, nil
   329  }
   330  
   331  // getHandleResponse handles the Get response.
   332  func (client *VirtualNetworksClient) getHandleResponse(resp *http.Response) (VirtualNetworksClientGetResponse, error) {
   333  	result := VirtualNetworksClientGetResponse{}
   334  	if err := runtime.UnmarshalAsJSON(resp, &result.VirtualNetwork); err != nil {
   335  		return VirtualNetworksClientGetResponse{}, err
   336  	}
   337  	return result, nil
   338  }
   339  
   340  // NewListPager - Gets all virtual networks in a resource group.
   341  //
   342  // Generated from API version 2024-05-01
   343  //   - resourceGroupName - The name of the resource group.
   344  //   - options - VirtualNetworksClientListOptions contains the optional parameters for the VirtualNetworksClient.NewListPager
   345  //     method.
   346  func (client *VirtualNetworksClient) NewListPager(resourceGroupName string, options *VirtualNetworksClientListOptions) *runtime.Pager[VirtualNetworksClientListResponse] {
   347  	return runtime.NewPager(runtime.PagingHandler[VirtualNetworksClientListResponse]{
   348  		More: func(page VirtualNetworksClientListResponse) bool {
   349  			return page.NextLink != nil && len(*page.NextLink) > 0
   350  		},
   351  		Fetcher: func(ctx context.Context, page *VirtualNetworksClientListResponse) (VirtualNetworksClientListResponse, error) {
   352  			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualNetworksClient.NewListPager")
   353  			nextLink := ""
   354  			if page != nil {
   355  				nextLink = *page.NextLink
   356  			}
   357  			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
   358  				return client.listCreateRequest(ctx, resourceGroupName, options)
   359  			}, nil)
   360  			if err != nil {
   361  				return VirtualNetworksClientListResponse{}, err
   362  			}
   363  			return client.listHandleResponse(resp)
   364  		},
   365  		Tracer: client.internal.Tracer(),
   366  	})
   367  }
   368  
   369  // listCreateRequest creates the List request.
   370  func (client *VirtualNetworksClient) listCreateRequest(ctx context.Context, resourceGroupName string, options *VirtualNetworksClientListOptions) (*policy.Request, error) {
   371  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks"
   372  	if resourceGroupName == "" {
   373  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   374  	}
   375  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   376  	if client.subscriptionID == "" {
   377  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   378  	}
   379  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   380  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   381  	if err != nil {
   382  		return nil, err
   383  	}
   384  	reqQP := req.Raw().URL.Query()
   385  	reqQP.Set("api-version", "2024-05-01")
   386  	req.Raw().URL.RawQuery = reqQP.Encode()
   387  	req.Raw().Header["Accept"] = []string{"application/json"}
   388  	return req, nil
   389  }
   390  
   391  // listHandleResponse handles the List response.
   392  func (client *VirtualNetworksClient) listHandleResponse(resp *http.Response) (VirtualNetworksClientListResponse, error) {
   393  	result := VirtualNetworksClientListResponse{}
   394  	if err := runtime.UnmarshalAsJSON(resp, &result.VirtualNetworkListResult); err != nil {
   395  		return VirtualNetworksClientListResponse{}, err
   396  	}
   397  	return result, nil
   398  }
   399  
   400  // NewListAllPager - Gets all virtual networks in a subscription.
   401  //
   402  // Generated from API version 2024-05-01
   403  //   - options - VirtualNetworksClientListAllOptions contains the optional parameters for the VirtualNetworksClient.NewListAllPager
   404  //     method.
   405  func (client *VirtualNetworksClient) NewListAllPager(options *VirtualNetworksClientListAllOptions) *runtime.Pager[VirtualNetworksClientListAllResponse] {
   406  	return runtime.NewPager(runtime.PagingHandler[VirtualNetworksClientListAllResponse]{
   407  		More: func(page VirtualNetworksClientListAllResponse) bool {
   408  			return page.NextLink != nil && len(*page.NextLink) > 0
   409  		},
   410  		Fetcher: func(ctx context.Context, page *VirtualNetworksClientListAllResponse) (VirtualNetworksClientListAllResponse, error) {
   411  			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualNetworksClient.NewListAllPager")
   412  			nextLink := ""
   413  			if page != nil {
   414  				nextLink = *page.NextLink
   415  			}
   416  			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
   417  				return client.listAllCreateRequest(ctx, options)
   418  			}, nil)
   419  			if err != nil {
   420  				return VirtualNetworksClientListAllResponse{}, err
   421  			}
   422  			return client.listAllHandleResponse(resp)
   423  		},
   424  		Tracer: client.internal.Tracer(),
   425  	})
   426  }
   427  
   428  // listAllCreateRequest creates the ListAll request.
   429  func (client *VirtualNetworksClient) listAllCreateRequest(ctx context.Context, options *VirtualNetworksClientListAllOptions) (*policy.Request, error) {
   430  	urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/virtualNetworks"
   431  	if client.subscriptionID == "" {
   432  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   433  	}
   434  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   435  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   436  	if err != nil {
   437  		return nil, err
   438  	}
   439  	reqQP := req.Raw().URL.Query()
   440  	reqQP.Set("api-version", "2024-05-01")
   441  	req.Raw().URL.RawQuery = reqQP.Encode()
   442  	req.Raw().Header["Accept"] = []string{"application/json"}
   443  	return req, nil
   444  }
   445  
   446  // listAllHandleResponse handles the ListAll response.
   447  func (client *VirtualNetworksClient) listAllHandleResponse(resp *http.Response) (VirtualNetworksClientListAllResponse, error) {
   448  	result := VirtualNetworksClientListAllResponse{}
   449  	if err := runtime.UnmarshalAsJSON(resp, &result.VirtualNetworkListResult); err != nil {
   450  		return VirtualNetworksClientListAllResponse{}, err
   451  	}
   452  	return result, nil
   453  }
   454  
   455  // BeginListDdosProtectionStatus - Gets the Ddos Protection Status of all IP Addresses under the Virtual Network
   456  //
   457  // Generated from API version 2024-05-01
   458  //   - resourceGroupName - The name of the resource group.
   459  //   - virtualNetworkName - The name of the virtual network.
   460  //   - options - VirtualNetworksClientBeginListDdosProtectionStatusOptions contains the optional parameters for the VirtualNetworksClient.BeginListDdosProtectionStatus
   461  //     method.
   462  func (client *VirtualNetworksClient) BeginListDdosProtectionStatus(ctx context.Context, resourceGroupName string, virtualNetworkName string, options *VirtualNetworksClientBeginListDdosProtectionStatusOptions) (*runtime.Poller[*runtime.Pager[VirtualNetworksClientListDdosProtectionStatusResponse]], error) {
   463  	pager := runtime.NewPager(runtime.PagingHandler[VirtualNetworksClientListDdosProtectionStatusResponse]{
   464  		More: func(page VirtualNetworksClientListDdosProtectionStatusResponse) bool {
   465  			return page.NextLink != nil && len(*page.NextLink) > 0
   466  		},
   467  		Fetcher: func(ctx context.Context, page *VirtualNetworksClientListDdosProtectionStatusResponse) (VirtualNetworksClientListDdosProtectionStatusResponse, error) {
   468  			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualNetworksClient.BeginListDdosProtectionStatus")
   469  			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), *page.NextLink, func(ctx context.Context) (*policy.Request, error) {
   470  				return client.listDdosProtectionStatusCreateRequest(ctx, resourceGroupName, virtualNetworkName, options)
   471  			}, nil)
   472  			if err != nil {
   473  				return VirtualNetworksClientListDdosProtectionStatusResponse{}, err
   474  			}
   475  			return client.listDdosProtectionStatusHandleResponse(resp)
   476  		},
   477  		Tracer: client.internal.Tracer(),
   478  	})
   479  	if options == nil || options.ResumeToken == "" {
   480  		resp, err := client.listDdosProtectionStatus(ctx, resourceGroupName, virtualNetworkName, options)
   481  		if err != nil {
   482  			return nil, err
   483  		}
   484  		poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[*runtime.Pager[VirtualNetworksClientListDdosProtectionStatusResponse]]{
   485  			FinalStateVia: runtime.FinalStateViaLocation,
   486  			Response:      &pager,
   487  			Tracer:        client.internal.Tracer(),
   488  		})
   489  		return poller, err
   490  	} else {
   491  		return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[*runtime.Pager[VirtualNetworksClientListDdosProtectionStatusResponse]]{
   492  			Response: &pager,
   493  			Tracer:   client.internal.Tracer(),
   494  		})
   495  	}
   496  }
   497  
   498  // ListDdosProtectionStatus - Gets the Ddos Protection Status of all IP Addresses under the Virtual Network
   499  //
   500  // Generated from API version 2024-05-01
   501  func (client *VirtualNetworksClient) listDdosProtectionStatus(ctx context.Context, resourceGroupName string, virtualNetworkName string, options *VirtualNetworksClientBeginListDdosProtectionStatusOptions) (*http.Response, error) {
   502  	var err error
   503  	const operationName = "VirtualNetworksClient.BeginListDdosProtectionStatus"
   504  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
   505  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
   506  	defer func() { endSpan(err) }()
   507  	req, err := client.listDdosProtectionStatusCreateRequest(ctx, resourceGroupName, virtualNetworkName, options)
   508  	if err != nil {
   509  		return nil, err
   510  	}
   511  	httpResp, err := client.internal.Pipeline().Do(req)
   512  	if err != nil {
   513  		return nil, err
   514  	}
   515  	if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) {
   516  		err = runtime.NewResponseError(httpResp)
   517  		return nil, err
   518  	}
   519  	return httpResp, nil
   520  }
   521  
   522  // listDdosProtectionStatusCreateRequest creates the ListDdosProtectionStatus request.
   523  func (client *VirtualNetworksClient) listDdosProtectionStatusCreateRequest(ctx context.Context, resourceGroupName string, virtualNetworkName string, options *VirtualNetworksClientBeginListDdosProtectionStatusOptions) (*policy.Request, error) {
   524  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/ddosProtectionStatus"
   525  	if resourceGroupName == "" {
   526  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   527  	}
   528  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   529  	if virtualNetworkName == "" {
   530  		return nil, errors.New("parameter virtualNetworkName cannot be empty")
   531  	}
   532  	urlPath = strings.ReplaceAll(urlPath, "{virtualNetworkName}", url.PathEscape(virtualNetworkName))
   533  	if client.subscriptionID == "" {
   534  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   535  	}
   536  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   537  	req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   538  	if err != nil {
   539  		return nil, err
   540  	}
   541  	reqQP := req.Raw().URL.Query()
   542  	reqQP.Set("api-version", "2024-05-01")
   543  	if options != nil && options.SkipToken != nil {
   544  		reqQP.Set("skipToken", *options.SkipToken)
   545  	}
   546  	if options != nil && options.Top != nil {
   547  		reqQP.Set("top", strconv.FormatInt(int64(*options.Top), 10))
   548  	}
   549  	req.Raw().URL.RawQuery = reqQP.Encode()
   550  	req.Raw().Header["Accept"] = []string{"application/json"}
   551  	return req, nil
   552  }
   553  
   554  // listDdosProtectionStatusHandleResponse handles the ListDdosProtectionStatus response.
   555  func (client *VirtualNetworksClient) listDdosProtectionStatusHandleResponse(resp *http.Response) (VirtualNetworksClientListDdosProtectionStatusResponse, error) {
   556  	result := VirtualNetworksClientListDdosProtectionStatusResponse{}
   557  	if err := runtime.UnmarshalAsJSON(resp, &result.VirtualNetworkDdosProtectionStatusResult); err != nil {
   558  		return VirtualNetworksClientListDdosProtectionStatusResponse{}, err
   559  	}
   560  	return result, nil
   561  }
   562  
   563  // NewListUsagePager - Lists usage stats.
   564  //
   565  // Generated from API version 2024-05-01
   566  //   - resourceGroupName - The name of the resource group.
   567  //   - virtualNetworkName - The name of the virtual network.
   568  //   - options - VirtualNetworksClientListUsageOptions contains the optional parameters for the VirtualNetworksClient.NewListUsagePager
   569  //     method.
   570  func (client *VirtualNetworksClient) NewListUsagePager(resourceGroupName string, virtualNetworkName string, options *VirtualNetworksClientListUsageOptions) *runtime.Pager[VirtualNetworksClientListUsageResponse] {
   571  	return runtime.NewPager(runtime.PagingHandler[VirtualNetworksClientListUsageResponse]{
   572  		More: func(page VirtualNetworksClientListUsageResponse) bool {
   573  			return page.NextLink != nil && len(*page.NextLink) > 0
   574  		},
   575  		Fetcher: func(ctx context.Context, page *VirtualNetworksClientListUsageResponse) (VirtualNetworksClientListUsageResponse, error) {
   576  			ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VirtualNetworksClient.NewListUsagePager")
   577  			nextLink := ""
   578  			if page != nil {
   579  				nextLink = *page.NextLink
   580  			}
   581  			resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
   582  				return client.listUsageCreateRequest(ctx, resourceGroupName, virtualNetworkName, options)
   583  			}, nil)
   584  			if err != nil {
   585  				return VirtualNetworksClientListUsageResponse{}, err
   586  			}
   587  			return client.listUsageHandleResponse(resp)
   588  		},
   589  		Tracer: client.internal.Tracer(),
   590  	})
   591  }
   592  
   593  // listUsageCreateRequest creates the ListUsage request.
   594  func (client *VirtualNetworksClient) listUsageCreateRequest(ctx context.Context, resourceGroupName string, virtualNetworkName string, options *VirtualNetworksClientListUsageOptions) (*policy.Request, error) {
   595  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/usages"
   596  	if resourceGroupName == "" {
   597  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   598  	}
   599  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   600  	if virtualNetworkName == "" {
   601  		return nil, errors.New("parameter virtualNetworkName cannot be empty")
   602  	}
   603  	urlPath = strings.ReplaceAll(urlPath, "{virtualNetworkName}", url.PathEscape(virtualNetworkName))
   604  	if client.subscriptionID == "" {
   605  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   606  	}
   607  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   608  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   609  	if err != nil {
   610  		return nil, err
   611  	}
   612  	reqQP := req.Raw().URL.Query()
   613  	reqQP.Set("api-version", "2024-05-01")
   614  	req.Raw().URL.RawQuery = reqQP.Encode()
   615  	req.Raw().Header["Accept"] = []string{"application/json"}
   616  	return req, nil
   617  }
   618  
   619  // listUsageHandleResponse handles the ListUsage response.
   620  func (client *VirtualNetworksClient) listUsageHandleResponse(resp *http.Response) (VirtualNetworksClientListUsageResponse, error) {
   621  	result := VirtualNetworksClientListUsageResponse{}
   622  	if err := runtime.UnmarshalAsJSON(resp, &result.VirtualNetworkListUsageResult); err != nil {
   623  		return VirtualNetworksClientListUsageResponse{}, err
   624  	}
   625  	return result, nil
   626  }
   627  
   628  // UpdateTags - Updates a virtual network tags.
   629  // If the operation fails it returns an *azcore.ResponseError type.
   630  //
   631  // Generated from API version 2024-05-01
   632  //   - resourceGroupName - The name of the resource group.
   633  //   - virtualNetworkName - The name of the virtual network.
   634  //   - parameters - Parameters supplied to update virtual network tags.
   635  //   - options - VirtualNetworksClientUpdateTagsOptions contains the optional parameters for the VirtualNetworksClient.UpdateTags
   636  //     method.
   637  func (client *VirtualNetworksClient) UpdateTags(ctx context.Context, resourceGroupName string, virtualNetworkName string, parameters TagsObject, options *VirtualNetworksClientUpdateTagsOptions) (VirtualNetworksClientUpdateTagsResponse, error) {
   638  	var err error
   639  	const operationName = "VirtualNetworksClient.UpdateTags"
   640  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
   641  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
   642  	defer func() { endSpan(err) }()
   643  	req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, virtualNetworkName, parameters, options)
   644  	if err != nil {
   645  		return VirtualNetworksClientUpdateTagsResponse{}, err
   646  	}
   647  	httpResp, err := client.internal.Pipeline().Do(req)
   648  	if err != nil {
   649  		return VirtualNetworksClientUpdateTagsResponse{}, err
   650  	}
   651  	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
   652  		err = runtime.NewResponseError(httpResp)
   653  		return VirtualNetworksClientUpdateTagsResponse{}, err
   654  	}
   655  	resp, err := client.updateTagsHandleResponse(httpResp)
   656  	return resp, err
   657  }
   658  
   659  // updateTagsCreateRequest creates the UpdateTags request.
   660  func (client *VirtualNetworksClient) updateTagsCreateRequest(ctx context.Context, resourceGroupName string, virtualNetworkName string, parameters TagsObject, options *VirtualNetworksClientUpdateTagsOptions) (*policy.Request, error) {
   661  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}"
   662  	if resourceGroupName == "" {
   663  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   664  	}
   665  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   666  	if virtualNetworkName == "" {
   667  		return nil, errors.New("parameter virtualNetworkName cannot be empty")
   668  	}
   669  	urlPath = strings.ReplaceAll(urlPath, "{virtualNetworkName}", url.PathEscape(virtualNetworkName))
   670  	if client.subscriptionID == "" {
   671  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   672  	}
   673  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   674  	req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   675  	if err != nil {
   676  		return nil, err
   677  	}
   678  	reqQP := req.Raw().URL.Query()
   679  	reqQP.Set("api-version", "2024-05-01")
   680  	req.Raw().URL.RawQuery = reqQP.Encode()
   681  	req.Raw().Header["Accept"] = []string{"application/json"}
   682  	if err := runtime.MarshalAsJSON(req, parameters); err != nil {
   683  		return nil, err
   684  	}
   685  	return req, nil
   686  }
   687  
   688  // updateTagsHandleResponse handles the UpdateTags response.
   689  func (client *VirtualNetworksClient) updateTagsHandleResponse(resp *http.Response) (VirtualNetworksClientUpdateTagsResponse, error) {
   690  	result := VirtualNetworksClientUpdateTagsResponse{}
   691  	if err := runtime.UnmarshalAsJSON(resp, &result.VirtualNetwork); err != nil {
   692  		return VirtualNetworksClientUpdateTagsResponse{}, err
   693  	}
   694  	return result, nil
   695  }