Skip to content

Commit f3428a9

Browse files
committed
Merge branch 'dev' of https://github.com/MabOneSdk/azure-powershell into mkherani
Conflicts: src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs
2 parents fe83f27 + d3cf619 commit f3428a9

File tree

12 files changed

+167
-128
lines changed

12 files changed

+167
-128
lines changed

src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@ internal static class AzureBackupCmdletHelpMessage
2121
public const string ResourceGroupName = "The ResourceGroup name.";
2222
public const string ResourceName = "The Resource name.";
2323
public const string TargetLocation = "The directory where the credentials file will be saved.";
24-
public const string ContainerName = "The container name.";
24+
public const string ContainerResourceName = "The container resource name aka friendly name.";
2525
public const string ContainerId = "The container ID.";
2626
public const string ContainerRegistrationStatus = "The container registration status.";
2727
public const string ContainerType = "The container type.";
28+
<<<<<<< HEAD
2829
public const string VirtualMachine = "Virtual Machine.";
30+
=======
31+
public const string ContainerResourceGroupName = "The container resource group name.";
32+
public const string ProtectionStatus = "Protection Status of the azure backup item.";
33+
public const string AzureBackUpItem = "Azure BackUp Item.";
34+
public const string RecoveryPointId = "Recovery Point Id.";
35+
>>>>>>> d3cf61941b7653ba9a2edf165b1ae23e38921395
2936
}
3037
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupDSCmdletBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ public abstract class AzureBackupDSCmdletBase : AzureBackupCmdletBase
3030
{
3131
// ToDO:
3232
// Correct Help message and other attributes related to paameters
33-
[Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ResourceGroupName, ValueFromPipelineByPropertyName = true)]
33+
[Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.AzureBackUpItem, ValueFromPipelineByPropertyName = true)]
3434
[ValidateNotNullOrEmpty]
35-
public AzureBackupItem AzureBackupItem { get; set; }
35+
public AzureBackupItem item { get; set; }
3636

3737
public override void ExecuteCmdlet()
3838
{
3939
base.ExecuteCmdlet();
4040

41-
WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}", AzureBackupItem.ResourceGroupName, AzureBackupItem.ResourceName));
41+
WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}", item.ResourceGroupName, item.ResourceName));
4242

43-
InitializeAzureBackupCmdlet(AzureBackupItem.ResourceGroupName, AzureBackupItem.ResourceName);
43+
InitializeAzureBackupCmdlet(item.ResourceGroupName, item.ResourceName);
4444
}
4545
}
4646
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/BackUp/TriggerBackUp.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
3131
/// <summary>
3232
/// Get list of containers
3333
/// </summary>
34-
[Cmdlet(VerbsCommon.New, "AzureBackupItem"), OutputType(typeof(MBS.OperationResponse))]
34+
[Cmdlet(VerbsData.Backup, "AzureBackupItem"), OutputType(typeof(MBS.OperationResponse))]
3535
public class TriggerAzureBackup : AzureBackupDSCmdletBase
3636
{
3737
public override void ExecuteCmdlet()
@@ -44,26 +44,26 @@ public override void ExecuteCmdlet()
4444

4545
MBS.OperationResponse triggerBackUpInfo =
4646
AzureBackupClient.BackUp.TriggerBackUpAsync(GetCustomRequestHeaders(),
47-
AzureBackupItem.ContainerName,
48-
AzureBackupItem.DataSourceType,
49-
AzureBackupItem.DataSourceId,
50-
CmdletCancellationToken).Result;
47+
item.ContainerUniqueName,
48+
item.Type,
49+
item.DataSourceId,
50+
CmdletCancellationToken).Result;
5151

5252
WriteVerbose("Received policy response");
5353
WriteVerbose("Received policy response2");
5454

5555
WriteVerbose("Converting response");
56-
WriteAzureBackupProtectionPolicy(triggerBackUpInfo);
56+
WriteAzureBackupOperationId(triggerBackUpInfo);
5757
});
5858
}
5959

60-
public void WriteAzureBackupProtectionPolicy(MBS.OperationResponse sourceOperationResponse)
60+
public void WriteAzureBackupOperationId(MBS.OperationResponse sourceOperationResponse)
6161
{
6262
// this needs to be uncommented once we have proper constructor
63-
//this.WriteObject(new AzureBackupRecoveryPoint(ResourceGroupName, ResourceName, sourceOperationResponse));
63+
// this.WriteObject(new AzureBackupRecoveryPoint(ResourceGroupName, ResourceName, sourceOperationResponse));
6464
}
6565

66-
public void WriteAzureBackupProtectionPolicy(IEnumerable<MBS.OperationResponse> sourceOperationResponseList)
66+
public void WriteAzureBackupOperationId(IEnumerable<MBS.OperationResponse> sourceOperationResponseList)
6767
{
6868
List<MBS.OperationResponse> targetList = new List<MBS.OperationResponse>();
6969

@@ -77,4 +77,3 @@ public void WriteAzureBackupProtectionPolicy(IEnumerable<MBS.OperationResponse>
7777
}
7878
}
7979
}
80-

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Container/GetAzureBackupContainer.cs

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using BCI = Microsoft.BackupManagementService.CommonInterface;
16+
using BMI = Microsoft.BackupManagementService.ManagementInterface;
17+
using Microsoft.Azure.Management.BackupServices.Models;
1518
using System;
1619
using System.Collections.Generic;
1720
using System.Linq;
@@ -27,19 +30,19 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
2730
[Cmdlet(VerbsCommon.Get, "AzureBackupContainer"), OutputType(typeof(AzureBackupContainer), typeof(List<AzureBackupContainer>))]
2831
public class GetAzureBackupContainer : AzureBackupVaultCmdletBase
2932
{
30-
[Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ContainerName)]
33+
[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ContainerResourceGroupName)]
3134
[ValidateNotNullOrEmpty]
32-
public string Name { get; set; }
35+
public string ContainerResourceGroupName { get; set; }
3336

34-
[Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ContainerId)]
37+
[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ContainerResourceName)]
3538
[ValidateNotNullOrEmpty]
36-
public string Id { get; set; }
39+
public string ContainerResourceName { get; set; }
3740

38-
[Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ContainerRegistrationStatus)]
41+
[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ContainerRegistrationStatus)]
3942
[ValidateNotNullOrEmpty]
4043
public AzureBackupContainerStatus Status { get; set; }
4144

42-
[Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ContainerType)]
45+
[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ContainerType)]
4346
[ValidateNotNullOrEmpty]
4447
public AzureBackupContainerType Type { get; set; }
4548

@@ -49,12 +52,64 @@ public override void ExecuteCmdlet()
4952

5053
ExecutionBlock(() =>
5154
{
52-
IEnumerable<AzureBackupContainer> containers = new List<AzureBackupContainer>();
55+
string queryFilterString = string.Empty;
56+
queryFilterString = ConstructQueryFilterString();
57+
ListContainerResponse listContainerResponse = AzureBackupClient.Container.ListAsync(queryFilterString,
58+
GetCustomRequestHeaders(), CmdletCancellationToken).Result;
5359

54-
// TODO: Call Hydra
60+
List<ContainerInfo> containerInfos = listContainerResponse.Objects.ToList();
5561

56-
WriteObject(containers);
62+
// When resource group name is specified, remove all containers whose resource group name
63+
// doesn't match the given resource group name
64+
if (!string.IsNullOrEmpty(ContainerResourceGroupName))
65+
{
66+
containerInfos.RemoveAll(containerInfo =>
67+
{
68+
return containerInfo.ParentContainerName != ContainerResourceGroupName;
69+
});
70+
}
71+
72+
WriteObject(containerInfos.ConvertAll(containerInfo =>
73+
{
74+
return new AzureBackupContainer(containerInfo);
75+
}));
5776
});
5877
}
78+
79+
private string ConstructQueryFilterString()
80+
{
81+
BMI.ContainerQueryObject containerQueryObject = new BMI.ContainerQueryObject();
82+
83+
switch (Type)
84+
{
85+
case AzureBackupContainerType.AzureVirtualMachine:
86+
containerQueryObject.Type = BCI.ContainerType.IaasVMContainer.ToString();
87+
break;
88+
default:
89+
break;
90+
}
91+
92+
switch (Status)
93+
{
94+
case AzureBackupContainerStatus.Registered:
95+
containerQueryObject.Status = BCI.RegistrationStatus.Registered.ToString();
96+
break;
97+
case AzureBackupContainerStatus.Registering:
98+
containerQueryObject.Status = BCI.RegistrationStatus.Registering.ToString();
99+
break;
100+
case AzureBackupContainerStatus.NotRegistered:
101+
containerQueryObject.Status = BCI.RegistrationStatus.NotRegistered.ToString();
102+
break;
103+
default:
104+
break;
105+
}
106+
107+
if (!string.IsNullOrEmpty(ContainerResourceName))
108+
{
109+
containerQueryObject.FriendlyName = ContainerResourceName;
110+
}
111+
112+
return BMI.BackupManagementAPIHelper.GetQueryString(containerQueryObject.GetNameValueCollection());
113+
}
59114
}
60115
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/DataSource/GetAzureBackupItem.cs

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.Xml;
1919
using System.Linq;
2020
using Microsoft.Azure.Management.BackupServices.Models;
21+
using System.Runtime.Serialization;
2122

2223
namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
2324
{
@@ -27,9 +28,9 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
2728
[Cmdlet(VerbsCommon.Get, "AzureBackupItem"), OutputType(typeof(AzureBackupItem), typeof(List<AzureBackupItem>))]
2829
public class GetAzureBackupItem : AzureBackupContainerCmdletBase
2930
{
30-
[Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)]
31+
[Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ProtectionStatus)]
3132
[ValidateNotNullOrEmpty]
32-
public string Id { get; set; }
33+
public protectionStatus ProtectionStatus { get; set; }
3334

3435
public override void ExecuteCmdlet()
3536
{
@@ -39,23 +40,38 @@ public override void ExecuteCmdlet()
3940
{
4041
WriteVerbose("Making client call");
4142

42-
var azureBackupDatasourceListResponse = AzureBackupClient.DataSource.ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result;
43-
var azureBackupPOListResponse = AzureBackupClient.ProtectableObject. ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result;
43+
DataSourceQueryParameter dsQueryParameter = new DataSourceQueryParameter()
44+
{
45+
ContainerName = AzureBackupContainer.ContainerName
46+
};
47+
48+
POQueryParameter pOQueryParameter = new POQueryParameter()
49+
{
50+
Status = this.ProtectionStatus.ToString()
51+
};
52+
53+
var azureBackupDatasourceListResponse = AzureBackupClient.DataSource.ListAsync(dsQueryParameter,GetCustomRequestHeaders(), CmdletCancellationToken).Result;
54+
var azureBackupPOListResponse = AzureBackupClient.ProtectableObject. ListAsync(pOQueryParameter, GetCustomRequestHeaders(), CmdletCancellationToken).Result;
4455

4556
WriteVerbose("Received policy response");
4657
WriteVerbose("Received policy response2");
47-
IEnumerable<DataSourceInfo> azureBackupDatasourceObjects = null;
48-
IEnumerable<ProtectableObjectInfo> azureBackupPOObjects = null;
58+
List<DataSourceInfo> azureBackupDatasourceObjects = null;
59+
List<ProtectableObjectInfo> azureBackupPOObjects = null;
4960

50-
if (Id != null)
51-
{
52-
azureBackupDatasourceObjects = azureBackupDatasourceListResponse.DataSources.Objects.Where(x => x.InstanceId.Equals(Id, System.StringComparison.InvariantCultureIgnoreCase));
53-
azureBackupPOObjects = azureBackupPOListResponse.ProtectableObject.Objects.Where(x => x.InstanceId.Equals(Id, System.StringComparison.InvariantCultureIgnoreCase));
54-
}
55-
else
61+
azureBackupDatasourceObjects = azureBackupDatasourceListResponse.DataSources.Objects.ToList();
62+
azureBackupPOObjects = azureBackupPOListResponse.ProtectableObject.Objects.Where(x => x.ContainerName.Equals(AzureBackupContainer.ContainerName, System.StringComparison.InvariantCultureIgnoreCase)).ToList();
63+
64+
//If user has stopped protection for some datasoure then we will have duplicate items(po and ds).
65+
//So in this case removing poitem.
66+
foreach (var DSItem in azureBackupDatasourceObjects)
5667
{
57-
azureBackupDatasourceObjects = azureBackupDatasourceListResponse.DataSources.Objects;
58-
azureBackupPOObjects = azureBackupPOListResponse.ProtectableObject.Objects;
68+
foreach(var POItem in azureBackupPOObjects)
69+
{
70+
if(DSItem.ProtectableObjectName == POItem.Name)
71+
{
72+
azureBackupPOObjects.Remove(POItem);
73+
}
74+
}
5975
}
6076

6177
WriteVerbose("Converting response");
@@ -68,7 +84,7 @@ public void WriteAzureBackupProtectionPolicy(DataSourceInfo sourceItem, AzureBac
6884
this.WriteObject(new AzureBackupItem(sourceItem, azureBackupItem));
6985
}
7086

71-
public void WriteAzureBackupProtectionPolicy(IEnumerable<DataSourceInfo> sourceDataSourceList,IEnumerable<ProtectableObjectInfo> sourcePOList, AzureBackupContainer azureBackupContainer)
87+
public void WriteAzureBackupProtectionPolicy(List<DataSourceInfo> sourceDataSourceList, List<ProtectableObjectInfo> sourcePOList, AzureBackupContainer azureBackupContainer)
7288
{
7389
List<AzureBackupItem> targetList = new List<AzureBackupItem>();
7490

@@ -85,5 +101,13 @@ public void WriteAzureBackupProtectionPolicy(IEnumerable<DataSourceInfo> sourceD
85101
this.WriteObject(targetList, true);
86102
}
87103

104+
public enum protectionStatus
105+
{
106+
[EnumMember]
107+
NotProtected = 0,
108+
109+
[EnumMember]
110+
Protected,
111+
}
88112
}
89113
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/RecoveryPoint/GetAzureBackupRecoveryPoint.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
2727
[Cmdlet(VerbsCommon.Get, "AzureBackupRecoveryPoint"), OutputType(typeof(AzureBackupRecoveryPoint), typeof(List<AzureBackupRecoveryPoint>))]
2828
public class GetAzureBackupRecoveryPoint : AzureBackupDSCmdletBase
2929
{
30-
[Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)]
30+
[Parameter(Position = 1, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.RecoveryPointId)]
3131
[ValidateNotNullOrEmpty]
3232
public string Id { get; set; }
3333

@@ -41,9 +41,9 @@ public override void ExecuteCmdlet()
4141

4242
RecoveryPointListResponse recoveryPointListResponse =
4343
AzureBackupClient.RecoveryPoint.ListAsync(GetCustomRequestHeaders(),
44-
AzureBackupItem.ContainerName,
45-
AzureBackupItem.DataSourceType,
46-
AzureBackupItem.DataSourceId,
44+
item.ContainerUniqueName,
45+
item.Type,
46+
item.DataSourceId,
4747
CmdletCancellationToken).Result;
4848

4949
WriteVerbose("Received policy response");
@@ -59,16 +59,16 @@ public override void ExecuteCmdlet()
5959
}
6060

6161
WriteVerbose("Converting response");
62-
WriteAzureBackupProtectionPolicy(recoveryPointObjects, AzureBackupItem);
62+
WriteAzureBackupRecoveryPoint(recoveryPointObjects, item);
6363
});
6464
}
6565

66-
public void WriteAzureBackupProtectionPolicy(RecoveryPointInfo sourceRecoverPoint, AzureBackupItem azureBackupItem)
66+
public void WriteAzureBackupRecoveryPoint(RecoveryPointInfo sourceRecoverPoint, AzureBackupItem azureBackupItem)
6767
{
6868
this.WriteObject(new AzureBackupRecoveryPoint(sourceRecoverPoint, azureBackupItem));
6969
}
7070

71-
public void WriteAzureBackupProtectionPolicy(IEnumerable<RecoveryPointInfo> sourceRecoverPointList, AzureBackupItem azureBackupItem)
71+
public void WriteAzureBackupRecoveryPoint(IEnumerable<RecoveryPointInfo> sourceRecoverPointList, AzureBackupItem azureBackupItem)
7272
{
7373
List<AzureBackupRecoveryPoint> targetList = new List<AzureBackupRecoveryPoint>();
7474

src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
<Compile Include="AzureBackupCmdletBase.cs" />
122122
<Compile Include="AzureBackupCmdletHelpMessage.cs" />
123123
<Compile Include="Cmdlets\BackUp\TriggerBackUp.cs" />
124+
<Compile Include="Cmdlets\RecoveryPoint\GetAzureBackupRecoveryPoint.cs" />
124125
<Compile Include="Cmdlets\Container\GetAzureBackupContainer.cs" />
125126
<Compile Include="Cmdlets\Container\RegisterAzureBackupContainer.cs" />
126127
<Compile Include="Cmdlets\Container\UnregisterAzureBackupContainer.cs" />

0 commit comments

Comments
 (0)