コード例 #1
0
        public override void ExecuteCmdlet()
        {
            RedisGetResponse response = CacheClient.GetCache(ResourceGroupName, Name);

            string skuName;
            string skuFamily;
            int    skuCapacity;

            if (string.IsNullOrEmpty(Sku))
            {
                skuName = response.Resource.Properties.Sku.Name;
            }
            else
            {
                skuName = Sku;
            }

            if (string.IsNullOrEmpty(Size))
            {
                skuFamily   = response.Resource.Properties.Sku.Family;
                skuCapacity = response.Resource.Properties.Sku.Capacity;
            }
            else
            {
                Size      = SizeConverter.GetSizeInRedisSpecificFormat(Size);
                skuFamily = Size.Substring(0, 1);
                int.TryParse(Size.Substring(1), out skuCapacity);
            }


            WriteObject(new RedisCacheAttributesWithAccessKeys(
                            CacheClient.CreateOrUpdateCache(ResourceGroupName, Name, response.Resource.Location, response.Resource.Properties.RedisVersion,
                                                            skuFamily, skuCapacity, skuName, RedisConfiguration, EnableNonSslPort),
                            ResourceGroupName));
        }
コード例 #2
0
        public override void ExecuteCmdlet()
        {
            Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name);
            RedisResource response = null;

            if (string.IsNullOrEmpty(ResourceGroupName))
            {
                response          = CacheClient.GetCache(Name);
                ResourceGroupName = Utility.GetResourceGroupNameFromRedisCacheId(response.Id);
            }
            else
            {
                response = CacheClient.GetCache(ResourceGroupName, Name);
            }

            string skuName;
            string skuFamily;
            int    skuCapacity;

            if (string.IsNullOrEmpty(Sku))
            {
                skuName = response.Sku.Name;
            }
            else
            {
                skuName = Sku;
            }

            if (string.IsNullOrEmpty(Size))
            {
                skuFamily   = response.Sku.Family;
                skuCapacity = response.Sku.Capacity;
            }
            else
            {
                Size = SizeConverter.GetSizeInRedisSpecificFormat(Size, SkuStrings.Premium.Equals(Sku));
                SizeConverter.ValidateSize(Size.ToUpper(), SkuStrings.Premium.Equals(Sku));
                skuFamily = Size.Substring(0, 1);
                int.TryParse(Size.Substring(1), out skuCapacity);
            }

            if (!ShardCount.HasValue && response.ShardCount.HasValue)
            {
                ShardCount = response.ShardCount;
            }

            ConfirmAction(
                string.Format(Resources.UpdateRedisCache, Name),
                Name,
                () =>
            {
                var redisResource = CacheClient.UpdateCache(ResourceGroupName, Name, skuFamily, skuCapacity,
                                                            skuName, RedisConfiguration, EnableNonSslPort, TenantSettings, ShardCount, Tag);
                var redisAccessKeys = CacheClient.GetAccessKeys(ResourceGroupName, Name);
                WriteObject(new RedisCacheAttributesWithAccessKeys(redisResource, redisAccessKeys, ResourceGroupName));
            });
        }
コード例 #3
0
        public override void ExecuteCmdlet()
        {
            string skuFamily;

            int skuCapacity = 1;

            if (string.IsNullOrEmpty(RedisVersion))
            {
                RedisVersion = redisDefaultVersion;
            }

            if (string.IsNullOrEmpty(Size))
            {
                Size = SizeConverter.C1String;
            }
            else
            {
                Size = SizeConverter.GetSizeInRedisSpecificFormat(Size);
            }

            // Size to SkuFamily and SkuCapacity conversion
            skuFamily = Size.Substring(0, 1);
            int.TryParse(Size.Substring(1), out skuCapacity);

            if (string.IsNullOrEmpty(Sku))
            {
                Sku = SkuStrings.Standard;
            }

            // If Force flag is not avaliable than check if cache is already available or not
            try
            {
                RedisGetResponse availableCache = CacheClient.GetCache(ResourceGroupName, Name);
                if (availableCache != null)
                {
                    throw new CloudException(string.Format(Resources.RedisCacheExists, Name));
                }
            }
            catch (CloudException ex)
            {
                if (ex.Error.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound"))
                {
                    // cache does not exists so go ahead and create one
                }
                else if (ex.Error.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
                {
                    // resource group not found, let create throw error don't throw from here
                }
                else
                {
                    // all other exceptions should be thrown
                    throw;
                }
            }
            WriteObject(new RedisCacheAttributesWithAccessKeys(CacheClient.CreateOrUpdateCache(ResourceGroupName, Name, Location, RedisVersion, skuFamily, skuCapacity, Sku, MaxMemoryPolicy, EnableNonSslPort), ResourceGroupName));
        }
コード例 #4
0
        public override void ExecuteCmdlet()
        {
            Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name);
            if (!string.IsNullOrEmpty(MaxMemoryPolicy))
            {
                throw new ArgumentException(Resources.MaxMemoryPolicyException);
            }

            RedisResource response = CacheClient.GetCache(ResourceGroupName, Name);

            string skuName;
            string skuFamily;
            int    skuCapacity;

            if (string.IsNullOrEmpty(Sku))
            {
                skuName = response.Sku.Name;
            }
            else
            {
                skuName = Sku;
            }

            if (string.IsNullOrEmpty(Size))
            {
                skuFamily   = response.Sku.Family;
                skuCapacity = response.Sku.Capacity;
            }
            else
            {
                Size      = SizeConverter.GetSizeInRedisSpecificFormat(Size, SkuStrings.Premium.Equals(Sku));
                skuFamily = Size.Substring(0, 1);
                int.TryParse(Size.Substring(1), out skuCapacity);
            }

            if (!ShardCount.HasValue && response.ShardCount.HasValue)
            {
                ShardCount = response.ShardCount;
            }


            WriteObject(new RedisCacheAttributesWithAccessKeys(
                            CacheClient.CreateOrUpdateCache(ResourceGroupName, Name, response.Location, skuFamily, skuCapacity, skuName, RedisConfiguration, EnableNonSslPort,
                                                            TenantSettings, ShardCount, response.SubnetId, response.StaticIP, response.Tags),
                            ResourceGroupName));
        }
コード例 #5
0
        protected override void ProcessRecord()
        {
            if (!string.IsNullOrEmpty(MaxMemoryPolicy))
            {
                throw new ArgumentException(Resources.MaxMemoryPolicyException);
            }

            RedisGetResponse response = CacheClient.GetCache(ResourceGroupName, Name);

            string skuName;
            string skuFamily;
            int    skuCapacity;

            if (string.IsNullOrEmpty(Sku))
            {
                skuName = response.Resource.Properties.Sku.Name;
            }
            else
            {
                skuName = Sku;
            }

            if (string.IsNullOrEmpty(Size))
            {
                skuFamily   = response.Resource.Properties.Sku.Family;
                skuCapacity = response.Resource.Properties.Sku.Capacity;
            }
            else
            {
                Size      = SizeConverter.GetSizeInRedisSpecificFormat(Size);
                skuFamily = Size.Substring(0, 1);
                int.TryParse(Size.Substring(1), out skuCapacity);
            }


            WriteObject(new RedisCacheAttributesWithAccessKeys(
                            CacheClient.CreateOrUpdateCache(ResourceGroupName, Name, response.Resource.Location, response.Resource.Properties.RedisVersion,
                                                            skuFamily, skuCapacity, skuName, RedisConfiguration, EnableNonSslPort),
                            ResourceGroupName));
        }
コード例 #6
0
        public override void ExecuteCmdlet()
        {
            Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name);
            if (string.IsNullOrEmpty(Sku))
            {
                Sku = SkuStrings.Standard;
            }


            if (string.IsNullOrEmpty(Size))
            {
                if (SkuStrings.Premium.Equals(Sku, StringComparison.OrdinalIgnoreCase))
                {
                    Size = SizeConverter.P1String;
                }
                else
                {
                    Size = SizeConverter.C1String;
                }
            }
            else
            {
                Size = SizeConverter.GetSizeInRedisSpecificFormat(Size, SkuStrings.Premium.Equals(Sku));
                SizeConverter.ValidateSize(Size.ToUpper(), SkuStrings.Premium.Equals(Sku));
            }

            int skuCapacity = 1;
            // Size to SkuFamily and SkuCapacity conversion
            string skuFamily = Size.Substring(0, 1);

            int.TryParse(Size.Substring(1), out skuCapacity);


            // If Force flag is not avaliable than check if cache is already available or not
            try
            {
                RedisResource availableCache = CacheClient.GetCache(ResourceGroupName, Name);
                if (availableCache != null)
                {
                    throw new CloudException(string.Format(Resources.RedisCacheExists, Name));
                }
            }
            catch (CloudException ex)
            {
                if (ex.Body.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound"))
                {
                    // cache does not exists so go ahead and create one
                }
                else if (ex.Body.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
                {
                    // resource group not found, let create throw error don't throw from here
                }
                else
                {
                    // all other exceptions should be thrown
                    throw;
                }
            }
            catch (ErrorResponseException ex)
            {
                if (ex.Body.Error.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound"))
                {
                    // cache does not exists so go ahead and create one
                }
                else if (ex.Body.Error.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
                {
                    // resource group not found, let create throw error don't throw from here
                }
                else
                {
                    // all other exceptions should be thrown
                    throw;
                }
            }

            ConfirmAction(
                string.Format(Resources.CreateRedisCache, Name),
                Name,
                () =>
            {
                var redisResource = CacheClient.CreateCache(ResourceGroupName, Name, Location, skuFamily, skuCapacity, Sku,
                                                            RedisConfiguration, EnableNonSslPort, TenantSettings, ShardCount, MinimumTlsVersion, SubnetId, StaticIP, Tag, Zone, RedisVersion, IdentityType, UserAssignedIdentity);
                var redisAccessKeys = CacheClient.GetAccessKeys(ResourceGroupName, Name);
                WriteObject(new RedisCacheAttributesWithAccessKeys(redisResource, redisAccessKeys, ResourceGroupName));
            });
        }
コード例 #7
0
        public override void ExecuteCmdlet()
        {
            if (!string.IsNullOrEmpty(RedisVersion))
            {
                WriteWarning("The RedisVersion parameter has been deprecated.  As such, it is no longer necessary to provide this parameter and any value specified is ignored.");
            }

            if (!string.IsNullOrEmpty(MaxMemoryPolicy))
            {
                throw new ArgumentException(Resources.MaxMemoryPolicyException);
            }

            if (string.IsNullOrEmpty(Sku))
            {
                Sku = SkuStrings.Standard;
            }


            if (string.IsNullOrEmpty(Size))
            {
                Size = SizeConverter.C1String;
            }
            else
            {
                Size = SizeConverter.GetSizeInRedisSpecificFormat(Size, SkuStrings.Premium.Equals(Sku));
            }

            int skuCapacity = 1;
            // Size to SkuFamily and SkuCapacity conversion
            string skuFamily = Size.Substring(0, 1);

            int.TryParse(Size.Substring(1), out skuCapacity);


            // If Force flag is not avaliable than check if cache is already available or not
            try
            {
                RedisResource availableCache = CacheClient.GetCache(ResourceGroupName, Name);
                if (availableCache != null)
                {
                    throw new CloudException(string.Format(Resources.RedisCacheExists, Name));
                }
            }
            catch (CloudException ex)
            {
                if (ex.Body.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound"))
                {
                    // cache does not exists so go ahead and create one
                }
                else if (ex.Body.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
                {
                    // resource group not found, let create throw error don't throw from here
                }
                else
                {
                    // all other exceptions should be thrown
                    throw;
                }
            }

            WriteObject(
                new RedisCacheAttributesWithAccessKeys(
                    CacheClient.CreateOrUpdateCache(ResourceGroupName, Name, Location, skuFamily, skuCapacity, Sku, RedisConfiguration, EnableNonSslPort, TenantSettings, ShardCount, VirtualNetwork, Subnet, StaticIP),
                    ResourceGroupName
                    )
                );
        }