Skip to content

Commit dfaceb5

Browse files
committed
Merge branch 'dev' of github.com:Azure/azure-powershell into deprecate
2 parents 8320698 + 17ea233 commit dfaceb5

29 files changed

+2596
-1057
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/Chef/SetAzureVMChefExtension.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ public class SetAzureVMChefExtensionCommand : VirtualMachineChefExtensionCmdletB
7676
[ValidateNotNullOrEmpty]
7777
public string OrganizationName { get; set; }
7878

79+
[Parameter(
80+
ValueFromPipelineByPropertyName = true,
81+
HelpMessage = "Flag to opt for auto chef-client update. Chef-client update is false by default.")]
82+
[ValidateNotNullOrEmpty]
83+
public SwitchParameter AutoUpdateClient { get; set; }
84+
7985
[Parameter(
8086
Mandatory = true,
8187
ParameterSetName = LinuxParameterSetName,
@@ -141,6 +147,7 @@ private void SetPublicConfig()
141147
bool IsChefServerUrlEmpty = string.IsNullOrEmpty(this.ChefServerUrl);
142148
bool IsValidationClientNameEmpty = string.IsNullOrEmpty(this.ValidationClientName);
143149
bool IsRunListEmpty = string.IsNullOrEmpty(this.RunList);
150+
string AutoUpdateClient = this.AutoUpdateClient.IsPresent ? "true" : "false";
144151

145152
//Cases handled:
146153
// 1. When clientRb given by user and:
@@ -192,14 +199,16 @@ private void SetPublicConfig()
192199

193200
if (IsRunListEmpty)
194201
{
195-
this.PublicConfiguration = string.Format("{{{0}}}",
202+
this.PublicConfiguration = string.Format("{{{0},{1}}}",
203+
string.Format(AutoUpdateTemplate, AutoUpdateClient),
196204
string.Format(ClientRbTemplate, ClientConfig));
197205
}
198206
else
199207
{
200-
this.PublicConfiguration = string.Format("{{{0},{1}}}",
201-
string.Format(ClientRbTemplate, ClientConfig),
202-
string.Format(RunListTemplate, this.RunList));
208+
this.PublicConfiguration = string.Format("{{{0},{1},{2}}}",
209+
string.Format(AutoUpdateTemplate, AutoUpdateClient),
210+
string.Format(ClientRbTemplate, ClientConfig),
211+
string.Format(RunListTemplate, this.RunList));
203212
}
204213
}
205214

@@ -223,4 +232,4 @@ protected override void ProcessRecord()
223232
ExecuteCommand();
224233
}
225234
}
226-
}
235+
}

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/Chef/VirtualMachineChefExtensionCmdletBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class VirtualMachineChefExtensionCmdletBase : VirtualMachineExtensionCmdl
2222
protected const string ExtensionDefaultName = "ChefClient";
2323
protected const string LinuxExtensionName = "LinuxChefClient";
2424
protected const string PrivateConfigurationTemplate = "{{\"validation_key\":\"{0}\"}}";
25+
protected const string AutoUpdateTemplate = "\"autoUpdateClient\":\"{0}\"";
2526
protected const string ClientRbTemplate = "\"client_rb\":\"{0}\"";
2627
protected const string RunListTemplate = "\"runlist\": \"\\\"{0}\\\"\"";
2728

@@ -44,4 +45,4 @@ protected string GetPlatformSpecificExtensionName()
4445
else { return null; }
4546
}
4647
}
47-
}
48+
}

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
}

0 commit comments

Comments
 (0)