Exemplo n.º 1
0
        public override void ExecuteCmdlet()
        {
            Utility.ValidateResourceGroupAndResourceName(null, PrimaryServerName);
            Utility.ValidateResourceGroupAndResourceName(null, SecondaryServerName);

            RedisResource primaryCache   = CacheClient.GetCache(PrimaryServerName);
            RedisResource secondaryCache = CacheClient.GetCache(SecondaryServerName);

            ConfirmAction(
                string.Format(Resources.LinkingRedisCache, SecondaryServerName, PrimaryServerName),
                PrimaryServerName,
                () =>
            {
                RedisLinkedServerWithProperties redisLinkedServer = CacheClient.SetLinkedServer(
                    resourceGroupName: Utility.GetResourceGroupNameFromRedisCacheId(primaryCache.Id),
                    cacheName: primaryCache.Name,
                    linkedCacheName: secondaryCache.Name,
                    linkedCacheId: secondaryCache.Id,
                    linkedCacheLocation: secondaryCache.Location,
                    serverRole: ReplicationRole.Secondary);

                if (redisLinkedServer == null)
                {
                    throw new CloudException(string.Format(Resources.LinkedServerCreationFailed, SecondaryServerName, PrimaryServerName));
                }
                WriteObject(new PSRedisLinkedServer(redisLinkedServer));
            }
                );
        }
 public string GetResourceGroupNameIfNotProvided(string resourceGroupName, string cacheName)
 {
     if (string.IsNullOrEmpty(resourceGroupName))
     {
         RedisResource response = GetCache(cacheName);
         return(Utility.GetResourceGroupNameFromRedisCacheId(response.Id));
     }
     return(resourceGroupName);
 }
Exemplo n.º 3
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));
            });
        }
        public override void ExecuteCmdlet()
        {
            Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name);
            if (!string.IsNullOrEmpty(Name))
            {
                if (!string.IsNullOrEmpty(ResourceGroupName))
                {
                    // Get single cache directly by RP call
                    WriteObject(new RedisCacheAttributes(CacheClient.GetCache(ResourceGroupName, Name), ResourceGroupName));
                }
                else
                {
                    // Get single cache from list of caches
                    RedisResource response = CacheClient.GetCache(Name);
                    WriteObject(new RedisCacheAttributes(response, Utility.GetResourceGroupNameFromRedisCacheId(response.Id)));
                }
            }
            else
            {
                // List all cache in given resource group if avaliable otherwise all cache in given subscription
                IPage <RedisResource>       response = CacheClient.ListCaches(ResourceGroupName);
                List <RedisCacheAttributes> list     = new List <RedisCacheAttributes>();
                foreach (RedisResource resource in response)
                {
                    list.Add(new RedisCacheAttributes(resource, ResourceGroupName));
                }
                WriteObject(list, true);

                while (!string.IsNullOrEmpty(response.NextPageLink))
                {
                    // List using next link
                    response = CacheClient.ListCachesUsingNextLink(ResourceGroupName, response.NextPageLink);
                    list     = new List <RedisCacheAttributes>();
                    foreach (RedisResource resource in response)
                    {
                        list.Add(new RedisCacheAttributes(resource, ResourceGroupName));
                    }
                    WriteObject(list, true);
                }
            }
        }
Exemplo n.º 5
0
 private void FetchResourceGroupNameAndNameFromResourceId()
 {
     ResourceGroupName = Utility.GetResourceGroupNameFromRedisCacheId(ResourceId);
     Name = Utility.GetRedisCacheNameFromRedisCacheId(ResourceId);
 }