Skip to content

Commit 5cda8ad

Browse files
Merge branch 'dev1' of https://github.com/MabOneSdk/azure-powershell into swatim-dev1
2 parents 8f19ef4 + 36e731c commit 5cda8ad

31 files changed

+446
-131
lines changed

setup/azurecmdfiles.wxi

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

src/ResourceManager/AzureBackup/Commands.AzureBackup.Test/ScenarioTests/AzureBackupVaultTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ function Test-AzureBackupVaultScenario
4242
Assert-AreEqual $vault.Region $Location;
4343
Assert-AreEqual $vault.Storage "GeoRedundant";
4444

45-
Remove-AzureRmBackupVault -Vault $vault;
45+
Remove-AzureRmBackupVault -Vault $vault -Force;
4646
}

src/ResourceManager/RecoveryServices.Backup/CmdletParameterHelpMessages.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,19 @@ internal static class Item
7272
public const string Status = "Status of the data source";
7373
public const string Container = "Container where the item resides";
7474
}
75+
76+
internal static class RecoveryPoint
77+
{
78+
public const string StartDate = "Start time of Time range for which recovery point need to be fetched";
79+
public const string EndDate = "End time of Time range for which recovery point need to be fetched";
80+
public const string Item = "Protected Item object for which recovery point need to be fetched";
81+
public const string RecoveryPointId = "Recovery point Id for which detail is needed";
82+
}
83+
84+
internal static class RestoreDisk
85+
{
86+
public const string RecoveryPoint = "Recovery point objected to be restored";
87+
public const string StorageAccountName = "Storage account name where the disk need to be recovered";
88+
}
7589
}
7690
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
2727
/// <summary>
2828
/// Get list of containers
2929
/// </summary>
30-
[Cmdlet(VerbsCommon.Get, "AzureRmRecoveryServicesContainer"), OutputType(typeof(List<AzureRmRecoveryServicesContainerBase>), typeof(AzureRmRecoveryServicesContainerBase))]
30+
[Cmdlet(VerbsCommon.Get, "AzureRmBackupManagementServer"), OutputType(typeof(List<AzureRmRecoveryServicesContainerBase>), typeof(AzureRmRecoveryServicesContainerBase))]
3131
public class GetAzureRmBackupManagementServer : RecoveryServicesBackupCmdletBase
3232
{
3333
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Container.Name)]

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
{

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

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public override void ExecuteCmdlet()
5050
{
5151
base.ExecuteCmdlet();
5252

53+
WriteDebug(string.Format("Input params - Policy: {0}" +
54+
"RetentionPolicy:{1}, SchedulePolicy:{2}",
55+
Policy == null ? "NULL" : Policy.ToString(),
56+
RetentionPolicy == null ? "NULL" : RetentionPolicy.ToString(),
57+
SchedulePolicy == null ? "NULL" : SchedulePolicy.ToString()));
58+
5359
// Validate policy name
5460
PolicyCmdletHelpers.ValidateProtectionPolicyName(Policy.Name);
5561

@@ -71,26 +77,45 @@ public override void ExecuteCmdlet()
7177
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(Policy.WorkloadType,
7278
Policy.BackupManagementType);
7379
ProtectionPolicyResponse policyResponse = psBackupProvider.ModifyPolicy();
80+
WriteDebug("ModifyPolicy http response from service: " + policyResponse.StatusCode.ToString());
7481

7582
if(policyResponse.StatusCode == System.Net.HttpStatusCode.Accepted)
7683
{
84+
WriteDebug("Tracking operation status URL for completion: " +
85+
policyResponse.AzureAsyncOperation);
86+
7787
// Track OperationStatus URL for operation completion
7888
BackUpOperationStatusResponse operationResponse = WaitForOperationCompletionUsingStatusLink(
7989
policyResponse.AzureAsyncOperation,
8090
HydraAdapter.GetProtectionPolicyOperationStatusByURL);
81-
82-
if(operationResponse.OperationStatus.Status == OperationStatusValues.Failed.ToString())
91+
92+
WriteDebug("Final operation status: " + operationResponse.OperationStatus.Status);
93+
94+
if (operationResponse.OperationStatus.Properties != null &&
95+
((OperationStatusJobsExtendedInfo)operationResponse.OperationStatus.Properties).JobIds != null)
8396
{
84-
// if operation failed, then trace warning/error
97+
// get list of jobIds and return jobResponses
98+
WriteObject(GetJobObject(((OperationStatusJobsExtendedInfo)operationResponse.OperationStatus.Properties).JobIds));
8599
}
86100

87-
// get list of jobIds and return jobResponses
88-
WriteObject(GetJobObject(((OperationStatusJobsExtendedInfo)operationResponse.OperationStatus.Properties).JobIds));
101+
if (operationResponse.OperationStatus.Status == OperationStatusValues.Failed.ToString())
102+
{
103+
// if operation failed, then trace error and throw exception
104+
if (operationResponse.OperationStatus.OperationStatusError != null)
105+
{
106+
WriteDebug(string.Format(
107+
"OperationStatus Error: {0} " +
108+
"OperationStatus Code: {1}",
109+
operationResponse.OperationStatus.OperationStatusError.Message,
110+
operationResponse.OperationStatus.OperationStatusError.Code));
111+
}
112+
}
89113
}
90114
else
91115
{
92116
// Hydra will return OK if NO datasources are associated with this policy
93-
// just trace and return
117+
WriteDebug("No datasources are associated with Policy, http response code: " +
118+
policyResponse.StatusCode.ToString());
94119
}
95120
});
96121
}

src/ResourceManager/RecoveryServices.Backup/Cmdlets/RecoveryPoint/GetAzureRMRecoveryServicesRecoveryPoint.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ public class GetAzureRMRecoveryServicesRecoveryPoint : RecoveryServicesBackupCmd
2929
internal const string DateTimeFilterParameterSet = "DateTimeFilter";
3030
internal const string RecoveryPointIdParameterSet = "RecoveryPointId";
3131

32-
[Parameter(Mandatory = true, ParameterSetName = DateTimeFilterParameterSet, HelpMessage = "", ValueFromPipeline = false)]
32+
[Parameter(Mandatory = true, ParameterSetName = DateTimeFilterParameterSet, ValueFromPipeline = false, Position = 0, HelpMessage = ParamHelpMsg.RecoveryPoint.StartDate)]
3333
[ValidateNotNullOrEmpty]
3434
public DateTime StartDate { get; set; }
3535

36-
[Parameter(Mandatory = true, ParameterSetName = DateTimeFilterParameterSet, HelpMessage = "", ValueFromPipeline = false)]
36+
[Parameter(Mandatory = true, ParameterSetName = DateTimeFilterParameterSet, ValueFromPipeline = false, Position = 1, HelpMessage = ParamHelpMsg.RecoveryPoint.EndDate)]
3737
[ValidateNotNullOrEmpty]
3838
public DateTime EndDate { get; set; }
3939

40-
[Parameter(Mandatory = true, ParameterSetName = DateTimeFilterParameterSet, HelpMessage = "", ValueFromPipeline = true)]
41-
[Parameter(Mandatory = true, ParameterSetName = RecoveryPointIdParameterSet, HelpMessage = "", ValueFromPipeline = true)]
40+
[Parameter(Mandatory = true, ParameterSetName = DateTimeFilterParameterSet, ValueFromPipeline = true, Position = 2, HelpMessage = ParamHelpMsg.RecoveryPoint.Item)]
41+
[Parameter(Mandatory = true, ParameterSetName = RecoveryPointIdParameterSet, ValueFromPipeline = true, Position = 0, HelpMessage = ParamHelpMsg.RecoveryPoint.Item)]
4242
[ValidateNotNullOrEmpty]
4343
public AzureRmRecoveryServicesItemBase Item { get; set; }
4444

45-
[Parameter(Mandatory = true, ParameterSetName = RecoveryPointIdParameterSet, HelpMessage = "", ValueFromPipeline = false)]
45+
[Parameter(Mandatory = true, ParameterSetName = RecoveryPointIdParameterSet, ValueFromPipeline = false, Position = 1, HelpMessage = ParamHelpMsg.RecoveryPoint.RecoveryPointId)]
4646
[ValidateNotNullOrEmpty]
4747
public string RecoveryPointId { get; set; }
4848

@@ -70,11 +70,14 @@ public override void ExecuteCmdlet()
7070
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(Item.ContainerType, Item.BackupManagementType);
7171
var rpList = psBackupProvider.ListRecoveryPoints();
7272
if (rpList.Count == 1)
73+
{
7374
WriteObject(rpList[0]);
75+
}
7476
else
77+
{
7578
WriteObject(rpList);
79+
}
7680
}
77-
7881
else if (this.ParameterSetName == RecoveryPointIdParameterSet)
7982
{
8083
//User want details of a particular recovery point

0 commit comments

Comments
 (0)