diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/Commands.ServiceManagement.csproj b/src/ServiceManagement/Compute/Commands.ServiceManagement/Commands.ServiceManagement.csproj index 4cd52cf3cdc8..10991fab8f12 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/Commands.ServiceManagement.csproj +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/Commands.ServiceManagement.csproj @@ -205,6 +205,7 @@ + diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerAutoPatchingPatchCategoryEnum.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerAutoPatchingPatchCategoryEnum.cs index 428dd8addf52..c0cd8cda7d3b 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerAutoPatchingPatchCategoryEnum.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerAutoPatchingPatchCategoryEnum.cs @@ -27,11 +27,6 @@ public enum AzureVMSqlServerAutoPatchingPatchCategoryEnum /// /// Important patches /// - Important = 0, - - /// - /// Optional patches - /// - Optional = 1 + Important = 1, } } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerAutoPatchingSettings.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerAutoPatchingSettings.cs index 3e2c4e031c68..0c1ebaf6fe57 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerAutoPatchingSettings.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerAutoPatchingSettings.cs @@ -19,9 +19,6 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions /// public class AutoPatchingSettings { - private const string Important = "important"; - private const string Optional = "optional"; - /// /// Enable / Disable auto patching /// @@ -36,53 +33,15 @@ public class AutoPatchingSettings /// Maintainance Windows Start hour ( 0 to 23 ) /// public int MaintenanceWindowStartingHour { get; set; } - + /// /// Maintainance window duration in minutes /// public int MaintenanceWindowDuration { get; set; } - - /// - /// pathc category returned as string - /// - public string PatchCategory - { - get - { - return this.patchCategory.ToString("G"); - } - } - - private AzureVMSqlServerAutoPatchingPatchCategoryEnum patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Unknown; - - public void UpdatePatchingCategory(AzureVMSqlServerAutoPatchingPatchCategoryEnum category) - { - this.patchCategory = category; - } /// - /// Update patching category enum + /// Patch category returned as string /// - /// - public void UpdatePatchingCategory(string category) - { - if (!string.IsNullOrEmpty(category)) - { - switch (category.ToLower()) - { - case Important: - this.patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Important; - break; - - case Optional: - this.patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Optional; - break; - - default: - this.patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Unknown; - break; - } - } - } + public string PatchCategory { get; set; } } } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerAutoTelemetrySettings.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerAutoTelemetrySettings.cs new file mode 100644 index 000000000000..0e6eae811435 --- /dev/null +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerAutoTelemetrySettings.cs @@ -0,0 +1,29 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Security; + +namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions +{ + /// + /// AutoTelemetry settings to configure telemetry collection on SQL VM + /// + public class AutoTelemetrySettings + { + /// + /// The name of the region the VM is running in. + /// + public string Region { get; set; } + } +} diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerPublicSettings.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerPublicSettings.cs index 91e551788795..ab7c69677d64 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerPublicSettings.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerPublicSettings.cs @@ -28,5 +28,10 @@ public class SqlServerPublicSettings /// Auto-backup settings /// public AutoBackupSettings AutoBackupSettings { get; set; } + + /// + /// Auto-telemetry settings + /// + public AutoTelemetrySettings AutoTelemetrySettings { get; set; } } } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/GetAzureVMSqlServerExtension.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/GetAzureVMSqlServerExtension.cs index b44a978410ed..c179bbcbd5e4 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/GetAzureVMSqlServerExtension.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/GetAzureVMSqlServerExtension.cs @@ -76,7 +76,7 @@ private VirtualMachineSqlServerExtensionContext GetExtensionContext(ResourceExte PrivateConfiguration = SecureStringHelper.GetSecureString(PrivateConfiguration), RoleName = VM.GetInstance().RoleName, }; - + // gather extension status messages List statusMessageList = new List(); @@ -155,7 +155,7 @@ private VirtualMachineSqlServerExtensionContext GetExtensionContext(ResourceExte NSM.DeploymentSlot.Production); } catch (CloudException e) - { + { if (e.Response.StatusCode != HttpStatusCode.NotFound) { throw; @@ -188,13 +188,13 @@ private VirtualMachineSqlServerExtensionContext GetExtensionContext(ResourceExte private AutoPatchingSettings DeSerializeAutoPatchingSettings(string category, string input) { AutoPatchingSettings aps = new AutoPatchingSettings(); - + if (!string.IsNullOrEmpty(input)) { try { aps = JsonConvert.DeserializeObject(input); - aps.UpdatePatchingCategory(this.ResolvePatchCategoryStringforPowerShell(aps.PatchCategory)); + aps.PatchCategory = this.ResolvePatchCategoryStringforPowerShell(aps.PatchCategory); } catch (JsonReaderException jre) { @@ -231,28 +231,22 @@ private AutoBackupSettings DeSerializeAutoBackupSettings(string category, string /// /// Map strings Auto-patching public settings -> Powershell API /// "WindowsMandatoryUpdates" -> "Important" - /// "MicrosoftOptionalUpdates" -> "Optional" /// /// /// - private AzureVMSqlServerAutoPatchingPatchCategoryEnum ResolvePatchCategoryStringforPowerShell(string category) + private string ResolvePatchCategoryStringforPowerShell(string category) { - AzureVMSqlServerAutoPatchingPatchCategoryEnum patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Important; + string patchCategory = string.Empty; if (!string.IsNullOrEmpty(category)) { switch (category.ToLower()) { case "windowsmandatoryupdates": - patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Important; - break; - - case "microsoftoptionalupdates": - patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Optional; + patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Important.ToString("G"); break; default: - patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Unknown; break; } } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/NewAzureVMSqlServerAutoPatchingConfig.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/NewAzureVMSqlServerAutoPatchingConfig.cs index 2747fdf5646b..1f2d71567066 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/NewAzureVMSqlServerAutoPatchingConfig.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/NewAzureVMSqlServerAutoPatchingConfig.cs @@ -24,11 +24,11 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions /// /// Helper cmdlet to construct instance of AutoPatching settings class /// - [Cmdlet( - VerbsCommon.New, - AzureVMSqlServerAutoPatchingConfigNoun), - OutputType( - typeof(AutoPatchingSettings))] + [Cmdlet( + VerbsCommon.New, + AzureVMSqlServerAutoPatchingConfigNoun), + OutputType( + typeof(AutoPatchingSettings))] public class NewAzureVMSqlServerAutoPatchingConfigCommand : PSCmdlet { protected const string AzureVMSqlServerAutoPatchingConfigNoun = "AzureVMSqlServerAutoPatchingConfig"; @@ -47,7 +47,7 @@ public class NewAzureVMSqlServerAutoPatchingConfigCommand : PSCmdlet public int MaintenanceWindowDuration { get; set; } [Parameter] - [ValidateSetAttribute(new string[] { "Important", "Optional" })] + [ValidateSetAttribute(new string[] { "Important" })] public string PatchCategory { get; set; } /// @@ -68,7 +68,7 @@ protected override void ProcessRecord() autoPatchingSettings.DayOfWeek = DayOfWeek; autoPatchingSettings.MaintenanceWindowStartingHour = MaintenanceWindowStartingHour; autoPatchingSettings.MaintenanceWindowDuration = MaintenanceWindowDuration; - autoPatchingSettings.UpdatePatchingCategory(PatchCategory); + autoPatchingSettings.PatchCategory = PatchCategory; WriteObject(autoPatchingSettings); } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/SetAzureVMSqlServerExtension.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/SetAzureVMSqlServerExtension.cs index d45c3c1d2a86..42177ad9f257 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/SetAzureVMSqlServerExtension.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/SetAzureVMSqlServerExtension.cs @@ -18,6 +18,7 @@ using Microsoft.WindowsAzure.Commands.Common.Storage; using Microsoft.WindowsAzure.Commands.ServiceManagement.Model; using Microsoft.WindowsAzure.Commands.ServiceManagement.Properties; +using System.Net; namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions { @@ -33,8 +34,8 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions typeof(IPersistentVM))] public class SetAzureVMSqlServerExtensionCommand : VirtualMachineSqlServerExtensionCmdletBase { - protected const string EnableExtensionParamSetName = "EnableSqlServerExtension"; - protected const string DisableSqlServerExtensionParamSetName = "DisableSqlServerExtension"; + protected const string EnableExtensionParamSetName = "EnableSqlServerExtension"; + protected const string DisableSqlServerExtensionParamSetName = "DisableSqlServerExtension"; protected const string UninstallSqlServerExtensionParamSetName = "UninstallSqlServerExtension"; [Parameter( @@ -105,10 +106,58 @@ protected override void ValidateParameters() { base.ValidateParameters(); this.ReferenceName = string.IsNullOrEmpty(this.ReferenceName) ? ExtensionDefaultName : this.ReferenceName; - + this.SetupAutoTelemetrySettings(); this.PublicConfiguration = GetPublicConfiguration(); this.PrivateConfiguration = GetPrivateConfiguration(); this.Version = this.Version ?? ExtensionDefaultVersion; } + + private void SetupAutoTelemetrySettings() + { + if (this.AutoTelemetrySettings == null || string.IsNullOrEmpty(this.AutoTelemetrySettings.Region)) + { + foreach (var hs in this.ComputeClient.HostedServices.List().HostedServices) + { + try + { + var deployment = this.ComputeClient.Deployments.GetBySlot(hs.ServiceName, Management.Compute.Models.DeploymentSlot.Production); + if (deployment != null) + { + var role = deployment.RoleInstances.FirstOrDefault(r => r.RoleName == VM.GetInstance().RoleName); + + string location = String.Empty; + if (role != null) + { + if (null != hs.Properties) + { + if (!string.IsNullOrEmpty(hs.Properties.Location)) + { + location = hs.Properties.Location; + } + else + { + if (!string.IsNullOrEmpty(hs.Properties.AffinityGroup)) + { + location = this.ManagementClient.AffinityGroups.Get(hs.Properties.AffinityGroup).Location; + } + } + } + + this.AutoTelemetrySettings = new AutoTelemetrySettings() { Region = location }; + WriteVerboseWithTimestamp("VM Location:" + location); + break; + } + } + } + catch (CloudException e) + { + if (e.Response.StatusCode != HttpStatusCode.NotFound) + { + throw; + } + } + } + } + } } } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/VirtualMachineSqlServerExtensionCmdletBase.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/VirtualMachineSqlServerExtensionCmdletBase.cs index 654a6bfd9f29..1d82cef7492a 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/VirtualMachineSqlServerExtensionCmdletBase.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/VirtualMachineSqlServerExtensionCmdletBase.cs @@ -37,7 +37,7 @@ public class VirtualMachineSqlServerExtensionCmdletBase : VirtualMachineExtensio /// /// Extension's default version /// - protected const string ExtensionDefaultVersion = "1.0"; + protected const string ExtensionDefaultVersion = "1.*"; /// /// value of Auto-patching settings object that can be set by derived classes @@ -49,6 +49,11 @@ public class VirtualMachineSqlServerExtensionCmdletBase : VirtualMachineExtensio /// public virtual AutoBackupSettings AutoBackupSettings { get; set; } + /// + /// value of Auto-telemetry settings object that can be set by derived classes + /// + public virtual AutoTelemetrySettings AutoTelemetrySettings { get; set; } + /// /// Sets extension's publisher and name /// @@ -68,7 +73,8 @@ protected string GetPublicConfiguration() new SqlServerPublicSettings { AutoPatchingSettings = this.AutoPatchingSettings, - AutoBackupSettings = this.AutoBackupSettings + AutoBackupSettings = this.AutoBackupSettings, + AutoTelemetrySettings = this.AutoTelemetrySettings })); } @@ -81,7 +87,7 @@ protected string GetPrivateConfiguration() return JsonUtilities.TryFormatJson(JsonConvert.SerializeObject( new SqlServerPrivateSettings { - StorageUrl = (this.AutoBackupSettings == null)? string.Empty: this.AutoBackupSettings.StorageUrl, + StorageUrl = (this.AutoBackupSettings == null) ? string.Empty : this.AutoBackupSettings.StorageUrl, StorageAccessKey = (this.AutoBackupSettings == null) ? string.Empty : this.AutoBackupSettings.StorageAccessKey, Password = (this.AutoBackupSettings == null) ? string.Empty : this.AutoBackupSettings.Password })); diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/Microsoft.WindowsAzure.Commands.ServiceManagement.dll-Help.xml b/src/ServiceManagement/Compute/Commands.ServiceManagement/Microsoft.WindowsAzure.Commands.ServiceManagement.dll-Help.xml index 182e82e58aa7..9efb79645d76 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/Microsoft.WindowsAzure.Commands.ServiceManagement.dll-Help.xml +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/Microsoft.WindowsAzure.Commands.ServiceManagement.dll-Help.xml @@ -33136,7 +33136,7 @@ PS C:\> Get-AzureVM -ServiceName "ContosoService03" -Name "Con PatchCategory - Defines if recommended updates should be included. + Defines if Important updates should be included. string @@ -33195,7 +33195,7 @@ PS C:\> Get-AzureVM -ServiceName "ContosoService03" -Name "Con PatchCategory - Defines if recommended updates should be included. + Defines if important updates should be included. string @@ -33261,14 +33261,14 @@ PS C:\> Get-AzureVM -ServiceName "ContosoService03" -Name "Con - C:\PS> $aps = New-AzureVMSqlServerAutoPatchingConfig -Enable -DayOfWeek "Thursday" -MaintenanceWindowStartingHour 11 -MaintenanceWindowDuration 120 -PatchCategory "Optional" + C:\PS> $aps = New-AzureVMSqlServerAutoPatchingConfig -Enable -DayOfWeek "Thursday" -MaintenanceWindowStartingHour 11 -MaintenanceWindowDuration 120 -PatchCategory "Important" PS C:\> $aps Enable : True DayOfWeek : Thursday MaintenanceWindowStartingHour : 11 MaintenanceWindowDuration : 120 - PatchCategory : Optional + PatchCategory : Important This command creates configuration object that can be used to configure automatic patching using Set-AzureVMSqlServerExtension