Skip to content

Commit aa24916

Browse files
authored
[Compute] Restore point and Restore point collection (#15588)
* adding restore point and restore point collection * Fixing tests * fixing test adding location * Updated help and test recording * adding license, fixing test and moving out of generated folder * help fixes * Changelog and removed unnecessary attributes
1 parent 95aa856 commit aa24916

23 files changed

+5532
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.WindowsAzure.Commands.ScenarioTest;
16+
using Xunit;
17+
18+
namespace Microsoft.Azure.Commands.Compute.Test.ScenarioTests
19+
{
20+
public class RestorePointsTests : ComputeTestRunner
21+
{
22+
public RestorePointsTests(Xunit.Abstractions.ITestOutputHelper output)
23+
: base(output)
24+
{
25+
}
26+
27+
[Fact]
28+
[Trait(Category.AcceptanceType, Category.CheckIn)]
29+
public void TestRestorePoints()
30+
{
31+
TestRunner.RunTestScript("Test-RestorePoints");
32+
}
33+
}
34+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
<#
16+
.SYNOPSIS
17+
Testing RestorePoints commands
18+
#>
19+
function Test-RestorePoints
20+
{
21+
# Setup
22+
$rgname = Get-ComputeTestResourceName;
23+
$restorePointCollectionName = 'rpc123' ;
24+
$restorePointName = 'rp123' ;
25+
$vmname = 'vm123'
26+
27+
try
28+
{
29+
# Common
30+
$loc = Get-ComputeVMLocation;
31+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
32+
33+
#create a new vm
34+
$user = "Foo12";
35+
$password = "temppass12345T";
36+
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
37+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
38+
[string]$domainNameLabel = "$vmname-$vmname".tolower();
39+
New-Azvm -ResourceGroupName $rgname -Name $vmname -Image Win2012R2Datacenter -Location $loc -Credential $cred -DomainNameLabel $domainNameLabel
40+
41+
42+
$vm1 = Get-AzVM -Name $vmname -ResourceGroupName $rgname -DisplayHint Expand;
43+
$tags = $tags = @{test1 = "testval1"; test2 = "testval2" };
44+
45+
#restorepoint
46+
New-AzRestorePointCollection -ResourceGroupName $rgname -Name $restorePointCollectionName -VmId $vm1.Id -Location "eastus"
47+
Get-AzRestorePointCollection -ResourceGroupName $rgname -Name $restorePointCollectionName
48+
Update-AzRestorePointCollection -ResourceGroupName $rgname -Name $restorePointCollectionName -Tag $tags
49+
50+
#restorepointcollection
51+
New-AzRestorePoint -ResourceGroupName $rgname -RestorePointCollectionName $restorePointCollectionName -Name $restorePointName
52+
Get-AzRestorePoint -ResourceGroupName $rgname -RestorePointCollectionName $restorePointCollectionName -Name $restorePointName
53+
54+
Remove-AzRestorePoint -ResourceGroupName $rgname -RestorePointCollectionName $restorePointCollectionName -Name $restorePointName
55+
56+
Remove-AzRestorePointCollection -ResourceGroupName $rgname -Name $restorePointCollectionName
57+
58+
}
59+
finally
60+
{
61+
# Cleanup
62+
Clean-ResourceGroup $rgname
63+
}
64+
}
65+

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.RestorePointsTests/TestRestorePoints.json

Lines changed: 3792 additions & 0 deletions
Large diffs are not rendered by default.

src/Compute/Compute/Az.Compute.psd1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ CmdletsToExport = 'Remove-AzAvailabilitySet', 'Get-AzAvailabilitySet',
175175
'New-AzCapacityReservationGroup',
176176
'Remove-AzCapacityReservationGroup',
177177
'Get-AzCapacityReservationGroup', 'New-AzCapacityReservation',
178-
'Get-AzCapacityReservation', 'Remove-AzCapacityReservation'
178+
'Get-AzCapacityReservation', 'Remove-AzCapacityReservation',
179+
'New-AzRestorePointCollection','Get-AzRestorePointCollection', 'Update-AzRestorePointCollection', 'Remove-AzRestorePointCollection',
180+
'New-AzRestorePoint', 'Get-AzRestorePoint', 'Remove-AzRestorePoint'
179181

180182
# Variables to export from this module
181183
# VariablesToExport = @()

src/Compute/Compute/ChangeLog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
## Upcoming Release
2323
* Added new parameters `-SshKeyName` and `-GenerateSshKey` to `New-AzVM` to create a VM with SSH
2424
* Fixed a bug in `Add-AzVHD` on Linux that caused uploads to fail for certain destination URI
25+
* Added new cmdlets for Restore Points and Restore Point Collection:
26+
- 'New-AzRestorePoint'
27+
- 'New-AzRestorePointCollection'
28+
- 'Get-AzRestorePoint'
29+
- 'Get-AzRestorePointCollection'
30+
- 'Update-AzRestorePointCollection'
31+
- 'Remove-AzRestorePoint'
32+
- 'Remove-AzRestorePointCollection'
2533
* Added new parameters '-EnableSpotRestore' and '-SpotRestoreTimeout' to 'New-AzVMSSConfig' to enable Spot Restore Policy
2634

2735
## Version 4.16.0

src/Compute/Compute/Generated/ComputeAutomationBaseCmdlet.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,22 @@ public ICapacityReservationsOperations CapacityReservationClient
257257
}
258258
}
259259

260+
public IRestorePointCollectionsOperations RestorePointCollectionsClient
261+
{
262+
get
263+
{
264+
return ComputeClient.ComputeManagementClient.RestorePointCollections;
265+
}
266+
}
267+
268+
public IRestorePointsOperations RestorePointClient
269+
{
270+
get
271+
{
272+
return ComputeClient.ComputeManagementClient.RestorePoints;
273+
}
274+
}
275+
260276
public static string FormatObject(Object obj)
261277
{
262278
var objType = obj.GetType();

src/Compute/Compute/Generated/Models/ComputeAutoMapperProfile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ private static void Initialize()
201201
cfg.CreateMap<FROM.CapacityReservation, TO.PSCapacityReservationList>();
202202
cfg.CreateMap<TO.PSCapacityReservationList, TO.PSCapacityReservation>();
203203
cfg.CreateMap<TO.PSCapacityReservation, TO.PSCapacityReservationList>();
204+
cfg.CreateMap<FROM.RestorePoint, TO.PSRestorePoint>();
205+
cfg.CreateMap<FROM.RestorePointCollection, TO.PSRestorePointCollection>();
204206
});
205207
_mapper = config.CreateMapper();
206208
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
16+
using Microsoft.Azure.Management.Compute.Models;
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Text;
20+
21+
namespace Microsoft.Azure.Commands.Compute.Automation.Models
22+
{
23+
class PSRestorePoint
24+
{
25+
// Summary:
26+
// Gets the details of the VM captured at the time of the restore point creation.
27+
public RestorePointSourceMetadata SourceMetadata { get; set; }
28+
//
29+
// Summary:
30+
// Gets the provisioning state of the restore point.
31+
public string ProvisioningState { get; set; }
32+
//
33+
// Summary:
34+
// Gets the consistency mode for the restore point. Please refer to https://aka.ms/RestorePoints
35+
// for more details. Possible values include: 'CrashConsistent', 'FileSystemConsistent',
36+
// 'ApplicationConsistent'
37+
public string ConsistencyMode { get; set; }
38+
//
39+
// Summary:
40+
// Gets the provisioning details set by the server during Create restore point operation.
41+
public RestorePointProvisioningDetails ProvisioningDetails { get; set; }
42+
//
43+
// Summary:
44+
// Gets or sets list of disk resource ids that the customer wishes to exclude from
45+
// the restore point. If no disks are specified, all disks will be included.
46+
public IList<ApiEntityReference> ExcludeDisks { get; set; }
47+
}
48+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
16+
using Microsoft.Azure.Management.Compute.Models;
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Text;
20+
21+
namespace Microsoft.Azure.Commands.Compute.Automation.Models
22+
{
23+
class PSRestorePointCollection
24+
{
25+
public RestorePointCollectionSourceProperties Source { get; set; }
26+
//
27+
// Summary:
28+
// Gets the provisioning state of the restore point collection.
29+
public string ProvisioningState { get; set; }
30+
//
31+
// Summary:
32+
// Gets the unique id of the restore point collection.
33+
public string RestorePointCollectionId { get; set; }
34+
//
35+
// Summary:
36+
// Gets a list containing all restore points created under this restore point collection.
37+
public IList<RestorePoint> RestorePoints { get; set; }
38+
}
39+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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;
16+
using System.Collections;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Management.Automation;
20+
using Microsoft.Azure.Commands.Compute.Automation.Models;
21+
using Microsoft.Azure.Commands.Compute.Models;
22+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
23+
using Microsoft.Azure.Management.Compute;
24+
using Microsoft.Azure.Management.Compute.Models;
25+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
26+
27+
namespace Microsoft.Azure.Commands.Compute.Automation
28+
{
29+
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RestorePoint", DefaultParameterSetName = "DefaultParameter")]
30+
[OutputType(typeof(PSRestorePoint))]
31+
public class GetAzureRestorePoint : ComputeAutomationBaseCmdlet
32+
{
33+
34+
[Parameter(
35+
Position = 0,
36+
Mandatory = true,
37+
ValueFromPipelineByPropertyName = true)]
38+
[ResourceGroupCompleter]
39+
public string ResourceGroupName { get; set; }
40+
41+
[Parameter(
42+
Position = 1,
43+
Mandatory = true,
44+
ValueFromPipelineByPropertyName = true)]
45+
public string RestorePointCollectionName{ get; set; }
46+
47+
[Parameter(
48+
Position = 1,
49+
Mandatory = true,
50+
ValueFromPipelineByPropertyName = true)]
51+
[Alias("RestorePointName")]
52+
public string Name { get; set; }
53+
54+
55+
public override void ExecuteCmdlet()
56+
{
57+
base.ExecuteCmdlet();
58+
ExecuteClientAction(() =>
59+
{
60+
string resourceGroup = this.ResourceGroupName;
61+
string restorePointName = this.Name;
62+
string restorePointCollectionName = this.RestorePointCollectionName;
63+
64+
var result = RestorePointClient.Get(resourceGroup, restorePointCollectionName, restorePointName);
65+
var psObject = new PSRestorePoint();
66+
ComputeAutomationAutoMapperProfile.Mapper.Map<RestorePoint, PSRestorePoint>(result, psObject);
67+
WriteObject(psObject);
68+
});
69+
}
70+
}
71+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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;
16+
using System.Collections;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Management.Automation;
20+
using Microsoft.Azure.Commands.Compute.Automation.Models;
21+
using Microsoft.Azure.Commands.Compute.Models;
22+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
23+
using Microsoft.Azure.Management.Compute;
24+
using Microsoft.Azure.Management.Compute.Models;
25+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
26+
27+
namespace Microsoft.Azure.Commands.Compute.Automation
28+
{
29+
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RestorePointCollection", DefaultParameterSetName = "DefaultParameter")]
30+
[OutputType(typeof(PSRestorePointCollection))]
31+
public class GetAzureRestorePointCollection : ComputeAutomationBaseCmdlet
32+
{
33+
34+
[Parameter(
35+
Position = 0,
36+
Mandatory = true,
37+
ValueFromPipelineByPropertyName = true)]
38+
[ResourceGroupCompleter]
39+
public string ResourceGroupName { get; set; }
40+
41+
[Parameter(
42+
Position = 1,
43+
Mandatory = true,
44+
ValueFromPipelineByPropertyName = true)]
45+
[Alias("RestorePointCollectionName")]
46+
public string Name { get; set; }
47+
48+
49+
public override void ExecuteCmdlet()
50+
{
51+
base.ExecuteCmdlet();
52+
ExecuteClientAction(() =>
53+
{
54+
string resourceGroup = this.ResourceGroupName;
55+
string restorePointCollectionName = this.Name;
56+
57+
var result = RestorePointCollectionsClient.Get(resourceGroup, restorePointCollectionName);
58+
var psObject = new PSRestorePointCollection();
59+
ComputeAutomationAutoMapperProfile.Mapper.Map<RestorePointCollection, PSRestorePointCollection>(result, psObject);
60+
WriteObject(psObject);
61+
});
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)