Skip to content

Commit 5785c7c

Browse files
committed
Merge pull request #25 from MabOneSdk/pikumar3
Pikumar3
2 parents 320ec1b + fbaa8c7 commit 5785c7c

File tree

8 files changed

+303
-50
lines changed

8 files changed

+303
-50
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,12 @@ internal static class AzureBackupCmdletHelpMessage
3232
public const string AzureBackUpItem = "Azure BackUp Item.";
3333
public const string RecoveryPointId = "Recovery Point Id.";
3434
public const string StorageType = "The vault back-end storage type.";
35+
public const string Type = "Type of Azure Backup Item.";
36+
public const string Status = "Status of Azure Backup Item";
37+
public const string AzureBackupContainer = "Azure Backup Container for Azure Backup Item.";
38+
public const string AzureBackupItem = "Azure Backup Item for enabling protection";
39+
public const string RemoveProtectionOption = "Remove Protection Option";
40+
public const string Reason = "Reson for removing protection";
41+
public const string Comments = "Comments for for removing protection";
3542
}
3643
}

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.AzureBackupItem, ValueFromPipelineByPropertyName = true)]
34+
[ValidateNotNullOrEmpty]
35+
public AzureBackupContainerContextObject Item { get; set; }
36+
37+
public override void ExecuteCmdlet()
38+
{
39+
base.ExecuteCmdlet();
40+
WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}, Location: {2}", Item.ResourceGroupName, Item.ResourceName, Item.Location));
41+
InitializeAzureBackupCmdlet(Item.ResourceGroupName, Item.ResourceName, Item.Location);
42+
}
43+
}
44+
}
45+
Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,88 @@
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(Position = 1, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.RemoveProtectionOption)]
26+
[ValidateSet("Invalid", "RetainBackupData", "DeleteBackupData")]
27+
public string RemoveProtectionOption { get; set; }
28+
29+
[Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.Reason)]
30+
public string Reason { get; set; }
31+
32+
[Parameter(Position = 3, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.Comments)]
33+
public string Comments { get; set; }
34+
35+
public override void ExecuteCmdlet()
36+
{
37+
base.ExecuteCmdlet();
38+
39+
ExecutionBlock(() =>
40+
{
41+
WriteVerbose("Making client call");
42+
RemoveProtectionRequestInput input = new RemoveProtectionRequestInput()
43+
{
44+
RemoveProtectionOption = this.RemoveProtectionOption == null ? "RetainBackupData" : this.RemoveProtectionOption,
45+
Reason = this.Reason,
46+
Comments = this.Comments,
47+
};
48+
49+
WriteVerbose("RemoveProtectionOption = " + input.RemoveProtectionOption);
50+
var disbaleAzureBackupProtection = AzureBackupClient.DataSource.DisableProtectionAsync(GetCustomRequestHeaders(), item.ContainerUniqueName, item.Type, item.DataSourceId, input, CmdletCancellationToken).Result;
51+
52+
WriteVerbose("Received policy response");
53+
WriteVerbose("Converting response");
54+
WriteAzureBackupProtectionPolicy(disbaleAzureBackupProtection);
55+
});
56+
}
57+
58+
public void WriteAzureBackupProtectionPolicy(OperationResponse sourceOperationResponse)
59+
{
60+
// this needs to be uncommented once we have proper constructor
61+
//this.WriteObject(new AzureBackupRecoveryPoint(ResourceGroupName, ResourceName, sourceOperationResponse));
62+
}
63+
64+
public void WriteAzureBackupProtectionPolicy(IEnumerable<OperationResponse> sourceOperationResponseList)
65+
{
66+
List<OperationResponse> targetList = new List<OperationResponse>();
67+
68+
foreach (var sourceOperationResponse in sourceOperationResponseList)
69+
{
70+
// this needs to be uncommented once we have proper constructor
71+
targetList.Add(sourceOperationResponse);
72+
}
73+
74+
this.WriteObject(targetList, true);
75+
}
76+
public enum removeProtectionOption
77+
{
78+
[EnumMember]
79+
Invalid = 0,
80+
81+
[EnumMember]
82+
RetainBackupData,
83+
84+
[EnumMember]
85+
DeleteBackupData,
86+
}
1187
}
1288
}
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 (Item.GetType() == ((AzureBackupItem)Item).GetType())
52+
{
53+
input.ProtectableObjectType = (Item as AzureBackupItem).Type;
54+
input.ProtectableObjects.Add((Item as AzureBackupItem).Name);
55+
}
56+
else if (Item.GetType() == ((AzureBackupContainer)Item).GetType())
57+
{
58+
if((Item as AzureBackupContainer).ContainerType == ContainerType.IaasVMContainer.ToString())
59+
{
60+
input.ProtectableObjectType = DataSourceType.VM.ToString();
61+
input.ProtectableObjects.Add((Item as AzureBackupContainer).ContainerUniqueName);
62+
}
63+
}
64+
else
65+
{
66+
throw new Exception("Uknown item type");
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)