private void CleanupDatabaseServers(AzureResourceType type, Dictionary <string, object> resources) { SafeExecute(() => { var manager = new AzureSqlManager(); foreach (var obj in resources.Values) { var server = obj as SqlAzureServer; if (server == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.GetSqlServer(server.Name, server.User, server.Password) != null) { var databases = server.GetDatabases(); // if after we deleted our databases there are still more than one (master) database, // it means some one reuses this server, so don't delete it if (databases.Count() <= 1) { manager.DeleteSqlServer(server.Name); } } } resources.Clear(); }, type.ToString()); }
internal static string ToSerializedValue(this AzureResourceType value) { switch (value) { case AzureResourceType.Website: return("Website"); case AzureResourceType.TrafficManager: return("TrafficManager"); } return(null); }
public static bool TryParseAzureResourceType(this Slot slot, out AzureResourceType azureResourceType, ILogger log) { log.LogInformation(slot.Dump()); azureResourceType = null; if (slot.Value.IsNullOrWhiteSpace() || slot.Resolution is null || !slot.Resolution.Authorities.Any() || slot.Resolution.Authorities.First().Values is null) { log.LogError($"Slot {slot.Name} error"); return(false); } var slotId = slot.Resolution.Authorities.First().Values.First().Value.Id; azureResourceType = AzureResourceTypes.Find(Convert.ToInt32(slotId)); return(azureResourceType != null); }
internal void Remember(AzureResourceType type, string key, object resource) { Dictionary <string, object> typeResources; if (!_resources.TryGetValue(type, out typeResources)) { typeResources = new Dictionary <string, object>(); _resources.Add(AzureResourceType.AffinityGroup, typeResources); } object existing; if (!typeResources.TryGetValue(key, out existing)) { typeResources.Add(key, resource); } }
private void CleanupContainers(AzureResourceType type, Dictionary <string, object> resources) { SafeExecute(() => { foreach (var c in resources.Values) { var container = c as CloudBlobContainer; if (container == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } container.DeleteIfExists(); } resources.Clear(); }, type.ToString()); }
private void CleanupBlobs(AzureResourceType type, Dictionary <string, object> resources) { SafeExecute(() => { foreach (var b in resources.Values) { var blob = b as CloudBlockBlob; if (blob == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } blob.DeleteIfExists(); } resources.Clear(); }, type.ToString()); }
private Task CreateResourceAsync( IAuthenticated azure, DeploymentOptions options, AzureResourceType resourceType) { string resourceName = GetRandomResourceName(resourceType); BaseDeployment deployment = null; switch (resourceType) { case AzureResourceType.AppService: case AzureResourceType.WebApp: deployment = new WebAppDeployment(resourceName, azure, options); break; case AzureResourceType.Storage: deployment = new StorageAccountDeployment(resourceName, azure, options); break; case AzureResourceType.CosmosDB: deployment = new CosmosDbAccountDeployment(resourceName, azure, options); break; case AzureResourceType.Functions: deployment = new AzureFunctionDeployment(resourceName, azure, options); break; case AzureResourceType.SqlDatabase: deployment = new SqlAzureDeployment(resourceName, azure, options); break; case AzureResourceType.KeyVault: deployment = new KeyVaultDeployment(resourceName, azure, options); break; default: Debug.WriteLine($"Service of type {resourceType} not supported!"); break; } return(deployment != null ? deployment.CreateAsync() : Task.CompletedTask); }
private static string GetRandomResourceName(AzureResourceType resourceType) { const int maxNameLength = 20; const string CosmosDBPrefix = "cosmos-"; const string FunctionsPrefix = "function-"; const string StoragePrefix = "storage"; const string WebAppPrefix = "web-"; const string SqlPrefix = "sql-"; const string KvPrefix = "vault-"; string prefix = string.Empty; switch (resourceType) { case AzureResourceType.AppService: case AzureResourceType.WebApp: prefix = WebAppPrefix; break; case AzureResourceType.Storage: prefix = StoragePrefix; break; case AzureResourceType.CosmosDB: prefix = CosmosDBPrefix; break; case AzureResourceType.Functions: prefix = FunctionsPrefix; break; case AzureResourceType.SqlDatabase: prefix = SqlPrefix; break; case AzureResourceType.KeyVault: prefix = KvPrefix; break; } return(SdkContext.RandomResourceName(prefix, maxNameLength)); }
internal void Forget(AzureResourceType type, string key) { if (_cleaningIsInProgress) { return; } Dictionary <string, object> typeResources; if (!_resources.TryGetValue(type, out typeResources)) { return; // nothing to forget } object existing; if (typeResources.TryGetValue(key, out existing)) { typeResources.Remove(key); } }
private void CleanupAffinityGroups(AzureResourceType type, Dictionary <string, object> resources) { SafeExecute(() => { var manager = new AzureAffinityGroupManager(); foreach (var obj in resources.Values) { var group = obj as string; if (group == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.GetAffinityGroup(group) != null) { manager.DeleteAffinityGroup(group); } } resources.Clear(); }, type.ToString()); }
private void CleanupDeployments(AzureResourceType type, Dictionary <string, object> resources) { SafeExecute(() => { var manager = new AzureCloudServiceManager(); foreach (var obj in resources.Values) { var deployment = obj as DeploymentInfo; if (deployment == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.GetDeployment(deployment.HostedService, deployment.Deployment.Name) != null) { manager.DeleteDeployment(deployment.HostedService, deployment.Deployment.Name); } } resources.Clear(); }, type.ToString()); }
private void CleanupHostedServices(AzureResourceType type, Dictionary <string, object> resources) { SafeExecute(() => { var manager = new AzureCloudServiceManager(); foreach (var obj in resources.Values) { var service = obj as string; if (service == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.GetHostedService(service) != null) { manager.DeleteHostedService(service); } } resources.Clear(); }, type.ToString()); }
private void CleanupWebSites(AzureResourceType type, Dictionary <string, object> resources) { SafeExecute(() => { var manager = new AzureWebSiteManager(); foreach (var obj in resources.Values) { var site = obj as WAML.WebSites.Models.WebSite; if (site == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.WebSiteExists(site.Name)) { manager.DeleteWebSite(site.Name); } } resources.Clear(); }, type.ToString()); }
private void CleanupDatabases(AzureResourceType type, Dictionary <string, object> resources) { SafeExecute(() => { var manager = new AzureSqlManager(); foreach (var obj in resources.Values) { var database = obj as SqlAzureDatabase; if (database == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.GetSqlServer(database.Server.Name, database.Server.User, database.Server.Password) != null && database.Server.DatabaseExists(database.Name)) { database.Server.DropDatabase(database.Name); } } resources.Clear(); }, type.ToString()); }
private void CleanupDatabaseServers(AzureResourceType type, Dictionary<string, object> resources) { SafeExecute(() => { var manager = new AzureSqlManager(); foreach (var obj in resources.Values) { var server = obj as SqlAzureServer; if (server == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.GetSqlServer(server.Name, server.User, server.Password) != null) { var databases = server.GetDatabases(); // if after we deleted our databases there are still more than one (master) database, // it means some one reuses this server, so don't delete it if (databases.Count() <= 1) { manager.DeleteSqlServer(server.Name); } } } resources.Clear(); }, type.ToString()); }
private void CleanupDatabases(AzureResourceType type, Dictionary<string, object> resources) { SafeExecute(() => { var manager = new AzureSqlManager(); foreach (var obj in resources.Values) { var database = obj as SqlAzureDatabase; if (database == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.GetSqlServer(database.Server.Name, database.Server.User, database.Server.Password) != null && database.Server.DatabaseExists(database.Name)) { database.Server.DropDatabase(database.Name); } } resources.Clear(); }, type.ToString()); }
private void CleanupWebSites(AzureResourceType type, Dictionary<string, object> resources) { SafeExecute(() => { var manager = new AzureWebSiteManager(); foreach (var obj in resources.Values) { var site = obj as WAML.WebSites.Models.WebSite; if (site == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if(manager.WebSiteExists(site.Name)) { manager.DeleteWebSite(site.Name); } } resources.Clear(); }, type.ToString()); }
private void CleanupHostedServices(AzureResourceType type, Dictionary<string, object> resources) { SafeExecute(() => { var manager = new AzureCloudServiceManager(); foreach (var obj in resources.Values) { var service = obj as string; if (service == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.GetHostedService(service) != null) { manager.DeleteHostedService(service); } } resources.Clear(); }, type.ToString()); }
private void CleanupDeployments(AzureResourceType type, Dictionary<string, object> resources) { SafeExecute(() => { var manager = new AzureCloudServiceManager(); foreach (var obj in resources.Values) { var deployment = obj as DeploymentInfo; if (deployment == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if (manager.GetDeployment(deployment.HostedService, deployment.Deployment.Name) != null) { manager.DeleteDeployment(deployment.HostedService, deployment.Deployment.Name); } } resources.Clear(); }, type.ToString()); }
private void CleanupAffinityGroups(AzureResourceType type, Dictionary<string, object> resources) { SafeExecute(() => { var manager = new AzureAffinityGroupManager(); foreach (var obj in resources.Values) { var group = obj as string; if (group == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } if(manager.GetAffinityGroup(group) != null) { manager.DeleteAffinityGroup(group); } } resources.Clear(); }, type.ToString()); }
private void CleanupContainers(AzureResourceType type, Dictionary<string, object> resources) { SafeExecute(() => { foreach (var c in resources.Values) { var container = c as CloudBlobContainer; if (container == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } container.DeleteIfExists(); } resources.Clear(); }, type.ToString()); }
private void CleanupBlobs(AzureResourceType type, Dictionary<string, object> resources) { SafeExecute(() => { foreach (var b in resources.Values) { var blob = b as CloudBlockBlob; if (blob == null) { throw new Exception(string.Format("Incorrect resource was stored in '{0}' collection", type)); } blob.DeleteIfExists(); } resources.Clear(); }, type.ToString()); }
static Task <Result> CreateResourceAsync(IAuthenticated azure, DeploymentOptions options, string resourceName, AzureResourceType resourceType) { var rName = GetRandomResourceName(resourceType, resourceName); BaseDeployment deployment = null; var notSupported = $"Service {resourceType} not supported!"; if (resourceType.Id == AzureResourceTypes.AppService.Id || resourceType.Id == AzureResourceTypes.WebApp.Id) { deployment = new WebAppDeployment(rName, azure, options); } else if (resourceType.Id == AzureResourceTypes.Storage.Id) { deployment = new StorageAccountDeployment(rName, azure, options); } else if (resourceType.Id == AzureResourceTypes.CosmosDB.Id) { deployment = new CosmosDbAccountDeployment(rName, azure, options); } else if (resourceType.Id == AzureResourceTypes.Functions.Id) { deployment = new AzureFunctionDeployment(rName, azure, options); } else if (resourceType.Id == AzureResourceTypes.SqlDatabase.Id) { deployment = new SqlAzureDeployment(rName, azure, options); } else if (resourceType.Id == AzureResourceTypes.KeyVault.Id) { deployment = new KeyVaultDeployment(rName, azure, options); } else if (resourceType.Id == AzureResourceTypes.VirtualMachine.Id) { deployment = new VirtualMachineDeployment(rName, azure, options); } else { Debug.WriteLine(notSupported); } return(deployment?.CreateAsync() ?? Task.FromResult(Result.Fail(notSupported))); }
internal void Remember(AzureResourceType type, string key, object resource) { Dictionary<string, object> typeResources; if (!_resources.TryGetValue(type, out typeResources)) { typeResources = new Dictionary<string, object>(); _resources.Add(AzureResourceType.AffinityGroup, typeResources); } object existing; if (!typeResources.TryGetValue(key, out existing)) { typeResources.Add(key, resource); } }
internal AzureKeyVaultProperties(AzureResourceType azureResourceType, bool?connectAsKubernetesCsiDriver) : base(azureResourceType) { ConnectAsKubernetesCsiDriver = connectAsKubernetesCsiDriver; AzureResourceType = azureResourceType; }
internal AzureResourcePropertiesBase(AzureResourceType azureResourceType) { AzureResourceType = azureResourceType; }
static string GetRandomResourceName(AzureResourceType resourceType, string resourceName = null) { const int maxNameLength = 20; return(SdkContext.RandomResourceName(resourceName is null ? resourceType.Prefix : $"{resourceName.ToLowerCamelCase()}", maxNameLength)); }
/// <summary> /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider" /// /> and <see cref="ignoreCase" /> /// </summary> /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param> /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param> /// <param name="formatProvider">not used by this TypeConverter.</param> /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param> /// <returns> /// an instance of <see cref="AzureResourceType" />, or <c>null</c> if there is no suitable conversion. /// </returns> public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => AzureResourceType.CreateFrom(sourceValue);
internal void Forget(AzureResourceType type, string key) { if (_cleaningIsInProgress) return; Dictionary<string, object> typeResources; if (!_resources.TryGetValue(type, out typeResources)) return; // nothing to forget object existing; if (typeResources.TryGetValue(key, out existing)) { typeResources.Remove(key); } }
public static string ToSerialString(this AzureResourceType value) => value switch {