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)); }); }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); 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(VirtualNetwork) || !string.IsNullOrEmpty(Subnet)) { WriteWarning("Parameters 'VirtualNetwork' and 'Subnet' are deprecated. Please use SubnetId instead."); if (string.IsNullOrEmpty(SubnetId)) { SubnetId = string.Format("{0}/subnets/{1}", VirtualNetwork, Subnet); } } 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; } } var redisResource = CacheClient.CreateCache(ResourceGroupName, Name, Location, skuFamily, skuCapacity, Sku, RedisConfiguration, EnableNonSslPort, TenantSettings, ShardCount, SubnetId, StaticIP); var redisAccessKeys = CacheClient.GetAccessKeys(ResourceGroupName, Name); WriteObject(new RedisCacheAttributesWithAccessKeys(redisResource, redisAccessKeys, ResourceGroupName)); }