1package network 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// WatchersClient is the network Client 30type WatchersClient struct { 31 BaseClient 32} 33 34// NewWatchersClient creates an instance of the WatchersClient client. 35func NewWatchersClient(subscriptionID string) WatchersClient { 36 return NewWatchersClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewWatchersClientWithBaseURI creates an instance of the WatchersClient client using a custom endpoint. Use this 40// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewWatchersClientWithBaseURI(baseURI string, subscriptionID string) WatchersClient { 42 return WatchersClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// CheckConnectivity verifies the possibility of establishing a direct TCP connection from a virtual machine to a given 46// endpoint including another VM or an arbitrary remote server. 47// Parameters: 48// resourceGroupName - the name of the network watcher resource group. 49// networkWatcherName - the name of the network watcher resource. 50// parameters - parameters that determine how the connectivity check will be performed. 51func (client WatchersClient) CheckConnectivity(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters ConnectivityParameters) (result WatchersCheckConnectivityFuture, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.CheckConnectivity") 54 defer func() { 55 sc := -1 56 if result.Response() != nil { 57 sc = result.Response().StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 if err := validation.Validate([]validation.Validation{ 63 {TargetValue: parameters, 64 Constraints: []validation.Constraint{{Target: "parameters.Source", Name: validation.Null, Rule: true, 65 Chain: []validation.Constraint{{Target: "parameters.Source.ResourceID", Name: validation.Null, Rule: true, Chain: nil}}}, 66 {Target: "parameters.Destination", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 67 return result, validation.NewError("network.WatchersClient", "CheckConnectivity", err.Error()) 68 } 69 70 req, err := client.CheckConnectivityPreparer(ctx, resourceGroupName, networkWatcherName, parameters) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "network.WatchersClient", "CheckConnectivity", nil, "Failure preparing request") 73 return 74 } 75 76 result, err = client.CheckConnectivitySender(req) 77 if err != nil { 78 err = autorest.NewErrorWithError(err, "network.WatchersClient", "CheckConnectivity", result.Response(), "Failure sending request") 79 return 80 } 81 82 return 83} 84 85// CheckConnectivityPreparer prepares the CheckConnectivity request. 86func (client WatchersClient) CheckConnectivityPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters ConnectivityParameters) (*http.Request, error) { 87 pathParameters := map[string]interface{}{ 88 "networkWatcherName": autorest.Encode("path", networkWatcherName), 89 "resourceGroupName": autorest.Encode("path", resourceGroupName), 90 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 91 } 92 93 const APIVersion = "2020-05-01" 94 queryParameters := map[string]interface{}{ 95 "api-version": APIVersion, 96 } 97 98 preparer := autorest.CreatePreparer( 99 autorest.AsContentType("application/json; charset=utf-8"), 100 autorest.AsPost(), 101 autorest.WithBaseURL(client.BaseURI), 102 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/connectivityCheck", pathParameters), 103 autorest.WithJSON(parameters), 104 autorest.WithQueryParameters(queryParameters)) 105 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 106} 107 108// CheckConnectivitySender sends the CheckConnectivity request. The method will close the 109// http.Response Body if it receives an error. 110func (client WatchersClient) CheckConnectivitySender(req *http.Request) (future WatchersCheckConnectivityFuture, err error) { 111 var resp *http.Response 112 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 113 if err != nil { 114 return 115 } 116 future.Future, err = azure.NewFutureFromResponse(resp) 117 return 118} 119 120// CheckConnectivityResponder handles the response to the CheckConnectivity request. The method always 121// closes the http.Response Body. 122func (client WatchersClient) CheckConnectivityResponder(resp *http.Response) (result ConnectivityInformation, err error) { 123 err = autorest.Respond( 124 resp, 125 client.ByInspecting(), 126 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 127 autorest.ByUnmarshallingJSON(&result), 128 autorest.ByClosing()) 129 result.Response = autorest.Response{Response: resp} 130 return 131} 132 133// CreateOrUpdate creates or updates a network watcher in the specified resource group. 134// Parameters: 135// resourceGroupName - the name of the resource group. 136// networkWatcherName - the name of the network watcher. 137// parameters - parameters that define the network watcher resource. 138func (client WatchersClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters Watcher) (result Watcher, err error) { 139 if tracing.IsEnabled() { 140 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.CreateOrUpdate") 141 defer func() { 142 sc := -1 143 if result.Response.Response != nil { 144 sc = result.Response.Response.StatusCode 145 } 146 tracing.EndSpan(ctx, sc, err) 147 }() 148 } 149 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, networkWatcherName, parameters) 150 if err != nil { 151 err = autorest.NewErrorWithError(err, "network.WatchersClient", "CreateOrUpdate", nil, "Failure preparing request") 152 return 153 } 154 155 resp, err := client.CreateOrUpdateSender(req) 156 if err != nil { 157 result.Response = autorest.Response{Response: resp} 158 err = autorest.NewErrorWithError(err, "network.WatchersClient", "CreateOrUpdate", resp, "Failure sending request") 159 return 160 } 161 162 result, err = client.CreateOrUpdateResponder(resp) 163 if err != nil { 164 err = autorest.NewErrorWithError(err, "network.WatchersClient", "CreateOrUpdate", resp, "Failure responding to request") 165 } 166 167 return 168} 169 170// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 171func (client WatchersClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters Watcher) (*http.Request, error) { 172 pathParameters := map[string]interface{}{ 173 "networkWatcherName": autorest.Encode("path", networkWatcherName), 174 "resourceGroupName": autorest.Encode("path", resourceGroupName), 175 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 176 } 177 178 const APIVersion = "2020-05-01" 179 queryParameters := map[string]interface{}{ 180 "api-version": APIVersion, 181 } 182 183 parameters.Etag = nil 184 preparer := autorest.CreatePreparer( 185 autorest.AsContentType("application/json; charset=utf-8"), 186 autorest.AsPut(), 187 autorest.WithBaseURL(client.BaseURI), 188 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}", pathParameters), 189 autorest.WithJSON(parameters), 190 autorest.WithQueryParameters(queryParameters)) 191 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 192} 193 194// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 195// http.Response Body if it receives an error. 196func (client WatchersClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 197 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 198} 199 200// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 201// closes the http.Response Body. 202func (client WatchersClient) CreateOrUpdateResponder(resp *http.Response) (result Watcher, err error) { 203 err = autorest.Respond( 204 resp, 205 client.ByInspecting(), 206 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 207 autorest.ByUnmarshallingJSON(&result), 208 autorest.ByClosing()) 209 result.Response = autorest.Response{Response: resp} 210 return 211} 212 213// Delete deletes the specified network watcher resource. 214// Parameters: 215// resourceGroupName - the name of the resource group. 216// networkWatcherName - the name of the network watcher. 217func (client WatchersClient) Delete(ctx context.Context, resourceGroupName string, networkWatcherName string) (result WatchersDeleteFuture, err error) { 218 if tracing.IsEnabled() { 219 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.Delete") 220 defer func() { 221 sc := -1 222 if result.Response() != nil { 223 sc = result.Response().StatusCode 224 } 225 tracing.EndSpan(ctx, sc, err) 226 }() 227 } 228 req, err := client.DeletePreparer(ctx, resourceGroupName, networkWatcherName) 229 if err != nil { 230 err = autorest.NewErrorWithError(err, "network.WatchersClient", "Delete", nil, "Failure preparing request") 231 return 232 } 233 234 result, err = client.DeleteSender(req) 235 if err != nil { 236 err = autorest.NewErrorWithError(err, "network.WatchersClient", "Delete", result.Response(), "Failure sending request") 237 return 238 } 239 240 return 241} 242 243// DeletePreparer prepares the Delete request. 244func (client WatchersClient) DeletePreparer(ctx context.Context, resourceGroupName string, networkWatcherName string) (*http.Request, error) { 245 pathParameters := map[string]interface{}{ 246 "networkWatcherName": autorest.Encode("path", networkWatcherName), 247 "resourceGroupName": autorest.Encode("path", resourceGroupName), 248 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 249 } 250 251 const APIVersion = "2020-05-01" 252 queryParameters := map[string]interface{}{ 253 "api-version": APIVersion, 254 } 255 256 preparer := autorest.CreatePreparer( 257 autorest.AsDelete(), 258 autorest.WithBaseURL(client.BaseURI), 259 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}", pathParameters), 260 autorest.WithQueryParameters(queryParameters)) 261 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 262} 263 264// DeleteSender sends the Delete request. The method will close the 265// http.Response Body if it receives an error. 266func (client WatchersClient) DeleteSender(req *http.Request) (future WatchersDeleteFuture, err error) { 267 var resp *http.Response 268 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 269 if err != nil { 270 return 271 } 272 future.Future, err = azure.NewFutureFromResponse(resp) 273 return 274} 275 276// DeleteResponder handles the response to the Delete request. The method always 277// closes the http.Response Body. 278func (client WatchersClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 279 err = autorest.Respond( 280 resp, 281 client.ByInspecting(), 282 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 283 autorest.ByClosing()) 284 result.Response = resp 285 return 286} 287 288// Get gets the specified network watcher by resource group. 289// Parameters: 290// resourceGroupName - the name of the resource group. 291// networkWatcherName - the name of the network watcher. 292func (client WatchersClient) Get(ctx context.Context, resourceGroupName string, networkWatcherName string) (result Watcher, err error) { 293 if tracing.IsEnabled() { 294 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.Get") 295 defer func() { 296 sc := -1 297 if result.Response.Response != nil { 298 sc = result.Response.Response.StatusCode 299 } 300 tracing.EndSpan(ctx, sc, err) 301 }() 302 } 303 req, err := client.GetPreparer(ctx, resourceGroupName, networkWatcherName) 304 if err != nil { 305 err = autorest.NewErrorWithError(err, "network.WatchersClient", "Get", nil, "Failure preparing request") 306 return 307 } 308 309 resp, err := client.GetSender(req) 310 if err != nil { 311 result.Response = autorest.Response{Response: resp} 312 err = autorest.NewErrorWithError(err, "network.WatchersClient", "Get", resp, "Failure sending request") 313 return 314 } 315 316 result, err = client.GetResponder(resp) 317 if err != nil { 318 err = autorest.NewErrorWithError(err, "network.WatchersClient", "Get", resp, "Failure responding to request") 319 } 320 321 return 322} 323 324// GetPreparer prepares the Get request. 325func (client WatchersClient) GetPreparer(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 = "2020-05-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}", pathParameters), 341 autorest.WithQueryParameters(queryParameters)) 342 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 343} 344 345// GetSender sends the Get request. The method will close the 346// http.Response Body if it receives an error. 347func (client WatchersClient) GetSender(req *http.Request) (*http.Response, error) { 348 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 349} 350 351// GetResponder handles the response to the Get request. The method always 352// closes the http.Response Body. 353func (client WatchersClient) GetResponder(resp *http.Response) (result Watcher, err error) { 354 err = autorest.Respond( 355 resp, 356 client.ByInspecting(), 357 azure.WithErrorUnlessStatusCode(http.StatusOK), 358 autorest.ByUnmarshallingJSON(&result), 359 autorest.ByClosing()) 360 result.Response = autorest.Response{Response: resp} 361 return 362} 363 364// GetAzureReachabilityReport nOTE: This feature is currently in preview and still being tested for stability. Gets the 365// relative latency score for internet service providers from a specified location to Azure regions. 366// Parameters: 367// resourceGroupName - the name of the network watcher resource group. 368// networkWatcherName - the name of the network watcher resource. 369// parameters - parameters that determine Azure reachability report configuration. 370func (client WatchersClient) GetAzureReachabilityReport(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters AzureReachabilityReportParameters) (result WatchersGetAzureReachabilityReportFuture, err error) { 371 if tracing.IsEnabled() { 372 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.GetAzureReachabilityReport") 373 defer func() { 374 sc := -1 375 if result.Response() != nil { 376 sc = result.Response().StatusCode 377 } 378 tracing.EndSpan(ctx, sc, err) 379 }() 380 } 381 if err := validation.Validate([]validation.Validation{ 382 {TargetValue: parameters, 383 Constraints: []validation.Constraint{{Target: "parameters.ProviderLocation", Name: validation.Null, Rule: true, 384 Chain: []validation.Constraint{{Target: "parameters.ProviderLocation.Country", Name: validation.Null, Rule: true, Chain: nil}}}, 385 {Target: "parameters.StartTime", Name: validation.Null, Rule: true, Chain: nil}, 386 {Target: "parameters.EndTime", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 387 return result, validation.NewError("network.WatchersClient", "GetAzureReachabilityReport", err.Error()) 388 } 389 390 req, err := client.GetAzureReachabilityReportPreparer(ctx, resourceGroupName, networkWatcherName, parameters) 391 if err != nil { 392 err = autorest.NewErrorWithError(err, "network.WatchersClient", "GetAzureReachabilityReport", nil, "Failure preparing request") 393 return 394 } 395 396 result, err = client.GetAzureReachabilityReportSender(req) 397 if err != nil { 398 err = autorest.NewErrorWithError(err, "network.WatchersClient", "GetAzureReachabilityReport", result.Response(), "Failure sending request") 399 return 400 } 401 402 return 403} 404 405// GetAzureReachabilityReportPreparer prepares the GetAzureReachabilityReport request. 406func (client WatchersClient) GetAzureReachabilityReportPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters AzureReachabilityReportParameters) (*http.Request, error) { 407 pathParameters := map[string]interface{}{ 408 "networkWatcherName": autorest.Encode("path", networkWatcherName), 409 "resourceGroupName": autorest.Encode("path", resourceGroupName), 410 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 411 } 412 413 const APIVersion = "2020-05-01" 414 queryParameters := map[string]interface{}{ 415 "api-version": APIVersion, 416 } 417 418 preparer := autorest.CreatePreparer( 419 autorest.AsContentType("application/json; charset=utf-8"), 420 autorest.AsPost(), 421 autorest.WithBaseURL(client.BaseURI), 422 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/azureReachabilityReport", pathParameters), 423 autorest.WithJSON(parameters), 424 autorest.WithQueryParameters(queryParameters)) 425 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 426} 427 428// GetAzureReachabilityReportSender sends the GetAzureReachabilityReport request. The method will close the 429// http.Response Body if it receives an error. 430func (client WatchersClient) GetAzureReachabilityReportSender(req *http.Request) (future WatchersGetAzureReachabilityReportFuture, err error) { 431 var resp *http.Response 432 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 433 if err != nil { 434 return 435 } 436 future.Future, err = azure.NewFutureFromResponse(resp) 437 return 438} 439 440// GetAzureReachabilityReportResponder handles the response to the GetAzureReachabilityReport request. The method always 441// closes the http.Response Body. 442func (client WatchersClient) GetAzureReachabilityReportResponder(resp *http.Response) (result AzureReachabilityReport, err error) { 443 err = autorest.Respond( 444 resp, 445 client.ByInspecting(), 446 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 447 autorest.ByUnmarshallingJSON(&result), 448 autorest.ByClosing()) 449 result.Response = autorest.Response{Response: resp} 450 return 451} 452 453// GetFlowLogStatus queries status of flow log and traffic analytics (optional) on a specified resource. 454// Parameters: 455// resourceGroupName - the name of the network watcher resource group. 456// networkWatcherName - the name of the network watcher resource. 457// parameters - parameters that define a resource to query flow log and traffic analytics (optional) status. 458func (client WatchersClient) GetFlowLogStatus(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters FlowLogStatusParameters) (result WatchersGetFlowLogStatusFuture, err error) { 459 if tracing.IsEnabled() { 460 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.GetFlowLogStatus") 461 defer func() { 462 sc := -1 463 if result.Response() != nil { 464 sc = result.Response().StatusCode 465 } 466 tracing.EndSpan(ctx, sc, err) 467 }() 468 } 469 if err := validation.Validate([]validation.Validation{ 470 {TargetValue: parameters, 471 Constraints: []validation.Constraint{{Target: "parameters.TargetResourceID", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 472 return result, validation.NewError("network.WatchersClient", "GetFlowLogStatus", err.Error()) 473 } 474 475 req, err := client.GetFlowLogStatusPreparer(ctx, resourceGroupName, networkWatcherName, parameters) 476 if err != nil { 477 err = autorest.NewErrorWithError(err, "network.WatchersClient", "GetFlowLogStatus", nil, "Failure preparing request") 478 return 479 } 480 481 result, err = client.GetFlowLogStatusSender(req) 482 if err != nil { 483 err = autorest.NewErrorWithError(err, "network.WatchersClient", "GetFlowLogStatus", result.Response(), "Failure sending request") 484 return 485 } 486 487 return 488} 489 490// GetFlowLogStatusPreparer prepares the GetFlowLogStatus request. 491func (client WatchersClient) GetFlowLogStatusPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters FlowLogStatusParameters) (*http.Request, error) { 492 pathParameters := map[string]interface{}{ 493 "networkWatcherName": autorest.Encode("path", networkWatcherName), 494 "resourceGroupName": autorest.Encode("path", resourceGroupName), 495 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 496 } 497 498 const APIVersion = "2020-05-01" 499 queryParameters := map[string]interface{}{ 500 "api-version": APIVersion, 501 } 502 503 preparer := autorest.CreatePreparer( 504 autorest.AsContentType("application/json; charset=utf-8"), 505 autorest.AsPost(), 506 autorest.WithBaseURL(client.BaseURI), 507 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/queryFlowLogStatus", pathParameters), 508 autorest.WithJSON(parameters), 509 autorest.WithQueryParameters(queryParameters)) 510 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 511} 512 513// GetFlowLogStatusSender sends the GetFlowLogStatus request. The method will close the 514// http.Response Body if it receives an error. 515func (client WatchersClient) GetFlowLogStatusSender(req *http.Request) (future WatchersGetFlowLogStatusFuture, err error) { 516 var resp *http.Response 517 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 518 if err != nil { 519 return 520 } 521 future.Future, err = azure.NewFutureFromResponse(resp) 522 return 523} 524 525// GetFlowLogStatusResponder handles the response to the GetFlowLogStatus request. The method always 526// closes the http.Response Body. 527func (client WatchersClient) GetFlowLogStatusResponder(resp *http.Response) (result FlowLogInformation, err error) { 528 err = autorest.Respond( 529 resp, 530 client.ByInspecting(), 531 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 532 autorest.ByUnmarshallingJSON(&result), 533 autorest.ByClosing()) 534 result.Response = autorest.Response{Response: resp} 535 return 536} 537 538// GetNetworkConfigurationDiagnostic gets Network Configuration Diagnostic data to help customers understand and debug 539// network behavior. It provides detailed information on what security rules were applied to a specified traffic flow 540// and the result of evaluating these rules. Customers must provide details of a flow like source, destination, 541// protocol, etc. The API returns whether traffic was allowed or denied, the rules evaluated for the specified flow and 542// the evaluation results. 543// Parameters: 544// resourceGroupName - the name of the resource group. 545// networkWatcherName - the name of the network watcher. 546// parameters - parameters to get network configuration diagnostic. 547func (client WatchersClient) GetNetworkConfigurationDiagnostic(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters ConfigurationDiagnosticParameters) (result WatchersGetNetworkConfigurationDiagnosticFuture, err error) { 548 if tracing.IsEnabled() { 549 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.GetNetworkConfigurationDiagnostic") 550 defer func() { 551 sc := -1 552 if result.Response() != nil { 553 sc = result.Response().StatusCode 554 } 555 tracing.EndSpan(ctx, sc, err) 556 }() 557 } 558 if err := validation.Validate([]validation.Validation{ 559 {TargetValue: parameters, 560 Constraints: []validation.Constraint{{Target: "parameters.TargetResourceID", Name: validation.Null, Rule: true, Chain: nil}, 561 {Target: "parameters.Profiles", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 562 return result, validation.NewError("network.WatchersClient", "GetNetworkConfigurationDiagnostic", err.Error()) 563 } 564 565 req, err := client.GetNetworkConfigurationDiagnosticPreparer(ctx, resourceGroupName, networkWatcherName, parameters) 566 if err != nil { 567 err = autorest.NewErrorWithError(err, "network.WatchersClient", "GetNetworkConfigurationDiagnostic", nil, "Failure preparing request") 568 return 569 } 570 571 result, err = client.GetNetworkConfigurationDiagnosticSender(req) 572 if err != nil { 573 err = autorest.NewErrorWithError(err, "network.WatchersClient", "GetNetworkConfigurationDiagnostic", result.Response(), "Failure sending request") 574 return 575 } 576 577 return 578} 579 580// GetNetworkConfigurationDiagnosticPreparer prepares the GetNetworkConfigurationDiagnostic request. 581func (client WatchersClient) GetNetworkConfigurationDiagnosticPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters ConfigurationDiagnosticParameters) (*http.Request, error) { 582 pathParameters := map[string]interface{}{ 583 "networkWatcherName": autorest.Encode("path", networkWatcherName), 584 "resourceGroupName": autorest.Encode("path", resourceGroupName), 585 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 586 } 587 588 const APIVersion = "2020-05-01" 589 queryParameters := map[string]interface{}{ 590 "api-version": APIVersion, 591 } 592 593 preparer := autorest.CreatePreparer( 594 autorest.AsContentType("application/json; charset=utf-8"), 595 autorest.AsPost(), 596 autorest.WithBaseURL(client.BaseURI), 597 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/networkConfigurationDiagnostic", pathParameters), 598 autorest.WithJSON(parameters), 599 autorest.WithQueryParameters(queryParameters)) 600 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 601} 602 603// GetNetworkConfigurationDiagnosticSender sends the GetNetworkConfigurationDiagnostic request. The method will close the 604// http.Response Body if it receives an error. 605func (client WatchersClient) GetNetworkConfigurationDiagnosticSender(req *http.Request) (future WatchersGetNetworkConfigurationDiagnosticFuture, err error) { 606 var resp *http.Response 607 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 608 if err != nil { 609 return 610 } 611 future.Future, err = azure.NewFutureFromResponse(resp) 612 return 613} 614 615// GetNetworkConfigurationDiagnosticResponder handles the response to the GetNetworkConfigurationDiagnostic request. The method always 616// closes the http.Response Body. 617func (client WatchersClient) GetNetworkConfigurationDiagnosticResponder(resp *http.Response) (result ConfigurationDiagnosticResponse, err error) { 618 err = autorest.Respond( 619 resp, 620 client.ByInspecting(), 621 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 622 autorest.ByUnmarshallingJSON(&result), 623 autorest.ByClosing()) 624 result.Response = autorest.Response{Response: resp} 625 return 626} 627 628// GetNextHop gets the next hop from the specified VM. 629// Parameters: 630// resourceGroupName - the name of the resource group. 631// networkWatcherName - the name of the network watcher. 632// parameters - parameters that define the source and destination endpoint. 633func (client WatchersClient) GetNextHop(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters NextHopParameters) (result WatchersGetNextHopFuture, err error) { 634 if tracing.IsEnabled() { 635 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.GetNextHop") 636 defer func() { 637 sc := -1 638 if result.Response() != nil { 639 sc = result.Response().StatusCode 640 } 641 tracing.EndSpan(ctx, sc, err) 642 }() 643 } 644 if err := validation.Validate([]validation.Validation{ 645 {TargetValue: parameters, 646 Constraints: []validation.Constraint{{Target: "parameters.TargetResourceID", Name: validation.Null, Rule: true, Chain: nil}, 647 {Target: "parameters.SourceIPAddress", Name: validation.Null, Rule: true, Chain: nil}, 648 {Target: "parameters.DestinationIPAddress", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 649 return result, validation.NewError("network.WatchersClient", "GetNextHop", err.Error()) 650 } 651 652 req, err := client.GetNextHopPreparer(ctx, resourceGroupName, networkWatcherName, parameters) 653 if err != nil { 654 err = autorest.NewErrorWithError(err, "network.WatchersClient", "GetNextHop", nil, "Failure preparing request") 655 return 656 } 657 658 result, err = client.GetNextHopSender(req) 659 if err != nil { 660 err = autorest.NewErrorWithError(err, "network.WatchersClient", "GetNextHop", result.Response(), "Failure sending request") 661 return 662 } 663 664 return 665} 666 667// GetNextHopPreparer prepares the GetNextHop request. 668func (client WatchersClient) GetNextHopPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters NextHopParameters) (*http.Request, error) { 669 pathParameters := map[string]interface{}{ 670 "networkWatcherName": autorest.Encode("path", networkWatcherName), 671 "resourceGroupName": autorest.Encode("path", resourceGroupName), 672 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 673 } 674 675 const APIVersion = "2020-05-01" 676 queryParameters := map[string]interface{}{ 677 "api-version": APIVersion, 678 } 679 680 preparer := autorest.CreatePreparer( 681 autorest.AsContentType("application/json; charset=utf-8"), 682 autorest.AsPost(), 683 autorest.WithBaseURL(client.BaseURI), 684 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/nextHop", pathParameters), 685 autorest.WithJSON(parameters), 686 autorest.WithQueryParameters(queryParameters)) 687 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 688} 689 690// GetNextHopSender sends the GetNextHop request. The method will close the 691// http.Response Body if it receives an error. 692func (client WatchersClient) GetNextHopSender(req *http.Request) (future WatchersGetNextHopFuture, err error) { 693 var resp *http.Response 694 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 695 if err != nil { 696 return 697 } 698 future.Future, err = azure.NewFutureFromResponse(resp) 699 return 700} 701 702// GetNextHopResponder handles the response to the GetNextHop request. The method always 703// closes the http.Response Body. 704func (client WatchersClient) GetNextHopResponder(resp *http.Response) (result NextHopResult, err error) { 705 err = autorest.Respond( 706 resp, 707 client.ByInspecting(), 708 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 709 autorest.ByUnmarshallingJSON(&result), 710 autorest.ByClosing()) 711 result.Response = autorest.Response{Response: resp} 712 return 713} 714 715// GetTopology gets the current network topology by resource group. 716// Parameters: 717// resourceGroupName - the name of the resource group. 718// networkWatcherName - the name of the network watcher. 719// parameters - parameters that define the representation of topology. 720func (client WatchersClient) GetTopology(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters TopologyParameters) (result Topology, err error) { 721 if tracing.IsEnabled() { 722 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.GetTopology") 723 defer func() { 724 sc := -1 725 if result.Response.Response != nil { 726 sc = result.Response.Response.StatusCode 727 } 728 tracing.EndSpan(ctx, sc, err) 729 }() 730 } 731 req, err := client.GetTopologyPreparer(ctx, resourceGroupName, networkWatcherName, parameters) 732 if err != nil { 733 err = autorest.NewErrorWithError(err, "network.WatchersClient", "GetTopology", nil, "Failure preparing request") 734 return 735 } 736 737 resp, err := client.GetTopologySender(req) 738 if err != nil { 739 result.Response = autorest.Response{Response: resp} 740 err = autorest.NewErrorWithError(err, "network.WatchersClient", "GetTopology", resp, "Failure sending request") 741 return 742 } 743 744 result, err = client.GetTopologyResponder(resp) 745 if err != nil { 746 err = autorest.NewErrorWithError(err, "network.WatchersClient", "GetTopology", resp, "Failure responding to request") 747 } 748 749 return 750} 751 752// GetTopologyPreparer prepares the GetTopology request. 753func (client WatchersClient) GetTopologyPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters TopologyParameters) (*http.Request, error) { 754 pathParameters := map[string]interface{}{ 755 "networkWatcherName": autorest.Encode("path", networkWatcherName), 756 "resourceGroupName": autorest.Encode("path", resourceGroupName), 757 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 758 } 759 760 const APIVersion = "2020-05-01" 761 queryParameters := map[string]interface{}{ 762 "api-version": APIVersion, 763 } 764 765 preparer := autorest.CreatePreparer( 766 autorest.AsContentType("application/json; charset=utf-8"), 767 autorest.AsPost(), 768 autorest.WithBaseURL(client.BaseURI), 769 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/topology", pathParameters), 770 autorest.WithJSON(parameters), 771 autorest.WithQueryParameters(queryParameters)) 772 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 773} 774 775// GetTopologySender sends the GetTopology request. The method will close the 776// http.Response Body if it receives an error. 777func (client WatchersClient) GetTopologySender(req *http.Request) (*http.Response, error) { 778 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 779} 780 781// GetTopologyResponder handles the response to the GetTopology request. The method always 782// closes the http.Response Body. 783func (client WatchersClient) GetTopologyResponder(resp *http.Response) (result Topology, err error) { 784 err = autorest.Respond( 785 resp, 786 client.ByInspecting(), 787 azure.WithErrorUnlessStatusCode(http.StatusOK), 788 autorest.ByUnmarshallingJSON(&result), 789 autorest.ByClosing()) 790 result.Response = autorest.Response{Response: resp} 791 return 792} 793 794// GetTroubleshooting initiate troubleshooting on a specified resource. 795// Parameters: 796// resourceGroupName - the name of the resource group. 797// networkWatcherName - the name of the network watcher resource. 798// parameters - parameters that define the resource to troubleshoot. 799func (client WatchersClient) GetTroubleshooting(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters TroubleshootingParameters) (result WatchersGetTroubleshootingFuture, err error) { 800 if tracing.IsEnabled() { 801 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.GetTroubleshooting") 802 defer func() { 803 sc := -1 804 if result.Response() != nil { 805 sc = result.Response().StatusCode 806 } 807 tracing.EndSpan(ctx, sc, err) 808 }() 809 } 810 if err := validation.Validate([]validation.Validation{ 811 {TargetValue: parameters, 812 Constraints: []validation.Constraint{{Target: "parameters.TargetResourceID", Name: validation.Null, Rule: true, Chain: nil}, 813 {Target: "parameters.TroubleshootingProperties", Name: validation.Null, Rule: true, 814 Chain: []validation.Constraint{{Target: "parameters.TroubleshootingProperties.StorageID", Name: validation.Null, Rule: true, Chain: nil}, 815 {Target: "parameters.TroubleshootingProperties.StoragePath", Name: validation.Null, Rule: true, Chain: nil}, 816 }}}}}); err != nil { 817 return result, validation.NewError("network.WatchersClient", "GetTroubleshooting", err.Error()) 818 } 819 820 req, err := client.GetTroubleshootingPreparer(ctx, resourceGroupName, networkWatcherName, parameters) 821 if err != nil { 822 err = autorest.NewErrorWithError(err, "network.WatchersClient", "GetTroubleshooting", nil, "Failure preparing request") 823 return 824 } 825 826 result, err = client.GetTroubleshootingSender(req) 827 if err != nil { 828 err = autorest.NewErrorWithError(err, "network.WatchersClient", "GetTroubleshooting", result.Response(), "Failure sending request") 829 return 830 } 831 832 return 833} 834 835// GetTroubleshootingPreparer prepares the GetTroubleshooting request. 836func (client WatchersClient) GetTroubleshootingPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters TroubleshootingParameters) (*http.Request, error) { 837 pathParameters := map[string]interface{}{ 838 "networkWatcherName": autorest.Encode("path", networkWatcherName), 839 "resourceGroupName": autorest.Encode("path", resourceGroupName), 840 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 841 } 842 843 const APIVersion = "2020-05-01" 844 queryParameters := map[string]interface{}{ 845 "api-version": APIVersion, 846 } 847 848 preparer := autorest.CreatePreparer( 849 autorest.AsContentType("application/json; charset=utf-8"), 850 autorest.AsPost(), 851 autorest.WithBaseURL(client.BaseURI), 852 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/troubleshoot", pathParameters), 853 autorest.WithJSON(parameters), 854 autorest.WithQueryParameters(queryParameters)) 855 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 856} 857 858// GetTroubleshootingSender sends the GetTroubleshooting request. The method will close the 859// http.Response Body if it receives an error. 860func (client WatchersClient) GetTroubleshootingSender(req *http.Request) (future WatchersGetTroubleshootingFuture, err error) { 861 var resp *http.Response 862 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 863 if err != nil { 864 return 865 } 866 future.Future, err = azure.NewFutureFromResponse(resp) 867 return 868} 869 870// GetTroubleshootingResponder handles the response to the GetTroubleshooting request. The method always 871// closes the http.Response Body. 872func (client WatchersClient) GetTroubleshootingResponder(resp *http.Response) (result TroubleshootingResult, err error) { 873 err = autorest.Respond( 874 resp, 875 client.ByInspecting(), 876 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 877 autorest.ByUnmarshallingJSON(&result), 878 autorest.ByClosing()) 879 result.Response = autorest.Response{Response: resp} 880 return 881} 882 883// GetTroubleshootingResult get the last completed troubleshooting result on a specified resource. 884// Parameters: 885// resourceGroupName - the name of the resource group. 886// networkWatcherName - the name of the network watcher resource. 887// parameters - parameters that define the resource to query the troubleshooting result. 888func (client WatchersClient) GetTroubleshootingResult(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters QueryTroubleshootingParameters) (result WatchersGetTroubleshootingResultFuture, err error) { 889 if tracing.IsEnabled() { 890 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.GetTroubleshootingResult") 891 defer func() { 892 sc := -1 893 if result.Response() != nil { 894 sc = result.Response().StatusCode 895 } 896 tracing.EndSpan(ctx, sc, err) 897 }() 898 } 899 if err := validation.Validate([]validation.Validation{ 900 {TargetValue: parameters, 901 Constraints: []validation.Constraint{{Target: "parameters.TargetResourceID", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 902 return result, validation.NewError("network.WatchersClient", "GetTroubleshootingResult", err.Error()) 903 } 904 905 req, err := client.GetTroubleshootingResultPreparer(ctx, resourceGroupName, networkWatcherName, parameters) 906 if err != nil { 907 err = autorest.NewErrorWithError(err, "network.WatchersClient", "GetTroubleshootingResult", nil, "Failure preparing request") 908 return 909 } 910 911 result, err = client.GetTroubleshootingResultSender(req) 912 if err != nil { 913 err = autorest.NewErrorWithError(err, "network.WatchersClient", "GetTroubleshootingResult", result.Response(), "Failure sending request") 914 return 915 } 916 917 return 918} 919 920// GetTroubleshootingResultPreparer prepares the GetTroubleshootingResult request. 921func (client WatchersClient) GetTroubleshootingResultPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters QueryTroubleshootingParameters) (*http.Request, error) { 922 pathParameters := map[string]interface{}{ 923 "networkWatcherName": autorest.Encode("path", networkWatcherName), 924 "resourceGroupName": autorest.Encode("path", resourceGroupName), 925 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 926 } 927 928 const APIVersion = "2020-05-01" 929 queryParameters := map[string]interface{}{ 930 "api-version": APIVersion, 931 } 932 933 preparer := autorest.CreatePreparer( 934 autorest.AsContentType("application/json; charset=utf-8"), 935 autorest.AsPost(), 936 autorest.WithBaseURL(client.BaseURI), 937 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/queryTroubleshootResult", pathParameters), 938 autorest.WithJSON(parameters), 939 autorest.WithQueryParameters(queryParameters)) 940 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 941} 942 943// GetTroubleshootingResultSender sends the GetTroubleshootingResult request. The method will close the 944// http.Response Body if it receives an error. 945func (client WatchersClient) GetTroubleshootingResultSender(req *http.Request) (future WatchersGetTroubleshootingResultFuture, err error) { 946 var resp *http.Response 947 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 948 if err != nil { 949 return 950 } 951 future.Future, err = azure.NewFutureFromResponse(resp) 952 return 953} 954 955// GetTroubleshootingResultResponder handles the response to the GetTroubleshootingResult request. The method always 956// closes the http.Response Body. 957func (client WatchersClient) GetTroubleshootingResultResponder(resp *http.Response) (result TroubleshootingResult, err error) { 958 err = autorest.Respond( 959 resp, 960 client.ByInspecting(), 961 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 962 autorest.ByUnmarshallingJSON(&result), 963 autorest.ByClosing()) 964 result.Response = autorest.Response{Response: resp} 965 return 966} 967 968// GetVMSecurityRules gets the configured and effective security group rules on the specified VM. 969// Parameters: 970// resourceGroupName - the name of the resource group. 971// networkWatcherName - the name of the network watcher. 972// parameters - parameters that define the VM to check security groups for. 973func (client WatchersClient) GetVMSecurityRules(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters SecurityGroupViewParameters) (result WatchersGetVMSecurityRulesFuture, err error) { 974 if tracing.IsEnabled() { 975 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.GetVMSecurityRules") 976 defer func() { 977 sc := -1 978 if result.Response() != nil { 979 sc = result.Response().StatusCode 980 } 981 tracing.EndSpan(ctx, sc, err) 982 }() 983 } 984 if err := validation.Validate([]validation.Validation{ 985 {TargetValue: parameters, 986 Constraints: []validation.Constraint{{Target: "parameters.TargetResourceID", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 987 return result, validation.NewError("network.WatchersClient", "GetVMSecurityRules", err.Error()) 988 } 989 990 req, err := client.GetVMSecurityRulesPreparer(ctx, resourceGroupName, networkWatcherName, parameters) 991 if err != nil { 992 err = autorest.NewErrorWithError(err, "network.WatchersClient", "GetVMSecurityRules", nil, "Failure preparing request") 993 return 994 } 995 996 result, err = client.GetVMSecurityRulesSender(req) 997 if err != nil { 998 err = autorest.NewErrorWithError(err, "network.WatchersClient", "GetVMSecurityRules", result.Response(), "Failure sending request") 999 return 1000 } 1001 1002 return 1003} 1004 1005// GetVMSecurityRulesPreparer prepares the GetVMSecurityRules request. 1006func (client WatchersClient) GetVMSecurityRulesPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters SecurityGroupViewParameters) (*http.Request, error) { 1007 pathParameters := map[string]interface{}{ 1008 "networkWatcherName": autorest.Encode("path", networkWatcherName), 1009 "resourceGroupName": autorest.Encode("path", resourceGroupName), 1010 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 1011 } 1012 1013 const APIVersion = "2020-05-01" 1014 queryParameters := map[string]interface{}{ 1015 "api-version": APIVersion, 1016 } 1017 1018 preparer := autorest.CreatePreparer( 1019 autorest.AsContentType("application/json; charset=utf-8"), 1020 autorest.AsPost(), 1021 autorest.WithBaseURL(client.BaseURI), 1022 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/securityGroupView", pathParameters), 1023 autorest.WithJSON(parameters), 1024 autorest.WithQueryParameters(queryParameters)) 1025 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 1026} 1027 1028// GetVMSecurityRulesSender sends the GetVMSecurityRules request. The method will close the 1029// http.Response Body if it receives an error. 1030func (client WatchersClient) GetVMSecurityRulesSender(req *http.Request) (future WatchersGetVMSecurityRulesFuture, err error) { 1031 var resp *http.Response 1032 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 1033 if err != nil { 1034 return 1035 } 1036 future.Future, err = azure.NewFutureFromResponse(resp) 1037 return 1038} 1039 1040// GetVMSecurityRulesResponder handles the response to the GetVMSecurityRules request. The method always 1041// closes the http.Response Body. 1042func (client WatchersClient) GetVMSecurityRulesResponder(resp *http.Response) (result SecurityGroupViewResult, err error) { 1043 err = autorest.Respond( 1044 resp, 1045 client.ByInspecting(), 1046 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 1047 autorest.ByUnmarshallingJSON(&result), 1048 autorest.ByClosing()) 1049 result.Response = autorest.Response{Response: resp} 1050 return 1051} 1052 1053// List gets all network watchers by resource group. 1054// Parameters: 1055// resourceGroupName - the name of the resource group. 1056func (client WatchersClient) List(ctx context.Context, resourceGroupName string) (result WatcherListResult, err error) { 1057 if tracing.IsEnabled() { 1058 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.List") 1059 defer func() { 1060 sc := -1 1061 if result.Response.Response != nil { 1062 sc = result.Response.Response.StatusCode 1063 } 1064 tracing.EndSpan(ctx, sc, err) 1065 }() 1066 } 1067 req, err := client.ListPreparer(ctx, resourceGroupName) 1068 if err != nil { 1069 err = autorest.NewErrorWithError(err, "network.WatchersClient", "List", nil, "Failure preparing request") 1070 return 1071 } 1072 1073 resp, err := client.ListSender(req) 1074 if err != nil { 1075 result.Response = autorest.Response{Response: resp} 1076 err = autorest.NewErrorWithError(err, "network.WatchersClient", "List", resp, "Failure sending request") 1077 return 1078 } 1079 1080 result, err = client.ListResponder(resp) 1081 if err != nil { 1082 err = autorest.NewErrorWithError(err, "network.WatchersClient", "List", resp, "Failure responding to request") 1083 } 1084 1085 return 1086} 1087 1088// ListPreparer prepares the List request. 1089func (client WatchersClient) ListPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { 1090 pathParameters := map[string]interface{}{ 1091 "resourceGroupName": autorest.Encode("path", resourceGroupName), 1092 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 1093 } 1094 1095 const APIVersion = "2020-05-01" 1096 queryParameters := map[string]interface{}{ 1097 "api-version": APIVersion, 1098 } 1099 1100 preparer := autorest.CreatePreparer( 1101 autorest.AsGet(), 1102 autorest.WithBaseURL(client.BaseURI), 1103 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers", pathParameters), 1104 autorest.WithQueryParameters(queryParameters)) 1105 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 1106} 1107 1108// ListSender sends the List request. The method will close the 1109// http.Response Body if it receives an error. 1110func (client WatchersClient) ListSender(req *http.Request) (*http.Response, error) { 1111 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 1112} 1113 1114// ListResponder handles the response to the List request. The method always 1115// closes the http.Response Body. 1116func (client WatchersClient) ListResponder(resp *http.Response) (result WatcherListResult, err error) { 1117 err = autorest.Respond( 1118 resp, 1119 client.ByInspecting(), 1120 azure.WithErrorUnlessStatusCode(http.StatusOK), 1121 autorest.ByUnmarshallingJSON(&result), 1122 autorest.ByClosing()) 1123 result.Response = autorest.Response{Response: resp} 1124 return 1125} 1126 1127// ListAll gets all network watchers by subscription. 1128func (client WatchersClient) ListAll(ctx context.Context) (result WatcherListResult, err error) { 1129 if tracing.IsEnabled() { 1130 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.ListAll") 1131 defer func() { 1132 sc := -1 1133 if result.Response.Response != nil { 1134 sc = result.Response.Response.StatusCode 1135 } 1136 tracing.EndSpan(ctx, sc, err) 1137 }() 1138 } 1139 req, err := client.ListAllPreparer(ctx) 1140 if err != nil { 1141 err = autorest.NewErrorWithError(err, "network.WatchersClient", "ListAll", nil, "Failure preparing request") 1142 return 1143 } 1144 1145 resp, err := client.ListAllSender(req) 1146 if err != nil { 1147 result.Response = autorest.Response{Response: resp} 1148 err = autorest.NewErrorWithError(err, "network.WatchersClient", "ListAll", resp, "Failure sending request") 1149 return 1150 } 1151 1152 result, err = client.ListAllResponder(resp) 1153 if err != nil { 1154 err = autorest.NewErrorWithError(err, "network.WatchersClient", "ListAll", resp, "Failure responding to request") 1155 } 1156 1157 return 1158} 1159 1160// ListAllPreparer prepares the ListAll request. 1161func (client WatchersClient) ListAllPreparer(ctx context.Context) (*http.Request, error) { 1162 pathParameters := map[string]interface{}{ 1163 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 1164 } 1165 1166 const APIVersion = "2020-05-01" 1167 queryParameters := map[string]interface{}{ 1168 "api-version": APIVersion, 1169 } 1170 1171 preparer := autorest.CreatePreparer( 1172 autorest.AsGet(), 1173 autorest.WithBaseURL(client.BaseURI), 1174 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/networkWatchers", pathParameters), 1175 autorest.WithQueryParameters(queryParameters)) 1176 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 1177} 1178 1179// ListAllSender sends the ListAll request. The method will close the 1180// http.Response Body if it receives an error. 1181func (client WatchersClient) ListAllSender(req *http.Request) (*http.Response, error) { 1182 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 1183} 1184 1185// ListAllResponder handles the response to the ListAll request. The method always 1186// closes the http.Response Body. 1187func (client WatchersClient) ListAllResponder(resp *http.Response) (result WatcherListResult, err error) { 1188 err = autorest.Respond( 1189 resp, 1190 client.ByInspecting(), 1191 azure.WithErrorUnlessStatusCode(http.StatusOK), 1192 autorest.ByUnmarshallingJSON(&result), 1193 autorest.ByClosing()) 1194 result.Response = autorest.Response{Response: resp} 1195 return 1196} 1197 1198// ListAvailableProviders nOTE: This feature is currently in preview and still being tested for stability. Lists all 1199// available internet service providers for a specified Azure region. 1200// Parameters: 1201// resourceGroupName - the name of the network watcher resource group. 1202// networkWatcherName - the name of the network watcher resource. 1203// parameters - parameters that scope the list of available providers. 1204func (client WatchersClient) ListAvailableProviders(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters AvailableProvidersListParameters) (result WatchersListAvailableProvidersFuture, err error) { 1205 if tracing.IsEnabled() { 1206 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.ListAvailableProviders") 1207 defer func() { 1208 sc := -1 1209 if result.Response() != nil { 1210 sc = result.Response().StatusCode 1211 } 1212 tracing.EndSpan(ctx, sc, err) 1213 }() 1214 } 1215 req, err := client.ListAvailableProvidersPreparer(ctx, resourceGroupName, networkWatcherName, parameters) 1216 if err != nil { 1217 err = autorest.NewErrorWithError(err, "network.WatchersClient", "ListAvailableProviders", nil, "Failure preparing request") 1218 return 1219 } 1220 1221 result, err = client.ListAvailableProvidersSender(req) 1222 if err != nil { 1223 err = autorest.NewErrorWithError(err, "network.WatchersClient", "ListAvailableProviders", result.Response(), "Failure sending request") 1224 return 1225 } 1226 1227 return 1228} 1229 1230// ListAvailableProvidersPreparer prepares the ListAvailableProviders request. 1231func (client WatchersClient) ListAvailableProvidersPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters AvailableProvidersListParameters) (*http.Request, error) { 1232 pathParameters := map[string]interface{}{ 1233 "networkWatcherName": autorest.Encode("path", networkWatcherName), 1234 "resourceGroupName": autorest.Encode("path", resourceGroupName), 1235 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 1236 } 1237 1238 const APIVersion = "2020-05-01" 1239 queryParameters := map[string]interface{}{ 1240 "api-version": APIVersion, 1241 } 1242 1243 preparer := autorest.CreatePreparer( 1244 autorest.AsContentType("application/json; charset=utf-8"), 1245 autorest.AsPost(), 1246 autorest.WithBaseURL(client.BaseURI), 1247 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/availableProvidersList", pathParameters), 1248 autorest.WithJSON(parameters), 1249 autorest.WithQueryParameters(queryParameters)) 1250 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 1251} 1252 1253// ListAvailableProvidersSender sends the ListAvailableProviders request. The method will close the 1254// http.Response Body if it receives an error. 1255func (client WatchersClient) ListAvailableProvidersSender(req *http.Request) (future WatchersListAvailableProvidersFuture, err error) { 1256 var resp *http.Response 1257 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 1258 if err != nil { 1259 return 1260 } 1261 future.Future, err = azure.NewFutureFromResponse(resp) 1262 return 1263} 1264 1265// ListAvailableProvidersResponder handles the response to the ListAvailableProviders request. The method always 1266// closes the http.Response Body. 1267func (client WatchersClient) ListAvailableProvidersResponder(resp *http.Response) (result AvailableProvidersList, err error) { 1268 err = autorest.Respond( 1269 resp, 1270 client.ByInspecting(), 1271 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 1272 autorest.ByUnmarshallingJSON(&result), 1273 autorest.ByClosing()) 1274 result.Response = autorest.Response{Response: resp} 1275 return 1276} 1277 1278// SetFlowLogConfiguration configures flow log and traffic analytics (optional) on a specified resource. 1279// Parameters: 1280// resourceGroupName - the name of the network watcher resource group. 1281// networkWatcherName - the name of the network watcher resource. 1282// parameters - parameters that define the configuration of flow log. 1283func (client WatchersClient) SetFlowLogConfiguration(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters FlowLogInformation) (result WatchersSetFlowLogConfigurationFuture, err error) { 1284 if tracing.IsEnabled() { 1285 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.SetFlowLogConfiguration") 1286 defer func() { 1287 sc := -1 1288 if result.Response() != nil { 1289 sc = result.Response().StatusCode 1290 } 1291 tracing.EndSpan(ctx, sc, err) 1292 }() 1293 } 1294 if err := validation.Validate([]validation.Validation{ 1295 {TargetValue: parameters, 1296 Constraints: []validation.Constraint{{Target: "parameters.TargetResourceID", Name: validation.Null, Rule: true, Chain: nil}, 1297 {Target: "parameters.FlowLogProperties", Name: validation.Null, Rule: true, 1298 Chain: []validation.Constraint{{Target: "parameters.FlowLogProperties.StorageID", Name: validation.Null, Rule: true, Chain: nil}, 1299 {Target: "parameters.FlowLogProperties.Enabled", Name: validation.Null, Rule: true, Chain: nil}, 1300 }}}}}); err != nil { 1301 return result, validation.NewError("network.WatchersClient", "SetFlowLogConfiguration", err.Error()) 1302 } 1303 1304 req, err := client.SetFlowLogConfigurationPreparer(ctx, resourceGroupName, networkWatcherName, parameters) 1305 if err != nil { 1306 err = autorest.NewErrorWithError(err, "network.WatchersClient", "SetFlowLogConfiguration", nil, "Failure preparing request") 1307 return 1308 } 1309 1310 result, err = client.SetFlowLogConfigurationSender(req) 1311 if err != nil { 1312 err = autorest.NewErrorWithError(err, "network.WatchersClient", "SetFlowLogConfiguration", result.Response(), "Failure sending request") 1313 return 1314 } 1315 1316 return 1317} 1318 1319// SetFlowLogConfigurationPreparer prepares the SetFlowLogConfiguration request. 1320func (client WatchersClient) SetFlowLogConfigurationPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters FlowLogInformation) (*http.Request, error) { 1321 pathParameters := map[string]interface{}{ 1322 "networkWatcherName": autorest.Encode("path", networkWatcherName), 1323 "resourceGroupName": autorest.Encode("path", resourceGroupName), 1324 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 1325 } 1326 1327 const APIVersion = "2020-05-01" 1328 queryParameters := map[string]interface{}{ 1329 "api-version": APIVersion, 1330 } 1331 1332 preparer := autorest.CreatePreparer( 1333 autorest.AsContentType("application/json; charset=utf-8"), 1334 autorest.AsPost(), 1335 autorest.WithBaseURL(client.BaseURI), 1336 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/configureFlowLog", pathParameters), 1337 autorest.WithJSON(parameters), 1338 autorest.WithQueryParameters(queryParameters)) 1339 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 1340} 1341 1342// SetFlowLogConfigurationSender sends the SetFlowLogConfiguration request. The method will close the 1343// http.Response Body if it receives an error. 1344func (client WatchersClient) SetFlowLogConfigurationSender(req *http.Request) (future WatchersSetFlowLogConfigurationFuture, err error) { 1345 var resp *http.Response 1346 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 1347 if err != nil { 1348 return 1349 } 1350 future.Future, err = azure.NewFutureFromResponse(resp) 1351 return 1352} 1353 1354// SetFlowLogConfigurationResponder handles the response to the SetFlowLogConfiguration request. The method always 1355// closes the http.Response Body. 1356func (client WatchersClient) SetFlowLogConfigurationResponder(resp *http.Response) (result FlowLogInformation, err error) { 1357 err = autorest.Respond( 1358 resp, 1359 client.ByInspecting(), 1360 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 1361 autorest.ByUnmarshallingJSON(&result), 1362 autorest.ByClosing()) 1363 result.Response = autorest.Response{Response: resp} 1364 return 1365} 1366 1367// UpdateTags updates a network watcher tags. 1368// Parameters: 1369// resourceGroupName - the name of the resource group. 1370// networkWatcherName - the name of the network watcher. 1371// parameters - parameters supplied to update network watcher tags. 1372func (client WatchersClient) UpdateTags(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters TagsObject) (result Watcher, err error) { 1373 if tracing.IsEnabled() { 1374 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.UpdateTags") 1375 defer func() { 1376 sc := -1 1377 if result.Response.Response != nil { 1378 sc = result.Response.Response.StatusCode 1379 } 1380 tracing.EndSpan(ctx, sc, err) 1381 }() 1382 } 1383 req, err := client.UpdateTagsPreparer(ctx, resourceGroupName, networkWatcherName, parameters) 1384 if err != nil { 1385 err = autorest.NewErrorWithError(err, "network.WatchersClient", "UpdateTags", nil, "Failure preparing request") 1386 return 1387 } 1388 1389 resp, err := client.UpdateTagsSender(req) 1390 if err != nil { 1391 result.Response = autorest.Response{Response: resp} 1392 err = autorest.NewErrorWithError(err, "network.WatchersClient", "UpdateTags", resp, "Failure sending request") 1393 return 1394 } 1395 1396 result, err = client.UpdateTagsResponder(resp) 1397 if err != nil { 1398 err = autorest.NewErrorWithError(err, "network.WatchersClient", "UpdateTags", resp, "Failure responding to request") 1399 } 1400 1401 return 1402} 1403 1404// UpdateTagsPreparer prepares the UpdateTags request. 1405func (client WatchersClient) UpdateTagsPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters TagsObject) (*http.Request, error) { 1406 pathParameters := map[string]interface{}{ 1407 "networkWatcherName": autorest.Encode("path", networkWatcherName), 1408 "resourceGroupName": autorest.Encode("path", resourceGroupName), 1409 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 1410 } 1411 1412 const APIVersion = "2020-05-01" 1413 queryParameters := map[string]interface{}{ 1414 "api-version": APIVersion, 1415 } 1416 1417 preparer := autorest.CreatePreparer( 1418 autorest.AsContentType("application/json; charset=utf-8"), 1419 autorest.AsPatch(), 1420 autorest.WithBaseURL(client.BaseURI), 1421 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}", pathParameters), 1422 autorest.WithJSON(parameters), 1423 autorest.WithQueryParameters(queryParameters)) 1424 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 1425} 1426 1427// UpdateTagsSender sends the UpdateTags request. The method will close the 1428// http.Response Body if it receives an error. 1429func (client WatchersClient) UpdateTagsSender(req *http.Request) (*http.Response, error) { 1430 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 1431} 1432 1433// UpdateTagsResponder handles the response to the UpdateTags request. The method always 1434// closes the http.Response Body. 1435func (client WatchersClient) UpdateTagsResponder(resp *http.Response) (result Watcher, err error) { 1436 err = autorest.Respond( 1437 resp, 1438 client.ByInspecting(), 1439 azure.WithErrorUnlessStatusCode(http.StatusOK), 1440 autorest.ByUnmarshallingJSON(&result), 1441 autorest.ByClosing()) 1442 result.Response = autorest.Response{Response: resp} 1443 return 1444} 1445 1446// VerifyIPFlow verify IP flow from the specified VM to a location given the currently configured NSG rules. 1447// Parameters: 1448// resourceGroupName - the name of the resource group. 1449// networkWatcherName - the name of the network watcher. 1450// parameters - parameters that define the IP flow to be verified. 1451func (client WatchersClient) VerifyIPFlow(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters VerificationIPFlowParameters) (result WatchersVerifyIPFlowFuture, err error) { 1452 if tracing.IsEnabled() { 1453 ctx = tracing.StartSpan(ctx, fqdn+"/WatchersClient.VerifyIPFlow") 1454 defer func() { 1455 sc := -1 1456 if result.Response() != nil { 1457 sc = result.Response().StatusCode 1458 } 1459 tracing.EndSpan(ctx, sc, err) 1460 }() 1461 } 1462 if err := validation.Validate([]validation.Validation{ 1463 {TargetValue: parameters, 1464 Constraints: []validation.Constraint{{Target: "parameters.TargetResourceID", Name: validation.Null, Rule: true, Chain: nil}, 1465 {Target: "parameters.LocalPort", Name: validation.Null, Rule: true, Chain: nil}, 1466 {Target: "parameters.RemotePort", Name: validation.Null, Rule: true, Chain: nil}, 1467 {Target: "parameters.LocalIPAddress", Name: validation.Null, Rule: true, Chain: nil}, 1468 {Target: "parameters.RemoteIPAddress", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 1469 return result, validation.NewError("network.WatchersClient", "VerifyIPFlow", err.Error()) 1470 } 1471 1472 req, err := client.VerifyIPFlowPreparer(ctx, resourceGroupName, networkWatcherName, parameters) 1473 if err != nil { 1474 err = autorest.NewErrorWithError(err, "network.WatchersClient", "VerifyIPFlow", nil, "Failure preparing request") 1475 return 1476 } 1477 1478 result, err = client.VerifyIPFlowSender(req) 1479 if err != nil { 1480 err = autorest.NewErrorWithError(err, "network.WatchersClient", "VerifyIPFlow", result.Response(), "Failure sending request") 1481 return 1482 } 1483 1484 return 1485} 1486 1487// VerifyIPFlowPreparer prepares the VerifyIPFlow request. 1488func (client WatchersClient) VerifyIPFlowPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, parameters VerificationIPFlowParameters) (*http.Request, error) { 1489 pathParameters := map[string]interface{}{ 1490 "networkWatcherName": autorest.Encode("path", networkWatcherName), 1491 "resourceGroupName": autorest.Encode("path", resourceGroupName), 1492 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 1493 } 1494 1495 const APIVersion = "2020-05-01" 1496 queryParameters := map[string]interface{}{ 1497 "api-version": APIVersion, 1498 } 1499 1500 preparer := autorest.CreatePreparer( 1501 autorest.AsContentType("application/json; charset=utf-8"), 1502 autorest.AsPost(), 1503 autorest.WithBaseURL(client.BaseURI), 1504 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/ipFlowVerify", pathParameters), 1505 autorest.WithJSON(parameters), 1506 autorest.WithQueryParameters(queryParameters)) 1507 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 1508} 1509 1510// VerifyIPFlowSender sends the VerifyIPFlow request. The method will close the 1511// http.Response Body if it receives an error. 1512func (client WatchersClient) VerifyIPFlowSender(req *http.Request) (future WatchersVerifyIPFlowFuture, err error) { 1513 var resp *http.Response 1514 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 1515 if err != nil { 1516 return 1517 } 1518 future.Future, err = azure.NewFutureFromResponse(resp) 1519 return 1520} 1521 1522// VerifyIPFlowResponder handles the response to the VerifyIPFlow request. The method always 1523// closes the http.Response Body. 1524func (client WatchersClient) VerifyIPFlowResponder(resp *http.Response) (result VerificationIPFlowResult, err error) { 1525 err = autorest.Respond( 1526 resp, 1527 client.ByInspecting(), 1528 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 1529 autorest.ByUnmarshallingJSON(&result), 1530 autorest.ByClosing()) 1531 result.Response = autorest.Response{Response: resp} 1532 return 1533} 1534