-
Notifications
You must be signed in to change notification settings - Fork 4k
[Az.Network] Updated New-AzNetworkWatcherPacketCaptureV2 command and added a new sub command 'New-AzPacketCaptureSettingsConfig' for Network watcher Packet capture include ring buffer change. #27880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6985eb0
5b063be
b7522c4
0ec50e2
252f3cd
2d2eccc
2df74d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Azure.Commands.Network.Models | ||
{ | ||
using Microsoft.WindowsAzure.Commands.Common.Attributes; | ||
using Newtonsoft.Json; | ||
|
||
public class PSPacketCaptureSettings | ||
{ | ||
/// <summary> | ||
/// Gets or sets number of file count. Default value of count is 10 and maximum | ||
/// number is 10000. | ||
/// </summary> | ||
[JsonProperty(Order = 1)] | ||
[Ps1Xml(Target = ViewControl.Table)] | ||
public int? FileCount { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets number of bytes captured per packet. Default value in bytes | ||
/// 104857600 (100MB) and maximum in bytes 4294967295 (4GB). | ||
/// </summary> | ||
[JsonProperty(Order = 2)] | ||
[Ps1Xml(Target = ViewControl.Table)] | ||
public long? FileSizeInBytes { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets maximum duration of the capture session in seconds is 604800s | ||
/// (7 days) for a file. Default value in second 86400s (1 day). | ||
/// </summary> | ||
[JsonProperty(Order = 3)] | ||
[Ps1Xml(Target = ViewControl.Table)] | ||
public int? SessionTimeLimitInSeconds { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,20 +12,17 @@ | |
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using AutoMapper; | ||
using Microsoft.Azure.Commands.Network.Models; | ||
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; | ||
using Microsoft.Azure.Commands.ResourceManager.Common.Tags; | ||
using Microsoft.Azure.Management.Network; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
using MNM = Microsoft.Azure.Management.Network.Models; | ||
|
||
namespace Microsoft.Azure.Commands.Network | ||
{ | ||
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "NetworkWatcherPacketCaptureV2", SupportsShouldProcess = true, DefaultParameterSetName = "SetByResource"),OutputType(typeof(PSPacketCaptureResult))] | ||
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "NetworkWatcherPacketCaptureV2", SupportsShouldProcess = true, DefaultParameterSetName = "SetByResource"), OutputType(typeof(PSPacketCaptureResult))] | ||
public class NewAzureNetworkWatcherPacketCaptureCommandV2 : PacketCaptureBaseCmdlet | ||
{ | ||
[Parameter( | ||
|
@@ -94,7 +91,7 @@ public class NewAzureNetworkWatcherPacketCaptureCommandV2 : PacketCaptureBaseCmd | |
[Parameter( | ||
Mandatory = false, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = "Local file path.")] | ||
HelpMessage = "Local File path.")] | ||
[ValidateNotNullOrEmpty] | ||
public string LocalFilePath { get; set; } | ||
|
||
|
@@ -140,6 +137,25 @@ public class NewAzureNetworkWatcherPacketCaptureCommandV2 : PacketCaptureBaseCmd | |
[ValidateNotNull] | ||
public PSPacketCaptureFilter[] Filter { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = false, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = "This continuous capture is a nullable boolean, which can hold 'null', 'true' or 'false' value. If we do not pass this parameter, it would be consider as 'null', default value is 'null'.")] | ||
public bool? ContinuousCapture { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = false, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = "This path is valid if 'ContinuousCapture' is provided and required if no storage ID is provided, otherwise optional. Must include the name of the capture file (*.cap).")] | ||
[ValidateNotNullOrEmpty] | ||
public string LocalPath { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = false, | ||
HelpMessage = "Filters for packet capture session.")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update the description from swagger repo. Also mentions, only required when continous capture field is being set. |
||
[ValidateNotNull] | ||
public PSPacketCaptureSettings CaptureSettings { get; set; } | ||
|
||
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] | ||
public SwitchParameter AsJob { get; set; } | ||
|
||
|
@@ -172,6 +188,68 @@ public override void Execute() | |
name = this.NetworkWatcherName; | ||
} | ||
|
||
#region Capture Settings Validations | ||
if (this.ContinuousCapture == null) | ||
{ | ||
if (string.IsNullOrEmpty(this.LocalFilePath) && string.IsNullOrEmpty(this.StorageAccountId)) | ||
{ | ||
throw new ArgumentException("PacketCaptureIsMissingStorageIdAndLocalFilePath: StorageLocation must have either storage id or local file path specified."); | ||
} | ||
} | ||
else | ||
{ | ||
if (this.TotalBytesPerSession != null) | ||
{ | ||
throw new ArgumentException("InvalidRequestPropertiesInPacketCaptureRequest: TotalBytesPerSession is not supported in packet capture request."); | ||
} | ||
|
||
if (this.TimeLimitInSecond != null) | ||
{ | ||
throw new ArgumentException("InvalidRequestPropertiesInPacketCaptureRequest: TimeLimitInSecond is not supported in packet capture request."); | ||
} | ||
|
||
if (this.LocalFilePath != null) | ||
{ | ||
throw new ArgumentException("PacketCaptureIsMissingStorageIdAndLocalPath: StorageLocation must have either storage id or local path specified."); | ||
} | ||
|
||
if (string.IsNullOrEmpty(this.LocalPath) && string.IsNullOrEmpty(this.StorageAccountId)) | ||
{ | ||
throw new ArgumentException("PacketCaptureIsMissingStorageIdAndLocalFilePath: StorageLocation must have either storage id or local file path specified."); | ||
} | ||
|
||
if (this.CaptureSettings == null) | ||
{ | ||
this.CaptureSettings = new PSPacketCaptureSettings | ||
{ | ||
FileCount = 10, | ||
FileSizeInBytes = 104857600, | ||
SessionTimeLimitInSeconds = 86400 | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to pass these default values ? |
||
} | ||
else | ||
{ | ||
this.CaptureSettings.FileCount = this.CaptureSettings.FileCount ?? 10; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to set default value here, it should be taken care by server only, lets test this behavior once. |
||
this.CaptureSettings.FileSizeInBytes = this.CaptureSettings.FileSizeInBytes ?? 104857600; | ||
this.CaptureSettings.SessionTimeLimitInSeconds = this.CaptureSettings.SessionTimeLimitInSeconds ?? 86400; | ||
|
||
if (this.CaptureSettings.FileCount < 1 || this.CaptureSettings.FileCount > 10000) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit - lets do the validation before assignment, |
||
{ | ||
throw new ArgumentException("FileCount must be between 1 and 10,000. Default is 10."); | ||
} | ||
if (this.CaptureSettings.FileSizeInBytes < 102400 || this.CaptureSettings.FileSizeInBytes > 4294967295) | ||
{ | ||
throw new ArgumentException("FileSizeInBytes must be between 102400 byte and 4,294,967,295 bytes (4 GB). Default is 104,857,600 bytes (100 MB)."); | ||
} | ||
if (this.CaptureSettings.SessionTimeLimitInSeconds < 1 || this.CaptureSettings.SessionTimeLimitInSeconds > 604800) | ||
{ | ||
throw new ArgumentException("SessionTimeLimitInSeconds must be between 1 second and 604,800 seconds (7 days). Default is 86,400 seconds."); | ||
} | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
var present = this.IsPacketCapturePresent(resourceGroupName, name, this.Name); | ||
|
||
if (!present) | ||
|
@@ -185,13 +263,17 @@ public override void Execute() | |
WriteObject(packetCapture); | ||
}); | ||
} | ||
else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets add this scenario in existing test-case or we can write a new one. |
||
{ | ||
throw new ArgumentException($"PacketCaptureExistingAlready: Existing Packet capture can not be updated."); | ||
} | ||
} | ||
|
||
private PSPacketCaptureResult CreatePacketCapture(string resourceGroupName, string networkWatcherName) | ||
{ | ||
MNM.PacketCapture packetCaptureProperties = new MNM.PacketCapture(); | ||
|
||
if(this.BytesToCapturePerPacket != null) | ||
if (this.BytesToCapturePerPacket != null) | ||
{ | ||
packetCaptureProperties.BytesToCapturePerPacket = this.BytesToCapturePerPacket; | ||
} | ||
|
@@ -209,10 +291,25 @@ private PSPacketCaptureResult CreatePacketCapture(string resourceGroupName, stri | |
packetCaptureProperties.Target = this.TargetId; | ||
|
||
packetCaptureProperties.StorageLocation = new MNM.PacketCaptureStorageLocation(); | ||
packetCaptureProperties.StorageLocation.FilePath = this.LocalFilePath; | ||
packetCaptureProperties.ContinuousCapture = this.ContinuousCapture; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. continousCapture only needs to be set when it's provided ? |
||
|
||
if (this.ContinuousCapture != null) | ||
{ | ||
packetCaptureProperties.StorageLocation.LocalPath = this.LocalPath; | ||
packetCaptureProperties.CaptureSettings = new MNM.PacketCaptureSettings() | ||
{ | ||
FileCount = this.CaptureSettings.FileCount, | ||
FileSizeInBytes = this.CaptureSettings.FileSizeInBytes, | ||
SessionTimeLimitInSeconds = this.CaptureSettings.SessionTimeLimitInSeconds | ||
}; | ||
} | ||
else | ||
{ | ||
packetCaptureProperties.StorageLocation.FilePath = this.LocalFilePath; | ||
} | ||
|
||
packetCaptureProperties.StorageLocation.StorageId = this.StorageAccountId; | ||
packetCaptureProperties.StorageLocation.StoragePath = this.StoragePath; | ||
|
||
packetCaptureProperties.TargetType = MNM.PacketCaptureTargetType.AzureVM; | ||
|
||
if (!string.IsNullOrEmpty(this.TargetType)) | ||
|
Uh oh!
There was an error while loading. Please reload this page.