Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,12 @@ internal static class AzureBackupCmdletHelpMessage
public const string AzureBackUpItem = "Azure BackUp Item.";
public const string RecoveryPointId = "Recovery Point Id.";
public const string StorageType = "The vault back-end storage type.";
public const string Type = "Type of Azure Backup Item.";
public const string Status = "Status of Azure Backup Item";
public const string AzureBackupContainer = "Azure Backup Container for Azure Backup Item.";
public const string AzureBackupItem = "Azure Backup Item for enabling protection";
public const string RemoveProtectionOption = "Remove Protection Option";
public const string Reason = "Reson for removing protection";
public const string Comments = "Comments for for removing protection";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
{
public abstract class AzureBackupContainerCmdletBase : AzureBackupCmdletBase
{
// ToDO:
// Correct Help message and other attributes related to paameters
[Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ResourceGroupName, ValueFromPipelineByPropertyName = true)]
[Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.AzureBackupContainer, ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
public AzureBackupContainer AzureBackupContainer { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Management.Automation;
using System.Collections.Generic;
using System.Xml;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.Azure.Common.Authentication;
using Microsoft.Azure.Common.Authentication.Models;
using System.Threading;
using Hyak.Common;
using Microsoft.Azure.Commands.AzureBackup.Properties;
using System.Net;

namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
{
public abstract class AzureBackupItemCmdletBase : AzureBackupCmdletBase
{
// ToDO:
// Correct Help message and other attributes related to paameters
[Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.AzureBackupItem, ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
public AzureBackupContainerContextObject Item { get; set; }

public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();
WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}, Location: {2}", Item.ResourceGroupName, Item.ResourceName, Item.Location));
InitializeAzureBackupCmdlet(Item.ResourceGroupName, Item.ResourceName, Item.Location);
}
}
}

Original file line number Diff line number Diff line change
@@ -1,12 +1,88 @@
using System;
using Microsoft.Azure.Management.BackupServices;
using Microsoft.Azure.Management.BackupServices.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets.DataSource
{
class Disable_AzureBackupProtection
// ToDo:
// Correct the Commandlet
// Correct the OperationResponse
// Get Tracking API from Piyush and Get JobResponse
// Get JobResponse Object from Aditya

/// <summary>
/// Enable Azure Backup protection
/// </summary>
[Cmdlet(VerbsLifecycle.Disable, "AzureBackupProtection"), OutputType(typeof(OperationResponse))]
public class DisableAzureBackupProtection : AzureBackupDSCmdletBase
{
[Parameter(Position = 1, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.RemoveProtectionOption)]
[ValidateSet("Invalid", "RetainBackupData", "DeleteBackupData")]
public string RemoveProtectionOption { get; set; }

[Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.Reason)]
public string Reason { get; set; }

[Parameter(Position = 3, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.Comments)]
public string Comments { get; set; }

public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();

ExecutionBlock(() =>
{
WriteVerbose("Making client call");
RemoveProtectionRequestInput input = new RemoveProtectionRequestInput()
{
RemoveProtectionOption = this.RemoveProtectionOption == null ? "RetainBackupData" : this.RemoveProtectionOption,
Reason = this.Reason,
Comments = this.Comments,
};

WriteVerbose("RemoveProtectionOption = " + input.RemoveProtectionOption);
var disbaleAzureBackupProtection = AzureBackupClient.DataSource.DisableProtectionAsync(GetCustomRequestHeaders(), item.ContainerUniqueName, item.Type, item.DataSourceId, input, CmdletCancellationToken).Result;

WriteVerbose("Received policy response");
WriteVerbose("Converting response");
WriteAzureBackupProtectionPolicy(disbaleAzureBackupProtection);
});
}

public void WriteAzureBackupProtectionPolicy(OperationResponse sourceOperationResponse)
{
// this needs to be uncommented once we have proper constructor
//this.WriteObject(new AzureBackupRecoveryPoint(ResourceGroupName, ResourceName, sourceOperationResponse));
}

public void WriteAzureBackupProtectionPolicy(IEnumerable<OperationResponse> sourceOperationResponseList)
{
List<OperationResponse> targetList = new List<OperationResponse>();

foreach (var sourceOperationResponse in sourceOperationResponseList)
{
// this needs to be uncommented once we have proper constructor
targetList.Add(sourceOperationResponse);
}

this.WriteObject(targetList, true);
}
public enum removeProtectionOption
{
[EnumMember]
Invalid = 0,

[EnumMember]
RetainBackupData,

[EnumMember]
DeleteBackupData,
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,125 @@
using System;
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Management.Automation;
using System.Collections.Generic;
using System.Xml;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.Management.BackupServices.Models;
using MBS = Microsoft.Azure.Management.BackupServices;
using System.Runtime.Serialization;
using Microsoft.Azure.Management.BackupServices;

namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets.DataSource
namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
{
class Enable_AzureBackupProtection
// ToDo:
// Correct the Commandlet
// Correct the OperationResponse
// Get Tracking API from Piyush and Get JobResponse
// Get JobResponse Object from Aditya

/// <summary>
/// Enable Azure Backup protection
/// </summary>
[Cmdlet(VerbsLifecycle.Enable, "AzureBackupProtection"), OutputType(typeof(OperationResponse))]
public class EnableAzureBackupProtection : AzureBackupItemCmdletBase
{
[Parameter(Position = 1, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)]
[ValidateNotNullOrEmpty]
public AzureBackupProtectionPolicy Policy { get; set; }
public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();

ExecutionBlock(() =>
{
WriteVerbose("Making client call");
SetProtectionRequestInput input = new SetProtectionRequestInput();
input.PolicyId = Policy.InstanceId;
if (Item.GetType() == ((AzureBackupItem)Item).GetType())
{
input.ProtectableObjectType = (Item as AzureBackupItem).Type;
input.ProtectableObjects.Add((Item as AzureBackupItem).Name);
}
else if (Item.GetType() == ((AzureBackupContainer)Item).GetType())
{
if((Item as AzureBackupContainer).ContainerType == ContainerType.IaasVMContainer.ToString())
{
input.ProtectableObjectType = DataSourceType.VM.ToString();
input.ProtectableObjects.Add((Item as AzureBackupContainer).ContainerUniqueName);
}
}
else
{
throw new Exception("Uknown item type");
}

var enableAzureBackupProtection = AzureBackupClient.DataSource.EnableProtectionAsync(GetCustomRequestHeaders(), input, CmdletCancellationToken).Result;

WriteVerbose("Received policy response");
WriteVerbose("Converting response");
WriteAzureBackupProtectionPolicy(enableAzureBackupProtection);
});
}

public void WriteAzureBackupProtectionPolicy(OperationResponse sourceOperationResponse)
{
// this needs to be uncommented once we have proper constructor
//this.WriteObject(new AzureBackupRecoveryPoint(ResourceGroupName, ResourceName, sourceOperationResponse));
}

public void WriteAzureBackupProtectionPolicy(IEnumerable<OperationResponse> sourceOperationResponseList)
{
List<OperationResponse> targetList = new List<OperationResponse>();

foreach (var sourceOperationResponse in sourceOperationResponseList)
{
// this needs to be uncommented once we have proper constructor
targetList.Add(sourceOperationResponse);
}

this.WriteObject(targetList, true);
}
public enum ContainerType
{
[EnumMember]
Invalid = 0,

[EnumMember]
Unknown,

// used by fabric adapter to populate discovered VMs
[EnumMember]
IaasVMContainer,

// used by fabric adapter to populate discovered services
// VMs are child containers of services they belong to
[EnumMember]
IaasVMServiceContainer
}
public enum DataSourceType
{
[EnumMember]
Invalid = 0,

[EnumMember]
VM

// TODO: fix GetJobTypes() in PortalMetadataInternalEP.cs
// [EnumMember]
// AzureStorageAccount
}
}
}
Loading