Ejemplo n.º 1
0
 public virtual VpnConnectionStartPacketCaptureOperation StartPacketCapture(VpnConnectionPacketCaptureStartParameters parameters = null, bool waitForCompletion = true, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("VpnConnection.StartPacketCapture");
     scope.Start();
     try
     {
         var response  = _vpnConnectionsRestClient.StartPacketCapture(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, parameters, cancellationToken);
         var operation = new VpnConnectionStartPacketCaptureOperation(_clientDiagnostics, Pipeline, _vpnConnectionsRestClient.CreateStartPacketCaptureRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, parameters).Request, response);
         if (waitForCompletion)
         {
             operation.WaitForCompletion(cancellationToken);
         }
         return(operation);
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
Ejemplo n.º 2
0
 public virtual ArmOperation <string> StartPacketCapture(WaitUntil waitUntil, VpnConnectionPacketCaptureStartParameters parameters = null, CancellationToken cancellationToken = default)
 {
     using var scope = _vpnConnectionClientDiagnostics.CreateScope("VpnConnection.StartPacketCapture");
     scope.Start();
     try
     {
         var response  = _vpnConnectionRestClient.StartPacketCapture(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, parameters, cancellationToken);
         var operation = new NetworkArmOperation <string>(new StringOperationSource(), _vpnConnectionClientDiagnostics, Pipeline, _vpnConnectionRestClient.CreateStartPacketCaptureRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, parameters).Request, response, OperationFinalStateVia.Location);
         if (waitUntil == WaitUntil.Completed)
         {
             operation.WaitForCompletion(cancellationToken);
         }
         return(operation);
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
        public async virtual Task <VpnConnectionStartPacketCaptureOperation> StartPacketCaptureAsync(bool waitForCompletion, VpnConnectionPacketCaptureStartParameters parameters = null, CancellationToken cancellationToken = default)
        {
            using var scope = _vpnConnectionClientDiagnostics.CreateScope("VpnConnection.StartPacketCapture");
            scope.Start();
            try
            {
                var response = await _vpnConnectionRestClient.StartPacketCaptureAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, parameters, cancellationToken).ConfigureAwait(false);

                var operation = new VpnConnectionStartPacketCaptureOperation(_vpnConnectionClientDiagnostics, Pipeline, _vpnConnectionRestClient.CreateStartPacketCaptureRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, parameters).Request, response);
                if (waitForCompletion)
                {
                    await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                }
                return(operation);
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
 /// <summary>
 /// Starts packet capture on Vpn connection in the specified resource group.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='gatewayName'>
 /// The name of the gateway.
 /// </param>
 /// <param name='vpnConnectionName'>
 /// The name of the vpn connection.
 /// </param>
 /// <param name='parameters'>
 /// Vpn Connection packet capture parameters supplied to start packet capture
 /// on gateway connection.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <string> BeginStartPacketCaptureAsync(this IVpnConnectionsOperations operations, string resourceGroupName, string gatewayName, string vpnConnectionName, VpnConnectionPacketCaptureStartParameters parameters = default(VpnConnectionPacketCaptureStartParameters), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginStartPacketCaptureWithHttpMessagesAsync(resourceGroupName, gatewayName, vpnConnectionName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Starts packet capture on Vpn connection in the specified resource group.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='gatewayName'>
 /// The name of the gateway.
 /// </param>
 /// <param name='vpnConnectionName'>
 /// The name of the vpn connection.
 /// </param>
 /// <param name='parameters'>
 /// Vpn Connection packet capture parameters supplied to start packet capture
 /// on gateway connection.
 /// </param>
 public static string BeginStartPacketCapture(this IVpnConnectionsOperations operations, string resourceGroupName, string gatewayName, string vpnConnectionName, VpnConnectionPacketCaptureStartParameters parameters = default(VpnConnectionPacketCaptureStartParameters))
 {
     return(operations.BeginStartPacketCaptureAsync(resourceGroupName, gatewayName, vpnConnectionName, parameters).GetAwaiter().GetResult());
 }
        public override void Execute()
        {
            if (ParameterSetName.Equals(CortexParameterSetNames.ByVpnConnectionName, StringComparison.OrdinalIgnoreCase))
            {
                this.ResourceGroupName  = this.ResourceGroupName;
                this.ParentResourceName = this.ParentResourceName;
                this.Name = this.Name;
            }
            else if (ParameterSetName.Equals(CortexParameterSetNames.ByVpnConnectionObject, StringComparison.OrdinalIgnoreCase))
            {
                this.ResourceId = this.InputObject.Id;

                if (string.IsNullOrWhiteSpace(this.ResourceId))
                {
                    throw new PSArgumentException(Properties.Resources.VpnConnectionNotFound);
                }

                var parsedResourceId = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName  = parsedResourceId.ResourceGroupName;
                this.ParentResourceName = parsedResourceId.ParentResource.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last();
                this.Name = parsedResourceId.ResourceName;
            }

            //// Get the vpngateway object - this will throw not found if the object is not found
            PSVpnGateway parentGateway = this.GetVpnGateway(this.ResourceGroupName, this.ParentResourceName);

            if (parentGateway == null ||
                parentGateway.Connections == null ||
                !parentGateway.Connections.Any(connection => connection.Name.Equals(this.Name, StringComparison.OrdinalIgnoreCase)))
            {
                throw new PSArgumentException(Properties.Resources.VpnConnectionNotFound);
            }

            var existingConnection = parentGateway.Connections.FirstOrDefault(connection => connection.Name.Equals(this.Name, StringComparison.OrdinalIgnoreCase));

            VpnConnectionPacketCaptureStartParameters parameters = new VpnConnectionPacketCaptureStartParameters();

            if (this.FilterData != null)
            {
                parameters.FilterData = FilterData;
            }

            if (this.LinkConnectionName != null)
            {
                parameters.LinkConnectionNames = LinkConnectionName.Split(',').Select(x => x.Trim()).ToList();
            }

            base.Execute();

            if (ShouldProcess(this.Name, String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name)))
            {
                WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name));
                PSVpnConnectionPacketCaptureResult output = new PSVpnConnectionPacketCaptureResult()
                {
                    Name = existingConnection.Name,
                    ResourceGroupName = parentGateway.ResourceGroupName,
                    Tag                = parentGateway.Tag,
                    ResourceGuid       = existingConnection.Id,
                    Location           = parentGateway.Location,
                    LinkConnectionName = this.LinkConnectionName
                };
                output.StartTime = DateTime.UtcNow;
                var result = this.VpnConnectionClient.StartPacketCapture(this.ResourceGroupName, ParentResourceName, this.Name, parameters);
                output.EndTime = DateTime.UtcNow;
                WriteObject(output);
            }
        }