public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { if (ShouldProcess(this.Name, VerbsCommon.New)) { string resourceGroupName = this.ResourceGroupName; string resourceName = this.Name; MaintenanceConfiguration configuration = new MaintenanceConfiguration(); if (this.Location != null) { configuration.Location = this.Location; } if (this.Tag != null) { configuration.Tags = this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value); } if (this.ExtensionProperty != null) { configuration.ExtensionProperties = this.ExtensionProperty.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value); } if (this.MaintenanceScope != null) { configuration.MaintenanceScope = this.MaintenanceScope; } var result = MaintenanceConfigurationsClient.CreateOrUpdate(resourceGroupName, resourceName, configuration); var psObject = new PSMaintenanceConfiguration(); MaintenanceAutomationAutoMapperProfile.Mapper.Map <MaintenanceConfiguration, PSMaintenanceConfiguration>(result, psObject); WriteObject(psObject); } }); }
public SettingsManager() { Config = new AppConfig(); MaintenanceConfig = new MaintenanceConfiguration(); PatchUpdaterConfig = new PatchUpdaterConfiguration(); GrayConnectConfig = new GrayConnectConfiguration(); }
public static void VerifyMaintenanceConfigurationProperties(MaintenanceConfiguration expected, MaintenanceConfiguration actual) { Assert.NotNull(actual); Assert.Equal(expected.Name, actual.Name); Assert.Equal(expected.Location, actual.Location); Assert.Equal(expected.MaintenanceScope, actual.MaintenanceScope); if (actual.MaintenanceScope == MaintenanceScope.InGuestPatch) { if (actual.InstallPatches == null) { Assert.Equal(expected.InstallPatches, actual.InstallPatches); return; } Assert.Equal(expected.InstallPatches.RebootSetting, actual.InstallPatches.RebootSetting); Assert.Equal(1, actual.InstallPatches.LinuxParameters.PackageNameMasksToInclude.Count); Assert.Equal(expected.InstallPatches.LinuxParameters.PackageNameMasksToInclude[0], actual.InstallPatches.LinuxParameters.PackageNameMasksToInclude[0]); Assert.Equal(1, actual.InstallPatches.LinuxParameters.ClassificationsToInclude.Count); Assert.Equal(expected.InstallPatches.LinuxParameters.ClassificationsToInclude[0], actual.InstallPatches.LinuxParameters.ClassificationsToInclude[0]); Assert.Equal(1, actual.InstallPatches.WindowsParameters.KbNumbersToInclude.Count); Assert.Equal(expected.InstallPatches.WindowsParameters.KbNumbersToInclude[0], actual.InstallPatches.WindowsParameters.KbNumbersToInclude[0]); Assert.Equal(2, actual.InstallPatches.WindowsParameters.ClassificationsToInclude.Count); Assert.Equal(expected.InstallPatches.WindowsParameters.ClassificationsToInclude[0], actual.InstallPatches.WindowsParameters.ClassificationsToInclude[0]); Assert.Equal(expected.InstallPatches.WindowsParameters.ClassificationsToInclude[1], actual.InstallPatches.WindowsParameters.ClassificationsToInclude[1]); Assert.Equal(1, actual.InstallPatches.PreTasks.Count); Assert.Equal(expected.InstallPatches.PreTasks[0].Source, actual.InstallPatches.PreTasks[0].Source); Assert.Equal(expected.InstallPatches.PreTasks[0].TaskScope, actual.InstallPatches.PreTasks[0].TaskScope); foreach (var kvp in expected.InstallPatches.PreTasks[0].Parameters) { Assert.True(actual.InstallPatches.PreTasks[0].Parameters.TryGetValue(kvp.Key, out var _)); Assert.Equal(expected.InstallPatches.PreTasks[0].Parameters[kvp.Key], actual.InstallPatches.PreTasks[0].Parameters[kvp.Key]); } } }
public static void VerifyMaintenanceConfigurationProperties(MaintenanceConfiguration expected, MaintenanceConfiguration actual) { Assert.NotNull(actual); Assert.Equal(expected.Name, actual.Name); Assert.Equal(expected.Location, actual.Location); Assert.Equal(expected.MaintenanceScope, actual.MaintenanceScope); }
public static MaintenanceConfiguration CreateTestMaintenanceConfiguration(string maintenanceConfigurationName) { var maintenanceConfiguration = new MaintenanceConfiguration( name: maintenanceConfigurationName, location: "westus", maintenanceScope: MaintenanceScope.Host); return(maintenanceConfiguration); }
public static MaintenanceConfiguration CreateTestPublicMaintenanceConfiguration(string maintenanceConfigurationName) { var maintenanceConfiguration = new MaintenanceConfiguration( name: maintenanceConfigurationName, location: "westus", startDateTime: "2020-04-01 01:00:00", visibility: Visibility.Public, maintenanceScope: MaintenanceScope.SQLDB); return(maintenanceConfiguration); }
public static MaintenanceConfiguration CreateTestMaintenanceConfigurationInGuestPatchScope(string maintenanceConfigurationName, bool advancePatchOption = false) { var maintenanceConfiguration = new MaintenanceConfiguration( name: maintenanceConfigurationName, location: "eastus2euap", startDateTime: "2021-09-01 01:00", maintenanceScope: MaintenanceScope.InGuestPatch, duration: "01:00", timeZone: "India Standard Time", recurEvery: "2Months Third Monday Offset-4"); if (advancePatchOption) { maintenanceConfiguration.InstallPatches = new InputPatchConfiguration() { PreTasks = new List <TaskProperties> { new TaskProperties() { Source = "/subscriptions/42c974dd-2c03-4f1b-96ad-b07f050aaa74/resourceGroups/DefaultResourceGroup-EUS/providers/Microsoft.Automation/automationAccounts/Automate-42c974dd-2c03-4f1b-96ad-b07f050aaa74-EUS/runbooks/foo", TaskScope = TaskScope.Global, Parameters = new Dictionary <string, string>() { ["param1"] = "value1" } } }, LinuxParameters = new InputLinuxParameters() { ClassificationsToInclude = new List <string> () { "Other" }, PackageNameMasksToInclude = new List <string>() { "apt" } }, WindowsParameters = new InputWindowsParameters() { ClassificationsToInclude = new List <string>() { "UpdateRollup", "ServicePack" }, KbNumbersToInclude = new List <string> { "KB123456" } }, RebootSetting = RebootOptions.IfRequired }; } return(maintenanceConfiguration); }
public static MaintenanceConfiguration CreateTestMaintenanceConfiguration(string maintenanceConfigurationName) { var maintenanceConfiguration = new MaintenanceConfiguration( name: maintenanceConfigurationName, location: "eastus2euap", startDateTime: "2021-09-01 01:00", duration: "03:00", timeZone: "India Standard Time", recurEvery: "2Weeks Monday", maintenanceScope: MaintenanceScope.Host); return(maintenanceConfiguration); }
public static MaintenanceConfiguration CreateTestPublicMaintenanceConfiguration(string maintenanceConfigurationName) { var maintenanceConfiguration = new MaintenanceConfiguration( name: maintenanceConfigurationName, location: "eastus2euap", startDateTime: "2021-09-01 01:00", duration: "02:00", timeZone: "India Standard Time", recurEvery: "2Weeks Monday", visibility: Visibility.Public, maintenanceScope: MaintenanceScope.SQLDB, extensionProperties: new Dictionary <string, string>() { ["isAvailable"] = "true" }); return(maintenanceConfiguration); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { if (ShouldProcess(this.Name, VerbsData.Update)) { string resourceGroupName = this.ResourceGroupName; string name = this.Name; MaintenanceConfiguration configuration = new MaintenanceConfiguration(); MaintenanceAutomationAutoMapperProfile.Mapper.Map <PSMaintenanceConfiguration, MaintenanceConfiguration>(this.Configuration, configuration); var result = MaintenanceConfigurationsClient.UpdateMethod(resourceGroupName, name, configuration); var psObject = new PSMaintenanceConfiguration(); MaintenanceAutomationAutoMapperProfile.Mapper.Map <MaintenanceConfiguration, PSMaintenanceConfiguration>(result, psObject); WriteObject(psObject); } }); }
/// <summary> /// Creates or updates a maintenance configuration in the specified managed /// cluster. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='resourceName'> /// The name of the managed cluster resource. /// </param> /// <param name='configName'> /// The name of the maintenance configuration. /// </param> /// <param name='parameters'> /// The maintenance configuration to create or update. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <MaintenanceConfiguration> CreateOrUpdateAsync(this IMaintenanceConfigurationsOperations operations, string resourceGroupName, string resourceName, string configName, MaintenanceConfiguration parameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, resourceName, configName, parameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Creates or updates a maintenance configuration in the specified managed /// cluster. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='resourceName'> /// The name of the managed cluster resource. /// </param> /// <param name='configName'> /// The name of the maintenance configuration. /// </param> /// <param name='parameters'> /// The maintenance configuration to create or update. /// </param> public static MaintenanceConfiguration CreateOrUpdate(this IMaintenanceConfigurationsOperations operations, string resourceGroupName, string resourceName, string configName, MaintenanceConfiguration parameters) { return(operations.CreateOrUpdateAsync(resourceGroupName, resourceName, configName, parameters).GetAwaiter().GetResult()); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); ExecuteClientAction(() => { if (ShouldProcess(this.Name, VerbsCommon.New)) { string resourceGroupName = this.ResourceGroupName; string resourceName = this.Name; MaintenanceConfiguration configuration = new MaintenanceConfiguration(); if (this.Location != null) { configuration.Location = this.Location; } if (this.Tag != null) { configuration.Tags = this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value); } if (this.ExtensionProperty != null) { configuration.ExtensionProperties = this.ExtensionProperty.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value); } if (this.MaintenanceScope != null) { configuration.MaintenanceScope = this.MaintenanceScope; } if (this.StartDateTime != null) { configuration.StartDateTime = this.StartDateTime; } if (this.ExpirationDateTime != null) { configuration.ExpirationDateTime = this.ExpirationDateTime; } if (this.Duration != null) { configuration.Duration = this.Duration.ToString((@"hh\:mm")); } if (this.Timezone != null) { configuration.TimeZone = this.Timezone; } if (this.RecurEvery != null) { configuration.RecurEvery = this.RecurEvery; } if (this.Visibility != null) { configuration.Visibility = this.Visibility; } if (this.InstallPatchRebootSetting != null) { configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration(); configuration.InstallPatches.RebootSetting = this.InstallPatchRebootSetting; } if (this.WindowParameterClassificationToInclude != null) { configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration(); configuration.InstallPatches.WindowsParameters = configuration.InstallPatches.WindowsParameters ?? new InputWindowsParameters(); configuration.InstallPatches.WindowsParameters.ClassificationsToInclude = this.WindowParameterClassificationToInclude.ToList(); } if (this.WindowParameterExcludeKbRequiringReboot.HasValue) { configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration(); configuration.InstallPatches.WindowsParameters = configuration.InstallPatches.WindowsParameters ?? new InputWindowsParameters(); configuration.InstallPatches.WindowsParameters.ExcludeKbsRequiringReboot = this.WindowParameterExcludeKbRequiringReboot; } if (this.WindowParameterKbNumberToExclude != null) { configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration(); configuration.InstallPatches.WindowsParameters = configuration.InstallPatches.WindowsParameters ?? new InputWindowsParameters(); configuration.InstallPatches.WindowsParameters.KbNumbersToExclude = this.WindowParameterKbNumberToExclude.ToList(); } if (this.WindowParameterKbNumberToInclude != null) { configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration(); configuration.InstallPatches.WindowsParameters = configuration.InstallPatches.WindowsParameters ?? new InputWindowsParameters(); configuration.InstallPatches.WindowsParameters.KbNumbersToInclude = this.WindowParameterKbNumberToInclude.ToList(); } if (this.LinuxParameterClassificationToInclude != null) { configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration(); configuration.InstallPatches.LinuxParameters = configuration.InstallPatches.LinuxParameters ?? new InputLinuxParameters(); configuration.InstallPatches.LinuxParameters.ClassificationsToInclude = this.LinuxParameterClassificationToInclude.ToList(); } if (this.LinuxParameterPackageNameMaskToExclude != null) { configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration(); configuration.InstallPatches.LinuxParameters = configuration.InstallPatches.LinuxParameters ?? new InputLinuxParameters(); configuration.InstallPatches.LinuxParameters.PackageNameMasksToExclude = this.LinuxParameterPackageNameMaskToExclude.ToList(); } if (this.LinuxParameterPackageNameMaskToInclude != null) { configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration(); configuration.InstallPatches.LinuxParameters = configuration.InstallPatches.LinuxParameters ?? new InputLinuxParameters(); configuration.InstallPatches.LinuxParameters.PackageNameMasksToInclude = this.LinuxParameterPackageNameMaskToInclude.ToList(); } if (this.PreTask != null) { configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration(); configuration.InstallPatches.PreTasks = JsonConvert.DeserializeObject <List <TaskProperties> >(this.PreTask); } if (this.PostTask != null) { configuration.InstallPatches = configuration.InstallPatches ?? new InputPatchConfiguration(); configuration.InstallPatches.PreTasks = JsonConvert.DeserializeObject <List <TaskProperties> >(this.PostTask); } var result = MaintenanceConfigurationsClient.CreateOrUpdate(resourceGroupName, resourceName, configuration); var psObject = new PSMaintenanceConfiguration(); MaintenanceAutomationAutoMapperProfile.Mapper.Map <MaintenanceConfiguration, PSMaintenanceConfiguration>(result, psObject); WriteObject(psObject); } }); }
/// <summary> /// Patch configuration record /// </summary> /// <param name='resourceGroupName'> /// Resource Group Name /// </param> /// <param name='resourceName'> /// Maintenance Configuration Name /// </param> /// <param name='configuration'> /// The configuration /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="MaintenanceErrorException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <exception cref="SerializationException"> /// Thrown when unable to deserialize the response /// </exception> /// <exception cref="ValidationException"> /// Thrown when a required parameter is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <AzureOperationResponse <MaintenanceConfiguration> > UpdateMethodWithHttpMessagesAsync(string resourceGroupName, string resourceName, MaintenanceConfiguration configuration, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (Client.SubscriptionId == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); } if (resourceGroupName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName"); } if (resourceName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "resourceName"); } if (configuration == null) { throw new ValidationException(ValidationRules.CannotBeNull, "configuration"); } if (Client.ApiVersion == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceGroupName", resourceGroupName); tracingParameters.Add("resourceName", resourceName); tracingParameters.Add("configuration", configuration); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "UpdateMethod", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Maintenance/maintenanceConfigurations/{resourceName}").ToString(); _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName)); _url = _url.Replace("{resourceName}", System.Uri.EscapeDataString(resourceName)); List <string> _queryParameters = new List <string>(); if (Client.ApiVersion != null) { _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); } if (_queryParameters.Count > 0) { _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); } // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("PATCH"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) { _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()); } if (Client.AcceptLanguage != null) { if (_httpRequest.Headers.Contains("accept-language")) { _httpRequest.Headers.Remove("accept-language"); } _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); } if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (configuration != null) { _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(configuration, Client.SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Set Credentials if (Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200) { var ex = new MaintenanceErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); MaintenanceError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject <MaintenanceError>(_responseContent, Client.DeserializationSettings); if (_errorBody != null) { ex.Body = _errorBody; } } catch (JsonException) { // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new AzureOperationResponse <MaintenanceConfiguration>(); _result.Request = _httpRequest; _result.Response = _httpResponse; if (_httpResponse.Headers.Contains("x-ms-request-id")) { _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } // Deserialize Response if ((int)_statusCode == 200) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject <MaintenanceConfiguration>(_responseContent, Client.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
/// <summary> /// Patch configuration record /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// Resource Group Name /// </param> /// <param name='resourceName'> /// Maintenance Configuration Name /// </param> /// <param name='configuration'> /// The configuration /// </param> public static MaintenanceConfiguration UpdateMethod(this IMaintenanceConfigurationsOperations operations, string resourceGroupName, string resourceName, MaintenanceConfiguration configuration) { return(operations.UpdateMethodAsync(resourceGroupName, resourceName, configuration).GetAwaiter().GetResult()); }