Skip to content
Closed
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
@@ -0,0 +1,46 @@
// ----------------------------------------------------------------------------------
//
// 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 AzureBackupContainerCmdletBase : AzureBackupCmdletBase
{
// ToDO:
// Correct Help message and other attributes related to paameters
[Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ResourceGroupName, ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
public AzureBackupContainer AzureBackupContainer { get; set; }

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

WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}", AzureBackupContainer.ResourceGroupName, AzureBackupContainer.ResourceName));

InitializeAzureBackupCmdlet(AzureBackupContainer.ResourceGroupName, AzureBackupContainer.ResourceName);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets.DataSource
{
class Disable_AzureBackupProtection
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets.DataSource
{
class Enable_AzureBackupProtection
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// ----------------------------------------------------------------------------------
//
// 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 Microsoft.Azure.Management.BackupServices.Models;

namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
{
/// <summary>
/// Get list of containers
/// </summary>
[Cmdlet(VerbsCommon.Get, "AzureBackupItem"), OutputType(typeof(AzureBackupItem), typeof(List<AzureBackupItem>))]
public class GetAzureBackupItem : AzureBackupContainerCmdletBase
{
[Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)]
[ValidateNotNullOrEmpty]
public string Id { get; set; }

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

ExecutionBlock(() =>
{
WriteVerbose("Making client call");

var azureBackupDatasourceListResponse = AzureBackupClient.DataSource.ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result;
var azureBackupPOListResponse = AzureBackupClient.ProtectableObject. ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result;

WriteVerbose("Received policy response");
WriteVerbose("Received policy response2");
IEnumerable<DataSourceInfo> azureBackupDatasourceObjects = null;
IEnumerable<ProtectableObjectInfo> azureBackupPOObjects = null;

if (Id != null)
{
azureBackupDatasourceObjects = azureBackupDatasourceListResponse.DataSources.Objects.Where(x => x.InstanceId.Equals(Id, System.StringComparison.InvariantCultureIgnoreCase));
azureBackupPOObjects = azureBackupPOListResponse.ProtectableObject.Objects.Where(x => x.InstanceId.Equals(Id, System.StringComparison.InvariantCultureIgnoreCase));
}
else
{
azureBackupDatasourceObjects = azureBackupDatasourceListResponse.DataSources.Objects;
azureBackupPOObjects = azureBackupPOListResponse.ProtectableObject.Objects;
}

WriteVerbose("Converting response");
WriteAzureBackupProtectionPolicy(azureBackupDatasourceObjects, azureBackupPOObjects, AzureBackupContainer);
});
}

public void WriteAzureBackupProtectionPolicy(DataSourceInfo sourceItem, AzureBackupContainer azureBackupItem)
{
this.WriteObject(new AzureBackupItem(sourceItem, azureBackupItem));
}

public void WriteAzureBackupProtectionPolicy(IEnumerable<DataSourceInfo> sourceDataSourceList,IEnumerable<ProtectableObjectInfo> sourcePOList, AzureBackupContainer azureBackupContainer)
{
List<AzureBackupItem> targetList = new List<AzureBackupItem>();

foreach (var item in sourceDataSourceList)
{
targetList.Add(new AzureBackupItem(item, azureBackupContainer));
}

foreach (var item in sourcePOList)
{
targetList.Add(new AzureBackupItem(item, azureBackupContainer));
}

this.WriteObject(targetList, true);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Management.BackupServices.Models;
namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
{
public class AzureBackupVaultContextObject
Expand Down Expand Up @@ -53,6 +54,27 @@ public class AzureBackupContainerContextObject : AzureBackupVaultContextObject
/// Id of the Azure Backup Container
/// </summary>
public string ContainerId { get; set; }

public AzureBackupContainerContextObject()
: base()
{
}

public AzureBackupContainerContextObject(AzureBackupContainerContextObject azureBackupContainer)
: base(azureBackupContainer.ResourceGroupName, azureBackupContainer.ResourceName)
{
ContainerType = azureBackupContainer.ContainerType;
ContainerName = azureBackupContainer.ContainerName;
ContainerId = azureBackupContainer.ContainerId;
}

public AzureBackupContainerContextObject(AzureBackupContainer azureBackupContainer)
: base(azureBackupContainer.ResourceGroupName, azureBackupContainer.ResourceName)
{
ContainerType = azureBackupContainer.ContainerType;
ContainerName = azureBackupContainer.ContainerName;
ContainerId = azureBackupContainer.ContainerId;
}
}

public class AzureBackupItemContextObject : AzureBackupContainerContextObject
Expand All @@ -66,5 +88,30 @@ public class AzureBackupItemContextObject : AzureBackupContainerContextObject
/// DataSourceId of Azure Backup Item
/// </summary>
public string DataSourceType { get; set; }

public AzureBackupItemContextObject()
: base()
{
}

public AzureBackupItemContextObject(AzureBackupItemContextObject azureBackupItemContextObject)
: base(azureBackupItemContextObject)
{
DataSourceId = azureBackupItemContextObject.DataSourceId;
DataSourceType = azureBackupItemContextObject.DataSourceType;
}

public AzureBackupItemContextObject(DataSourceInfo item, AzureBackupContainer azureBackupContainer)
: base(azureBackupContainer)
{
DataSourceId = item.InstanceId;
DataSourceType = item.Type;
}

public AzureBackupItemContextObject(ProtectableObjectInfo item, AzureBackupContainer azureBackupContainer)
: base(azureBackupContainer)
{
DataSourceType = item.Type;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
/// <summary>
/// Represents Azure Backup Container
/// </summary>
public class AzureBackupContainer : AzureBackupVaultContextObject
public class AzureBackupContainer : AzureBackupContainerContextObject
{
/// <summary>
/// Type of the Azure Backup container
/// </summary>
public string ContainerType { get; set; }

/// <summary>
/// Friendly name for the Azure Backup container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.Management.BackupServices.Models;

namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
{
Expand Down Expand Up @@ -79,5 +80,33 @@ public class AzureBackupItem : AzureBackupItemContextObject
/// Last Backup Job Id for the Azure Backup Item
/// </summary>
public string LastBackupJobId { get; set; }

public AzureBackupItem()
: base()
{
}

public AzureBackupItem(DataSourceInfo datasource, AzureBackupContainer azureBackupContainer)
: base(datasource,azureBackupContainer)
{
Status = datasource.Status;
ProtectionStatus = datasource.ProtectionStatus;
ProtectableObjectName = datasource.ProtectableObjectName;
ProtectionPolicyName = datasource.ProtectionPolicyName;
ProtectionPolicyId = datasource.ProtectionPolicyId;
PolicyInconsistent = datasource.PolicyInconsistent;
RecoveryPointsCount = datasource.RecoveryPointsCount;
LastRecoveryPoint = datasource.LastRecoveryPoint;
LastBackupTime = datasource.LastBackupTime;
LastBackupStatus = datasource.LastBackupStatus;
LastBackupJobId = datasource.LastBackupJobId;
}

public AzureBackupItem(ProtectableObjectInfo pPOItem, AzureBackupContainer azureBackupContainer)
: base(pPOItem, azureBackupContainer)
{
ProtectionStatus = pPOItem.ProtectionStatus;
ProtectableObjectName = pPOItem.Name;
}
}
}