internal PsApiManagementRegion(AdditionalLocation additionalLocation)
            : this()
        {
            if (additionalLocation == null)
            {
                throw new ArgumentNullException("regionResource");
            }

            Location           = additionalLocation.Location;
            Sku                = Mappers.MapSku(additionalLocation.Sku.Name);
            Capacity           = additionalLocation.Sku.Capacity ?? 1;
            RuntimeRegionalUrl = additionalLocation.GatewayRegionalUrl;
            PublicIPAddresses  = additionalLocation.PublicIPAddresses != null?additionalLocation.PublicIPAddresses.ToArray() : null;

            PrivateIPAddresses = additionalLocation.PrivateIPAddresses != null?additionalLocation.PrivateIPAddresses.ToArray() : null;

            var staticIPList = new List <string>();

            if (additionalLocation.PublicIPAddresses != null)
            {
                staticIPList.AddRange(additionalLocation.PublicIPAddresses);
            }
            if (additionalLocation.PrivateIPAddresses != null)
            {
                staticIPList.AddRange(additionalLocation.PrivateIPAddresses);
            }
#pragma warning disable CS0618
            StaticIPs = staticIPList.ToArray();
#pragma warning restore CS0618
            if (additionalLocation.VirtualNetworkConfiguration != null)
            {
                VirtualNetwork = new PsApiManagementVirtualNetwork(additionalLocation.VirtualNetworkConfiguration);
            }
        }
Example #2
0
        public PsApiManagementRegion AddRegion(
            string location,
            PsApiManagementSku sku = PsApiManagementSku.Developer,
            int capacity           = 1,
            PsApiManagementVirtualNetwork virtualNetwork = null)
        {
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }

            if (location.Equals(Location) || AdditionalRegions.Any(r => location.Equals(r.Location)))
            {
                throw new ArgumentException(string.Format(Resources.AddRegionExistsMessage, location), "location");
            }

            var newRegion = new PsApiManagementRegion
            {
                Location       = location,
                Sku            = sku,
                Capacity       = capacity,
                VirtualNetwork = virtualNetwork
            };

            AdditionalRegions.Add(newRegion);

            return(newRegion);
        }
Example #3
0
        public void UpdateRegion(string location, PsApiManagementSku sku, int capacity, PsApiManagementVirtualNetwork virtualNetwork)
        {
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }

            var regionToUpdate = AdditionalRegions.FirstOrDefault(r => location.Equals(r.Location));

            if (regionToUpdate != null)
            {
                regionToUpdate.Sku            = sku;
                regionToUpdate.Capacity       = capacity;
                regionToUpdate.VirtualNetwork = virtualNetwork;
            }
            else if (location.Equals(Location))
            {
                Sku            = sku;
                Capacity       = capacity;
                VirtualNetwork = virtualNetwork;
            }
            else
            {
                throw new ArgumentException(string.Format(Resources.UpdateRegionDoesNotExistsMessage, location), "location");
            }
        }
        internal PsApiManagementRegion(AdditionalLocation additionalLocation)
            : this()
        {
            if (additionalLocation == null)
            {
                throw new ArgumentNullException("regionResource");
            }

            Location           = additionalLocation.Location;
            Sku                = Mappers.MapSku(additionalLocation.Sku.Name);
            Capacity           = additionalLocation.Sku.Capacity;
            RuntimeRegionalUrl = additionalLocation.GatewayRegionalUrl;
            PublicIPAddresses  = additionalLocation.PublicIPAddresses != null?additionalLocation.PublicIPAddresses.ToArray() : null;

            PrivateIPAddresses = additionalLocation.PrivateIPAddresses != null?additionalLocation.PrivateIPAddresses.ToArray() : null;

            Zone              = additionalLocation.Zones?.ToArray();
            DisableGateway    = additionalLocation.DisableGateway;
            PublicIpAddressId = additionalLocation.PublicIpAddressId;
            PlatformVersion   = additionalLocation.PlatformVersion;
            if (additionalLocation.VirtualNetworkConfiguration != null)
            {
                VirtualNetwork = new PsApiManagementVirtualNetwork(additionalLocation.VirtualNetworkConfiguration);
            }
        }
        public PsApiManagement(ApiServiceResource apiServiceResource)
            : this()
        {
            if (apiServiceResource == null)
            {
                throw new ArgumentNullException("apiServiceResource");
            }

            Id = apiServiceResource.Id;
            Name = apiServiceResource.Name;
            Location = apiServiceResource.Location;
            Sku = Mapper.Map<SkuType, PsApiManagementSku>(apiServiceResource.Properties.SkuProperties.SkuType);
            Capacity = apiServiceResource.Properties.SkuProperties.Capacity ?? 1;
            ProvisioningState = apiServiceResource.Properties.ProvisioningState;
            RuntimeUrl = apiServiceResource.Properties.ProxyEndpoint;
            PortalUrl = apiServiceResource.Properties.ManagementPortalEndpoint;
            StaticIPs = apiServiceResource.Properties.StaticIPs.ToArray();

            if (apiServiceResource.Properties.AdditionalRegions != null)
            {
                AdditionalRegions =
                    apiServiceResource.Properties.AdditionalRegions
                        .Select(region => new PsApiManagementRegion(region))
                        .ToList();
            }

            if (apiServiceResource.Properties.VirtualNetworkConfiguration != null)
            {
                VirtualNetwork = new PsApiManagementVirtualNetwork(apiServiceResource.Properties.VirtualNetworkConfiguration);
            }

            if (apiServiceResource.Properties.HostnameConfigurations != null)
            {
                var portalHostnameResource = apiServiceResource.Properties.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Portal);
                if (portalHostnameResource != null)
                {
                    PortalHostnameConfiguration = new PsApiManagementHostnameConfiguration(portalHostnameResource);
                }

                var proxyHostnameResource = apiServiceResource.Properties.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Proxy);
                if (proxyHostnameResource != null)
                {
                    ProxyHostnameConfiguration = new PsApiManagementHostnameConfiguration(proxyHostnameResource);
                }
            }

            if (apiServiceResource.Tags != null)
            {
                Tags = apiServiceResource.Tags;
            }
        }
Example #6
0
        public PsApiManagement(ApiServiceResource apiServiceResource)
            : this()
        {
            if (apiServiceResource == null)
            {
                throw new ArgumentNullException("apiServiceResource");
            }

            Id                = apiServiceResource.Id;
            Name              = apiServiceResource.Name;
            Location          = apiServiceResource.Location;
            Sku               = Mapper.Map <SkuType, PsApiManagementSku>(apiServiceResource.Properties.SkuProperties.SkuType);
            Capacity          = apiServiceResource.Properties.SkuProperties.Capacity ?? 1;
            ProvisioningState = apiServiceResource.Properties.ProvisioningState;
            RuntimeUrl        = apiServiceResource.Properties.ProxyEndpoint;
            PortalUrl         = apiServiceResource.Properties.ManagementPortalEndpoint;
            StaticIPs         = apiServiceResource.Properties.StaticIPs.ToArray();

            if (apiServiceResource.Properties.AdditionalRegions != null)
            {
                AdditionalRegions =
                    apiServiceResource.Properties.AdditionalRegions
                    .Select(region => new PsApiManagementRegion(region))
                    .ToList();
            }

            if (apiServiceResource.Properties.VirtualNetworkConfiguration != null)
            {
                VirtualNetwork = new PsApiManagementVirtualNetwork(apiServiceResource.Properties.VirtualNetworkConfiguration);
            }

            if (apiServiceResource.Properties.HostnameConfigurations != null)
            {
                var portalHostnameResource = apiServiceResource.Properties.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Portal);
                if (portalHostnameResource != null)
                {
                    PortalHostnameConfiguration = new PsApiManagementHostnameConfiguration(portalHostnameResource);
                }

                var proxyHostnameResource = apiServiceResource.Properties.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Proxy);
                if (proxyHostnameResource != null)
                {
                    ProxyHostnameConfiguration = new PsApiManagementHostnameConfiguration(proxyHostnameResource);
                }
            }

            if (apiServiceResource.Tags != null)
            {
                Tags = apiServiceResource.Tags;
            }
        }
        internal PsApiManagementRegion(AdditionalRegion regionResource)
            : this()
        {
            if (regionResource == null)
            {
                throw new ArgumentNullException("regionResource");
            }

            Location  = regionResource.Location;
            Sku       = Mapper.Map <SkuType, PsApiManagementSku>(regionResource.SkuType);
            Capacity  = regionResource.SkuUnitCount ?? 1;
            StaticIPs = regionResource.StaticIPs.ToArray();

            if (regionResource.VirtualNetworkConfiguration != null)
            {
                VirtualNetwork = new PsApiManagementVirtualNetwork(regionResource.VirtualNetworkConfiguration);
            }
        }
        internal PsApiManagementRegion(AdditionalRegion regionResource)
            : this()
        {
            if (regionResource == null)
            {
                throw new ArgumentNullException("regionResource");
            }

            Location = regionResource.Location;
            Sku = Mapper.Map<SkuType, PsApiManagementSku>(regionResource.SkuType);
            Capacity = regionResource.SkuUnitCount ?? 1;
            StaticIPs = regionResource.StaticIPs.ToArray();

            if (regionResource.VirtualNetworkConfiguration != null)
            {
                VirtualNetwork = new PsApiManagementVirtualNetwork(regionResource.VirtualNetworkConfiguration);
            }
        }
        public void UpdateRegion(
            string location,
            PsApiManagementSku sku,
            int capacity,
            PsApiManagementVirtualNetwork virtualNetwork,
            string[] zone,
            bool?disableGateway,
            string publicIpAddressId)
        {
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }

            var regionToUpdate = AdditionalRegions.FirstOrDefault(r => location.Trim().Equals(r.Location, StringComparison.OrdinalIgnoreCase));

            if (regionToUpdate != null)
            {
                // if this is additional region
                regionToUpdate.Sku               = sku;
                regionToUpdate.Capacity          = capacity;
                regionToUpdate.VirtualNetwork    = virtualNetwork;
                regionToUpdate.Zone              = zone;
                regionToUpdate.DisableGateway    = disableGateway;
                regionToUpdate.PublicIpAddressId = publicIpAddressId;
            }
            else if (location.Equals(Location))
            {
                // if this is master region
                Sku               = sku;
                Capacity          = capacity;
                VirtualNetwork    = virtualNetwork;
                Zone              = zone;
                DisableGateway    = disableGateway;
                PublicIpAddressId = publicIpAddressId;
            }
            else
            {
                throw new ArgumentException(string.Format(Resources.UpdateRegionDoesNotExistsMessage, location), "location");
            }
        }
        public void UpdateRegion(string location, PsApiManagementSku sku, int capacity, PsApiManagementVirtualNetwork virtualNetwork)
        {
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }

            var regionToUpdate = AdditionalRegions.FirstOrDefault(r => location.Equals(r.Location));
            if (regionToUpdate != null)
            {
                regionToUpdate.Sku = sku;
                regionToUpdate.Capacity = capacity;
                regionToUpdate.VirtualNetwork = virtualNetwork;
            }
            else if (location.Equals(Location))
            {
                Sku = sku;
                Capacity = capacity;
                VirtualNetwork = virtualNetwork;
            }
            else
            {
                throw new ArgumentException(string.Format(Resources.UpdateRegionDoesNotExistsMessage, location), "location");
            }
        }
        public PsApiManagementRegion AddRegion(
            string location,
            PsApiManagementSku sku = PsApiManagementSku.Developer,
            int capacity = 1,
            PsApiManagementVirtualNetwork virtualNetwork = null)
        {
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }

            if (location.Equals(Location) || AdditionalRegions.Any(r => location.Equals(r.Location)))
            {
                throw new ArgumentException(string.Format(Resources.AddRegionExistsMessage, location), "location");
            }

            var newRegion = new PsApiManagementRegion
            {
                Location = location,
                Sku = sku,
                Capacity = capacity,
                VirtualNetwork = virtualNetwork
            };

            AdditionalRegions.Add(newRegion);

            return newRegion;
        }
        public ApiManagementLongRunningOperation BeginUpdateDeployments(
            string resourceGroupName,
            string serviceName,
            string location,
            PsApiManagementSku sku,
            int capacity,
            PsApiManagementVirtualNetwork vnetConfiguration,
            IList<PsApiManagementRegion> additionalRegions)
        {
            var parameters = new ApiServiceManageDeploymentsParameters(location, MapSku(sku))
            {
                SkuUnitCount = capacity
            };

            if (vnetConfiguration != null)
            {
                parameters.VirtualNetworkConfiguration = new VirtualNetworkConfiguration
                {
                    Location = vnetConfiguration.Location,
                    SubnetName = vnetConfiguration.SubnetName,
                    VnetId = vnetConfiguration.VnetId
                };
            }

            if (additionalRegions != null && additionalRegions.Any())
            {
                parameters.AdditionalRegions =
                    additionalRegions
                        .Select(region =>
                            new AdditionalRegion
                            {
                                Location = region.Location,
                                SkuType = MapSku(region.Sku),
                                SkuUnitCount = region.Capacity,
                                VirtualNetworkConfiguration = region.VirtualNetwork == null
                                    ? null
                                    : new VirtualNetworkConfiguration
                                    {
                                        Location = region.VirtualNetwork.Location,
                                        SubnetName = region.VirtualNetwork.SubnetName,
                                        VnetId = region.VirtualNetwork.VnetId
                                    }
                            })
                        .ToList();
            }

            var longrunningResponse = Client.ResourceProvider.BeginManagingDeployments(resourceGroupName, serviceName, parameters);
            AdjustRetryAfter(longrunningResponse, _client.LongRunningOperationInitialTimeout);
            return ApiManagementLongRunningOperation.CreateLongRunningOperation("Update-AzureRmApiManagementDeployment", longrunningResponse);
        }
Example #13
0
        public PsApiManagement(ApiManagementServiceResource apiServiceResource)
            : this()
        {
            if (apiServiceResource == null)
            {
                throw new ArgumentNullException("apiServiceResource");
            }

            Id                      = apiServiceResource.Id;
            Name                    = apiServiceResource.Name;
            Location                = apiServiceResource.Location;
            Sku                     = ApiManagementClient.Mapper.Map <string, PsApiManagementSku>(apiServiceResource.Sku.Name);
            Capacity                = apiServiceResource.Sku.Capacity ?? 1;
            CreatedTimeUtc          = apiServiceResource.CreatedAtUtc;
            PublisherEmail          = apiServiceResource.PublisherEmail;
            OrganizationName        = apiServiceResource.PublisherName;
            NotificationSenderEmail = apiServiceResource.NotificationSenderEmail;
            ProvisioningState       = apiServiceResource.ProvisioningState;
            RuntimeUrl              = apiServiceResource.GatewayUrl;
            RuntimeRegionalUrl      = apiServiceResource.GatewayRegionalUrl;
            PortalUrl               = apiServiceResource.PortalUrl;
            DeveloperPortalUrl      = apiServiceResource.DeveloperPortalUrl;
            ManagementApiUrl        = apiServiceResource.ManagementApiUrl;
            ScmUrl                  = apiServiceResource.ScmUrl;
            PublicIPAddresses       = apiServiceResource.PublicIPAddresses != null?apiServiceResource.PublicIPAddresses.ToArray() : null;

            PrivateIPAddresses = apiServiceResource.PrivateIPAddresses != null?apiServiceResource.PrivateIPAddresses.ToArray() : null;

            EnableClientCertificate = apiServiceResource.EnableClientCertificate;

            VpnType = ApiManagementClient.Mapper.Map <string, PsApiManagementVpnType>(apiServiceResource.VirtualNetworkType);

            if (apiServiceResource.AdditionalLocations != null)
            {
                AdditionalRegions =
                    apiServiceResource.AdditionalLocations
                    .Select(region => new PsApiManagementRegion(region))
                    .ToList();
            }

            if (apiServiceResource.VirtualNetworkConfiguration != null)
            {
                VirtualNetwork = new PsApiManagementVirtualNetwork(apiServiceResource.VirtualNetworkConfiguration);
            }

            if (apiServiceResource.HostnameConfigurations != null &&
                apiServiceResource.HostnameConfigurations.Any())
            {
                var portalHostnameResource = apiServiceResource.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Portal);
                if (portalHostnameResource != null)
                {
                    PortalCustomHostnameConfiguration = new PsApiManagementCustomHostNameConfiguration(portalHostnameResource);
                }

                var proxyHostnameResources = apiServiceResource.HostnameConfigurations.Where(conf => conf.Type == HostnameType.Proxy);
                if (proxyHostnameResources != null && proxyHostnameResources.Any())
                {
                    var proxyCustomHostnameResources = new List <PsApiManagementCustomHostNameConfiguration>();
                    foreach (var proxyHostNameResource in proxyHostnameResources)
                    {
                        proxyCustomHostnameResources.Add(new PsApiManagementCustomHostNameConfiguration(proxyHostNameResource));
                    }

                    ProxyCustomHostnameConfiguration = proxyCustomHostnameResources.ToArray();
                }

                var managementHostnameResource = apiServiceResource.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Management);
                if (managementHostnameResource != null)
                {
                    ManagementCustomHostnameConfiguration = new PsApiManagementCustomHostNameConfiguration(managementHostnameResource);
                }

                var scmHostnameResource = apiServiceResource.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Scm);
                if (scmHostnameResource != null)
                {
                    ScmCustomHostnameConfiguration = new PsApiManagementCustomHostNameConfiguration(scmHostnameResource);
                }

                var developerPortalResource = apiServiceResource.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.DeveloperPortal);
                if (developerPortalResource != null)
                {
                    DeveloperPortalHostnameConfiguration = new PsApiManagementCustomHostNameConfiguration(developerPortalResource);
                }
            }

            if (apiServiceResource.Certificates != null && apiServiceResource.Certificates.Any())
            {
                var systemCertificates = new List <PsApiManagementSystemCertificate>();
                foreach (var certificate in apiServiceResource.Certificates)
                {
                    systemCertificates.Add(new PsApiManagementSystemCertificate(certificate));
                }
                SystemCertificates = systemCertificates.ToArray();
            }

            // prepare the SSL settings
            if (apiServiceResource.CustomProperties != null && apiServiceResource.CustomProperties.Any())
            {
                SslSetting = new PsApiManagementSslSetting(apiServiceResource.CustomProperties);
            }

            if (apiServiceResource.Tags != null)
            {
                Tags = apiServiceResource.Tags;
            }

            if (apiServiceResource.Identity != null)
            {
                this.Identity = new PsApiManagementServiceIdentity(apiServiceResource.Identity);
            }
        }
        public PsApiManagement(ApiManagementServiceResource apiServiceResource)
            : this()
        {
            if (apiServiceResource == null)
            {
                throw new ArgumentNullException("apiServiceResource");
            }

            Id                      = apiServiceResource.Id;
            Name                    = apiServiceResource.Name;
            Location                = apiServiceResource.Location;
            Sku                     = ApiManagementClient.Mapper.Map <string, PsApiManagementSku>(apiServiceResource.Sku.Name);
            Capacity                = apiServiceResource.Sku.Capacity ?? 1;
            PublisherEmail          = apiServiceResource.PublisherEmail;
            OrganizationName        = apiServiceResource.PublisherName;
            NotificationSenderEmail = apiServiceResource.NotificationSenderEmail;
            ProvisioningState       = apiServiceResource.ProvisioningState;
            RuntimeUrl              = apiServiceResource.GatewayUrl;
            RuntimeRegionalUrl      = apiServiceResource.GatewayRegionalUrl;
            PortalUrl               = apiServiceResource.PortalUrl;
            ManagementApiUrl        = apiServiceResource.ManagementApiUrl;
            ScmUrl                  = apiServiceResource.ScmUrl;
            PublicIPAddresses       = apiServiceResource.PublicIPAddresses != null?apiServiceResource.PublicIPAddresses.ToArray() : null;

            PrivateIPAddresses = apiServiceResource.PrivateIPAddresses != null?apiServiceResource.PrivateIPAddresses.ToArray() : null;

            var staticIPList = new List <string>();

            if (apiServiceResource.PublicIPAddresses != null)
            {
                staticIPList.AddRange(apiServiceResource.PublicIPAddresses);
            }
            if (apiServiceResource.PrivateIPAddresses != null)
            {
                staticIPList.AddRange(apiServiceResource.PrivateIPAddresses);
            }
#pragma warning disable CS0618
            StaticIPs = staticIPList.ToArray();
#pragma warning restore CS0618
            VpnType = ApiManagementClient.Mapper.Map <string, PsApiManagementVpnType>(apiServiceResource.VirtualNetworkType);

            if (apiServiceResource.AdditionalLocations != null)
            {
                AdditionalRegions =
                    apiServiceResource.AdditionalLocations
                    .Select(region => new PsApiManagementRegion(region))
                    .ToList();
            }

            if (apiServiceResource.VirtualNetworkConfiguration != null)
            {
                VirtualNetwork = new PsApiManagementVirtualNetwork(apiServiceResource.VirtualNetworkConfiguration);
            }

            if (apiServiceResource.HostnameConfigurations != null &&
                apiServiceResource.HostnameConfigurations.Any())
            {
                var portalHostnameResource = apiServiceResource.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Portal);
                if (portalHostnameResource != null)
                {
#pragma warning disable CS0618
                    PortalHostnameConfiguration = new PsApiManagementHostnameConfiguration(portalHostnameResource);
#pragma warning restore CS0618
                    PortalCustomHostnameConfiguration = new PsApiManagementCustomHostNameConfiguration(portalHostnameResource);
                }

                var proxyHostnameResources = apiServiceResource.HostnameConfigurations.Where(conf => conf.Type == HostnameType.Proxy);
                if (proxyHostnameResources != null && proxyHostnameResources.Any())
                {
#pragma warning disable CS0618
                    ProxyHostnameConfiguration = new PsApiManagementHostnameConfiguration(proxyHostnameResources.First());
#pragma warning restore CS0618
                    var proxyCustomHostnameResources = new List <PsApiManagementCustomHostNameConfiguration>();
                    foreach (var proxyHostNameResource in proxyHostnameResources)
                    {
                        proxyCustomHostnameResources.Add(new PsApiManagementCustomHostNameConfiguration(proxyHostNameResource));
                    }

                    ProxyCustomHostnameConfiguration = proxyCustomHostnameResources.ToArray();
                }

                var managementHostnameResource = apiServiceResource.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Management);
                if (managementHostnameResource != null)
                {
#pragma warning disable CS0618
                    ManagementHostnameConfiguration = new PsApiManagementHostnameConfiguration(managementHostnameResource);
#pragma warning restore CS0618
                    ManagementCustomHostnameConfiguration = new PsApiManagementCustomHostNameConfiguration(managementHostnameResource);
                }

                var scmHostnameResource = apiServiceResource.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Scm);
                if (scmHostnameResource != null)
                {
#pragma warning disable CS0618
                    ScmHostnameConfiguration = new PsApiManagementHostnameConfiguration(scmHostnameResource);
#pragma warning restore CS0618
                    ScmCustomHostnameConfiguration = new PsApiManagementCustomHostNameConfiguration(scmHostnameResource);
                }
            }

            if (apiServiceResource.Certificates != null && apiServiceResource.Certificates.Any())
            {
                var systemCertificates = new List <PsApiManagementSystemCertificate>();
                foreach (var certificate in apiServiceResource.Certificates)
                {
                    systemCertificates.Add(new PsApiManagementSystemCertificate(certificate));
                }
                SystemCertificates = systemCertificates.ToArray();
            }

            if (apiServiceResource.Tags != null)
            {
                Tags = apiServiceResource.Tags;
            }

            if (apiServiceResource.Identity != null)
            {
                this.Identity = new PsApiManagementServiceIdentity(apiServiceResource.Identity);
            }
        }