Skip to content

Commit a783533

Browse files
committed
Merge branch 'mkheranidev1' into dev1
2 parents d0c1f97 + 9e1aec4 commit a783533

File tree

14 files changed

+446
-9
lines changed

14 files changed

+446
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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.RecoveryServices.Backup.Cmdlets.Models;
16+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Linq;
20+
using System.Management.Automation;
21+
using System.Text;
22+
using System.Threading.Tasks;
23+
24+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
25+
{
26+
[Cmdlet(VerbsCommon.Get, "AzureRMRecoveryServicesRecoveryPoint"), OutputType(typeof(List<AzureRmRecoveryServicesRecoveryPointBase>), typeof(AzureRmRecoveryServicesRecoveryPointBase))]
27+
public class GetAzureRMRecoveryServicesRecoveryPoint : RecoveryServicesBackupCmdletBase
28+
{
29+
internal const string DateTimeFilterParameterSet = "DateTimeFilter";
30+
internal const string RecoveryPointIdParameterSet = "RecoveryPointId";
31+
32+
[Parameter(Mandatory = true, ParameterSetName = DateTimeFilterParameterSet, HelpMessage = "", ValueFromPipeline = false)]
33+
[ValidateNotNullOrEmpty]
34+
public DateTime StartDate { get; set; }
35+
36+
[Parameter(Mandatory = true, ParameterSetName = DateTimeFilterParameterSet, HelpMessage = "", ValueFromPipeline = false)]
37+
[ValidateNotNullOrEmpty]
38+
public DateTime EndDate { get; set; }
39+
40+
[Parameter(Mandatory = true, ParameterSetName = DateTimeFilterParameterSet, HelpMessage = "", ValueFromPipeline = true)]
41+
[Parameter(Mandatory = true, ParameterSetName = RecoveryPointIdParameterSet, HelpMessage = "", ValueFromPipeline = true)]
42+
[ValidateNotNullOrEmpty]
43+
public AzureRmRecoveryServicesItemBase Item { get; set; }
44+
45+
[Parameter(Mandatory = true, ParameterSetName = RecoveryPointIdParameterSet, HelpMessage = "", ValueFromPipeline = false)]
46+
[ValidateNotNullOrEmpty]
47+
public string RecoveryPointId { get; set; }
48+
49+
public override void ExecuteCmdlet()
50+
{
51+
ExecutionBlock(() =>
52+
{
53+
//Validate start time < end time
54+
base.ExecuteCmdlet();
55+
56+
Dictionary<System.Enum, object> parameter = new Dictionary<System.Enum, object>();
57+
parameter.Add(GetRecoveryPointParams.Item, Item);
58+
59+
if(this.ParameterSetName == DateTimeFilterParameterSet)
60+
{
61+
//User want list of RPs between given time range
62+
if (StartDate >= EndDate)
63+
{
64+
throw new Exception("End date should be greated than start date"); //tbd: Correct nsg and exception type
65+
}
66+
67+
parameter.Add(GetRecoveryPointParams.StartDate, StartDate);
68+
parameter.Add(GetRecoveryPointParams.EndDate, EndDate);
69+
PsBackupProviderManager providerManager = new PsBackupProviderManager(parameter, HydraAdapter);
70+
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(Item.ContainerType, Item.BackupManagementType);
71+
var rpList = psBackupProvider.ListRecoveryPoints();
72+
if (rpList.Count == 1)
73+
WriteObject(rpList[0]);
74+
else
75+
WriteObject(rpList);
76+
}
77+
78+
else if (this.ParameterSetName == RecoveryPointIdParameterSet)
79+
{
80+
//User want details of a particular recovery point
81+
parameter.Add(GetRecoveryPointParams.RecoveryPointId, RecoveryPointId);
82+
PsBackupProviderManager providerManager = new PsBackupProviderManager(parameter, HydraAdapter);
83+
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(Item.ContainerType, Item.BackupManagementType);
84+
WriteObject(psBackupProvider.GetRecoveryPointDetails());
85+
}
86+
else
87+
{
88+
throw new Exception("Unsupported Parameter set");
89+
}
90+
});
91+
}
92+
}
93+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.RecoveryServices.Backup.Cmdlets.Models;
16+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Linq;
20+
using System.Management.Automation;
21+
using System.Text;
22+
using System.Threading.Tasks;
23+
24+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
25+
{
26+
[Cmdlet(VerbsData.Restore, "AzureRMRecoveryServicesBackupItem"), OutputType(typeof(AzureRmRecoveryServicesJobBase))]
27+
class RestoreAzureRMRecoveryServicesBackupItem : RecoveryServicesBackupCmdletBase
28+
{
29+
[Parameter(Mandatory = true, HelpMessage = "", ValueFromPipeline = true)]
30+
[ValidateNotNullOrEmpty]
31+
public AzureRmRecoveryServicesRecoveryPointBase RecoveryPoint { get; set; }
32+
33+
[Parameter(Mandatory = true, HelpMessage = "")]
34+
[ValidateNotNullOrEmpty]
35+
public string StorageAccountName { get; set; }
36+
37+
public override void ExecuteCmdlet()
38+
{
39+
ExecutionBlock(() =>
40+
{
41+
base.ExecuteCmdlet();
42+
PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary<System.Enum, object>()
43+
{
44+
{RestoreBackupItemParams.RecoveryPoint, RecoveryPoint},
45+
{RestoreBackupItemParams.StorageAccountName, StorageAccountName}
46+
}, HydraAdapter);
47+
48+
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(RecoveryPoint.ContainerType, RecoveryPoint.BackupManagementType);
49+
psBackupProvider.TriggerRestore();
50+
});
51+
}
52+
}
53+
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Cmdlets.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
<Compile Include="Cmdlets\ProtectionPolicy\NewAzureRmRecoveryServicesPolicy.cs" />
8484
<Compile Include="CmdletWarningAndErrorMessages.cs" />
8585
<Compile Include="Constants.cs" />
86+
<Compile Include="Cmdlets\RecoveryPoint\GetAzureRMRecoveryServicesRecoveryPoint.cs" />
87+
<Compile Include="Cmdlets\Restore\RestoreAzureRMRecoveryServicesBackupItem.cs" />
8688
<Compile Include="Properties\AssemblyInfo.cs" />
8789
<Compile Include="RecoveryServicesBackupVaultCmdletBase.cs" />
8890
<Compile Include="RecoveryServicesBackupCmdletBase.cs" />
@@ -93,6 +95,7 @@
9395
<Folder Include="Cmdlets\Item\" />
9496
<Folder Include="Cmdlets\RecoveryPoint\" />
9597
<Folder Include="Cmdlets\Restore\" />
98+
<Folder Include="Cmdlets\Jobs\" />
9699
</ItemGroup>
97100
<ItemGroup>
98101
<ProjectReference Include="..\..\Common\Commands.Common\Commands.Common.csproj">

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Helpers/Commands.RecoveryServices.Backup.Helpers.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
</ItemGroup>
5151
<ItemGroup>
5252
<Compile Include="Conversions\JobConversions.cs" />
53+
<Compile Include="Conversions\RecoveryPointConversions.cs" />
5354
<Compile Include="Utils.cs" />
5455
<Compile Include="Validations\PolicyValidations.cs" />
5556
<Compile Include="Conversions\SchedulePolicyConversions.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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.RecoveryServices.Backup.Cmdlets.Models;
16+
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
17+
using System;
18+
using System.Collections.Generic;
19+
20+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
21+
{
22+
public class RecoveryPointConversions
23+
{
24+
public static List<AzureRmRecoveryServicesRecoveryPointBase> GetPSAzureRecoveryPoints(RecoveryPointListResponse rpList, AzureRmRecoveryServicesItemBase item)
25+
{
26+
if (rpList == null || rpList.RecoveryPointList == null || rpList.RecoveryPointList.RecoveryPoints == null)
27+
{
28+
throw new ArgumentNullException("rpList is null");
29+
}
30+
31+
List<AzureRmRecoveryServicesRecoveryPointBase> result = new List<AzureRmRecoveryServicesRecoveryPointBase>();
32+
foreach (RecoveryPointResource rp in rpList.RecoveryPointList.RecoveryPoints)
33+
{
34+
RecoveryPoint recPoint = rp.Properties as RecoveryPoint;
35+
AzureRmRecoveryServicesIaasVmRecoveryPoint rpBase = new AzureRmRecoveryServicesIaasVmRecoveryPoint()
36+
{
37+
BackupManagementType = item.BackupManagementType,
38+
ContainerName = item.ContainerName,
39+
ContainerType = item.ContainerType,
40+
RecoveryPointTime = Convert.ToDateTime(recPoint.RecoveryPointTime).ToLocalTime(),
41+
RecoveryPointType = recPoint.RecoveryPointType,
42+
WorkloadType = item.WorkloadType,
43+
RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo,
44+
};
45+
result.Add(rpBase);
46+
}
47+
48+
return result;
49+
}
50+
51+
public static AzureRmRecoveryServicesRecoveryPointBase GetPSAzureRecoveryPoints(RecoveryPointResponse rpResponse, AzureRmRecoveryServicesItemBase item)
52+
{
53+
if (rpResponse == null || rpResponse.RecPoint == null)
54+
{
55+
throw new ArgumentNullException("rpResponse is null");
56+
}
57+
58+
RecoveryPoint recPoint = rpResponse.RecPoint.Properties as RecoveryPoint;
59+
60+
AzureRmRecoveryServicesIaasVmRecoveryPoint result = new AzureRmRecoveryServicesIaasVmRecoveryPoint()
61+
{
62+
BackupManagementType = item.BackupManagementType,
63+
ContainerName = item.ContainerName,
64+
ContainerType = item.ContainerType,
65+
RecoveryPointTime = Convert.ToDateTime(recPoint.RecoveryPointTime).ToLocalTime(),
66+
RecoveryPointType = recPoint.RecoveryPointType,
67+
WorkloadType = item.WorkloadType,
68+
RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo,
69+
};
70+
return result;
71+
}
72+
}
73+
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.HydraAdapter/BMSAPIs/ContainerAPIs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ public BaseRecoveryServicesJobResponse RefreshContainers()
5252
BmsAdapter.GetCustomRequestHeaders(), AzureFabricName, BmsAdapter.CmdletCancellationToken).Result;
5353
return response;
5454
}
55+
5556
}
5657
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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.Management.RecoveryServices.Backup.Models;
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Text;
20+
using System.Threading.Tasks;
21+
22+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
23+
{
24+
public partial class HydraAdapter
25+
{
26+
/// <summary>
27+
///
28+
/// </summary>
29+
/// <param name="resourceGroupName"></param>
30+
/// <param name="resourceName"></param>
31+
/// <param name="containerName"></param>
32+
/// <param name="protectedItemName"></param>
33+
/// <param name="recoveryPointId"></param>
34+
/// <returns></returns>
35+
public RecoveryPointResponse GetRecoveryPointDetails(string containerName, string protectedItemName, string recoveryPointId)
36+
{
37+
var vault = BmsAdapter.GetVaultCredentials();
38+
string resourceGroupName = vault.ResourceGroupName;
39+
string resourceName = vault.ResourceName;
40+
41+
var response = BmsAdapter.Client.RecoveryPoint.GetAsync(resourceGroupName, resourceName,
42+
BmsAdapter.GetCustomRequestHeaders(), AzureFabricName, containerName, protectedItemName, recoveryPointId, BmsAdapter.CmdletCancellationToken).Result;
43+
44+
return response;
45+
}
46+
47+
/// <summary>
48+
///
49+
/// </summary>
50+
/// <param name="resourceGroupName"></param>
51+
/// <param name="resourceName"></param>
52+
/// <param name="containerName"></param>
53+
/// <param name="protectedItemName"></param>
54+
/// <param name="queryFilter"></param>
55+
/// <returns></returns>
56+
public RecoveryPointListResponse GetRecoveryPoints(string containerName, string protectedItemName, RecoveryPointQueryParameters queryFilter)
57+
{
58+
var vault = BmsAdapter.GetVaultCredentials();
59+
string resourceGroupName = vault.ResourceGroupName;
60+
string resourceName = vault.ResourceName;
61+
62+
var response = BmsAdapter.Client.RecoveryPoint.ListAsync(resourceGroupName, resourceName,
63+
BmsAdapter.GetCustomRequestHeaders(), AzureFabricName, containerName, protectedItemName, queryFilter, BmsAdapter.CmdletCancellationToken).Result;
64+
65+
return response;
66+
}
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.Generic;
17+
using System.Linq;
18+
using System.Text;
19+
using System.Threading.Tasks;
20+
21+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
22+
{
23+
public class AzureRmRecoveryServicesIaasVmRecoveryPoint : AzureRmRecoveryServicesRecoveryPointBase
24+
{
25+
/// <summary>
26+
///
27+
/// </summary>
28+
///
29+
public string RecoveryPointAdditionalInfo { get; set; }
30+
31+
public AzureRmRecoveryServicesIaasVmRecoveryPoint()
32+
{
33+
34+
}
35+
public override void Validate()
36+
{
37+
base.Validate();
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)