public static ValidateResourceGroupAndResourceName ( string resourceGroupName, string name ) : void | ||
resourceGroupName | string | |
name | string | |
return | void |
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 override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); ResourceGroupName = CacheClient.GetResourceGroupNameIfNotProvided(ResourceGroupName, Name); IList <ScheduleEntry> response = CacheClient.GetPatchSchedules(ResourceGroupName, Name); if (response == null) { throw new CloudException(string.Format(Resources.PatchScheduleNotFound, Name)); } List <PSScheduleEntry> returnValue = new List <PSScheduleEntry>(); foreach (var schedule in response) { returnValue.Add(new PSScheduleEntry { DayOfWeek = schedule.DayOfWeek.ToString(), StartHourUtc = schedule.StartHourUtc, MaintenanceWindow = schedule.MaintenanceWindow }); } WriteObject(returnValue); }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); ResourceGroupName = CacheClient.GetResourceGroupNameIfNotProvided(ResourceGroupName, Name); RedisKeyType keyTypeToRegenerated = RedisKeyType.Primary; if (KeyType.Equals("Secondary")) { keyTypeToRegenerated = RedisKeyType.Secondary; } ConfirmAction( Force.IsPresent, string.Format(Resources.RegeneratingRedisCacheKey, Name, keyTypeToRegenerated.ToString()), string.Format(Resources.RegenerateRedisCacheKey, Name, keyTypeToRegenerated.ToString()), Name, () => { CacheClient.RegenerateAccessKeys(ResourceGroupName, Name, keyTypeToRegenerated); RedisAccessKeys keysResponse = CacheClient.GetAccessKeys(ResourceGroupName, Name); WriteObject(keysResponse); } ); }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); if (!string.IsNullOrEmpty(ResourceGroupName) && !string.IsNullOrEmpty(Name)) { // Get for single cache WriteObject(new RedisCacheAttributes(CacheClient.GetCache(ResourceGroupName, Name), ResourceGroupName)); } 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); } } }
public override void ExecuteCmdlet() { // In case of piped parent object "RedisCacheAttributes" fetch ResourceGroupName and Name from it if (ParameterSetName.Equals(InputObjectParameterSet)) { FetchResourceGroupNameAndNameFromInputObject(); } else if (ParameterSetName.Equals(ResourceIdParameterSet)) { FetchResourceGroupNameAndNameFromResourceId(); } Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); ResourceGroupName = CacheClient.GetResourceGroupNameIfNotProvided(ResourceGroupName, Name); ConfirmAction( string.Format(Resources.CreatingFirewallRule, Name), Name, () => { RedisFirewallRule redisFirewallRule = CacheClient.SetFirewallRule( resourceGroupName: ResourceGroupName, cacheName: Name, ruleName: RuleName, startIP: StartIP, endIP: EndIP); if (redisFirewallRule == null) { throw new CloudException(string.Format(Resources.FirewallRuleCreationFailed)); } WriteObject(new PSRedisFirewallRule(ResourceGroupName, Name, redisFirewallRule)); } ); }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); // Convert from PSScheduleEntry to ScheduleEntry List <ScheduleEntry> requestData = new List <ScheduleEntry>(); foreach (var schedule in Entries) { requestData.Add(new ScheduleEntry { DayOfWeek = (DayOfWeekEnum)Enum.Parse(typeof(DayOfWeekEnum), schedule.DayOfWeek, true), StartHourUtc = schedule.StartHourUtc, MaintenanceWindow = schedule.MaintenanceWindow }); } IList <ScheduleEntry> response = CacheClient.SetPatchSchedules(ResourceGroupName, Name, requestData); List <PSScheduleEntry> returnValue = new List <PSScheduleEntry>(); foreach (var schedule in response) { returnValue.Add(new PSScheduleEntry { DayOfWeek = schedule.DayOfWeek.ToString(), StartHourUtc = schedule.StartHourUtc, MaintenanceWindow = schedule.MaintenanceWindow }); } WriteObject(returnValue); }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); RedisAccessKeys keysResponse = CacheClient.GetAccessKeys(ResourceGroupName, Name); WriteObject(keysResponse); }
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); CacheClient.ExportToCache(ResourceGroupName, Name, Container, Prefix, Format); if (PassThru) { WriteObject(true); } }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); RedisCacheAttributes cache = new RedisCacheAttributes(CacheClient.GetCache(ResourceGroupName, Name), ResourceGroupName); ConfirmAction( string.Format(Resources.RemoveRedisCacheDiagnostics, Name), Name, () => CacheClient.SetDiagnostics(cache.Id, null)); }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); RedisListKeysResult keysResponse = CacheClient.GetAccessKeys(ResourceGroupName, Name); WriteObject(new RedisAccessKeys() { PrimaryKey = keysResponse.PrimaryKey, SecondaryKey = keysResponse.SecondaryKey }); }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); ResourceGroupName = CacheClient.GetResourceGroupNameIfNotProvided(ResourceGroupName, Name); RedisCacheAttributes cache = new RedisCacheAttributes(CacheClient.GetCache(ResourceGroupName, Name), ResourceGroupName); ConfirmAction( string.Format(Resources.SetRedisCacheDiagnostics, Name), Name, () => { CacheClient.SetDiagnostics(cache.Id, StorageAccountId); }); }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); ResourceGroupName = CacheClient.GetResourceGroupNameIfNotProvided(ResourceGroupName, Name); ConfirmAction( Force.IsPresent, string.Format(Resources.RebootingRedisCache, Name, RebootType), string.Format(Resources.RebootRedisCache, Name), Name, () => CacheClient.RebootCache(ResourceGroupName, Name, RebootType, ShardId)); if (PassThru) { WriteObject(true); } }
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)); }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); ResourceGroupName = CacheClient.GetResourceGroupNameIfNotProvided(ResourceGroupName, Name); ConfirmAction( string.Format(Resources.ExportRedisCache, Name), Name, () => { CacheClient.ExportToCache(ResourceGroupName, Name, Container, Prefix, Format); if (PassThru) { WriteObject(true); } }); }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); IList <ScheduleEntry> response = CacheClient.GetPatchSchedules(ResourceGroupName, Name); List <PSScheduleEntry> returnValue = new List <PSScheduleEntry>(); foreach (var schedule in response) { returnValue.Add(new PSScheduleEntry { DayOfWeek = schedule.DayOfWeek, StartHourUtc = schedule.StartHourUtc, MaintenanceWindow = schedule.MaintenanceWindow }); } WriteObject(returnValue); }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); ResourceGroupName = CacheClient.GetResourceGroupNameIfNotProvided(ResourceGroupName, Name); ConfirmAction( string.Format(Resources.RemovePatchSchedule, Name), Name, () => { CacheClient.RemovePatchSchedules(ResourceGroupName, Name); if (PassThru) { WriteObject(true); } }); }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); ConfirmAction( Force.IsPresent, string.Format(Resources.RemovingRedisCache, Name), string.Format(Resources.RemoveRedisCache, Name), Name, () => { CacheClient.DeleteCache(ResourceGroupName, Name); if (PassThru) { WriteObject(true); } }); }
private string GetStorageAccountName(string storageAccountId) { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); if (string.IsNullOrEmpty(storageAccountId)) { throw new ArgumentException(Resources.StorageAccountIdException); } else { string[] resourceParts = storageAccountId.Split('/'); // Valid ARM uri when split on '/' should have 9 parts. Ex: /subscriptions/<sub-id>/resourceGroups/<resource group name>/providers/Microsoft.ClassicStorage/storageAccounts/<account name> if (resourceParts.Length != 9) { throw new ArgumentException(Resources.StorageAccountIdException); } return(resourceParts[8]); } }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(null, PrimaryServerName); Utility.ValidateResourceGroupAndResourceName(null, SecondaryServerName); string resourceGroupName = CacheClient.GetResourceGroupNameIfNotProvided(null, PrimaryServerName); ConfirmAction( string.Format(Resources.RemoveLinkedServer, SecondaryServerName, PrimaryServerName), PrimaryServerName, () => { CacheClient.RemoveLinkedServer(resourceGroupName, PrimaryServerName, SecondaryServerName); if (PassThru) { WriteObject(true); } }); }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(null, Name); Utility.ValidateResourceGroupAndResourceName(null, PrimaryServerName); Utility.ValidateResourceGroupAndResourceName(null, SecondaryServerName); if (!string.IsNullOrWhiteSpace(Name)) { // All links for cache List <PSRedisLinkedServer> list = GetAllLinks(Name); WriteObject(list, true); } else if (!string.IsNullOrWhiteSpace(PrimaryServerName) && !string.IsNullOrWhiteSpace(SecondaryServerName)) { // specific link only string resourceGroupName = CacheClient.GetResourceGroupNameIfNotProvided(null, PrimaryServerName); RedisLinkedServerWithProperties redisLinkedServer = CacheClient.GetLinkedServer( resourceGroupName: resourceGroupName, cacheName: PrimaryServerName, linkedCacheName: SecondaryServerName); if (redisLinkedServer == null || redisLinkedServer.ServerRole != ReplicationRole.Secondary) { throw new CloudException(string.Format(Resources.LinkedServerNotFound, PrimaryServerName, SecondaryServerName)); } WriteObject(new PSRedisLinkedServer(redisLinkedServer)); } else if (!string.IsNullOrWhiteSpace(PrimaryServerName)) { // all primary links only List <PSRedisLinkedServer> list = GetAllLinksByRoleType(PrimaryServerName, ReplicationRole.Primary); WriteObject(list, true); } else { // all secondary links only List <PSRedisLinkedServer> list = GetAllLinksByRoleType(SecondaryServerName, ReplicationRole.Secondary); WriteObject(list, true); } }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); ResourceGroupName = CacheClient.GetResourceGroupNameIfNotProvided(ResourceGroupName, Name); if (!string.IsNullOrEmpty(RuleName)) { RedisFirewallRule redisFirewallRule = CacheClient.GetFirewallRule( resourceGroupName: ResourceGroupName, cacheName: Name, ruleName: RuleName); if (redisFirewallRule == null) { throw new CloudException(string.Format(Resources.FirewallRuleNotFound, Name, RuleName)); } WriteObject(new PSRedisFirewallRule(ResourceGroupName, Name, redisFirewallRule)); } else { IPage <RedisFirewallRule> response = CacheClient.ListFirewallRules(ResourceGroupName, Name); List <PSRedisFirewallRule> list = new List <PSRedisFirewallRule>(); foreach (RedisFirewallRule redisFirewallRule in response) { list.Add(new PSRedisFirewallRule(ResourceGroupName, Name, redisFirewallRule)); } while (!string.IsNullOrEmpty(response.NextPageLink)) { response = CacheClient.ListFirewallRules(response.NextPageLink); foreach (RedisFirewallRule redisFirewallRule in response) { list.Add(new PSRedisFirewallRule(ResourceGroupName, Name, redisFirewallRule)); } } WriteObject(list, true); } }
public override void ExecuteCmdlet() { Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); if (!Force.IsPresent) { ConfirmAction( Force.IsPresent, string.Format(Resources.ImportingRedisCache, Name), string.Format(Resources.ImportRedisCache, Name), Name, () => CacheClient.ImportToCache(ResourceGroupName, Name, Files, Format)); } else { CacheClient.ImportToCache(ResourceGroupName, Name, Files, Format); } if (PassThru) { WriteObject(true); } }
public override void ExecuteCmdlet() { if (ParameterSetName.Equals(InputObjectParameterSet)) { ResourceGroupName = InputObject.ResourceGroupName; Name = InputObject.Name; RuleName = InputObject.RuleName; } Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name); ResourceGroupName = CacheClient.GetResourceGroupNameIfNotProvided(ResourceGroupName, Name); ConfirmAction( string.Format(Resources.RemoveFirewallRule, RuleName, Name), Name, () => { CacheClient.RemoveFirewallRule(ResourceGroupName, Name, RuleName); if (PassThru) { WriteObject(true); } }); }
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); CacheClient.RemovePatchSchedules(ResourceGroupName, Name); }
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; } } WriteObject( new RedisCacheAttributesWithAccessKeys( CacheClient.CreateOrUpdateCache(ResourceGroupName, Name, Location, skuFamily, skuCapacity, Sku, RedisConfiguration, EnableNonSslPort, TenantSettings, ShardCount, SubnetId, StaticIP), ResourceGroupName ) ); }