public override void Execute() { base.Execute(); if (this.IsExpressRouteGatewayPresent(this.ResourceGroupName, this.Name)) { throw new PSArgumentException(string.Format(Properties.Resources.ResourceAlreadyPresentInResourceGroup, this.Name, this.ResourceGroupName)); } var expressRouteGateway = new PSExpressRouteGateway(); expressRouteGateway.Name = this.Name; expressRouteGateway.ResourceGroupName = this.ResourceGroupName; expressRouteGateway.VirtualHub = null; //// Resolve and Set the virtual hub if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubObject, StringComparison.OrdinalIgnoreCase)) { this.VirtualHubName = this.VirtualHub.Name; } else if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubResourceId, StringComparison.OrdinalIgnoreCase)) { var parsedResourceId = new ResourceIdentifier(this.VirtualHubId); this.VirtualHubName = parsedResourceId.ResourceName; } //// At this point, we should have the virtual hub name resolved. Fail this operation if it is not. if (string.IsNullOrWhiteSpace(this.VirtualHubName)) { throw new PSArgumentException(Properties.Resources.VirtualHubRequiredForExpressRouteGateway); } var resolvedVirtualHub = new VirtualHubBaseCmdlet().GetVirtualHub(this.ResourceGroupName, this.VirtualHubName); expressRouteGateway.Location = resolvedVirtualHub.Location; expressRouteGateway.VirtualHub = new PSVirtualHubId() { Id = resolvedVirtualHub.Id }; if (this.MaxScaleUnits > 0 && this.MinScaleUnits > this.MaxScaleUnits) { throw new PSArgumentException(string.Format(Properties.Resources.InvalidAutoScaleConfiguration, this.MinScaleUnits, this.MaxScaleUnits)); } expressRouteGateway.AutoScaleConfiguration = new PSExpressRouteGatewayAutoscaleConfiguration(); expressRouteGateway.AutoScaleConfiguration.Bounds = new PSExpressRouteGatewayPropertiesAutoScaleConfigurationBounds(); expressRouteGateway.AutoScaleConfiguration.Bounds.Min = Convert.ToInt32(this.MinScaleUnits); expressRouteGateway.AutoScaleConfiguration.Bounds.Max = (this.MaxScaleUnits > 0) ? Convert.ToInt32(this.MaxScaleUnits) : Convert.ToInt32(this.MinScaleUnits); ConfirmAction( Properties.Resources.CreatingResourceMessage, this.Name, () => { WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name)); WriteObject(this.CreateOrUpdateExpressRouteGateway(this.ResourceGroupName, this.Name, expressRouteGateway, this.Tag)); }); }
public void IsParentVirtualHubPresent(string resourceGroupName, string parentHubName) { // Get the virtual hub - this will throw not found if the resource does not exist PSVirtualHub resolvedVirtualHub = new VirtualHubBaseCmdlet().GetVirtualHub(resourceGroupName, parentHubName); if (resolvedVirtualHub == null) { throw new PSArgumentException(Properties.Resources.ParentVirtualHubNotFound); } }
public override void Execute() { base.Execute(); if (this.IsP2SVpnGatewayPresent(this.ResourceGroupName, this.Name)) { throw new PSArgumentException(string.Format(Properties.Resources.ResourceAlreadyPresentInResourceGroup, this.Name, this.ResourceGroupName)); } var p2sVpnGateway = new PSP2SVpnGateway(); p2sVpnGateway.Name = this.Name; p2sVpnGateway.ResourceGroupName = this.ResourceGroupName; p2sVpnGateway.VirtualHub = null; p2sVpnGateway.VpnServerConfiguration = null; string virtualHubResourceGroupName = this.ResourceGroupName; // default to common RG for ByVirtualHubName parameter set //// Resolve and Set the virtual hub if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualHubObject)) { this.VirtualHubName = this.VirtualHub.Name; virtualHubResourceGroupName = this.VirtualHub.ResourceGroupName; } else if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualHubResourceId)) { var parsedResourceId = new ResourceIdentifier(this.VirtualHubId); this.VirtualHubName = parsedResourceId.ResourceName; virtualHubResourceGroupName = parsedResourceId.ResourceGroupName; } //// At this point, we should have the virtual hub name resolved. Fail this operation if it is not. if (string.IsNullOrWhiteSpace(this.VirtualHubName)) { throw new PSArgumentException(Properties.Resources.VirtualHubRequiredForVpnGateway); } var resolvedVirtualHub = new VirtualHubBaseCmdlet().GetVirtualHub(virtualHubResourceGroupName, this.VirtualHubName); if (resolvedVirtualHub == null) { throw new PSArgumentException(Properties.Resources.VirtualHubRequiredForExpressRouteGateway); } p2sVpnGateway.Location = resolvedVirtualHub.Location; p2sVpnGateway.VirtualHub = new PSResourceId() { Id = resolvedVirtualHub.Id }; //// Set P2SConnectionConfigurations. Currently, only one P2SConnectionConfiguration is allowed. PSP2SConnectionConfiguration p2sConnectionConfig = new PSP2SConnectionConfiguration() { Name = P2SConnectionConfigurationName, VpnClientAddressPool = new PSAddressSpace() { AddressPrefixes = new List <string>(this.VpnClientAddressPool) }, }; // By default EnableInternetSecurity will be true if not specified explicitly by customer. p2sConnectionConfig.EnableInternetSecurity = true; if (this.EnableInternetSecurityFlag.IsPresent) { p2sConnectionConfig.EnableInternetSecurity = true; } if (this.DisableInternetSecurityFlag.IsPresent) { p2sConnectionConfig.EnableInternetSecurity = false; } if (this.RoutingConfiguration != null) { if (this.RoutingConfiguration.VnetRoutes != null && this.RoutingConfiguration.VnetRoutes.StaticRoutes != null && this.RoutingConfiguration.VnetRoutes.StaticRoutes.Any()) { throw new PSArgumentException(Properties.Resources.StaticRoutesNotSupportedForThisRoutingConfiguration); } p2sConnectionConfig.RoutingConfiguration = RoutingConfiguration; } p2sVpnGateway.P2SConnectionConfigurations = new List <PSP2SConnectionConfiguration>() { p2sConnectionConfig }; //// Scale unit, if specified p2sVpnGateway.VpnGatewayScaleUnit = 0; if (this.VpnGatewayScaleUnit > 0) { p2sVpnGateway.VpnGatewayScaleUnit = Convert.ToInt32(this.VpnGatewayScaleUnit); } //// Resolve the VpnServerConfiguration reference //// And set it in the P2SVpnGateway object. string vpnServerConfigurationResolvedId = null; if (ParameterSetName.Contains(CortexParameterSetNames.ByVpnServerConfigurationObject)) { vpnServerConfigurationResolvedId = this.VpnServerConfiguration.Id; } else if (ParameterSetName.Contains(CortexParameterSetNames.ByVpnServerConfigurationResourceId)) { vpnServerConfigurationResolvedId = this.VpnServerConfigurationId; } if (string.IsNullOrWhiteSpace(vpnServerConfigurationResolvedId)) { throw new PSArgumentException(Properties.Resources.VpnServerConfigurationRequiredForP2SVpnGateway); } //// Let's not resolve the vpnServerConfiguration here. If this does not exist, NRP/GWM will fail the call. p2sVpnGateway.VpnServerConfiguration = new PSResourceId() { Id = vpnServerConfigurationResolvedId }; p2sVpnGateway.VpnServerConfigurationLocation = string.IsNullOrWhiteSpace(this.VpnServerConfiguration.Location) ? string.Empty : this.VpnServerConfiguration.Location; // Set the custom dns servers, if it is specified by customer. if (CustomDnsServer != null && this.CustomDnsServer.Any()) { p2sVpnGateway.CustomDnsServers = CustomDnsServer?.ToList(); } // Set the Routing Preference Internet, if it is specified by customer. p2sVpnGateway.IsRoutingPreferenceInternet = EnableRoutingPreferenceInternetFlag.IsPresent; ConfirmAction( Properties.Resources.CreatingResourceMessage, this.Name, () => { WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name)); WriteObject(this.CreateOrUpdateP2SVpnGateway(this.ResourceGroupName, this.Name, p2sVpnGateway, this.Tag)); }); }
public override void Execute() { base.Execute(); if (this.IsVpnGatewayPresent(this.ResourceGroupName, this.Name)) { throw new PSArgumentException(string.Format(Properties.Resources.ResourceAlreadyPresentInResourceGroup, this.Name, this.ResourceGroupName)); } var vpnGateway = new PSVpnGateway(); vpnGateway.Name = this.Name; vpnGateway.ResourceGroupName = this.ResourceGroupName; vpnGateway.VirtualHub = null; //// Resolve and Set the virtual hub if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubObject, StringComparison.OrdinalIgnoreCase)) { this.VirtualHubName = this.VirtualHub.Name; } else if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubResourceId, StringComparison.OrdinalIgnoreCase)) { var parsedResourceId = new ResourceIdentifier(this.VirtualHubId); this.VirtualHubName = parsedResourceId.ResourceName; } //// At this point, we should have the virtual hub name resolved. Fail this operation if it is not. if (string.IsNullOrWhiteSpace(this.VirtualHubName)) { throw new PSArgumentException(Properties.Resources.VirtualHubRequiredForVpnGateway); } var resolvedVirtualHub = new VirtualHubBaseCmdlet().GetVirtualHub(this.ResourceGroupName, this.VirtualHubName); vpnGateway.Location = resolvedVirtualHub.Location; vpnGateway.VirtualHub = new PSResourceId() { Id = resolvedVirtualHub.Id }; //// VpnConnections, if specified vpnGateway.Connections = new List <PSVpnConnection>(); if (this.VpnConnection != null && this.VpnConnection.Any()) { vpnGateway.Connections.AddRange(this.VpnConnection); } //// Scale unit, if specified vpnGateway.VpnGatewayScaleUnit = 0; if (this.VpnGatewayScaleUnit > 0) { vpnGateway.VpnGatewayScaleUnit = Convert.ToInt32(this.VpnGatewayScaleUnit); } vpnGateway.BgpSettings = null; ConfirmAction( Properties.Resources.CreatingResourceMessage, this.Name, () => { WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name)); WriteObject(this.CreateOrUpdateVpnGateway(this.ResourceGroupName, this.Name, vpnGateway, this.Tag)); }); }