1package network 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "net/http" 16) 17 18// VirtualHubBgpConnectionClient is the network Client 19type VirtualHubBgpConnectionClient struct { 20 BaseClient 21} 22 23// NewVirtualHubBgpConnectionClient creates an instance of the VirtualHubBgpConnectionClient client. 24func NewVirtualHubBgpConnectionClient(subscriptionID string) VirtualHubBgpConnectionClient { 25 return NewVirtualHubBgpConnectionClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewVirtualHubBgpConnectionClientWithBaseURI creates an instance of the VirtualHubBgpConnectionClient client using a 29// custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, 30// Azure stack). 31func NewVirtualHubBgpConnectionClientWithBaseURI(baseURI string, subscriptionID string) VirtualHubBgpConnectionClient { 32 return VirtualHubBgpConnectionClient{NewWithBaseURI(baseURI, subscriptionID)} 33} 34 35// CreateOrUpdate creates a VirtualHubBgpConnection resource if it doesn't exist else updates the existing 36// VirtualHubBgpConnection. 37// Parameters: 38// resourceGroupName - the resource group name of the VirtualHub. 39// virtualHubName - the name of the VirtualHub. 40// connectionName - the name of the connection. 41// parameters - parameters of Bgp connection. 42func (client VirtualHubBgpConnectionClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string, parameters BgpConnection) (result VirtualHubBgpConnectionCreateOrUpdateFuture, err error) { 43 if tracing.IsEnabled() { 44 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualHubBgpConnectionClient.CreateOrUpdate") 45 defer func() { 46 sc := -1 47 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 48 sc = result.FutureAPI.Response().StatusCode 49 } 50 tracing.EndSpan(ctx, sc, err) 51 }() 52 } 53 if err := validation.Validate([]validation.Validation{ 54 {TargetValue: parameters, 55 Constraints: []validation.Constraint{{Target: "parameters.BgpConnectionProperties", Name: validation.Null, Rule: false, 56 Chain: []validation.Constraint{{Target: "parameters.BgpConnectionProperties.PeerAsn", Name: validation.Null, Rule: false, 57 Chain: []validation.Constraint{{Target: "parameters.BgpConnectionProperties.PeerAsn", Name: validation.InclusiveMaximum, Rule: int64(4294967295), Chain: nil}, 58 {Target: "parameters.BgpConnectionProperties.PeerAsn", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}, 59 }}, 60 }}}}}); err != nil { 61 return result, validation.NewError("network.VirtualHubBgpConnectionClient", "CreateOrUpdate", err.Error()) 62 } 63 64 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, virtualHubName, connectionName, parameters) 65 if err != nil { 66 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionClient", "CreateOrUpdate", nil, "Failure preparing request") 67 return 68 } 69 70 result, err = client.CreateOrUpdateSender(req) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionClient", "CreateOrUpdate", nil, "Failure sending request") 73 return 74 } 75 76 return 77} 78 79// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 80func (client VirtualHubBgpConnectionClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string, parameters BgpConnection) (*http.Request, error) { 81 pathParameters := map[string]interface{}{ 82 "connectionName": autorest.Encode("path", connectionName), 83 "resourceGroupName": autorest.Encode("path", resourceGroupName), 84 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 85 "virtualHubName": autorest.Encode("path", virtualHubName), 86 } 87 88 const APIVersion = "2020-11-01" 89 queryParameters := map[string]interface{}{ 90 "api-version": APIVersion, 91 } 92 93 parameters.Etag = nil 94 parameters.Type = nil 95 preparer := autorest.CreatePreparer( 96 autorest.AsContentType("application/json; charset=utf-8"), 97 autorest.AsPut(), 98 autorest.WithBaseURL(client.BaseURI), 99 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/bgpConnections/{connectionName}", pathParameters), 100 autorest.WithJSON(parameters), 101 autorest.WithQueryParameters(queryParameters)) 102 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 103} 104 105// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 106// http.Response Body if it receives an error. 107func (client VirtualHubBgpConnectionClient) CreateOrUpdateSender(req *http.Request) (future VirtualHubBgpConnectionCreateOrUpdateFuture, err error) { 108 var resp *http.Response 109 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 110 if err != nil { 111 return 112 } 113 var azf azure.Future 114 azf, err = azure.NewFutureFromResponse(resp) 115 future.FutureAPI = &azf 116 future.Result = future.result 117 return 118} 119 120// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 121// closes the http.Response Body. 122func (client VirtualHubBgpConnectionClient) CreateOrUpdateResponder(resp *http.Response) (result BgpConnection, err error) { 123 err = autorest.Respond( 124 resp, 125 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 126 autorest.ByUnmarshallingJSON(&result), 127 autorest.ByClosing()) 128 result.Response = autorest.Response{Response: resp} 129 return 130} 131 132// Delete deletes a VirtualHubBgpConnection. 133// Parameters: 134// resourceGroupName - the resource group name of the VirtualHubBgpConnection. 135// virtualHubName - the name of the VirtualHub. 136// connectionName - the name of the connection. 137func (client VirtualHubBgpConnectionClient) Delete(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string) (result VirtualHubBgpConnectionDeleteFuture, err error) { 138 if tracing.IsEnabled() { 139 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualHubBgpConnectionClient.Delete") 140 defer func() { 141 sc := -1 142 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 143 sc = result.FutureAPI.Response().StatusCode 144 } 145 tracing.EndSpan(ctx, sc, err) 146 }() 147 } 148 req, err := client.DeletePreparer(ctx, resourceGroupName, virtualHubName, connectionName) 149 if err != nil { 150 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionClient", "Delete", nil, "Failure preparing request") 151 return 152 } 153 154 result, err = client.DeleteSender(req) 155 if err != nil { 156 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionClient", "Delete", nil, "Failure sending request") 157 return 158 } 159 160 return 161} 162 163// DeletePreparer prepares the Delete request. 164func (client VirtualHubBgpConnectionClient) DeletePreparer(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string) (*http.Request, error) { 165 pathParameters := map[string]interface{}{ 166 "connectionName": autorest.Encode("path", connectionName), 167 "resourceGroupName": autorest.Encode("path", resourceGroupName), 168 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 169 "virtualHubName": autorest.Encode("path", virtualHubName), 170 } 171 172 const APIVersion = "2020-11-01" 173 queryParameters := map[string]interface{}{ 174 "api-version": APIVersion, 175 } 176 177 preparer := autorest.CreatePreparer( 178 autorest.AsDelete(), 179 autorest.WithBaseURL(client.BaseURI), 180 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/bgpConnections/{connectionName}", pathParameters), 181 autorest.WithQueryParameters(queryParameters)) 182 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 183} 184 185// DeleteSender sends the Delete request. The method will close the 186// http.Response Body if it receives an error. 187func (client VirtualHubBgpConnectionClient) DeleteSender(req *http.Request) (future VirtualHubBgpConnectionDeleteFuture, err error) { 188 var resp *http.Response 189 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 190 if err != nil { 191 return 192 } 193 var azf azure.Future 194 azf, err = azure.NewFutureFromResponse(resp) 195 future.FutureAPI = &azf 196 future.Result = future.result 197 return 198} 199 200// DeleteResponder handles the response to the Delete request. The method always 201// closes the http.Response Body. 202func (client VirtualHubBgpConnectionClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 203 err = autorest.Respond( 204 resp, 205 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 206 autorest.ByClosing()) 207 result.Response = resp 208 return 209} 210 211// Get retrieves the details of a Virtual Hub Bgp Connection. 212// Parameters: 213// resourceGroupName - the resource group name of the VirtualHub. 214// virtualHubName - the name of the VirtualHub. 215// connectionName - the name of the connection. 216func (client VirtualHubBgpConnectionClient) Get(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string) (result BgpConnection, err error) { 217 if tracing.IsEnabled() { 218 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualHubBgpConnectionClient.Get") 219 defer func() { 220 sc := -1 221 if result.Response.Response != nil { 222 sc = result.Response.Response.StatusCode 223 } 224 tracing.EndSpan(ctx, sc, err) 225 }() 226 } 227 req, err := client.GetPreparer(ctx, resourceGroupName, virtualHubName, connectionName) 228 if err != nil { 229 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionClient", "Get", nil, "Failure preparing request") 230 return 231 } 232 233 resp, err := client.GetSender(req) 234 if err != nil { 235 result.Response = autorest.Response{Response: resp} 236 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionClient", "Get", resp, "Failure sending request") 237 return 238 } 239 240 result, err = client.GetResponder(resp) 241 if err != nil { 242 err = autorest.NewErrorWithError(err, "network.VirtualHubBgpConnectionClient", "Get", resp, "Failure responding to request") 243 return 244 } 245 246 return 247} 248 249// GetPreparer prepares the Get request. 250func (client VirtualHubBgpConnectionClient) GetPreparer(ctx context.Context, resourceGroupName string, virtualHubName string, connectionName string) (*http.Request, error) { 251 pathParameters := map[string]interface{}{ 252 "connectionName": autorest.Encode("path", connectionName), 253 "resourceGroupName": autorest.Encode("path", resourceGroupName), 254 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 255 "virtualHubName": autorest.Encode("path", virtualHubName), 256 } 257 258 const APIVersion = "2020-11-01" 259 queryParameters := map[string]interface{}{ 260 "api-version": APIVersion, 261 } 262 263 preparer := autorest.CreatePreparer( 264 autorest.AsGet(), 265 autorest.WithBaseURL(client.BaseURI), 266 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/bgpConnections/{connectionName}", pathParameters), 267 autorest.WithQueryParameters(queryParameters)) 268 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 269} 270 271// GetSender sends the Get request. The method will close the 272// http.Response Body if it receives an error. 273func (client VirtualHubBgpConnectionClient) GetSender(req *http.Request) (*http.Response, error) { 274 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 275} 276 277// GetResponder handles the response to the Get request. The method always 278// closes the http.Response Body. 279func (client VirtualHubBgpConnectionClient) GetResponder(resp *http.Response) (result BgpConnection, err error) { 280 err = autorest.Respond( 281 resp, 282 azure.WithErrorUnlessStatusCode(http.StatusOK), 283 autorest.ByUnmarshallingJSON(&result), 284 autorest.ByClosing()) 285 result.Response = autorest.Response{Response: resp} 286 return 287} 288