Skip to content

Commit cfe2e5c

Browse files
author
dragonfly91
committed
Resolved merge conflicts
2 parents 024ee92 + 3fcc717 commit cfe2e5c

File tree

44 files changed

+1175
-110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1175
-110
lines changed

setup/azurecmdfiles.wxi

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

src/ResourceManager/RecoveryServices.Backup/CmdletParameterHelpMessages.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ internal static class Container
2828
public const string ResourceGroupName = "The ResourceGroup of the resource being managed by the Azure Backup service (for example: ResourceGroup name of the VM).";
2929
public const string Status = "The registration status of the Azure Backup container.";
3030
public const string ContainerType = "The type of the Azure Backup container. This can be a Windows Server, an Azure IaaS VM, or a Data Protection Manager server.";
31+
public const string BackupManagementType = "The backup management type of the Azure Backup container";
32+
public const string RegisteredContainer = "The recovery services backup container.";
3133
}
3234

3335
internal static class Common
@@ -71,5 +73,19 @@ internal static class Item
7173
public const string Container = "Container where the item resides";
7274
public const string ExpiryDate = "Retention period for the recovery points created by this backup operaiton";
7375
}
76+
77+
internal static class RecoveryPoint
78+
{
79+
public const string StartDate = "Start time of Time range for which recovery point need to be fetched";
80+
public const string EndDate = "End time of Time range for which recovery point need to be fetched";
81+
public const string Item = "Protected Item object for which recovery point need to be fetched";
82+
public const string RecoveryPointId = "Recovery point Id for which detail is needed";
83+
}
84+
85+
internal static class RestoreDisk
86+
{
87+
public const string RecoveryPoint = "Recovery point objected to be restored";
88+
public const string StorageAccountName = "Storage account name where the disk need to be recovered";
89+
}
7490
}
7591
}
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+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
16+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
17+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Linq;
21+
using System.Management.Automation;
22+
using System.Text;
23+
using System.Threading.Tasks;
24+
25+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
26+
{
27+
/// <summary>
28+
/// Get list of containers
29+
/// </summary>
30+
[Cmdlet(VerbsCommon.Get, "AzureRmBackupManagementServer"), OutputType(typeof(List<AzureRmRecoveryServicesContainerBase>), typeof(AzureRmRecoveryServicesContainerBase))]
31+
public class GetAzureRmBackupManagementServer : RecoveryServicesBackupCmdletBase
32+
{
33+
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Container.Name)]
34+
[ValidateNotNullOrEmpty]
35+
public string Name { get; set; }
36+
37+
public override void ExecuteCmdlet()
38+
{
39+
ExecutionBlock(() =>
40+
{
41+
base.ExecuteCmdlet();
42+
43+
PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary<System.Enum, object>()
44+
{
45+
{ContainerParams.ContainerType, ContainerType.Windows},
46+
{ContainerParams.BackupManagementType, BackupManagementType.Scdpm},
47+
{ContainerParams.Name, Name}
48+
}, HydraAdapter);
49+
50+
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(ContainerType.Windows, BackupManagementType.Scdpm);
51+
52+
var containerModels = psBackupProvider.ListProtectionContainers();
53+
54+
if (containerModels.Count == 1)
55+
{
56+
WriteObject(containerModels.First());
57+
}
58+
else
59+
{
60+
WriteObject(containerModels);
61+
}
62+
});
63+
}
64+
}
65+
}

src/ResourceManager/RecoveryServices.Backup/Cmdlets/Container/GetAzureRmRecoveryServicesContainer.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public class GetAzureRmRecoveryServicesContainer : RecoveryServicesBackupCmdletB
3434
[ValidateNotNullOrEmpty]
3535
public ContainerType ContainerType { get; set; }
3636

37+
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Container.BackupManagementType)]
38+
[ValidateNotNullOrEmpty]
39+
public BackupManagementType BackupManagementType { get; set; }
40+
3741
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Container.Name)]
3842
[ValidateNotNullOrEmpty]
3943
public string Name { get; set; }
@@ -55,12 +59,13 @@ public override void ExecuteCmdlet()
5559
PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary<System.Enum, object>()
5660
{
5761
{ContainerParams.ContainerType, ContainerType},
62+
{ContainerParams.BackupManagementType, BackupManagementType},
5863
{ContainerParams.Name, Name},
5964
{ContainerParams.ResourceGroupName, ResourceGroupName},
6065
{ContainerParams.Status, Status},
6166
}, HydraAdapter);
6267

63-
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(ContainerType);
68+
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(ContainerType, BackupManagementType);
6469
var containerModels = psBackupProvider.ListProtectionContainers();
6570

6671
if (containerModels.Count == 1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Linq;
21+
using System.Management.Automation;
22+
using System.Text;
23+
using System.Threading.Tasks;
24+
25+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Container
26+
{
27+
[Cmdlet(VerbsLifecycle.Unregister, "AzureRmBackupManagementServer")]
28+
public class UnregisterAzureRmBackupManagementServer : RecoveryServicesBackupCmdletBase
29+
{
30+
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Container.RegisteredContainer)]
31+
[ValidateNotNullOrEmpty]
32+
public AzureRmRecoveryServicesContainerBase Container { get; set; }
33+
34+
public override void ExecuteCmdlet()
35+
{
36+
ExecutionBlock(() =>
37+
{
38+
base.ExecuteCmdlet();
39+
40+
if (Container.ContainerType != ContainerType.Windows || Container.BackupManagementType != BackupManagementType.Scdpm)
41+
{
42+
throw new ArgumentException(String.Format("Please provide Container of containerType Windows and backupManagementType Scdpm. Provided Container has containerType {0} and backupManagementType {1}", Container.ContainerType, Container.BackupManagementType));
43+
}
44+
45+
string containerName = Container.Name;
46+
HydraAdapter.UnregisterContainers(containerName);
47+
});
48+
}
49+
}
50+
}
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 Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Linq;
21+
using System.Management.Automation;
22+
using System.Text;
23+
using System.Threading.Tasks;
24+
25+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
26+
{
27+
/// <summary>
28+
/// Get list of containers
29+
/// </summary>
30+
[Cmdlet(VerbsLifecycle.Unregister, "AzureRmRecoveryServicesBackupContainer")]
31+
public class UnregisterAzureRmRecoveryServicesBackupContainer : RecoveryServicesBackupCmdletBase
32+
{
33+
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Container.RegisteredContainer)]
34+
[ValidateNotNullOrEmpty]
35+
public AzureRmRecoveryServicesContainerBase Container { get; set; }
36+
37+
public override void ExecuteCmdlet()
38+
{
39+
ExecutionBlock(() =>
40+
{
41+
base.ExecuteCmdlet();
42+
43+
if (Container.ContainerType != ContainerType.Windows || Container.BackupManagementType != BackupManagementType.Mars)
44+
{
45+
throw new ArgumentException(String.Format("Please provide Container of containerType Windows and backupManagementType Mars. Provided Container has containerType {0} and backupManagementType {1}", Container.ContainerType, Container.BackupManagementType));
46+
}
47+
string containerName = Container.Name;
48+
HydraAdapter.UnregisterContainers(containerName);
49+
});
50+
}
51+
}
52+
}
53+

src/ResourceManager/RecoveryServices.Backup/Cmdlets/ProtectionPolicy/GetAzureRmRecoveryServicesPolicy.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,31 @@ public class GetAzureRmRecoveryServicesProtectionPolicy : RecoveryServicesBackup
4444
[Parameter(ParameterSetName = WorkloadParamSet, Position = 2, Mandatory = true, HelpMessage = ParamHelpMsg.Common.WorkloadType)]
4545
[Parameter(ParameterSetName = WorkloadBackupMangementTypeParamSet, Position = 2, Mandatory = true, HelpMessage = ParamHelpMsg.Common.WorkloadType)]
4646
[ValidateNotNullOrEmpty]
47-
public WorkloadType WorkloadType { get; set; }
47+
public WorkloadType? WorkloadType { get; set; }
4848

4949
[Parameter(ParameterSetName = WorkloadBackupMangementTypeParamSet, Position = 3, Mandatory = true, HelpMessage = ParamHelpMsg.Common.BackupManagementType)]
5050
[ValidateNotNullOrEmpty]
51-
public BackupManagementType BackupManagementType { get; set; }
51+
public BackupManagementType? BackupManagementType { get; set; }
5252

5353
public override void ExecuteCmdlet()
5454
{
5555
ExecutionBlock(() =>
5656
{
5757
base.ExecuteCmdlet();
5858

59-
List<AzureRmRecoveryServicesPolicyBase> policyList = new List<AzureRmRecoveryServicesPolicyBase>();
59+
WriteDebug(string.Format("Input params - Name:{0}, " +
60+
"WorkloadType: {1}, BackupManagementType:{2}, " +
61+
"ParameterSetName: {3}",
62+
Name == null ? "NULL" : Name,
63+
WorkloadType.HasValue ? WorkloadType.ToString() : "NULL",
64+
BackupManagementType.HasValue ? BackupManagementType.ToString() : "NULL",
65+
this.ParameterSetName));
66+
6067

68+
List<AzureRmRecoveryServicesPolicyBase> policyList = new List<AzureRmRecoveryServicesPolicyBase>();
69+
6170
if (this.ParameterSetName == PolicyNameParamSet)
62-
{
71+
{
6372
// validate policyName
6473
PolicyCmdletHelpers.ValidateProtectionPolicyName(Name);
6574

@@ -82,7 +91,7 @@ public override void ExecuteCmdlet()
8291
case WorkloadParamSet:
8392
if (WorkloadType == Models.WorkloadType.AzureVM)
8493
{
85-
hydraProviderType = HydraHelpers.GetHydraProviderType(WorkloadType);
94+
hydraProviderType = HydraHelpers.GetHydraProviderType(Models.WorkloadType.AzureVM);
8695
}
8796
break;
8897

@@ -93,7 +102,7 @@ public override void ExecuteCmdlet()
93102
{
94103
throw new ArgumentException(Resources.AzureVMUnsupportedBackupManagementTypeException);
95104
}
96-
hydraProviderType = HydraHelpers.GetHydraProviderType(WorkloadType);
105+
hydraProviderType = HydraHelpers.GetHydraProviderType(Models.WorkloadType.AzureVM);
97106
}
98107
else
99108
{
@@ -116,19 +125,12 @@ public override void ExecuteCmdlet()
116125
{
117126
BackupManagementType = hydraProviderType
118127
};
128+
129+
WriteDebug("going to query service to get list of policies");
119130
HydraModel.ProtectionPolicyListResponse respList = HydraAdapter.ListProtectionPolicy(queryParams);
120-
if (respList != null && respList.ItemList != null &&
121-
respList.ItemList.Value != null && respList.ItemList.Value.Count != 0)
122-
{
123-
foreach (HydraModel.ProtectionPolicyResource policy in respList.ItemList.Value)
124-
{
125-
AzureRmRecoveryServicesPolicyBase psModel = ConversionHelpers.GetPolicyModel(policy);
126-
if (psModel != null)
127-
{
128-
policyList.Add(ConversionHelpers.GetPolicyModel(policy));
129-
}
130-
}
131-
}
131+
WriteDebug("Successfully got response from service");
132+
133+
policyList = ConversionHelpers.GetPolicyModelList(respList);
132134
}
133135

134136
WriteObject(policyList);

src/ResourceManager/RecoveryServices.Backup/Cmdlets/ProtectionPolicy/NewAzureRmRecoveryServicesPolicy.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ public override void ExecuteCmdlet()
5858
{
5959
base.ExecuteCmdlet();
6060

61+
WriteDebug(string.Format("Input params - Name:{0}, WorkloadType:{1}, " +
62+
"BackupManagementType: {2}, " +
63+
"RetentionPolicy:{3}, SchedulePolicy:{4}",
64+
Name, WorkloadType.ToString(),
65+
BackupManagementType.HasValue ? BackupManagementType.ToString() : "NULL",
66+
RetentionPolicy == null ? "NULL" : RetentionPolicy.ToString(),
67+
SchedulePolicy == null ? "NULL" : SchedulePolicy.ToString()));
68+
6169
// validate policy name
6270
PolicyCmdletHelpers.ValidateProtectionPolicyName(Name);
6371

@@ -70,19 +78,20 @@ public override void ExecuteCmdlet()
7078
PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary<System.Enum, object>()
7179
{
7280
{PolicyParams.PolicyName, Name},
73-
{PolicyParams.WorkloadType, WorkloadType},
74-
{PolicyParams.BackupManagementType, BackupManagementType},
81+
{PolicyParams.WorkloadType, WorkloadType},
7582
{PolicyParams.RetentionPolicy, RetentionPolicy},
7683
{PolicyParams.SchedulePolicy, SchedulePolicy},
7784
}, HydraAdapter);
7885

7986
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(WorkloadType, BackupManagementType);
8087
psBackupProvider.CreatePolicy();
8188

89+
WriteDebug("Successfully created policy, now fetching it from service: " + Name);
90+
8291
// now get the created policy and return
8392
HydraModel.ProtectionPolicyResponse policy = PolicyCmdletHelpers.GetProtectionPolicyByName(
84-
Name,
85-
HydraAdapter);
93+
Name,
94+
HydraAdapter);
8695
// now convert hydraPolicy to PSObject
8796
WriteObject(ConversionHelpers.GetPolicyModel(policy.Item));
8897
});

src/ResourceManager/RecoveryServices.Backup/Cmdlets/ProtectionPolicy/PolicyCmdletHelpers.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ public static ProtectionPolicyResponse GetProtectionPolicyByName(string policyNa
5151
ProtectionPolicyResponse response = null;
5252

5353
try
54-
{
54+
{
5555
response = hydraAdapter.GetProtectionPolicy(policyName);
56+
Logger.Instance.WriteDebug("Successfully fetched policy from service: " + policyName);
5657
}
5758
catch
5859
{

0 commit comments

Comments
 (0)