private PSVirtualWan CreateVirtualWan()
        {
            if (this.IsVirtualWanPresent(this.ResourceGroupName, this.Name))
            {
                throw new PSArgumentException(string.Format(Properties.Resources.ResourceAlreadyPresentInResourceGroup, this.Name, this.ResourceGroupName));
            }

            var virtualWan = new PSVirtualWan();

            virtualWan.Name = this.Name;
            virtualWan.ResourceGroupName          = this.ResourceGroupName;
            virtualWan.Location                   = this.Location;
            virtualWan.AllowBranchToBranchTraffic = this.AllowBranchToBranchTraffic.IsPresent;
            virtualWan.AllowVnetToVnetTraffic     = true;

            if (string.IsNullOrWhiteSpace(this.VirtualWANType))
            {
                virtualWan.VirtualWANType = "Standard";
            }

            var virtualWanModel = NetworkResourceManagerProfile.Mapper.Map <MNM.VirtualWAN>(virtualWan);

            virtualWanModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);

            this.VirtualWanClient.CreateOrUpdate(this.ResourceGroupName, this.Name, virtualWanModel);

            return(this.GetVirtualWan(this.ResourceGroupName, this.Name));
        }
예제 #2
0
        private PSVirtualWan UpdateVirtualWan()
        {
            PSVirtualWan virtualWanToUpdate = null;

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

                virtualWanToUpdate = GetVirtualWan(this.ResourceGroupName, this.Name);
            }

            if (virtualWanToUpdate == null)
            {
                throw new PSArgumentException(Properties.Resources.VirtualWanNotFound);
            }

            if (this.AllowBranchToBranchTraffic.HasValue)
            {
                virtualWanToUpdate.AllowBranchToBranchTraffic = this.AllowBranchToBranchTraffic.Value;
            }

            if (this.AllowVnetToVnetTraffic.HasValue)
            {
                virtualWanToUpdate.AllowVnetToVnetTraffic = true;
            }

            if (!string.IsNullOrWhiteSpace(this.VirtualWANType))
            {
                virtualWanToUpdate.VirtualWANType = this.VirtualWANType;
            }

            var virtualWanModel = NetworkResourceManagerProfile.Mapper.Map <MNM.VirtualWAN>(virtualWanToUpdate);

            virtualWanModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);

            this.VirtualWanClient.CreateOrUpdate(this.ResourceGroupName, this.Name, virtualWanModel);

            return(this.GetVirtualWan(this.ResourceGroupName, this.Name));
        }
        public override void Execute()
        {
            base.Execute();

            PSVirtualWan virtualWan = null;

            if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualWanObject, StringComparison.OrdinalIgnoreCase))
            {
                virtualWan             = this.VirtualWanObject;
                this.ResourceGroupName = this.VirtualWanObject.ResourceGroupName;
                this.Name = this.VirtualWanObject.Name;
            }
            else
            {
                if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualWanResourceId, StringComparison.OrdinalIgnoreCase))
                {
                    var parsedResourceId = new ResourceIdentifier(this.ResourceId);
                    this.Name = parsedResourceId.ResourceName;
                    this.ResourceGroupName = parsedResourceId.ResourceGroupName;
                }

                virtualWan = GetVirtualWan(this.ResourceGroupName, this.Name);
            }

            if (virtualWan == null)
            {
                throw new PSArgumentException(Properties.Resources.VirtualWanNotFound);
            }

            // 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 serializedVpnServerConfigurations = this.NetworkClient.GetVirtualWanVpnServerConfigurations(this.ResourceGroupName, this.Name);

            MNM.VpnServerConfigurationsResponse vpnServerConfigurations = new MNM.VpnServerConfigurationsResponse();
            try
            {
                vpnServerConfigurations = JsonConvert.DeserializeObject <MNM.VpnServerConfigurationsResponse>(serializedVpnServerConfigurations);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            PSVpnServerConfigurationsResponse vpnServerConfigurationsResponse = new PSVpnServerConfigurationsResponse()
            {
                VpnServerConfigurationResourceIds = vpnServerConfigurations?.VpnServerConfigurationResourceIds.ToList()
            };

            WriteObject(vpnServerConfigurationsResponse);
        }
        public PSVirtualWanVpnSitesConfiguration GetVirtualWanVpnSitesConfiguration(PSVirtualWan virtualWan, List <string> vpnSiteIds, string outputBlobSasUrl)
        {
            GetVpnSitesConfigurationRequest request = new GetVpnSitesConfigurationRequest();

            request.OutputBlobSasUrl = outputBlobSasUrl;
            request.VpnSites         = new List <string>();

            foreach (string vpnSiteId in vpnSiteIds)
            {
                request.VpnSites.Add(vpnSiteId);
            }

            this.VpnSitesConfigurationClient.Download(virtualWan.ResourceGroupName, virtualWan.Name, request);

            return(new PSVirtualWanVpnSitesConfiguration()
            {
                SasUrl = outputBlobSasUrl
            });
        }
        public List <PSVirtualWan> ListVirtualWans(string resourceGroupName)
        {
            var virtualWans = ShouldListBySubscription(resourceGroupName, null) ?
                              this.VirtualWanClient.List() :                                //// List by sub id
                              this.VirtualWanClient.ListByResourceGroup(resourceGroupName); //// List by RG name

            List <PSVirtualWan> wansToReturn = new List <PSVirtualWan>();

            if (virtualWans != null)
            {
                foreach (MNM.VirtualWAN virtualWan in virtualWans)
                {
                    PSVirtualWan wanToReturn = ToPsVirtualWan(virtualWan);
                    wanToReturn.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(virtualWan.Id);
                    wansToReturn.Add(wanToReturn);
                }
            }

            return(wansToReturn);
        }
예제 #6
0
        public List <PSVirtualWan> ListVirtualWans(string resourceGroupName)
        {
            var virtualWans = string.IsNullOrWhiteSpace(resourceGroupName) ?
                              this.VirtualWanClient.List() :                                //// List by sub id
                              this.VirtualWanClient.ListByResourceGroup(resourceGroupName); //// List by RG name

            List <PSVirtualWan> wansToReturn = new List <PSVirtualWan>();

            if (virtualWans != null)
            {
                foreach (MNM.VirtualWAN virtualWan in virtualWans)
                {
                    PSVirtualWan wanToReturn = ToPsVirtualWan(virtualWan);
                    wanToReturn.ResourceGroupName = resourceGroupName;
                    wansToReturn.Add(wanToReturn);
                }
            }

            return(wansToReturn);
        }
        public override void Execute()
        {
            base.Execute();

            //// Resolve the virtual wan
            if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualWanObject))
            {
                this.ResourceGroupName = this.InputObject.ResourceGroupName;
                this.Name = this.InputObject.Name;
            }
            else if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualWanResourceId))
            {
                var parsedResourceId = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName = parsedResourceId.ResourceGroupName;
                this.Name = parsedResourceId.ResourceName;
            }

            if (string.IsNullOrWhiteSpace(this.ResourceGroupName) || string.IsNullOrWhiteSpace(this.Name))
            {
                throw new PSArgumentException(Properties.Resources.VirtualWanRequiredForVpnSiteConfiguration);
            }

            PSVirtualWan virtualWan = this.GetVirtualWan(this.ResourceGroupName, this.Name);

            List <string> vpnSiteIdsToGetConfigurationFor = new List <string>();

            if (ParameterSetName.Contains(CortexParameterSetNames.ByVpnSiteObject))
            {
                foreach (PSVpnSite psVpnSite in this.VpnSite)
                {
                    vpnSiteIdsToGetConfigurationFor.Add(psVpnSite.Id);
                }
            }

            if (ParameterSetName.Contains(CortexParameterSetNames.ByVpnSiteResourceId))
            {
                vpnSiteIdsToGetConfigurationFor.AddRange(this.VpnSiteId);
            }

            WriteObject(this.GetVirtualWanVpnSitesConfiguration(virtualWan, vpnSiteIdsToGetConfigurationFor, this.StorageSasUrl));
        }
예제 #8
0
        public override void Execute()
        {
            base.Execute();

            PSVirtualWan virtualWan = null;

            if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualWanObject))
            {
                virtualWan             = this.VirtualWanObject;
                this.ResourceGroupName = this.VirtualWanObject.ResourceGroupName;
                this.Name = this.VirtualWanObject.Name;
            }
            else
            {
                if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualWanResourceId))
                {
                    var parsedResourceId = new ResourceIdentifier(this.ResourceId);
                    this.Name = parsedResourceId.ResourceName;
                    this.ResourceGroupName = parsedResourceId.ResourceGroupName;
                }

                virtualWan = GetVirtualWan(this.ResourceGroupName, this.Name);
            }

            if (virtualWan == null)
            {
                throw new PSArgumentException(Properties.Resources.VirtualWanNotFound);
            }

            PSVirtualWanVpnProfileParameters virtualWanVpnProfileParams = new PSVirtualWanVpnProfileParameters();

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

            if (this.VpnServerConfiguration != null)
            {
                virtualWanVpnProfileParams.VpnServerConfigurationResourceId = this.VpnServerConfiguration.Id;
            }

            var virtualWanVpnProfileParametersModel = NetworkResourceManagerProfile.Mapper.Map <MNM.VirtualWanVpnProfileParameters>(virtualWanVpnProfileParams);

            // 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.GenerateVirtualWanVpnProfile(this.ResourceGroupName, this.Name, virtualWanVpnProfileParametersModel);

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

            PSVpnProfileResponse vpnProfileResponse = new PSVpnProfileResponse()
            {
                ProfileUrl = vpnProfile.ProfileUrl
            };

            WriteObject(vpnProfileResponse);
        }