internal VpnConnection(ArmResource options, VpnConnectionData resource) : base(options, new ResourceIdentifier(resource.Id)) { HasData = true; _data = resource; _clientDiagnostics = new ClientDiagnostics(ClientOptions); _vpnConnectionsRestClient = new VpnConnectionsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri); }
public async Task <Response <VpnConnectionData> > GetAsync(string resourceGroupName, string gatewayName, string connectionName, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (gatewayName == null) { throw new ArgumentNullException(nameof(gatewayName)); } if (connectionName == null) { throw new ArgumentNullException(nameof(connectionName)); } using var message = CreateGetRequest(resourceGroupName, gatewayName, connectionName); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: { VpnConnectionData value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = VpnConnectionData.DeserializeVpnConnectionData(document.RootElement); return(Response.FromValue(value, message.Response)); }
VpnConnection IOperationSource <VpnConnection> .CreateResult(Response response, CancellationToken cancellationToken) { using var document = JsonDocument.Parse(response.ContentStream); var data = VpnConnectionData.DeserializeVpnConnectionData(document.RootElement); return(new VpnConnection(_client, data)); }
internal VpnConnection(ArmResource options, VpnConnectionData resource) : base(options, resource.Id) { HasData = true; _data = resource; _clientDiagnostics = new ClientDiagnostics(ClientOptions); _restClient = new VpnConnectionsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, Id.SubscriptionId, BaseUri); _vpnLinkConnectionsRestClient = new VpnLinkConnectionsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, Id.SubscriptionId, BaseUri); _vpnSiteLinkConnectionsRestClient = new VpnSiteLinkConnectionsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, Id.SubscriptionId, BaseUri); }
public async virtual Task <VpnConnectionCreateOrUpdateOperation> CreateOrUpdateAsync(bool waitForCompletion, string connectionName, VpnConnectionData vpnConnectionParameters, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(connectionName, nameof(connectionName)); if (vpnConnectionParameters == null) { throw new ArgumentNullException(nameof(vpnConnectionParameters)); } using var scope = _vpnConnectionClientDiagnostics.CreateScope("VpnConnectionCollection.CreateOrUpdate"); scope.Start(); try { var response = await _vpnConnectionRestClient.CreateOrUpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, connectionName, vpnConnectionParameters, cancellationToken).ConfigureAwait(false); var operation = new VpnConnectionCreateOrUpdateOperation(ArmClient, _vpnConnectionClientDiagnostics, Pipeline, _vpnConnectionRestClient.CreateCreateOrUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, connectionName, vpnConnectionParameters).Request, response); if (waitForCompletion) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
internal VpnConnectionResource(ArmClient client, VpnConnectionData data) : this(client, new ResourceIdentifier(data.Id)) { HasData = true; _data = data; }
public virtual ArmOperation <VpnConnectionResource> Update(WaitUntil waitUntil, VpnConnectionData data, CancellationToken cancellationToken = default) { Argument.AssertNotNull(data, nameof(data)); using var scope = _vpnConnectionClientDiagnostics.CreateScope("VpnConnectionResource.Update"); scope.Start(); try { var response = _vpnConnectionRestClient.CreateOrUpdate(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, data, cancellationToken); var operation = new NetworkArmOperation <VpnConnectionResource>(new VpnConnectionOperationSource(Client), _vpnConnectionClientDiagnostics, Pipeline, _vpnConnectionRestClient.CreateCreateOrUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, data).Request, response, OperationFinalStateVia.AzureAsyncOperation); if (waitUntil == WaitUntil.Completed) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual VpnConnectionCreateOrUpdateOperation CreateOrUpdate(string connectionName, VpnConnectionData vpnConnectionParameters, bool waitForCompletion = true, CancellationToken cancellationToken = default) { if (connectionName == null) { throw new ArgumentNullException(nameof(connectionName)); } if (vpnConnectionParameters == null) { throw new ArgumentNullException(nameof(vpnConnectionParameters)); } using var scope = _clientDiagnostics.CreateScope("VpnConnectionCollection.CreateOrUpdate"); scope.Start(); try { var response = _vpnConnectionsRestClient.CreateOrUpdate(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, connectionName, vpnConnectionParameters, cancellationToken); var operation = new VpnConnectionCreateOrUpdateOperation(Parent, _clientDiagnostics, Pipeline, _vpnConnectionsRestClient.CreateCreateOrUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, connectionName, vpnConnectionParameters).Request, response); if (waitForCompletion) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
internal static VpnGatewayData DeserializeVpnGatewayData(JsonElement element) { Optional <ETag> etag = default; Optional <ResourceIdentifier> id = default; Optional <string> name = default; Optional <ResourceType> type = default; Optional <AzureLocation> location = default; Optional <IDictionary <string, string> > tags = default; Optional <WritableSubResource> virtualHub = default; Optional <IList <VpnConnectionData> > connections = default; Optional <BgpSettings> bgpSettings = default; Optional <NetworkProvisioningState> provisioningState = default; Optional <int> vpnGatewayScaleUnit = default; Optional <IReadOnlyList <VpnGatewayIPConfiguration> > ipConfigurations = default; Optional <bool> isRoutingPreferenceInternet = default; Optional <IList <VpnGatewayNatRuleData> > natRules = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("etag")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } etag = new ETag(property.Value.GetString()); continue; } if (property.NameEquals("id")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } type = new ResourceType(property.Value.GetString()); continue; } if (property.NameEquals("location")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } location = new AzureLocation(property.Value.GetString()); continue; } if (property.NameEquals("tags")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var property0 in property.Value.EnumerateObject()) { dictionary.Add(property0.Name, property0.Value.GetString()); } tags = dictionary; continue; } if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("virtualHub")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } virtualHub = JsonSerializer.Deserialize <WritableSubResource>(property0.Value.ToString()); continue; } if (property0.NameEquals("connections")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <VpnConnectionData> array = new List <VpnConnectionData>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(VpnConnectionData.DeserializeVpnConnectionData(item)); } connections = array; continue; } if (property0.NameEquals("bgpSettings")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } bgpSettings = BgpSettings.DeserializeBgpSettings(property0.Value); continue; } if (property0.NameEquals("provisioningState")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } provisioningState = new NetworkProvisioningState(property0.Value.GetString()); continue; } if (property0.NameEquals("vpnGatewayScaleUnit")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } vpnGatewayScaleUnit = property0.Value.GetInt32(); continue; } if (property0.NameEquals("ipConfigurations")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <VpnGatewayIPConfiguration> array = new List <VpnGatewayIPConfiguration>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(VpnGatewayIPConfiguration.DeserializeVpnGatewayIPConfiguration(item)); } ipConfigurations = array; continue; } if (property0.NameEquals("isRoutingPreferenceInternet")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } isRoutingPreferenceInternet = property0.Value.GetBoolean(); continue; } if (property0.NameEquals("natRules")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <VpnGatewayNatRuleData> array = new List <VpnGatewayNatRuleData>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(VpnGatewayNatRuleData.DeserializeVpnGatewayNatRuleData(item)); } natRules = array; continue; } } continue; } } return(new VpnGatewayData(id.Value, name.Value, Optional.ToNullable(type), Optional.ToNullable(location), Optional.ToDictionary(tags), Optional.ToNullable(etag), virtualHub, Optional.ToList(connections), bgpSettings.Value, Optional.ToNullable(provisioningState), Optional.ToNullable(vpnGatewayScaleUnit), Optional.ToList(ipConfigurations), Optional.ToNullable(isRoutingPreferenceInternet), Optional.ToList(natRules))); }
internal VpnConnectionResource(ArmClient client, VpnConnectionData data) : this(client, data.Id) { HasData = true; _data = data; }
public virtual ArmOperation <VpnConnection> CreateOrUpdate(bool waitForCompletion, string connectionName, VpnConnectionData vpnConnectionParameters, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(connectionName, nameof(connectionName)); Argument.AssertNotNull(vpnConnectionParameters, nameof(vpnConnectionParameters)); using var scope = _vpnConnectionClientDiagnostics.CreateScope("VpnConnectionCollection.CreateOrUpdate"); scope.Start(); try { var response = _vpnConnectionRestClient.CreateOrUpdate(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, connectionName, vpnConnectionParameters, cancellationToken); var operation = new NetworkArmOperation <VpnConnection>(new VpnConnectionOperationSource(Client), _vpnConnectionClientDiagnostics, Pipeline, _vpnConnectionRestClient.CreateCreateOrUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, connectionName, vpnConnectionParameters).Request, response, OperationFinalStateVia.AzureAsyncOperation); if (waitForCompletion) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }