Skip to content

Commit

Permalink
Merge pull request #8 from MabOneSdk/panbha
Browse files Browse the repository at this point in the history
Local Changes for Commandlets
  • Loading branch information
panbha committed Jun 2, 2015
2 parents 6966a2d + b22b9b4 commit bab1c8e
Show file tree
Hide file tree
Showing 7 changed files with 316 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// ----------------------------------------------------------------------------------
//
// 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 AzureBackupDSCmdletBase : AzureBackupCmdletBase
{
// ToDO:
// Correct Help message and other attributes related to paameters
[Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ResourceGroupName, ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
public AzureBackupItem AzureBackupItem { get; set; }

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

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

InitializeAzureBackupCmdlet(AzureBackupItem.ResourceGroupName, AzureBackupItem.ResourceName);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// ----------------------------------------------------------------------------------
//
// 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;
using MBS = Microsoft.Azure.Management.BackupServices;

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

/// <summary>
/// Get list of containers
/// </summary>
[Cmdlet(VerbsCommon.New, "AzureBackupItem"), OutputType(typeof(MBS.OperationResponse))]
public class TriggerAzureBackup : AzureBackupDSCmdletBase
{
public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();

ExecutionBlock(() =>
{
WriteVerbose("Making client call");
MBS.OperationResponse triggerBackUpInfo =
AzureBackupClient.BackUp.TriggerBackUpAsync(GetCustomRequestHeaders(),
AzureBackupItem.ContainerName,
AzureBackupItem.DataSourceType,
AzureBackupItem.DataSourceId,
CmdletCancellationToken).Result;
WriteVerbose("Received policy response");
WriteVerbose("Received policy response2");
WriteVerbose("Converting response");
WriteAzureBackupProtectionPolicy(triggerBackUpInfo);
});
}

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

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

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

this.WriteObject(targetList, true);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public override void ExecuteCmdlet()
IEnumerable<ProtectionPolicyInfo> policyObjects = null;
if (Name != null)
{
policyObjects = policyListResponse.Objects.Where(x => x.Name.Equals(Name, System.StringComparison.InvariantCultureIgnoreCase));
policyObjects = policyListResponse.ProtectionPolicies.Objects.Where(x => x.Name.Equals(Name, System.StringComparison.InvariantCultureIgnoreCase));
}
else
{
policyObjects = policyListResponse.Objects;
policyObjects = policyListResponse.ProtectionPolicies.Objects;
}
WriteVerbose("Converting response");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// ----------------------------------------------------------------------------------
//
// 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, "AzureBackupRecoveryPoint"), OutputType(typeof(AzureBackupRecoveryPoint), typeof(List<AzureBackupRecoveryPoint>))]
public class GetAzureBackupRecoveryPoint : AzureBackupDSCmdletBase
{
[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");
RecoveryPointListResponse recoveryPointListResponse =
AzureBackupClient.RecoveryPoint.ListAsync(GetCustomRequestHeaders(),
AzureBackupItem.ContainerName,
AzureBackupItem.DataSourceType,
AzureBackupItem.DataSourceId,
CmdletCancellationToken).Result;
WriteVerbose("Received policy response");
WriteVerbose("Received policy response2");
IEnumerable<RecoveryPointInfo> recoveryPointObjects = null;
if (Id != null)
{
recoveryPointObjects = recoveryPointListResponse.RecoveryPoints.Objects.Where(x => x.InstanceId.Equals(Id, System.StringComparison.InvariantCultureIgnoreCase));
}
else
{
recoveryPointObjects = recoveryPointListResponse.RecoveryPoints.Objects;
}
WriteVerbose("Converting response");
WriteAzureBackupProtectionPolicy(recoveryPointObjects, AzureBackupItem);
});
}

public void WriteAzureBackupProtectionPolicy(RecoveryPointInfo sourceRecoverPoint, AzureBackupItem azureBackupItem)
{
this.WriteObject(new AzureBackupRecoveryPoint(sourceRecoverPoint, azureBackupItem));
}

public void WriteAzureBackupProtectionPolicy(IEnumerable<RecoveryPointInfo> sourceRecoverPointList, AzureBackupItem azureBackupItem)
{
List<AzureBackupRecoveryPoint> targetList = new List<AzureBackupRecoveryPoint>();

foreach (var sourceRecoverPoint in sourceRecoverPointList)
{
targetList.Add(new AzureBackupRecoveryPoint(sourceRecoverPoint, azureBackupItem));
}

this.WriteObject(targetList, true);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@
<Reference Include="Microsoft.WindowsAzure.Management">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Management.BackupServicesManagment, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Microsoft.WindowsAzure.Management.BackupServicesManagment.dll</HintPath>
<Reference Include="Microsoft.WindowsAzure.Management.BackupServicesManagment">
<HintPath>..\..\..\..\..\azure-sdk-for-net\src\ResourceManagement\AzureBackup\BackupServicesManagment\bin\Net40-Debug\Microsoft.WindowsAzure.Management.BackupServicesManagment.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Management.Scheduler">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Scheduler.6.0.0\lib\net40\Microsoft.WindowsAzure.Management.Scheduler.dll</HintPath>
Expand Down Expand Up @@ -111,12 +110,18 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AzureBackupDSCmdletBase.cs" />
<Compile Include="AzureBackupVaultCmdletBase.cs" />
<Compile Include="AzureBackupCmdletBase.cs" />
<Compile Include="AzureBackupCmdletHelpMessage.cs" />
<Compile Include="Cmdlets\BackUp\TriggerBackUp.cs" />
<Compile Include="Cmdlets\Jobs\GetAzureBackupJob.cs" />
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureBackupProtectionPolicy.cs" />
<Compile Include="Cmdlets\RecoveryPoint\GetAzureBackupRecoveryPoint.cs" />
<Compile Include="Models\AzureBackupBaseObjects.cs" />
<Compile Include="Models\AzureBackupContainer.cs" />
<Compile Include="Models\AzureBackupItem.cs" />
<Compile Include="Models\AzureBackupRecoveryPoint.cs" />
<Compile Include="Models\ProtectionPolicy.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ public class AzureBackupContainerContextObject : AzureBackupVaultContextObject
/// Id of the Azure Backup Container
/// </summary>
public string ContainerId { get; set; }

public AzureBackupContainerContextObject()
: base()
{
}

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

public class AzureBackupItemContextObject : AzureBackupContainerContextObject
Expand All @@ -66,5 +79,17 @@ 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;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// ----------------------------------------------------------------------------------
//
// 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 Microsoft.Azure.Management.BackupServices.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
{
public class AzureBackupRecoveryPointContextObject : AzureBackupItemContextObject
{
/// <summary>
/// RecoveryPointId of Azure Backup Item
/// </summary>
public string RecoveryPointId { get; set; }

public AzureBackupRecoveryPointContextObject()
: base()
{
}

public AzureBackupRecoveryPointContextObject(RecoveryPointInfo recoveryPointInfo, AzureBackupItem azureBackupItem)
: base(azureBackupItem)
{
RecoveryPointId = recoveryPointInfo.InstanceId;
}
}

/// <summary>
/// Represents Azure Backup Container
/// </summary>
public class AzureBackupRecoveryPoint : AzureBackupRecoveryPointContextObject
{
/// <summary>
/// Last Recovery Point for the Azure Backup Item
/// </summary>
public DateTime RecoveryPointTime { get; set; }

/// <summary>
/// DataSourceId of Azure Backup Item
/// </summary>
public string RecoveryPointType { get; set; }

public AzureBackupRecoveryPoint()
: base()
{
}

public AzureBackupRecoveryPoint(RecoveryPointInfo recoveryPointInfo, AzureBackupItem azureBackupItem)
: base(recoveryPointInfo, azureBackupItem)
{
RecoveryPointTime = recoveryPointInfo.RecoveryPointTime;
RecoveryPointType = recoveryPointInfo.RecoveryPointType;
}
}
}

0 comments on commit bab1c8e

Please sign in to comment.