Skip to content

Commit ff1acac

Browse files
committed
Enable/Disable-Protection completed.
1 parent c9e8906 commit ff1acac

File tree

7 files changed

+295
-51
lines changed

7 files changed

+295
-51
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@ internal static class AzureBackupCmdletHelpMessage
2727
public const string ContainerType = "The container type.";
2828
public const string ContainerResourceGroupName = "The container resource group name.";
2929
public const string ProtectionStatus = "Protection Status of the azure backup item.";
30+
public const string Type = "Type of Azure Backup Item.";
31+
public const string Status = "Status of Azure Backup Item";
32+
public const string AzureBackupContainer = "Azure Backup Container for Azure Backup Item.";
3033
}
3134
}

src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupContainerCmdletBase.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
2828
{
2929
public abstract class AzureBackupContainerCmdletBase : AzureBackupCmdletBase
3030
{
31-
// ToDO:
32-
// Correct Help message and other attributes related to paameters
33-
[Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ResourceGroupName, ValueFromPipelineByPropertyName = true)]
31+
[Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.AzureBackupContainer, ValueFromPipelineByPropertyName = true)]
3432
[ValidateNotNullOrEmpty]
3533
public AzureBackupContainer AzureBackupContainer { get; set; }
3634

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.Management.Automation;
17+
using System.Collections.Generic;
18+
using System.Xml;
19+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
20+
using Microsoft.Azure.Common.Authentication;
21+
using Microsoft.Azure.Common.Authentication.Models;
22+
using System.Threading;
23+
using Hyak.Common;
24+
using Microsoft.Azure.Commands.AzureBackup.Properties;
25+
using System.Net;
26+
27+
namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
28+
{
29+
public abstract class AzureBackupItemCmdletBase : AzureBackupCmdletBase
30+
{
31+
// ToDO:
32+
// Correct Help message and other attributes related to paameters
33+
[Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ResourceGroupName, ValueFromPipelineByPropertyName = true)]
34+
[ValidateNotNullOrEmpty]
35+
public AzureBackupContainerContextObject AzureBackupItem { get; set; }
36+
37+
public override void ExecuteCmdlet()
38+
{
39+
base.ExecuteCmdlet();
40+
WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}", AzureBackupItem.ResourceGroupName, AzureBackupItem.ResourceName));
41+
InitializeAzureBackupCmdlet(AzureBackupItem.ResourceGroupName, AzureBackupItem.ResourceName);
42+
}
43+
}
44+
}
45+
Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,76 @@
1-
using System;
1+
using Microsoft.Azure.Management.BackupServices;
2+
using Microsoft.Azure.Management.BackupServices.Models;
3+
using System;
24
using System.Collections.Generic;
35
using System.Linq;
6+
using System.Management.Automation;
7+
using System.Runtime.Serialization;
48
using System.Text;
59
using System.Threading.Tasks;
610

711
namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets.DataSource
812
{
9-
class Disable_AzureBackupProtection
13+
// ToDo:
14+
// Correct the Commandlet
15+
// Correct the OperationResponse
16+
// Get Tracking API from Piyush and Get JobResponse
17+
// Get JobResponse Object from Aditya
18+
19+
/// <summary>
20+
/// Enable Azure Backup protection
21+
/// </summary>
22+
[Cmdlet(VerbsLifecycle.Disable, "AzureBackupProtection"), OutputType(typeof(OperationResponse))]
23+
public class DisableAzureBackupProtection : AzureBackupDSCmdletBase
1024
{
25+
[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)]
26+
[ValidateSet("Invalid", "RetainBackupData", "DeleteBackupData")]
27+
public string RemoveProtectionOption { get; set; }
28+
public override void ExecuteCmdlet()
29+
{
30+
base.ExecuteCmdlet();
31+
32+
ExecutionBlock(() =>
33+
{
34+
WriteVerbose("Making client call");
35+
RemoveProtectionRequestInput input = new RemoveProtectionRequestInput();
36+
input.RemoveProtectionOption = this.RemoveProtectionOption == null ? "RetainBackupData" : this.RemoveProtectionOption;
37+
WriteVerbose("RemoveProtectionOption = " + input.RemoveProtectionOption);
38+
var disbaleAzureBackupProtection = AzureBackupClient.DataSource.DisableProtectionAsync(GetCustomRequestHeaders(), AzureBackupItem.ContainerUniqueName, AzureBackupItem.Type, AzureBackupItem.DataSourceId, input, CmdletCancellationToken).Result;
39+
40+
WriteVerbose("Received policy response");
41+
WriteVerbose("Converting response");
42+
WriteAzureBackupProtectionPolicy(disbaleAzureBackupProtection);
43+
});
44+
}
45+
46+
public void WriteAzureBackupProtectionPolicy(OperationResponse sourceOperationResponse)
47+
{
48+
// this needs to be uncommented once we have proper constructor
49+
//this.WriteObject(new AzureBackupRecoveryPoint(ResourceGroupName, ResourceName, sourceOperationResponse));
50+
}
51+
52+
public void WriteAzureBackupProtectionPolicy(IEnumerable<OperationResponse> sourceOperationResponseList)
53+
{
54+
List<OperationResponse> targetList = new List<OperationResponse>();
55+
56+
foreach (var sourceOperationResponse in sourceOperationResponseList)
57+
{
58+
// this needs to be uncommented once we have proper constructor
59+
targetList.Add(sourceOperationResponse);
60+
}
61+
62+
this.WriteObject(targetList, true);
63+
}
64+
public enum removeProtectionOption
65+
{
66+
[EnumMember]
67+
Invalid = 0,
68+
69+
[EnumMember]
70+
RetainBackupData,
71+
72+
[EnumMember]
73+
DeleteBackupData,
74+
}
1175
}
1276
}
Lines changed: 118 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,125 @@
1-
using System;
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.Management.Automation;
217
using System.Collections.Generic;
18+
using System.Xml;
319
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
20+
using Microsoft.Azure.Management.BackupServices.Models;
21+
using MBS = Microsoft.Azure.Management.BackupServices;
22+
using System.Runtime.Serialization;
23+
using Microsoft.Azure.Management.BackupServices;
624

7-
namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets.DataSource
25+
namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
826
{
9-
class Enable_AzureBackupProtection
27+
// ToDo:
28+
// Correct the Commandlet
29+
// Correct the OperationResponse
30+
// Get Tracking API from Piyush and Get JobResponse
31+
// Get JobResponse Object from Aditya
32+
33+
/// <summary>
34+
/// Enable Azure Backup protection
35+
/// </summary>
36+
[Cmdlet(VerbsLifecycle.Enable, "AzureBackupProtection"), OutputType(typeof(OperationResponse))]
37+
public class EnableAzureBackupProtection : AzureBackupItemCmdletBase
1038
{
39+
[Parameter(Position = 1, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)]
40+
[ValidateNotNullOrEmpty]
41+
public AzureBackupProtectionPolicy Policy { get; set; }
42+
public override void ExecuteCmdlet()
43+
{
44+
base.ExecuteCmdlet();
45+
46+
ExecutionBlock(() =>
47+
{
48+
WriteVerbose("Making client call");
49+
SetProtectionRequestInput input = new SetProtectionRequestInput();
50+
input.PolicyId = Policy.InstanceId;
51+
if (AzureBackupItem.GetType() == ((AzureBackupItem)AzureBackupItem).GetType())
52+
{
53+
input.ProtectableObjectType = (AzureBackupItem as AzureBackupItem).Type;
54+
input.ProtectableObjects.Add((AzureBackupItem as AzureBackupItem).Name);
55+
}
56+
else if (AzureBackupItem.GetType() == ((AzureBackupContainer)AzureBackupItem).GetType())
57+
{
58+
if((AzureBackupItem as AzureBackupContainer).ContainerType == ContainerType.IaasVMContainer.ToString())
59+
{
60+
input.ProtectableObjectType = DataSourceType.VM.ToString();
61+
input.ProtectableObjects.Add((AzureBackupItem as AzureBackupContainer).ContainerUniqueName);
62+
}
63+
}
64+
else
65+
{
66+
67+
}
68+
69+
var enableAzureBackupProtection = AzureBackupClient.DataSource.EnableProtectionAsync(GetCustomRequestHeaders(), input, CmdletCancellationToken).Result;
70+
71+
WriteVerbose("Received policy response");
72+
WriteVerbose("Converting response");
73+
WriteAzureBackupProtectionPolicy(enableAzureBackupProtection);
74+
});
75+
}
76+
77+
public void WriteAzureBackupProtectionPolicy(OperationResponse sourceOperationResponse)
78+
{
79+
// this needs to be uncommented once we have proper constructor
80+
//this.WriteObject(new AzureBackupRecoveryPoint(ResourceGroupName, ResourceName, sourceOperationResponse));
81+
}
82+
83+
public void WriteAzureBackupProtectionPolicy(IEnumerable<OperationResponse> sourceOperationResponseList)
84+
{
85+
List<OperationResponse> targetList = new List<OperationResponse>();
86+
87+
foreach (var sourceOperationResponse in sourceOperationResponseList)
88+
{
89+
// this needs to be uncommented once we have proper constructor
90+
targetList.Add(sourceOperationResponse);
91+
}
92+
93+
this.WriteObject(targetList, true);
94+
}
95+
public enum ContainerType
96+
{
97+
[EnumMember]
98+
Invalid = 0,
99+
100+
[EnumMember]
101+
Unknown,
102+
103+
// used by fabric adapter to populate discovered VMs
104+
[EnumMember]
105+
IaasVMContainer,
106+
107+
// used by fabric adapter to populate discovered services
108+
// VMs are child containers of services they belong to
109+
[EnumMember]
110+
IaasVMServiceContainer
111+
}
112+
public enum DataSourceType
113+
{
114+
[EnumMember]
115+
Invalid = 0,
116+
117+
[EnumMember]
118+
VM
119+
120+
// TODO: fix GetJobTypes() in PortalMetadataInternalEP.cs
121+
// [EnumMember]
122+
// AzureStorageAccount
123+
}
11124
}
12125
}

0 commit comments

Comments
 (0)