Skip to content

Commit 49dd37e

Browse files
committed
Merge pull request #95 from MabOneSdk/dev1-pikumar
Dev1 pikumar
2 parents 1130974 + 53be604 commit 49dd37e

File tree

7 files changed

+60
-34
lines changed

7 files changed

+60
-34
lines changed

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Item/Disable-AzureBackupProtection .cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets.DataSource
3232
public class DisableAzureBackupProtection : AzureBackupDSCmdletBase
3333
{
3434
[Parameter(Position = 1, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.RemoveProtectionOption)]
35-
public SwitchParameter RemoveRecoveryPoints
35+
public SwitchParameter RemoveRecoveryPoints
3636
{
3737
get { return DeleteBackupData; }
38-
set { DeleteBackupData = value; }
38+
set { DeleteBackupData = value; }
3939
}
4040
private bool DeleteBackupData;
4141

@@ -46,15 +46,16 @@ public SwitchParameter RemoveRecoveryPoints
4646
public string Comments { get; set; }
4747

4848
public override void ExecuteCmdlet()
49-
{
49+
{
5050
ExecutionBlock(() =>
5151
{
5252
base.ExecuteCmdlet();
5353
Guid operationId = Guid.Empty;
5454
WriteDebug("Making client call");
5555

56-
if(!this.DeleteBackupData)
56+
if (!this.DeleteBackupData)
5757
{
58+
//Calling update protection with policy Id as empty.
5859
CSMUpdateProtectionRequest input = new CSMUpdateProtectionRequest()
5960
{
6061
Properties = new CSMUpdateProtectionRequestProperties(string.Empty)
@@ -65,6 +66,7 @@ public override void ExecuteCmdlet()
6566

6667
else
6768
{
69+
//Calling disable protection
6870
operationId = AzureBackupClient.DisableProtection(Item.ContainerUniqueName, Item.ItemName);
6971
}
7072

@@ -75,4 +77,4 @@ public override void ExecuteCmdlet()
7577
});
7678
}
7779
}
78-
}
80+
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Item/Enable-AzureBackupProtection .cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,20 @@ public override void ExecuteCmdlet()
4343

4444
WriteDebug("Making client call");
4545
string itemName = string.Empty;
46+
4647
CSMSetProtectionRequest input = new CSMSetProtectionRequest();
47-
input.Properties.PolicyId = Policy.InstanceId;
48+
input.Properties = new CSMSetProtectionRequestProperties();
49+
input.Properties.PolicyId = Policy.PolicyId;
50+
4851
if (Item.GetType() == typeof(AzureBackupItem))
4952
{
5053
itemName = (Item as AzureBackupItem).ItemName;
5154
}
55+
5256
else if (Item.GetType() == typeof(AzureBackupContainer))
5357
{
5458
WriteDebug("Input is container Type = " + Item.GetType());
55-
if ((Item as AzureBackupContainer).ContainerType == ManagedContainerType.IaasVMContainer.ToString())
59+
if ((Item as AzureBackupContainer).ContainerType == ManagedContainerType.IaasVM.ToString())
5660
{
5761
itemName = (Item as AzureBackupContainer).ContainerUniqueName;
5862
}
@@ -61,17 +65,18 @@ public override void ExecuteCmdlet()
6165
throw new Exception("Uknown item type");
6266
}
6367
}
68+
6469
else
6570
{
6671
throw new Exception("Uknown item type");
6772
}
6873

69-
var operationId = AzureBackupClient.EnableProtection(Item.ContainerUniqueName,itemName, input);
74+
var operationId = AzureBackupClient.EnableProtection(Item.ContainerUniqueName, itemName, input);
7075
WriteDebug("Received enable azure backup protection response");
7176

7277
var operationStatus = GetOperationStatus(operationId);
7378
this.WriteObject(GetCreatedJobs(new Models.AzurePSBackupVault(Item.ResourceGroupName, Item.ResourceName, Item.Location), operationStatus.JobList).FirstOrDefault());
7479
});
7580
}
7681
}
77-
}
82+
}

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
3232
public class GetAzureBackupItem : AzureBackupContainerCmdletBase
3333
{
3434
[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ProtectionStatus)]
35-
[ValidateSet("Protected","Protecting","NotProtected")]
35+
[ValidateSet("Protected", "Protecting", "NotProtected")]
3636
public string ProtectionStatus { get; set; }
3737

3838
[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.Status)]
39-
[ValidateSet("IRPending", "ProtectionStopped", "ProtectionError", "Protected")]
39+
[ValidateSet("IRPending", "ProtectionStopped", "ProtectionError", "Protected")]
4040
public string Status { get; set; }
4141

4242
[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.Type)]
43-
[ValidateSet("VM")]
43+
[ValidateSet("IaasVM")]
4444
public string Type { get; set; }
4545

4646
public override void ExecuteCmdlet()
@@ -55,8 +55,8 @@ public override void ExecuteCmdlet()
5555
WriteDebug("Making client call");
5656
CSMProtectedItemQueryObject DSQueryParam = new CSMProtectedItemQueryObject()
5757
{
58-
ProtectionStatus = this.Status,
59-
Status = this.ProtectionStatus,
58+
ProtectionStatus = this.ProtectionStatus,
59+
Status = this.Status,
6060
Type = this.Type
6161
};
6262

@@ -68,12 +68,18 @@ public override void ExecuteCmdlet()
6868

6969
var azureBackupDatasourceListResponse = AzureBackupClient.ListDataSources(DSQueryParam);
7070

71-
azureBackupDatasourceObjects = azureBackupDatasourceListResponse.Where(x => x.Properties.ContainerId.Split('/').Last().Equals(Container.ContainerUniqueName, System.StringComparison.InvariantCultureIgnoreCase)).ToList();
71+
if (azureBackupDatasourceListResponse != null)
72+
{
73+
azureBackupDatasourceObjects = azureBackupDatasourceListResponse.Where(x => x.Properties.ContainerId.Split('/').Last().Equals(Container.ContainerUniqueName, System.StringComparison.InvariantCultureIgnoreCase)).ToList();
74+
}
7275

7376
if (this.Status == null)
7477
{
7578
var azureBackupPOListResponse = AzureBackupClient.ListProtectableObjects(POQueryParam);
76-
azureBackupPOObjects = azureBackupPOListResponse.Where(x => x.Properties.ContainerId.Split('/').Last().Equals(Container.ContainerUniqueName, System.StringComparison.InvariantCultureIgnoreCase)).ToList();
79+
if (azureBackupPOListResponse != null)
80+
{
81+
azureBackupPOObjects = azureBackupPOListResponse.Where(x => x.Properties.ContainerId.Split('/').Last().Equals(Container.ContainerUniqueName, System.StringComparison.InvariantCultureIgnoreCase)).ToList();
82+
}
7783
}
7884

7985
WriteDebug("Received azure backup item response");
@@ -90,17 +96,20 @@ public void WriteAzureBackupItem(List<CSMProtectedItemResponse> sourceDataSource
9096
{
9197
List<AzureBackupItem> targetList = new List<AzureBackupItem>();
9298

93-
foreach (var item in sourceDataSourceList)
99+
if (sourceDataSourceList != null)
94100
{
95-
targetList.Add(new AzureBackupItem(item, azureBackupContainer));
101+
foreach (var item in sourceDataSourceList)
102+
{
103+
targetList.Add(new AzureBackupItem(item, azureBackupContainer));
104+
}
96105
}
97106

98107
if (sourcePOList != null)
99108
{
100109
foreach (var item in sourcePOList)
101110
{
102111
//If user has stopped protection for some datasoure then we will have duplicate items(po and ds).
103-
//So in this case removing poitems from the list.
112+
//So in this case removing po items from the list.
104113
if (targetList.FindIndex(element => element.ItemName == item.Name) < 0)
105114
{
106115
targetList.Add(new AzureBackupItem(item, azureBackupContainer));
@@ -119,4 +128,4 @@ public void WriteAzureBackupItem(List<CSMProtectedItemResponse> sourceDataSource
119128
}
120129

121130
}
122-
}
131+
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,12 @@
121121
<Compile Include="AzureBackupClientAdapter\ItemAdapter.cs" />
122122
<Compile Include="AzureBackupClientAdapter\JobAdapter.cs" />
123123
<Compile Include="AzureBackupClientAdapter\OperationStatusAdapter.cs" />
124+
<Compile Include="AzureBackupClientAdapter\PolicyAdapter.cs" />
124125
<Compile Include="AzureBackupClientAdapter\VaultAdapter.cs" />
125126
<Compile Include="AzureBackupContainerCmdletBase.cs" />
126127
<Compile Include="AzureBackupDSCmdletBase.cs" />
127128
<Compile Include="AzureBackupItemCmdletBase.cs" />
129+
<Compile Include="AzureBackupPolicyCmdletBase.cs" />
128130
<Compile Include="AzureBackUpRestoreBase.cs" />
129131
<Compile Include="AzureBackupVaultCmdletBase.cs" />
130132
<Compile Include="AzureBackupCmdletBase.cs" />
@@ -134,11 +136,19 @@
134136
<Compile Include="Cmdlets\Container\GetAzureBackupContainer.cs" />
135137
<Compile Include="Cmdlets\Container\RegisterAzureBackupContainer.cs" />
136138
<Compile Include="Cmdlets\Container\UnregisterAzureBackupContainer.cs" />
139+
<Compile Include="Cmdlets\Item\Disable-AzureBackupProtection .cs" />
140+
<Compile Include="Cmdlets\Item\Enable-AzureBackupProtection .cs" />
141+
<Compile Include="Cmdlets\Item\GetAzureBackupItem.cs" />
137142
<Compile Include="Cmdlets\Jobs\AzureBackupJobHelper.cs" />
138143
<Compile Include="Cmdlets\Jobs\GetAzureBackupJob.cs" />
139144
<Compile Include="Cmdlets\Jobs\GetAzureBackupJobDetails.cs" />
140145
<Compile Include="Cmdlets\Jobs\StopAzureBackukpJob.cs" />
141146
<Compile Include="Cmdlets\Jobs\WaitAzureBackupJob.cs" />
147+
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureBackupProtectionPolicy.cs" />
148+
<Compile Include="Cmdlets\ProtectionPolicy\NewAzureBackupProtectionPolicy.cs" />
149+
<Compile Include="Cmdlets\ProtectionPolicy\NewAzureBackupRetentionPolicyObject.cs" />
150+
<Compile Include="Cmdlets\ProtectionPolicy\RemoveAzureBackupProtectionPolicy.cs" />
151+
<Compile Include="Cmdlets\ProtectionPolicy\SetAzureBackupProtectionPolicy.cs" />
142152
<Compile Include="Cmdlets\RecoveryPoint\GetAzureBackupRecoveryPoint.cs" />
143153
<Compile Include="Cmdlets\Restore\TriggerRestore.cs" />
144154
<Compile Include="Cmdlets\VaultCredentials\GetAzureBackupVaultCredentials.cs" />
@@ -147,6 +157,7 @@
147157
<Compile Include="Cmdlets\Vault\SetAzureBackupVault.cs" />
148158
<Compile Include="Cmdlets\Vault\NewAzureBackupVault.cs" />
149159
<Compile Include="Helpers\ContainerHelpers.cs" />
160+
<Compile Include="Helpers\ProtectionPolicyHelpers.cs" />
150161
<Compile Include="Helpers\VaultHelpers.cs" />
151162
<Compile Include="Library\CertUtils.cs" />
152163
<Compile Include="Models\AzureBackupBaseObjects.cs" />
@@ -157,6 +168,7 @@
157168
<Compile Include="Models\AzurePSBackupVault.cs" />
158169
<Compile Include="Models\JobObjects.cs" />
159170
<Compile Include="Models\ListContainerQueryParameter.cs" />
171+
<Compile Include="Models\ProtectionPolicy.cs" />
160172
<Compile Include="Models\VaultCredentials.cs" />
161173
<Compile Include="Properties\Resources.Designer.cs">
162174
<AutoGen>True</AutoGen>
@@ -200,6 +212,9 @@
200212
<Name>Commands.Utilities</Name>
201213
</ProjectReference>
202214
</ItemGroup>
215+
<ItemGroup>
216+
<Folder Include="Cmdlets\RegisterContainer\" />
217+
</ItemGroup>
203218
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
204219
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
205220
<Import Project="..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />

src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/AzureBackupEnums.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,6 @@ public enum ManagedContainerType
8888
IaasVMService,
8989
}
9090

91-
public enum ScheduleType
92-
{
93-
Invalid = 0,
94-
Daily = 1,
95-
Weekly = 2
96-
}
97-
9891
public enum RetentionType
9992
{
10093
Invalid = 0,

src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/AzureBackupItem.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ public class AzureBackupItem : AzureBackupItemContextObject
3737
public string ProtectionStatus { get; set; }
3838

3939
/// <summary>
40-
/// DataSourceId of Azure Backup Item
41-
/// </summary>
42-
public string DataSourceId { get; set; }
43-
44-
/// <summary>
45-
/// DataSourceId of Azure Backup Item
40+
/// Type of Azure Backup Item
4641
/// </summary>
4742
public string Type { get; set; }
4843

@@ -72,16 +67,23 @@ public AzureBackupItem(CSMProtectedItemResponse datasource, AzureBackupContainer
7267
DataSourceStatus = datasource.Properties.ProtectionStatus;
7368
ProtectionStatus = datasource.Properties.Status;
7469
ItemName = datasource.Name;
75-
ProtectionPolicyName = datasource.Properties.ProtectionPolicyId;
70+
71+
if (datasource.Properties.ProtectionPolicyId != null)
72+
{
73+
ProtectionPolicyName = datasource.Properties.ProtectionPolicyId.Split('/').Last();
74+
}
75+
7676
ProtectionPolicyId = datasource.Properties.ProtectionPolicyId;
7777
RecoveryPointsCount = datasource.Properties.RecoveryPointsCount;
78+
Type = datasource.Properties.ItemType;
7879
}
7980

8081
public AzureBackupItem(CSMItemResponse pPOItem, AzureBackupContainer azureBackupContainer)
8182
: base(pPOItem, azureBackupContainer)
8283
{
8384
ProtectionStatus = pPOItem.Properties.Status;
8485
ItemName = pPOItem.Name;
86+
Type = pPOItem.Properties.ItemType;
8587
}
8688
}
8789
}

0 commit comments

Comments
 (0)