forked from Azure/azure-powershell
-
Notifications
You must be signed in to change notification settings - Fork 2
Local Changes for Commandlets #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupDSCmdletBase.cs
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Piysuh I made changes in ProtectionPloicy info also but seems that is missing in CR.