Skip to content

Commit 1413096

Browse files
- telemetry settings added, In Set-* cmdlet, we pass in region info;
- auto-patching - removed "optional". Only "Important" is supported. - patch category name resolution issues were fixed
1 parent 04137b7 commit 1413096

10 files changed

+118
-80
lines changed

src/ServiceManagement/Compute/Commands.ServiceManagement/Commands.ServiceManagement.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
<Compile Include="IaaS\Extensions\MicrosoftAntimalware\SetAzureVMMicrosoftAntimalwareExtension.cs" />
206206
<Compile Include="IaaS\Extensions\MicrosoftAntimalware\VirtualMachineMicrosoftAntimalwareExtensionCmdletBase.cs" />
207207
<Compile Include="IaaS\Extensions\MicrosoftAntimalware\VirtualMachineMicrosoftAntimalwareExtensionContext.cs" />
208+
<Compile Include="IaaS\Extensions\SqlServer\AzureVMSqlServerAutoTelemetrySettings.cs" />
208209
<Compile Include="IaaS\Extensions\SqlServer\GetAzureVMSqlServerExtension.cs" />
209210
<Compile Include="IaaS\Extensions\SqlServer\NewAzureVMSqlServerAutoBackupConfig.cs" />
210211
<Compile Include="IaaS\Extensions\SqlServer\NewAzureVMSqlServerAutoPatchingConfig.cs" />

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerAutoPatchingPatchCategoryEnum.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ public enum AzureVMSqlServerAutoPatchingPatchCategoryEnum
2727
/// <summary>
2828
/// Important patches
2929
/// </summary>
30-
Important = 0,
31-
32-
/// <summary>
33-
/// Optional patches
34-
/// </summary>
35-
Optional = 1
30+
Important = 1,
3631
}
3732
}

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerAutoPatchingSettings.cs

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions
1919
/// </summary>
2020
public class AutoPatchingSettings
2121
{
22-
private const string Important = "important";
23-
private const string Optional = "optional";
24-
2522
/// <summary>
2623
/// Enable / Disable auto patching
2724
/// </summary>
@@ -36,53 +33,15 @@ public class AutoPatchingSettings
3633
/// Maintainance Windows Start hour ( 0 to 23 )
3734
/// </summary>
3835
public int MaintenanceWindowStartingHour { get; set; }
39-
36+
4037
/// <summary>
4138
/// Maintainance window duration in minutes
4239
/// </summary>
4340
public int MaintenanceWindowDuration { get; set; }
44-
45-
/// <summary>
46-
/// pathc category returned as string
47-
/// </summary>
48-
public string PatchCategory
49-
{
50-
get
51-
{
52-
return this.patchCategory.ToString("G");
53-
}
54-
}
55-
56-
private AzureVMSqlServerAutoPatchingPatchCategoryEnum patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Unknown;
57-
58-
public void UpdatePatchingCategory(AzureVMSqlServerAutoPatchingPatchCategoryEnum category)
59-
{
60-
this.patchCategory = category;
61-
}
6241

6342
/// <summary>
64-
/// Update patching category enum
43+
/// Patch category returned as string
6544
/// </summary>
66-
/// <param name="category"></param>
67-
public void UpdatePatchingCategory(string category)
68-
{
69-
if (!string.IsNullOrEmpty(category))
70-
{
71-
switch (category.ToLower())
72-
{
73-
case Important:
74-
this.patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Important;
75-
break;
76-
77-
case Optional:
78-
this.patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Optional;
79-
break;
80-
81-
default:
82-
this.patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Unknown;
83-
break;
84-
}
85-
}
86-
}
45+
public string PatchCategory { get; set; }
8746
}
8847
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Security;
16+
17+
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions
18+
{
19+
/// <summary>
20+
/// AutoTelemetry settings to configure telemetry collection on SQL VM
21+
/// </summary>
22+
public class AutoTelemetrySettings
23+
{
24+
/// <summary>
25+
/// The name of the region the VM is running in.
26+
/// </summary>
27+
public string Region { get; set; }
28+
}
29+
}

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/AzureVMSqlServerPublicSettings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,10 @@ public class SqlServerPublicSettings
2828
/// Auto-backup settings
2929
/// </summary>
3030
public AutoBackupSettings AutoBackupSettings { get; set; }
31+
32+
/// <summary>
33+
/// Auto-telemetry settings
34+
/// </summary>
35+
public AutoTelemetrySettings AutoTelemetrySettings { get; set; }
3136
}
3237
}

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/GetAzureVMSqlServerExtension.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private VirtualMachineSqlServerExtensionContext GetExtensionContext(ResourceExte
7676
PrivateConfiguration = SecureStringHelper.GetSecureString(PrivateConfiguration),
7777
RoleName = VM.GetInstance().RoleName,
7878
};
79-
79+
8080
// gather extension status messages
8181
List<string> statusMessageList = new List<string>();
8282

@@ -155,7 +155,7 @@ private VirtualMachineSqlServerExtensionContext GetExtensionContext(ResourceExte
155155
NSM.DeploymentSlot.Production);
156156
}
157157
catch (CloudException e)
158-
{
158+
{
159159
if (e.Response.StatusCode != HttpStatusCode.NotFound)
160160
{
161161
throw;
@@ -188,13 +188,13 @@ private VirtualMachineSqlServerExtensionContext GetExtensionContext(ResourceExte
188188
private AutoPatchingSettings DeSerializeAutoPatchingSettings(string category, string input)
189189
{
190190
AutoPatchingSettings aps = new AutoPatchingSettings();
191-
191+
192192
if (!string.IsNullOrEmpty(input))
193193
{
194194
try
195195
{
196196
aps = JsonConvert.DeserializeObject<AutoPatchingSettings>(input);
197-
aps.UpdatePatchingCategory(this.ResolvePatchCategoryStringforPowerShell(aps.PatchCategory));
197+
aps.PatchCategory = this.ResolvePatchCategoryStringforPowerShell(aps.PatchCategory);
198198
}
199199
catch (JsonReaderException jre)
200200
{
@@ -231,28 +231,22 @@ private AutoBackupSettings DeSerializeAutoBackupSettings(string category, string
231231
/// <summary>
232232
/// Map strings Auto-patching public settings -> Powershell API
233233
/// "WindowsMandatoryUpdates" -> "Important"
234-
/// "MicrosoftOptionalUpdates" -> "Optional"
235234
/// </summary>
236235
/// <param name="patchCategory"></param>
237236
/// <returns></returns>
238-
private AzureVMSqlServerAutoPatchingPatchCategoryEnum ResolvePatchCategoryStringforPowerShell(string category)
237+
private string ResolvePatchCategoryStringforPowerShell(string category)
239238
{
240-
AzureVMSqlServerAutoPatchingPatchCategoryEnum patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Important;
239+
string patchCategory = string.Empty;
241240

242241
if (!string.IsNullOrEmpty(category))
243242
{
244243
switch (category.ToLower())
245244
{
246245
case "windowsmandatoryupdates":
247-
patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Important;
248-
break;
249-
250-
case "microsoftoptionalupdates":
251-
patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Optional;
246+
patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Important.ToString("G");
252247
break;
253248

254249
default:
255-
patchCategory = AzureVMSqlServerAutoPatchingPatchCategoryEnum.Unknown;
256250
break;
257251
}
258252
}

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/NewAzureVMSqlServerAutoPatchingConfig.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions
2424
/// <summary>
2525
/// Helper cmdlet to construct instance of AutoPatching settings class
2626
/// </summary>
27-
[Cmdlet(
28-
VerbsCommon.New,
29-
AzureVMSqlServerAutoPatchingConfigNoun),
30-
OutputType(
31-
typeof(AutoPatchingSettings))]
27+
[Cmdlet(
28+
VerbsCommon.New,
29+
AzureVMSqlServerAutoPatchingConfigNoun),
30+
OutputType(
31+
typeof(AutoPatchingSettings))]
3232
public class NewAzureVMSqlServerAutoPatchingConfigCommand : PSCmdlet
3333
{
3434
protected const string AzureVMSqlServerAutoPatchingConfigNoun = "AzureVMSqlServerAutoPatchingConfig";
@@ -47,7 +47,7 @@ public class NewAzureVMSqlServerAutoPatchingConfigCommand : PSCmdlet
4747
public int MaintenanceWindowDuration { get; set; }
4848

4949
[Parameter]
50-
[ValidateSetAttribute(new string[] { "Important", "Optional" })]
50+
[ValidateSetAttribute(new string[] { "Important" })]
5151
public string PatchCategory { get; set; }
5252

5353
/// <summary>
@@ -68,7 +68,7 @@ protected override void ProcessRecord()
6868
autoPatchingSettings.DayOfWeek = DayOfWeek;
6969
autoPatchingSettings.MaintenanceWindowStartingHour = MaintenanceWindowStartingHour;
7070
autoPatchingSettings.MaintenanceWindowDuration = MaintenanceWindowDuration;
71-
autoPatchingSettings.UpdatePatchingCategory(PatchCategory);
71+
autoPatchingSettings.PatchCategory = PatchCategory;
7272

7373
WriteObject(autoPatchingSettings);
7474
}

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/SetAzureVMSqlServerExtension.cs

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.WindowsAzure.Commands.Common.Storage;
1919
using Microsoft.WindowsAzure.Commands.ServiceManagement.Model;
2020
using Microsoft.WindowsAzure.Commands.ServiceManagement.Properties;
21+
using System.Net;
2122

2223
namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions
2324
{
@@ -33,8 +34,8 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions
3334
typeof(IPersistentVM))]
3435
public class SetAzureVMSqlServerExtensionCommand : VirtualMachineSqlServerExtensionCmdletBase
3536
{
36-
protected const string EnableExtensionParamSetName = "EnableSqlServerExtension";
37-
protected const string DisableSqlServerExtensionParamSetName = "DisableSqlServerExtension";
37+
protected const string EnableExtensionParamSetName = "EnableSqlServerExtension";
38+
protected const string DisableSqlServerExtensionParamSetName = "DisableSqlServerExtension";
3839
protected const string UninstallSqlServerExtensionParamSetName = "UninstallSqlServerExtension";
3940

4041
[Parameter(
@@ -105,10 +106,58 @@ protected override void ValidateParameters()
105106
{
106107
base.ValidateParameters();
107108
this.ReferenceName = string.IsNullOrEmpty(this.ReferenceName) ? ExtensionDefaultName : this.ReferenceName;
108-
109+
this.SetupAutoTelemetrySettings();
109110
this.PublicConfiguration = GetPublicConfiguration();
110111
this.PrivateConfiguration = GetPrivateConfiguration();
111112
this.Version = this.Version ?? ExtensionDefaultVersion;
112113
}
114+
115+
private void SetupAutoTelemetrySettings()
116+
{
117+
if (this.AutoTelemetrySettings == null || string.IsNullOrEmpty(this.AutoTelemetrySettings.Region))
118+
{
119+
foreach (var hs in this.ComputeClient.HostedServices.List().HostedServices)
120+
{
121+
try
122+
{
123+
var deployment = this.ComputeClient.Deployments.GetBySlot(hs.ServiceName, Management.Compute.Models.DeploymentSlot.Production);
124+
if (deployment != null)
125+
{
126+
var role = deployment.RoleInstances.FirstOrDefault(r => r.RoleName == VM.GetInstance().RoleName);
127+
128+
string location = String.Empty;
129+
if (role != null)
130+
{
131+
if (null != hs.Properties)
132+
{
133+
if (!string.IsNullOrEmpty(hs.Properties.Location))
134+
{
135+
location = hs.Properties.Location;
136+
}
137+
else
138+
{
139+
if (!string.IsNullOrEmpty(hs.Properties.AffinityGroup))
140+
{
141+
location = this.ManagementClient.AffinityGroups.Get(hs.Properties.AffinityGroup).Location;
142+
}
143+
}
144+
}
145+
146+
this.AutoTelemetrySettings = new AutoTelemetrySettings() { Region = location };
147+
WriteVerboseWithTimestamp("VM Location:" + location);
148+
break;
149+
}
150+
}
151+
}
152+
catch (CloudException e)
153+
{
154+
if (e.Response.StatusCode != HttpStatusCode.NotFound)
155+
{
156+
throw;
157+
}
158+
}
159+
}
160+
}
161+
}
113162
}
114163
}

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/SqlServer/VirtualMachineSqlServerExtensionCmdletBase.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class VirtualMachineSqlServerExtensionCmdletBase : VirtualMachineExtensio
3737
/// <summary>
3838
/// Extension's default version
3939
/// </summary>
40-
protected const string ExtensionDefaultVersion = "1.0";
40+
protected const string ExtensionDefaultVersion = "1.*";
4141

4242
/// <summary>
4343
/// value of Auto-patching settings object that can be set by derived classes
@@ -49,6 +49,11 @@ public class VirtualMachineSqlServerExtensionCmdletBase : VirtualMachineExtensio
4949
/// </summary>
5050
public virtual AutoBackupSettings AutoBackupSettings { get; set; }
5151

52+
/// <summary>
53+
/// value of Auto-telemetry settings object that can be set by derived classes
54+
/// </summary>
55+
public virtual AutoTelemetrySettings AutoTelemetrySettings { get; set; }
56+
5257
/// <summary>
5358
/// Sets extension's publisher and name
5459
/// </summary>
@@ -68,7 +73,8 @@ protected string GetPublicConfiguration()
6873
new SqlServerPublicSettings
6974
{
7075
AutoPatchingSettings = this.AutoPatchingSettings,
71-
AutoBackupSettings = this.AutoBackupSettings
76+
AutoBackupSettings = this.AutoBackupSettings,
77+
AutoTelemetrySettings = this.AutoTelemetrySettings
7278
}));
7379
}
7480

@@ -81,7 +87,7 @@ protected string GetPrivateConfiguration()
8187
return JsonUtilities.TryFormatJson(JsonConvert.SerializeObject(
8288
new SqlServerPrivateSettings
8389
{
84-
StorageUrl = (this.AutoBackupSettings == null)? string.Empty: this.AutoBackupSettings.StorageUrl,
90+
StorageUrl = (this.AutoBackupSettings == null) ? string.Empty : this.AutoBackupSettings.StorageUrl,
8591
StorageAccessKey = (this.AutoBackupSettings == null) ? string.Empty : this.AutoBackupSettings.StorageAccessKey,
8692
Password = (this.AutoBackupSettings == null) ? string.Empty : this.AutoBackupSettings.Password
8793
}));

src/ServiceManagement/Compute/Commands.ServiceManagement/Microsoft.WindowsAzure.Commands.ServiceManagement.dll-Help.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33136,7 +33136,7 @@ PS C:\&gt; Get-AzureVM -ServiceName &quot;ContosoService03&quot; -Name &quot;Con
3313633136
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
3313733137
<maml:name>PatchCategory</maml:name>
3313833138
<maml:description>
33139-
<maml:para>Defines if recommended updates should be included.</maml:para>
33139+
<maml:para>Defines if Important updates should be included.</maml:para>
3314033140
</maml:description>
3314133141
<command:parameterValue required="true" variableLength="false">string</command:parameterValue>
3314233142
</command:parameter>
@@ -33195,7 +33195,7 @@ PS C:\&gt; Get-AzureVM -ServiceName &quot;ContosoService03&quot; -Name &quot;Con
3319533195
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
3319633196
<maml:name>PatchCategory</maml:name>
3319733197
<maml:description>
33198-
<maml:para>Defines if recommended updates should be included.</maml:para>
33198+
<maml:para>Defines if important updates should be included.</maml:para>
3319933199
</maml:description>
3320033200
<command:parameterValue required="true" variableLength="false">string</command:parameterValue>
3320133201
<dev:type>
@@ -33261,14 +33261,14 @@ PS C:\&gt; Get-AzureVM -ServiceName &quot;ContosoService03&quot; -Name &quot;Con
3326133261
<maml:para></maml:para>
3326233262
</maml:introduction>
3326333263
<dev:code>
33264-
C:\PS&gt; $aps = New-AzureVMSqlServerAutoPatchingConfig -Enable -DayOfWeek &quot;Thursday&quot; -MaintenanceWindowStartingHour 11 -MaintenanceWindowDuration 120 -PatchCategory &quot;Optional&quot;
33264+
C:\PS&gt; $aps = New-AzureVMSqlServerAutoPatchingConfig -Enable -DayOfWeek &quot;Thursday&quot; -MaintenanceWindowStartingHour 11 -MaintenanceWindowDuration 120 -PatchCategory &quot;Important&quot;
3326533265

3326633266
PS C:\&gt; $aps
3326733267
Enable : True
3326833268
DayOfWeek : Thursday
3326933269
MaintenanceWindowStartingHour : 11
3327033270
MaintenanceWindowDuration : 120
33271-
PatchCategory : Optional
33271+
PatchCategory : Important
3327233272
</dev:code>
3327333273
<dev:remarks>
3327433274
<maml:para>This command creates configuration object that can be used to configure automatic patching using Set-AzureVMSqlServerExtension</maml:para>

0 commit comments

Comments
 (0)