コード例 #1
0
        public override void Execute()
        {
            base.Execute();

            PSP2SVpnGateway existingP2SVpnGateway = null;

            if (ParameterSetName.Equals(CortexParameterSetNames.ByP2SVpnGatewayObject, StringComparison.OrdinalIgnoreCase))
            {
                existingP2SVpnGateway  = this.InputObject;
                this.ResourceGroupName = this.InputObject.ResourceGroupName;
                this.Name = this.InputObject.Name;
            }
            else
            {
                if (ParameterSetName.Equals(CortexParameterSetNames.ByP2SVpnGatewayResourceId, StringComparison.OrdinalIgnoreCase))
                {
                    var parsedResourceId = new ResourceIdentifier(ResourceId);
                    Name = parsedResourceId.ResourceName;
                    ResourceGroupName = parsedResourceId.ResourceGroupName;
                }

                existingP2SVpnGateway = this.GetP2SVpnGateway(this.ResourceGroupName, this.Name);
            }

            if (existingP2SVpnGateway == null)
            {
                throw new PSArgumentException(Properties.Resources.P2SVpnGatewayNotFound);
            }

            PSP2SVpnProfileParameters p2sVpnProfileParams = new PSP2SVpnProfileParameters();

            p2sVpnProfileParams.AuthenticationMethod = string.IsNullOrWhiteSpace(this.AuthenticationMethod)
                ? MNM.AuthenticationMethod.EAPTLS.ToString()
                : this.AuthenticationMethod;

            var p2sVpnProfileParametersModel = NetworkResourceManagerProfile.Mapper.Map <MNM.P2SVpnProfileParameters>(p2sVpnProfileParams);

            // There may be a required Json serialize for the package URL to conform to REST-API
            // The try-catch below handles the case till the change is made and deployed to PROD
            string serializedPackageUrl = this.NetworkClient.GenerateP2SVpnGatewayVpnProfile(this.ResourceGroupName, this.Name, p2sVpnProfileParametersModel);

            MNM.VpnProfileResponse p2sVpnGatewayVpnProfile = new MNM.VpnProfileResponse();
            try
            {
                p2sVpnGatewayVpnProfile = JsonConvert.DeserializeObject <MNM.VpnProfileResponse>(serializedPackageUrl);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            PSVpnProfileResponse vpnProfileResponse = new PSVpnProfileResponse()
            {
                ProfileUrl = p2sVpnGatewayVpnProfile?.ProfileUrl
            };

            WriteObject(vpnProfileResponse);
        }
        public override void Execute()
        {
            base.Execute();

            PSP2SVpnGateway existingP2SVpnGateway = null;

            if (ParameterSetName.Equals(CortexParameterSetNames.ByP2SVpnGatewayObject, StringComparison.OrdinalIgnoreCase))
            {
                existingP2SVpnGateway  = this.InputObject;
                this.ResourceGroupName = this.InputObject.ResourceGroupName;
                this.Name = this.InputObject.Name;
            }
            else
            {
                if (ParameterSetName.Equals(CortexParameterSetNames.ByP2SVpnGatewayResourceId, StringComparison.OrdinalIgnoreCase))
                {
                    var parsedResourceId = new ResourceIdentifier(ResourceId);
                    Name = parsedResourceId.ResourceName;
                    ResourceGroupName = parsedResourceId.ResourceGroupName;
                }

                existingP2SVpnGateway = this.GetP2SVpnGateway(this.ResourceGroupName, this.Name);
            }

            if (existingP2SVpnGateway == null)
            {
                throw new PSArgumentException(Properties.Resources.P2SVpnGatewayNotFound);
            }

            PSP2SVpnConnectionHealthRequest p2sVpnConnectionHealthParams = new PSP2SVpnConnectionHealthRequest();

            p2sVpnConnectionHealthParams.OutputBlobSasUrl   = this.OutputBlobSasUrl;
            p2sVpnConnectionHealthParams.VpnUserNamesFilter = this.VpnUserNamesFilter != null?this.VpnUserNamesFilter?.ToList() : new List <string>();

            var p2sVpnConnectionHealthParamsModel = NetworkResourceManagerProfile.Mapper.Map <MNM.P2SVpnConnectionHealthRequest>(p2sVpnConnectionHealthParams);

            // There may be a required Json serialize for the returned contents to conform to REST-API
            // The try-catch below handles the case till the change is made and deployed to PROD
            string serializedP2SVpnGatewayDetailedConnectionHealth = this.NetworkClient.GetP2SVpnGatewayDetailedConnectionHealth(this.ResourceGroupName, this.Name, p2sVpnConnectionHealthParamsModel);

            MNM.P2SVpnConnectionHealth p2sVpnGatewayDetailedConnectionHealth = new MNM.P2SVpnConnectionHealth();
            try
            {
                p2sVpnGatewayDetailedConnectionHealth = JsonConvert.DeserializeObject <MNM.P2SVpnConnectionHealth>(serializedP2SVpnGatewayDetailedConnectionHealth);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            PSP2SVpnConnectionHealth p2sVpnGatewayWithHealthResponse = new PSP2SVpnConnectionHealth()
            {
                SasUrl = p2sVpnGatewayDetailedConnectionHealth?.SasUrl
            };

            WriteObject(p2sVpnGatewayWithHealthResponse);
        }
コード例 #3
0
        public PSP2SVpnGateway CreateOrUpdateP2SVpnGateway(string resourceGroupName, string p2sVpnGatewayName, PSP2SVpnGateway p2sVpnGateway, Hashtable tags)
        {
            var p2sVpnGatewayModel = NetworkResourceManagerProfile.Mapper.Map <MNM.P2SVpnGateway>(p2sVpnGateway);

            p2sVpnGatewayModel.Tags = TagsConversionHelper.CreateTagDictionary(tags, validate: true);

            var             p2sVpnGatewayCreatedOrUpdated = this.P2SVpnGatewayClient.CreateOrUpdate(resourceGroupName, p2sVpnGatewayName, p2sVpnGatewayModel);
            PSP2SVpnGateway gatewayToReturn = this.ToPsP2SVpnGateway(p2sVpnGatewayCreatedOrUpdated);

            gatewayToReturn.ResourceGroupName = resourceGroupName;

            return(gatewayToReturn);
        }
コード例 #4
0
        public override void Execute()
        {
            base.Execute();

            PSP2SVpnGateway existingP2SVpnGateway = null;

            if (ParameterSetName.Equals(CortexParameterSetNames.ByP2SVpnGatewayObject, StringComparison.OrdinalIgnoreCase))
            {
                existingP2SVpnGateway  = this.InputObject;
                this.ResourceGroupName = this.InputObject.ResourceGroupName;
                this.Name = this.InputObject.Name;
            }
            else
            {
                if (ParameterSetName.Equals(CortexParameterSetNames.ByP2SVpnGatewayResourceId, StringComparison.OrdinalIgnoreCase))
                {
                    var parsedResourceId = new ResourceIdentifier(ResourceId);
                    Name = parsedResourceId.ResourceName;
                    ResourceGroupName = parsedResourceId.ResourceGroupName;
                }

                existingP2SVpnGateway = this.GetP2SVpnGateway(this.ResourceGroupName, this.Name);
            }

            if (existingP2SVpnGateway == null)
            {
                throw new PSArgumentException(Properties.Resources.P2SVpnGatewayNotFound);
            }

            // There may be a required Json serialize for the returned contents to conform to REST-API
            // The try-catch below handles the case till the change is made and deployed to PROD
            string serializedP2SVpnGatewayConnectionHealth = this.NetworkClient.GetP2SVpnGatewayConnectionHealth(this.ResourceGroupName, this.Name);

            WriteObject(serializedP2SVpnGatewayConnectionHealth);

            MNM.P2SVpnGateway p2sVpnGatewayConnectionHealth = new MNM.P2SVpnGateway();
            try
            {
                p2sVpnGatewayConnectionHealth = JsonConvert.DeserializeObject <MNM.P2SVpnGateway>(serializedP2SVpnGatewayConnectionHealth);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            var psP2SVpnGatewayConnectionHealth = this.ToPsP2SVpnGateway(p2sVpnGatewayConnectionHealth);

            psP2SVpnGatewayConnectionHealth.ResourceGroupName = this.ResourceGroupName;
            WriteObject(psP2SVpnGatewayConnectionHealth);
        }
コード例 #5
0
        public List <PSP2SVpnGateway> ListP2SVpnGateways(string resourceGroupName)
        {
            var p2sVpnGateways = ShouldListBySubscription(resourceGroupName, null) ?
                                 this.P2SVpnGatewayClient.List() :                                //// List by sub id
                                 this.P2SVpnGatewayClient.ListByResourceGroup(resourceGroupName); //// List by RG name

            List <PSP2SVpnGateway> gatewaysToReturn = new List <PSP2SVpnGateway>();

            if (p2sVpnGateways != null)
            {
                foreach (MNM.P2SVpnGateway gateway in p2sVpnGateways)
                {
                    PSP2SVpnGateway gatewayToReturn = ToPsP2SVpnGateway(gateway);
                    gatewayToReturn.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(gateway.Id);
                    gatewaysToReturn.Add(gatewayToReturn);
                }
            }

            return(gatewaysToReturn);
        }
コード例 #6
0
        public override void Execute()
        {
            PSP2SVpnGateway existingVpnGateway = null;

            if (ParameterSetName.Equals(CortexParameterSetNames.ByP2SVpnGatewayObject))
            {
                existingVpnGateway     = this.InputObject;
                this.ResourceGroupName = this.InputObject.ResourceGroupName;
                this.Name = this.InputObject.Name;
            }
            else
            {
                if (ParameterSetName.Equals(CortexParameterSetNames.ByP2SVpnGatewayResourceId))
                {
                    var parsedResourceId = new ResourceIdentifier(ResourceId);
                    Name = parsedResourceId.ResourceName;
                    ResourceGroupName = parsedResourceId.ResourceGroupName;
                }

                existingVpnGateway = this.GetP2SVpnGateway(this.ResourceGroupName, this.Name);
            }

            if (existingVpnGateway == null)
            {
                throw new PSArgumentException(Properties.Resources.P2SVpnGatewayNotFound);
            }

            string shouldProcessMessage = string.Format("Execute {0}P2sVpnGateway for ResourceGroupName {1} P2SVpnGateway {2}", ResourceManager.Common.AzureRMConstants.AzureRMPrefix, this.ResourceGroupName, this.Name);

            if (ShouldProcess(shouldProcessMessage, VerbsCommon.Reset))
            {
                this.P2SVpnGatewayClient.Reset(this.ResourceGroupName, this.Name);

                var getVpnGateway = this.GetP2SVpnGateway(this.ResourceGroupName, this.Name);
                WriteObject(getVpnGateway);
            }
        }
コード例 #7
0
        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));
            });
        }
コード例 #8
0
        public override void Execute()
        {
            PSP2SVpnGateway existingP2SVpnGateway = null;

            if (ParameterSetName.Contains(CortexParameterSetNames.ByP2SVpnGatewayObject))
            {
                existingP2SVpnGateway  = this.InputObject;
                this.ResourceGroupName = this.InputObject.ResourceGroupName;
                this.Name = this.InputObject.Name;
            }
            else
            {
                if (ParameterSetName.Contains(CortexParameterSetNames.ByP2SVpnGatewayResourceId))
                {
                    var parsedResourceId = new ResourceIdentifier(ResourceId);
                    Name = parsedResourceId.ResourceName;
                    ResourceGroupName = parsedResourceId.ResourceGroupName;
                }

                existingP2SVpnGateway = this.GetP2SVpnGateway(this.ResourceGroupName, this.Name);
            }

            if (existingP2SVpnGateway == null)
            {
                throw new PSArgumentException(Properties.Resources.P2SVpnGatewayNotFound);
            }

            //// Modify scale unit if specified
            if (this.VpnGatewayScaleUnit > 0)
            {
                existingP2SVpnGateway.VpnGatewayScaleUnit = Convert.ToInt32(this.VpnGatewayScaleUnit);
            }

            //// Modify the P2SConnectionConfigurations
            if (this.VpnClientAddressPool != null)
            {
                if (existingP2SVpnGateway.P2SConnectionConfigurations != null && existingP2SVpnGateway.P2SConnectionConfigurations.Any())
                {
                    existingP2SVpnGateway.P2SConnectionConfigurations[0].VpnClientAddressPool.AddressPrefixes.Clear();
                    existingP2SVpnGateway.P2SConnectionConfigurations[0].VpnClientAddressPool.AddressPrefixes = new List <string>(this.VpnClientAddressPool);
                }
                else
                {
                    PSP2SConnectionConfiguration p2sConnectionConfig = new PSP2SConnectionConfiguration()
                    {
                        Name = P2SConnectionConfigurationName,
                        VpnClientAddressPool = new PSAddressSpace()
                        {
                            AddressPrefixes = new List <string>(this.VpnClientAddressPool)
                        }
                    };
                    existingP2SVpnGateway.P2SConnectionConfigurations = new List <PSP2SConnectionConfiguration>()
                    {
                        p2sConnectionConfig
                    };
                }
            }

            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);
                }

                if (existingP2SVpnGateway.P2SConnectionConfigurations != null && existingP2SVpnGateway.P2SConnectionConfigurations.Any())
                {
                    existingP2SVpnGateway.P2SConnectionConfigurations[0].RoutingConfiguration = RoutingConfiguration;
                }
                else
                {
                    PSP2SConnectionConfiguration p2sConnectionConfig = new PSP2SConnectionConfiguration()
                    {
                        Name = P2SConnectionConfigurationName,
                        RoutingConfiguration = RoutingConfiguration
                    };
                    existingP2SVpnGateway.P2SConnectionConfigurations = new List <PSP2SConnectionConfiguration>()
                    {
                        p2sConnectionConfig
                    };
                }
            }

            // Set the custom dns servers, if it is specified by customer.
            if (CustomDnsServer != null && this.CustomDnsServer.Any())
            {
                existingP2SVpnGateway.CustomDnsServers = CustomDnsServer?.ToList();
            }
            else
            {
                existingP2SVpnGateway.CustomDnsServers = null;
            }

            //// Resolve the VpnServerConfiguration, if specified
            string vpnServerConfigurationResourceGroupName = string.Empty;
            string vpnServerConfigurationName = string.Empty;

            if (!ParameterSetName.Contains(CortexParameterSetNames.NoVpnServerConfigurationUpdate))
            {
                if (ParameterSetName.Contains(CortexParameterSetNames.ByVpnServerConfigurationObject))
                {
                    vpnServerConfigurationResourceGroupName = this.VpnServerConfiguration.ResourceGroupName;
                    vpnServerConfigurationName = this.VpnServerConfiguration.Name;
                }
                else if (ParameterSetName.Contains(CortexParameterSetNames.ByVpnServerConfigurationResourceId))
                {
                    var parsedVpnServerConfigurationResourceId = new ResourceIdentifier(this.VpnServerConfigurationId);
                    vpnServerConfigurationResourceGroupName = parsedVpnServerConfigurationResourceId.ResourceGroupName;
                    vpnServerConfigurationName = parsedVpnServerConfigurationResourceId.ResourceName;
                }

                if (!string.IsNullOrWhiteSpace(vpnServerConfigurationResourceGroupName) && !string.IsNullOrWhiteSpace(vpnServerConfigurationName))
                {
                    PSVpnServerConfiguration resolvedVpnServerConfiguration = new VpnServerConfigurationBaseCmdlet().GetVpnServerConfiguration(vpnServerConfigurationResourceGroupName, vpnServerConfigurationName);

                    if (resolvedVpnServerConfiguration == null)
                    {
                        throw new PSArgumentException(Properties.Resources.VpnServerConfigurationNotFound);
                    }

                    existingP2SVpnGateway.VpnServerConfiguration = new PSResourceId()
                    {
                        Id = resolvedVpnServerConfiguration.Id
                    };
                }
            }

            ConfirmAction(
                Properties.Resources.SettingResourceMessage,
                this.Name,
                () =>
            {
                WriteVerbose(String.Format(Properties.Resources.UpdatingLongRunningOperationMessage, this.ResourceGroupName, this.Name));
                WriteObject(this.CreateOrUpdateP2SVpnGateway(this.ResourceGroupName, this.Name, existingP2SVpnGateway, this.Tag));
            });
        }