Skip to content

Commit ab992a1

Browse files
author
Jianghao Lu
committed
Merge pull request #852 from sethusrinivasan/release-0.9.8
ARM cmdlets for SQLVM extension supporting auto-patching and auto-backup
2 parents e696d66 + e2ebac5 commit ab992a1

16 files changed

+934
-0
lines changed

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
* Get-AzureSqlServerActiveDirectoryAdministrator
4444
* Set-AzureSqlServerActiveDirectoryAdministrator
4545
* Remove-AzureSqlServerActiveDirectoryAdministrator
46+
* SQL Server VM cmdlets (ARM)
47+
* New-AzureVMSqlServerAutoPatchingConfig
48+
* New-AzureVMSqlServerAutoBackupConfig
49+
* Set-AzureVMSqlServerExtension
50+
* Get-AzureVMSqlServerExtension
51+
* Remove-AzureVMSqlServerExtension
4652

4753
## 2015.08.17 version 0.9.7
4854
* Azure Profile cmdlets

src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,17 @@
223223
<Compile Include="Extension\SetAzureVMExtensionCommand.cs" />
224224
<Compile Include="Extension\RemoveAzureVMExtensionCommand.cs" />
225225
<Compile Include="Extension\GetAzureVMExtensionCommand.cs" />
226+
<Compile Include="Extension\SqlServer\AzureVMSqlServerAutoBackupSettings.cs" />
227+
<Compile Include="Extension\SqlServer\AzureVMSqlServerAutoPatchingSettings.cs" />
228+
<Compile Include="Extension\SqlServer\AzureVMSqlServerAutoTelemetrySettings.cs" />
229+
<Compile Include="Extension\SqlServer\AzureVMSqlServerPrivateSettings.cs" />
230+
<Compile Include="Extension\SqlServer\AzureVMSqlServerPublicSettings.cs" />
231+
<Compile Include="Extension\SqlServer\GetAzureVMSqlServerExtensionCommand.cs" />
232+
<Compile Include="Extension\SqlServer\NewAzureVMSqlServerAutoBackupConfig.cs" />
233+
<Compile Include="Extension\SqlServer\NewAzureVMSqlServerAutoPatchingConfig.cs" />
234+
<Compile Include="Extension\SqlServer\RemoveAzureVMSqlServerExtensionCommand.cs" />
235+
<Compile Include="Extension\SqlServer\SetAzureVMSqlServerExtensionCommand.cs" />
236+
<Compile Include="Extension\SqlServer\VirtualMachineSqlServerExtensionContext.cs" />
226237
<Compile Include="Images\GetAzureVMImageCommand.cs" />
227238
<Compile Include="Common\HashTableExtensions.cs" />
228239
<Compile Include="Models\PSComputeLongRunningOperation.cs" />

src/ResourceManager/Compute/Commands.Compute/Common/ConstantStringTypes.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,8 @@ public static class ProfileNouns
9999
public const string VirtualMachineDscConfiguration = "AzureVMDscConfiguration";
100100

101101
public const string Vhd = "AzureVhd";
102+
103+
// Sql Server
104+
public const string VirtualMachineSqlServerExtension = "AzureVMSqlServerExtension";
102105
}
103106
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
using Newtonsoft.Json;
15+
16+
namespace Microsoft.Azure.Commands.Compute
17+
{
18+
/// <summary>
19+
/// Autobackup settings to configure managed backup on SQL VM
20+
/// </summary>
21+
public class AutoBackupSettings
22+
{
23+
/// <summary>
24+
/// Defines if the Auto-backup feature is enabled or disabled
25+
/// </summary>
26+
public bool Enable { get; set; }
27+
28+
/// <summary>
29+
/// Defines if backups will be encrypted or not
30+
/// </summary>
31+
public bool EnableEncryption { get; set; }
32+
33+
/// <summary>
34+
/// Defines the number of days to keep the backups
35+
/// </summary>
36+
public int RetentionPeriod { get; set; }
37+
38+
/// <summary>
39+
/// storage url where databases will be backed up
40+
/// </summary>
41+
[JsonIgnoreAttribute()]
42+
public string StorageUrl { get; set; }
43+
44+
/// <summary>
45+
/// Key of storage account used by managed backup
46+
/// </summary>
47+
[JsonIgnoreAttribute()]
48+
public string StorageAccessKey { get; set; }
49+
50+
/// <summary>
51+
/// Password required for certification when encryption is enabled
52+
/// </summary>
53+
[JsonIgnoreAttribute()]
54+
public string Password { get; set; }
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
namespace Microsoft.Azure.Commands.Compute
16+
{
17+
/// <summary>
18+
/// AutoPatching settings to configure auto-patching on SQL VM
19+
/// </summary>
20+
public class AutoPatchingSettings
21+
{
22+
/// <summary>
23+
/// Enable / Disable auto patching
24+
/// </summary>
25+
public bool Enable { get; set; }
26+
27+
/// <summary>
28+
/// Day of the week
29+
/// </summary>
30+
public string DayOfWeek { get; set; }
31+
32+
/// <summary>
33+
/// Maintainance Windows Start hour ( 0 to 23 )
34+
/// </summary>
35+
public int MaintenanceWindowStartingHour { get; set; }
36+
37+
/// <summary>
38+
/// Maintainance window duration in minutes
39+
/// </summary>
40+
public int MaintenanceWindowDuration { get; set; }
41+
42+
/// <summary>
43+
/// Patch category returned as string
44+
/// </summary>
45+
public string PatchCategory { get; set; }
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
namespace Microsoft.Azure.Commands.Compute
16+
{
17+
/// <summary>
18+
/// AutoTelemetry settings to configure telemetry collection on SQL VM
19+
/// </summary>
20+
public class AutoTelemetrySettings
21+
{
22+
/// <summary>
23+
/// The name of the region the VM is running in.
24+
/// </summary>
25+
public string Region { get; set; }
26+
}
27+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
namespace Microsoft.Azure.Commands.Compute
16+
{
17+
/// <summary>
18+
/// SQL Server extension's private settings
19+
/// </summary>
20+
public class SqlServerPrivateSettings
21+
{
22+
/// <summary>
23+
/// Azure blob store URL
24+
/// </summary>
25+
public string StorageUrl;
26+
27+
/// <summary>
28+
/// Storage account access key
29+
/// </summary>
30+
public string StorageAccessKey;
31+
32+
/// <summary>
33+
/// Password required for certification when encryption is enabled
34+
/// </summary>
35+
public string Password;
36+
}
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
namespace Microsoft.Azure.Commands.Compute
16+
{
17+
/// <summary>
18+
/// SQL Server Extension's public settings
19+
/// </summary>
20+
public class SqlServerPublicSettings
21+
{
22+
/// <summary>
23+
/// Auto patching settings
24+
/// </summary>
25+
public AutoPatchingSettings AutoPatchingSettings { get; set; }
26+
27+
/// <summary>
28+
/// Auto-backup settings
29+
/// </summary>
30+
public AutoBackupSettings AutoBackupSettings { get; set; }
31+
32+
/// <summary>
33+
/// Auto-telemetry settings
34+
/// </summary>
35+
public AutoTelemetrySettings AutoTelemetrySettings { get; set; }
36+
}
37+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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 Microsoft.Azure.Commands.Compute.Common;
16+
using Microsoft.Azure.Commands.Compute.Models;
17+
using Microsoft.Azure.Management.Compute;
18+
using System;
19+
using System.Management.Automation;
20+
using Newtonsoft.Json;
21+
using System.Globalization;
22+
23+
namespace Microsoft.Azure.Commands.Compute
24+
{
25+
[Cmdlet(
26+
VerbsCommon.Get,
27+
ProfileNouns.VirtualMachineSqlServerExtension,
28+
DefaultParameterSetName = GetSqlServerExtensionParamSetName),
29+
OutputType(
30+
typeof(VirtualMachineSqlServerExtensionContext))]
31+
public class GetAzureVMSqlServerExtensionCommand : VirtualMachineExtensionBaseCmdlet
32+
{
33+
protected const string GetSqlServerExtensionParamSetName = "GetSqlServerExtension";
34+
35+
[Parameter(
36+
Mandatory = true,
37+
Position = 0,
38+
ValueFromPipelineByPropertyName = true,
39+
HelpMessage = "The resource group name.")]
40+
[ValidateNotNullOrEmpty]
41+
public string ResourceGroupName { get; set; }
42+
43+
[Parameter(
44+
Mandatory = true,
45+
Position = 1,
46+
ValueFromPipelineByPropertyName = true,
47+
HelpMessage = "The virtual machine name.")]
48+
[ValidateNotNullOrEmpty]
49+
public string VMName { get; set; }
50+
51+
[Parameter(
52+
Position = 2,
53+
ValueFromPipelineByPropertyName = true,
54+
HelpMessage = "Name of the ARM resource that represents the extension. The Set-AzureVMSqlServerExtension cmdlet sets this name to " +
55+
"'Microsoft.SqlServer.Management.SqlIaaSAgent', which is the same value used by Get-AzureVMSqlServerExtension. Specify this parameter only if you changed " +
56+
"the default name in the Set cmdlet or used a different resource name in an ARM template.")]
57+
[ValidateNotNullOrEmpty]
58+
public string Name { get; set; }
59+
60+
public override void ExecuteCmdlet()
61+
{
62+
base.ExecuteCmdlet();
63+
64+
if (String.IsNullOrEmpty(Name))
65+
{
66+
Name = VirtualMachineSqlServerExtensionContext.ExtensionPublishedNamespace + "." + VirtualMachineSqlServerExtensionContext.ExtensionPublishedName;
67+
}
68+
69+
var result = VirtualMachineExtensionClient.GetWithInstanceView(ResourceGroupName, VMName, Name);
70+
var extension = result.ToPSVirtualMachineExtension(ResourceGroupName);
71+
72+
if (
73+
extension.Publisher.Equals(VirtualMachineSqlServerExtensionContext.ExtensionPublishedNamespace,
74+
StringComparison.InvariantCultureIgnoreCase) &&
75+
extension.ExtensionType.Equals(VirtualMachineSqlServerExtensionContext.ExtensionPublishedName,
76+
StringComparison.InvariantCultureIgnoreCase))
77+
{
78+
WriteObject(GetSqlServerExtensionContext(extension));
79+
}
80+
else
81+
{
82+
WriteObject(null);
83+
}
84+
}
85+
86+
private VirtualMachineSqlServerExtensionContext GetSqlServerExtensionContext(PSVirtualMachineExtension extension)
87+
{
88+
SqlServerPublicSettings extensionPublicSettings = null;
89+
VirtualMachineSqlServerExtensionContext context = null;
90+
91+
try
92+
{
93+
extensionPublicSettings = string.IsNullOrEmpty(extension.PublicSettings) ? null
94+
: JsonConvert.DeserializeObject<SqlServerPublicSettings>(extension.PublicSettings);
95+
96+
// #$ISSUE- extension.Statuses is always null, follow up with Azure team
97+
context = new VirtualMachineSqlServerExtensionContext
98+
{
99+
ResourceGroupName = extension.ResourceGroupName,
100+
Name = extension.Name,
101+
Location = extension.Location,
102+
Etag = extension.Etag,
103+
Publisher = extension.Publisher,
104+
ExtensionType = extension.ExtensionType,
105+
TypeHandlerVersion = extension.TypeHandlerVersion,
106+
Id = extension.Id,
107+
PublicSettings = JsonConvert.SerializeObject(extensionPublicSettings),
108+
ProtectedSettings = extension.ProtectedSettings,
109+
ProvisioningState = extension.ProvisioningState,
110+
AutoBackupSettings = extensionPublicSettings.AutoBackupSettings,
111+
AutoPatchingSettings = extensionPublicSettings.AutoPatchingSettings,
112+
Statuses = extension.Statuses
113+
};
114+
115+
}
116+
catch (JsonException e)
117+
{
118+
ThrowTerminatingError(
119+
new ErrorRecord(
120+
new JsonException(
121+
String.Format(
122+
CultureInfo.CurrentUICulture,
123+
Properties.Resources.AzureVMSqlServerWrongSettingsFormat,
124+
extension.PublicSettings),
125+
e),
126+
string.Empty,
127+
ErrorCategory.ParserError,
128+
null));
129+
}
130+
131+
return context;
132+
}
133+
}
134+
}

0 commit comments

Comments
 (0)