Exemple #1
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));
            });
        }
Exemple #2
0
        public override void Execute()
        {
            base.Execute();

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

            string virtualWanRGName = null;
            string virtualWanName   = null;

            //// Resolve the virtual wan
            if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualWanObject, StringComparison.OrdinalIgnoreCase))
            {
                virtualWanRGName = this.VirtualWan.ResourceGroupName;
                virtualWanName   = this.VirtualWan.Name;
            }
            else if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualWanResourceId, StringComparison.OrdinalIgnoreCase))
            {
                var parsedWanResourceId = new ResourceIdentifier(this.VirtualWanId);
                virtualWanName   = parsedWanResourceId.ResourceName;
                virtualWanRGName = parsedWanResourceId.ResourceGroupName;
            }

            if (string.IsNullOrWhiteSpace(virtualWanRGName) || string.IsNullOrWhiteSpace(virtualWanName))
            {
                throw new PSArgumentException(Properties.Resources.VirtualWanReferenceNeededForVirtualHub);
            }

            PSVirtualWan resolvedVirtualWan = new VirtualWanBaseCmdlet().GetVirtualWan(virtualWanRGName, virtualWanName);

            ConfirmAction(
                Properties.Resources.CreatingResourceMessage,
                Name,
                () =>
            {
                WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name));
                PSVirtualHub virtualHub = new PSVirtualHub
                {
                    ResourceGroupName = this.ResourceGroupName,
                    Name       = this.Name,
                    VirtualWan = new PSResourceId()
                    {
                        Id = resolvedVirtualWan.Id
                    },
                    AddressPrefix = this.AddressPrefix,
                    Location      = this.Location
                };

                virtualHub.VirtualNetworkConnections = new List <PSHubVirtualNetworkConnection>();
                if (this.HubVnetConnection != null)
                {
                    virtualHub.VirtualNetworkConnections.AddRange(this.HubVnetConnection);
                }

                virtualHub.RouteTable = this.RouteTable;

                WriteObject(this.CreateOrUpdateVirtualHub(
                                this.ResourceGroupName,
                                this.Name,
                                virtualHub,
                                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));
            });
        }
Exemple #4
0
        public override void Execute()
        {
            base.Execute();
            Dictionary <string, List <string> > auxAuthHeader = null;

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

            string virtualWanRGName = null;
            string virtualWanName   = null;

            //// Resolve the virtual wan
            if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualWanObject, StringComparison.OrdinalIgnoreCase))
            {
                virtualWanRGName = this.VirtualWan.ResourceGroupName;
                virtualWanName   = this.VirtualWan.Name;
            }
            else if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualWanResourceId, StringComparison.OrdinalIgnoreCase))
            {
                var parsedWanResourceId = new ResourceIdentifier(this.VirtualWanId);
                virtualWanName   = parsedWanResourceId.ResourceName;
                virtualWanRGName = parsedWanResourceId.ResourceGroupName;
            }

            if (string.IsNullOrWhiteSpace(virtualWanRGName) || string.IsNullOrWhiteSpace(virtualWanName))
            {
                throw new PSArgumentException(Properties.Resources.VirtualWanReferenceNeededForVirtualHub);
            }

            PSVirtualWan resolvedVirtualWan = new VirtualWanBaseCmdlet().GetVirtualWan(virtualWanRGName, virtualWanName);

            ConfirmAction(
                Properties.Resources.CreatingResourceMessage,
                Name,
                () =>
            {
                WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name));
                PSVirtualHub virtualHub = new PSVirtualHub
                {
                    ResourceGroupName = this.ResourceGroupName,
                    Name       = this.Name,
                    VirtualWan = new PSResourceId()
                    {
                        Id = resolvedVirtualWan.Id
                    },
                    AddressPrefix = this.AddressPrefix,
                    Location      = this.Location
                };

                virtualHub.VirtualNetworkConnections = new List <PSHubVirtualNetworkConnection>();
                if (this.HubVnetConnection != null)
                {
                    virtualHub.VirtualNetworkConnections.AddRange(this.HubVnetConnection);

                    // get auth headers for cross-tenant hubvnet conn
                    List <string> resourceIds = new List <string>();
                    foreach (var connection in this.HubVnetConnection)
                    {
                        resourceIds.Add(connection.RemoteVirtualNetwork.Id);
                    }

                    var auxHeaderDictionary = GetAuxilaryAuthHeaderFromResourceIds(resourceIds);
                    if (auxHeaderDictionary != null && auxHeaderDictionary.Count > 0)
                    {
                        auxAuthHeader = new Dictionary <string, List <string> >(auxHeaderDictionary);
                    }
                }

                virtualHub.RouteTable  = this.RouteTable;
                virtualHub.RouteTables = new List <PSVirtualHubRouteTable>();

                if (string.IsNullOrWhiteSpace(this.Sku))
                {
                    virtualHub.Sku = "Standard";
                }

                WriteObject(this.CreateOrUpdateVirtualHub(
                                this.ResourceGroupName,
                                this.Name,
                                virtualHub,
                                this.Tag,
                                auxAuthHeader));
            });
        }