示例#1
0
        public PSVpnSite CreateOrUpdateVpnSite(string resourceGroupName, string vpnSiteName, PSVpnSite vpnSite, Hashtable tags)
        {
            var vpnSiteModel = NetworkResourceManagerProfile.Mapper.Map <MNM.VpnSite>(vpnSite);

            vpnSiteModel.Location = vpnSite.Location;
            vpnSiteModel.Tags     = TagsConversionHelper.CreateTagDictionary(tags, validate: true);

            var       vpnSiteCreatedOrUpdated = this.VpnSiteClient.CreateOrUpdate(resourceGroupName, vpnSiteName, vpnSiteModel);
            PSVpnSite siteToReturn            = ToPsVpnSite(vpnSiteCreatedOrUpdated);

            siteToReturn.ResourceGroupName = resourceGroupName;

            return(siteToReturn);
        }
示例#2
0
        public List <PSVpnSite> ListVpnSites(string resourceGroupName)
        {
            var vpnSites = ShouldListBySubscription(resourceGroupName, null) ?
                           this.VpnSiteClient.List() :                                //// List by SubId
                           this.VpnSiteClient.ListByResourceGroup(resourceGroupName); //// List by RG Name

            List <PSVpnSite> sitesToReturn = new List <PSVpnSite>();

            if (vpnSites != null)
            {
                foreach (MNM.VpnSite vpnSite in vpnSites)
                {
                    PSVpnSite siteToReturn = ToPsVpnSite(vpnSite);
                    siteToReturn.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(vpnSite.Id);
                    sitesToReturn.Add(siteToReturn);
                }
            }

            return(sitesToReturn);
        }
        public List <PSVpnSite> ListVpnSites(string resourceGroupName)
        {
            var vpnSites = string.IsNullOrWhiteSpace(resourceGroupName) ?
                           this.VpnSiteClient.List() :                                //// List by SubId
                           this.VpnSiteClient.ListByResourceGroup(resourceGroupName); //// List by RG Name

            List <PSVpnSite> sitesToReturn = new List <PSVpnSite>();

            if (vpnSites != null)
            {
                foreach (MNM.VpnSite vpnSite in vpnSites)
                {
                    PSVpnSite siteToReturn = ToPsVpnSite(vpnSite);
                    siteToReturn.ResourceGroupName = resourceGroupName;
                    sitesToReturn.Add(siteToReturn);
                }
            }

            return(sitesToReturn);
        }
示例#4
0
        public override void Execute()
        {
            base.Execute();

            PSVpnSite vpnSiteToCreate = new PSVpnSite();

            vpnSiteToCreate.ResourceGroupName = this.ResourceGroupName;
            vpnSiteToCreate.Name     = this.Name;
            vpnSiteToCreate.Location = this.Location;

            if (this.IsVpnSitePresent(this.ResourceGroupName, this.Name))
            {
                throw new PSArgumentException(string.Format(Properties.Resources.ResourceAlreadyPresentInResourceGroup, this.Name, this.ResourceGroupName));
            }

            //// Resolve the virtual wan
            if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualWanObject))
            {
                this.VirtualWanResourceGroupName = this.VirtualWan.ResourceGroupName;
                this.VirtualWanName = this.VirtualWan.Name;
            }
            else if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualWanResourceId))
            {
                var parsedWanResourceId = new ResourceIdentifier(this.VirtualWanId);
                this.VirtualWanResourceGroupName = parsedWanResourceId.ResourceGroupName;
                this.VirtualWanName = parsedWanResourceId.ResourceName;
            }

            PSVirtualWan resolvedVirtualWan = new VirtualWanBaseCmdlet().GetVirtualWan(this.VirtualWanResourceGroupName, this.VirtualWanName);

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

            vpnSiteToCreate.VirtualWan = new PSResourceId()
            {
                Id = resolvedVirtualWan.Id
            };

            //// VpnSite device settings
            if (!string.IsNullOrWhiteSpace(this.DeviceModel) || !string.IsNullOrWhiteSpace(this.DeviceVendor))
            {
                vpnSiteToCreate.DeviceProperties = this.ValidateAndCreateVpnSiteDeviceProperties(
                    this.DeviceModel ?? string.Empty,
                    this.DeviceVendor ?? string.Empty,
                    this.LinkSpeedInMbps);
            }

            if (ParameterSetName.Contains(CortexParameterSetNames.ByVpnSiteIpAddress))
            {
                //// IpAddress
                System.Net.IPAddress ipAddress;
                if (!System.Net.IPAddress.TryParse(this.IpAddress, out ipAddress))
                {
                    throw new PSArgumentException(Properties.Resources.InvalidIPAddress);
                }

                vpnSiteToCreate.IpAddress = this.IpAddress;

                //// Bgp Settings
                if (this.BgpAsn > 0 || this.BgpPeeringWeight > 0 || !string.IsNullOrWhiteSpace(this.BgpPeeringAddress))
                {
                    vpnSiteToCreate.BgpSettings = this.ValidateAndCreatePSBgpSettings(this.BgpAsn, this.BgpPeeringWeight, this.BgpPeeringAddress);
                }
            }

            //// Address spaces
            if (this.AddressSpace != null && this.AddressSpace.Any())
            {
                vpnSiteToCreate.AddressSpace = new PSAddressSpace();
                vpnSiteToCreate.AddressSpace.AddressPrefixes = new List <string>();
                vpnSiteToCreate.AddressSpace.AddressPrefixes.AddRange(this.AddressSpace);
            }

            if (this.VpnSiteLink != null)
            {
                //// Use only link properties instead of Site properties.
                if (this.BgpAsn > 0 || this.BgpPeeringWeight > 0 || !string.IsNullOrWhiteSpace(this.BgpPeeringAddress) || this.LinkSpeedInMbps > 0 || !string.IsNullOrWhiteSpace(this.IpAddress))
                {
                    throw new PSArgumentException(Properties.Resources.VpnSitePropertyIsDeprecated);
                }

                vpnSiteToCreate.VpnSiteLinks = new List <PSVpnSiteLink>();
                vpnSiteToCreate.VpnSiteLinks.AddRange(this.VpnSiteLink);
            }

            if (this.O365Policy != null)
            {
                vpnSiteToCreate.O365Policy = this.O365Policy;
            }

            ConfirmAction(
                Properties.Resources.CreatingResourceMessage,
                this.Name,
                () =>
            {
                WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name));
                WriteObject(this.CreateOrUpdateVpnSite(this.ResourceGroupName, this.Name, vpnSiteToCreate, this.Tag));
            });
        }
        public override void Execute()
        {
            base.Execute();

            PSVpnSite vpnSiteToUpdate = null;

            if (ParameterSetName.Contains(CortexParameterSetNames.ByVpnSiteObject))
            {
                vpnSiteToUpdate        = this.InputObject;
                this.ResourceGroupName = this.InputObject.ResourceGroupName;
                this.Name = this.InputObject.Name;
            }
            else
            {
                if (ParameterSetName.Contains(CortexParameterSetNames.ByVpnSiteResourceId))
                {
                    var parsedResourceId = new ResourceIdentifier(this.ResourceId);
                    this.Name = parsedResourceId.ResourceName;
                    this.ResourceGroupName = parsedResourceId.ResourceGroupName;
                }

                vpnSiteToUpdate = this.GetVpnSite(this.ResourceGroupName, this.Name);
            }

            if (vpnSiteToUpdate == null)
            {
                throw new PSArgumentException(Properties.Resources.VpnSiteNotFound);
            }

            //// Resolve the virtual wan, if specified
            if (!ParameterSetName.Contains("NoVirtualWanUpdate"))
            {
                if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualWanObject))
                {
                    this.VirtualWanResourceGroupName = this.VirtualWan.ResourceGroupName;
                    this.VirtualWanName = this.VirtualWan.Name;
                }
                else if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualWanResourceId))
                {
                    var parsedWanResourceId = new ResourceIdentifier(this.VirtualWanId);
                    this.VirtualWanResourceGroupName = parsedWanResourceId.ResourceGroupName;
                    this.VirtualWanName = parsedWanResourceId.ResourceName;
                }

                if (!string.IsNullOrWhiteSpace(this.VirtualWanResourceGroupName) && !string.IsNullOrWhiteSpace(this.VirtualWanName))
                {
                    PSVirtualWan resolvedVirtualWan = new VirtualWanBaseCmdlet().GetVirtualWan(this.VirtualWanResourceGroupName, this.VirtualWanName);

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

                    vpnSiteToUpdate.VirtualWan = new PSResourceId()
                    {
                        Id = resolvedVirtualWan.Id
                    };
                }
            }

            //// Bgp Settings
            if (this.BgpAsn > 0 || this.BgpPeeringWeight > 0 || !string.IsNullOrWhiteSpace(this.BgpPeeringAddress))
            {
                if (vpnSiteToUpdate.BgpSettings == null)
                {
                    //// New BGP settings
                    vpnSiteToUpdate.BgpSettings = this.ValidateAndCreatePSBgpSettings(this.BgpAsn, this.BgpPeeringWeight, this.BgpPeeringAddress);
                }
                else
                {
                    //// Update BGP settings for the specified values only
                    if (this.BgpAsn > 0)
                    {
                        vpnSiteToUpdate.BgpSettings.Asn = this.BgpAsn;
                    }

                    if (this.BgpPeeringWeight > 0)
                    {
                        vpnSiteToUpdate.BgpSettings.PeerWeight = Convert.ToInt32(this.BgpPeeringWeight);
                    }

                    if (!string.IsNullOrWhiteSpace(this.BgpPeeringAddress))
                    {
                        vpnSiteToUpdate.BgpSettings.BgpPeeringAddress = this.BgpPeeringAddress;
                    }
                }
            }

            //// VpnSite device settings
            if (!string.IsNullOrWhiteSpace(this.DeviceModel) || !string.IsNullOrWhiteSpace(this.DeviceVendor))
            {
                vpnSiteToUpdate.DeviceProperties = this.ValidateAndCreateVpnSiteDeviceProperties(
                    this.DeviceModel ?? string.Empty,
                    this.DeviceVendor ?? string.Empty,
                    this.LinkSpeedInMbps);
            }

            //// IpAddress
            if (!string.IsNullOrWhiteSpace(this.IpAddress))
            {
                System.Net.IPAddress ipAddress;
                if (!System.Net.IPAddress.TryParse(this.IpAddress, out ipAddress))
                {
                    throw new PSArgumentException(Properties.Resources.InvalidIPAddress);
                }

                vpnSiteToUpdate.IpAddress = this.IpAddress;
            }

            //// Adress spaces
            if (this.AddressSpace != null && this.AddressSpace.Any())
            {
                if (vpnSiteToUpdate.AddressSpace == null)
                {
                    vpnSiteToUpdate.AddressSpace = new PSAddressSpace();
                }

                vpnSiteToUpdate.AddressSpace.AddressPrefixes.AddRange(this.AddressSpace);
            }

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