-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from MabOneSdk/panbha
Local Changes for Commandlets
- Loading branch information
Showing
7 changed files
with
316 additions
and
5 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupDSCmdletBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
|
80 changes: 80 additions & 0 deletions
80
src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/BackUp/TriggerBackUp.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...ger/AzureBackup/Commands.AzureBackup/Cmdlets/RecoveryPoint/GetAzureBackupRecoveryPoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/AzureBackupRecoveryPoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |