public void ExecuteCommand() { ValidateParameters(); bool removeAll = Role == null || !Role.Any(); ExtensionConfigurationBuilder configBuilder = ExtensionManager.GetBuilder(Deployment != null ? Deployment.ExtensionConfiguration : null); if ((UninstallConfiguration || removeAll) && configBuilder.ExistAny(ProviderNamespace, ExtensionName)) { // Remove extension for all roles configBuilder.RemoveAny(ProviderNamespace, ExtensionName); WriteWarning(string.Format(Resources.ServiceExtensionRemovingFromAllRoles, ExtensionName, ServiceName)); ChangeDeployment(configBuilder.ToConfiguration()); } else if (!removeAll && configBuilder.Exist(Role, ProviderNamespace, ExtensionName)) { // Remove extension for the specified roles bool defaultExists = configBuilder.ExistDefault(ProviderNamespace, ExtensionName); foreach (var r in Role) { var singleRoleAsArray = new string[] { r }; if (configBuilder.Exist(singleRoleAsArray, ProviderNamespace, ExtensionName)) { configBuilder.Remove(singleRoleAsArray, ProviderNamespace, ExtensionName); WriteWarning(string.Format(Resources.ServiceExtensionRemovingFromSpecificRoles, ExtensionName, r, ServiceName)); } else { WriteWarning(string.Format(Resources.ServiceExtensionNoExistingExtensionsEnabledOnRole, ProviderNamespace, ExtensionName, r)); } if (defaultExists) { WriteWarning(string.Format(Resources.ServiceExtensionRemovingSpecificAndApplyingDefault, ExtensionName, r)); } } ChangeDeployment(configBuilder.ToConfiguration()); } else { WriteWarning(string.Format(Resources.ServiceExtensionNoExistingExtensionsEnabledOnRoles, ProviderNamespace, ExtensionName)); } if (UninstallConfiguration) { var allConfig = ExtensionManager.GetBuilder(); var deploymentList = (from slot in (new string[] { DeploymentSlot.Production.ToString(), DeploymentSlot.Staging.ToString() }) let d = GetDeployment(slot) where d != null select d).ToList(); deploymentList.ForEach(d => allConfig.Add(d.ExtensionConfiguration)); ExtensionManager.Uninstall(ProviderNamespace, ExtensionName, allConfig.ToConfiguration()); } }
public void ExecuteCommand() { ValidateParameters(); ExtensionConfigurationBuilder configBuilder = ExtensionManager.GetBuilder(Deployment != null ? Deployment.ExtensionConfiguration : null); if (UninstallConfiguration && configBuilder.ExistAny(ExtensionNameSpace, ExtensionType)) { configBuilder.RemoveAny(ExtensionNameSpace, ExtensionType); WriteVerbose(string.Format(Resources.ServiceExtensionRemovingFromAllRoles, ExtensionType, ServiceName)); ChangeDeployment(configBuilder.ToConfiguration()); } else if (configBuilder.Exist(Role, ExtensionNameSpace, ExtensionType)) { configBuilder.Remove(Role, ExtensionNameSpace, ExtensionType); if (Role == null || !Role.Any()) { WriteVerbose(string.Format(Resources.ServiceExtensionRemovingFromAllRoles, ExtensionType, ServiceName)); } else { bool defaultExists = configBuilder.ExistDefault(ExtensionNameSpace, ExtensionType); foreach (var r in Role) { WriteVerbose(string.Format(Resources.ServiceExtensionRemovingFromSpecificRoles, ExtensionType, r, ServiceName)); if (defaultExists) { WriteVerbose(string.Format(Resources.ServiceExtensionRemovingSpecificAndApplyingDefault, ExtensionType, r)); } } } ChangeDeployment(configBuilder.ToConfiguration()); } else { WriteVerbose(string.Format(Resources.ServiceExtensionNoExistingExtensionsEnabledOnRoles, ExtensionNameSpace, ExtensionType)); } if (UninstallConfiguration) { var allConfig = ExtensionManager.GetBuilder(); var deploymentList = (from slot in (new string[] { DeploymentSlotType.Production, DeploymentSlotType.Staging }) let d = GetDeployment(slot) where d != null select d).ToList(); deploymentList.ForEach(d => allConfig.Add(d.ExtensionConfiguration)); ExtensionManager.Uninstall(ExtensionNameSpace, ExtensionType, allConfig.ToConfiguration()); } }
protected void RemoveExtension() { ExtensionConfigurationBuilder configBuilder = ExtensionManager.GetBuilder(Deployment != null ? Deployment.ExtensionConfiguration : null); if (UninstallConfiguration && configBuilder.ExistAny(ProviderNamespace, ExtensionName)) { configBuilder.RemoveAny(ProviderNamespace, ExtensionName); WriteWarning(string.Format(Resources.ServiceExtensionRemovingFromAllRoles, ExtensionName, ServiceName)); ChangeDeployment(configBuilder.ToConfiguration()); } else if (configBuilder.Exist(Role, ProviderNamespace, ExtensionName)) { configBuilder.Remove(Role, ProviderNamespace, ExtensionName); if (Role == null || !Role.Any()) { WriteWarning(string.Format(Resources.ServiceExtensionRemovingFromAllRoles, ExtensionName, ServiceName)); } else { bool defaultExists = configBuilder.ExistDefault(ProviderNamespace, ExtensionName); foreach (var r in Role) { WriteWarning(string.Format(Resources.ServiceExtensionRemovingFromSpecificRoles, ExtensionName, r, ServiceName)); if (defaultExists) { WriteWarning(string.Format(Resources.ServiceExtensionRemovingSpecificAndApplyingDefault, ExtensionName, r)); } } } ChangeDeployment(configBuilder.ToConfiguration()); } else { WriteWarning(string.Format(Resources.ServiceExtensionNoExistingExtensionsEnabledOnRoles, ProviderNamespace, ExtensionName)); } if (UninstallConfiguration) { var allConfig = ExtensionManager.GetBuilder(); var deploymentList = (from slot in (new string[] { DeploymentSlot.Production.ToString(), DeploymentSlot.Staging.ToString() }) let d = GetDeployment(slot) where d != null select d).ToList(); deploymentList.ForEach(d => allConfig.Add(d.ExtensionConfiguration)); ExtensionManager.Uninstall(ProviderNamespace, ExtensionName, allConfig.ToConfiguration()); } }
protected void RemoveAntimalwareExtension() { ProviderNamespace = AntimalwareExtensionProviderNamespace; ExtensionName = AntimalwareExtensionName; ExtensionConfigurationBuilder configBuilder = ExtensionManager.GetBuilder(Deployment != null ? Deployment.ExtensionConfiguration : null); if (UninstallConfiguration && configBuilder.ExistAny(ProviderNamespace, ExtensionName)) { configBuilder.RemoveAny(ProviderNamespace, ExtensionName); WriteWarning(string.Format(Resources.ServiceExtensionRemovingFromAllRoles, ExtensionName, ServiceName)); ChangeDeployment(configBuilder.ToConfiguration()); } else if (configBuilder.Exist(Role, ProviderNamespace, ExtensionName)) { configBuilder.Remove(Role, ProviderNamespace, ExtensionName); if (Role == null || !Role.Any()) { WriteWarning(string.Format(Resources.ServiceExtensionRemovingFromAllRoles, ExtensionName, ServiceName)); } else { bool defaultExists = configBuilder.ExistDefault(ProviderNamespace, ExtensionName); foreach (var r in Role) { WriteWarning(string.Format(Resources.ServiceExtensionRemovingFromSpecificRoles, ExtensionName, r, ServiceName)); if (defaultExists) { WriteWarning(string.Format(Resources.ServiceExtensionRemovingSpecificAndApplyingDefault, ExtensionName, r)); } } } ChangeDeployment(configBuilder.ToConfiguration()); } else { WriteWarning(string.Format(Resources.ServiceExtensionNoExistingExtensionsEnabledOnRoles, ProviderNamespace, ExtensionName)); } }
/// <summary> /// The configuration must be defined in either allRoles or namedRoles. /// Otherwise, it will fail for trying to apply the same extension. /// We only apply the fix here but not in ExtensionManager, so other commands won't get affected. /// </summary> /// <param name="configInput">The configuration used for InstallExtension()</param> /// <param name="extConfig">The extension config after InstallExtension()</param> private Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration PostProcessExtensionConfigAfterInstallExtension( ExtensionConfigurationInput configInput, Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration extConfig) { ExtensionConfigurationBuilder builder = ExtensionManager.GetBuilder(extConfig); if (configInput.Roles.All(r => r.Default)) { // If the configuration applies to all roles, remove the ones defined in each named roles foreach (var role in Deployment.Roles) { builder.Remove(role.RoleName, ProviderNamespace, ExtensionName); } } else { // If the configuration applies to some specific roles and there is already extension defined in allRoles, // we remove the setting from allRoles and move it to specific namedRoles. if (builder.ExistDefault(ProviderNamespace, ExtensionName)) { var diagnosticExtensionId = extConfig.AllRoles.FirstOrDefault(ext => { var e = ExtensionManager.GetExtension(ext.Id); return(e != null && e.ProviderNamespace == ProviderNamespace && e.Type == ExtensionName); }).Id; builder.RemoveDefault(diagnosticExtensionId); foreach (var role in Deployment.Roles) { // The role is previously configured by allRoles, move it to the namedRole itself if (!configInput.Roles.Exists(r => r.RoleName == role.RoleName)) { builder.Add(role.RoleName, diagnosticExtensionId); } } } } return(builder.ToConfiguration()); }