Skip to content
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

Csm panbha1 #67

Merged
merged 2 commits into from
Jul 15, 2015
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
@@ -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;
using Microsoft.Azure.Commands.AzureBackup.Models;
using Microsoft.Azure.Commands.AzureBackup.Cmdlets;

namespace Microsoft.Azure.Commands.AzureBackup
{
public abstract class AzureBackupRestoreBase : AzureBackupCmdletBase
{
// ToDO:
// Correct Help message and other attributes related to paameters
[Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.AzureBackUpRecoveryPoint, ValueFromPipeline = true)]
[ValidateNotNullOrEmpty]
public AzureBackupRecoveryPoint RecoveryPoint { get; set; }

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

WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}", RecoveryPoint.ResourceGroupName, RecoveryPoint.ResourceName));
InitializeAzureBackupCmdlet(RecoveryPoint.ResourceGroupName, RecoveryPoint.ResourceName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ public Guid EnableProtection(SetProtectionRequestInput request)
/// <returns></returns>
public Guid TriggerBackup(string containerName, string dsType, string dsId)
{
return Guid.NewGuid();
var response = AzureBackupClient.BackUp.TriggerBackUpAsync(GetCustomRequestHeaders(), containerName, dsType, dsId, CmdletCancellationToken).Result;
return response.OperationId;
//return response.OperationId;
}

/// <summary>
Expand All @@ -100,8 +101,9 @@ public Guid TriggerBackup(string containerName, string dsType, string dsId)
/// <returns></returns>
public IEnumerable<RecoveryPointInfo> ListRecoveryPoints(string containerName, string dsType, string dsId)
{
var response = AzureBackupClient.RecoveryPoint.ListAsync(GetCustomRequestHeaders(), containerName, dsType, dsId, CmdletCancellationToken).Result;
return (response != null) ? response.RecoveryPoints.Objects : null;
return null;
//var response = AzureBackupClient.RecoveryPoint.ListAsync(GetCustomRequestHeaders(), containerName, dsType, dsId, CmdletCancellationToken).Result;
//return (response != null) ? response.RecoveryPoints.Objects : null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ internal static class AzureBackupCmdletHelpMessage
public const string ProtectionStatus = "Protection Status of the azure backup item.";
public const string AzureBackUpItem = "Azure BackUp Item.";
public const string RecoveryPointId = "Recovery Point Id.";
public const string StorageAccountName = "Storage Account Name.";
public const string AzureBackUpRecoveryPoint = "Recovery Point.";
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.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public override void ExecuteCmdlet()

WriteDebug("Triggered backup. Converting response");

var operationStatus = TrackOperation(operationId);
WriteObject(GetCreatedJobs(new Models.AzurePSBackupVault(Item.ResourceGroupName, Item.ResourceName, Item.Location), operationStatus.Jobs).FirstOrDefault());
//var operationStatus = TrackOperation(operationId);
//WriteObject(GetCreatedJobs(new Models.AzurePSBackupVault(Item.ResourceGroupName, Item.ResourceName, Item.Location), operationStatus.Jobs).FirstOrDefault());
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,33 @@ public override void ExecuteCmdlet()

var recoveryPointListResponse = AzureBackupClient.ListRecoveryPoints(Item.ContainerUniqueName, Item.Type, Item.DataSourceId);

WriteDebug("Received recovery point response");

IEnumerable<RecoveryPointInfo> recoveryPointObjects = null;
if (Id != null)
if (recoveryPointListResponse != null)
{
RecoveryPointInfo recoveryPointObject = null;
recoveryPointObjects = recoveryPointListResponse.Where(x => x.InstanceId.Equals(Id, System.StringComparison.InvariantCultureIgnoreCase));
if (recoveryPointObjects != null && recoveryPointObjects.Any<RecoveryPointInfo>())
WriteDebug("Received recovery point response");

IEnumerable<RecoveryPointInfo> recoveryPointObjects = null;
if (Id != null)
{
WriteDebug("Converting response");
recoveryPointObject = recoveryPointObjects.FirstOrDefault<RecoveryPointInfo>();
WriteAzureBackupRecoveryPoint(recoveryPointObject, Item);
RecoveryPointInfo recoveryPointObject = null;
recoveryPointObjects = recoveryPointListResponse.Where(x => x.InstanceId.Equals(Id, System.StringComparison.InvariantCultureIgnoreCase));
if (recoveryPointObjects != null && recoveryPointObjects.Any<RecoveryPointInfo>())
{
WriteDebug("Converting response");
recoveryPointObject = recoveryPointObjects.FirstOrDefault<RecoveryPointInfo>();
WriteAzureBackupRecoveryPoint(recoveryPointObject, Item);
}
else
{
WriteDebug(string.Format("{0}{1}", "No recovery point exist with Id := ", Id));
}
}
else
{
WriteDebug(string.Format("{0}{1}", "No recovery point exist with Id := ", Id));
WriteDebug("Converting response");
recoveryPointObjects = recoveryPointListResponse.OrderByDescending(x => x.RecoveryPointTime);
WriteAzureBackupRecoveryPoint(recoveryPointObjects, Item);
}
}
else
{
WriteDebug("Converting response");
recoveryPointObjects = recoveryPointListResponse.OrderByDescending(x => x.RecoveryPointTime);
WriteAzureBackupRecoveryPoint(recoveryPointObjects, Item);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// ----------------------------------------------------------------------------------
//
// 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
{
/// <summary>
/// Trigger Restore Job
/// </summary>
[Cmdlet(VerbsData.Restore, "AzureBackupItem"), OutputType(typeof(Guid))]
public class RestoreAzureBackup : AzureBackupRestoreBase
{
[Parameter(Position = 1, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.StorageAccountName)]
[ValidateNotNullOrEmpty]
public string StorageAccountName { get; set; }

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

ExecutionBlock(() =>
{
WriteVerbose("Making client call");
Guid jobId = Guid.NewGuid();
WriteDebug("Triggered Restore. Converting response");
/*
AzureIaaSVMRecoveryInputsCSMObject azureIaaSVMRecoveryInputsCSMObject = new AzureIaaSVMRecoveryInputsCSMObject()
{
CloudServiceName = string.Empty,
VmName = string.Empty,
CreateNewCloudService = false,
ContinueProtection = false,
InputStorageAccountName = StorageAccountName,
AffinityGroup = "",
Region = RecoveryPoint.Location,
};

JavaScriptSerializer serializer = new JavaScriptSerializer();
string azureIaaSVMRecoveryInputsCSMObjectString = serializer.Serialize(azureIaaSVMRecoveryInputsCSMObject);

CSMRestoreRequest csmRestoreRequest = new CSMRestoreRequest()
{
Properties = new CSMRestoreRequestProperties()
{
TypeOfRecovery = RecoveryType.RestoreDisks.ToString(),
RecoveryDSTypeSpecificInputs = azureIaaSVMRecoveryInputsCSMObjectString,
},
};

Guid operationId = AzureBackupClient.TriggerRestore(RecoveryPoint.ContainerUniqueName, RecoveryPoint.ItemName, RecoveryPoint.RecoveryPointName, csmRestoreRequest);
WriteDebug("Triggered Restore. Converting response");

var operationStatus = TrackOperation(operationId);
WriteObject(GetCreatedJobs(new Models.AzurePSBackupVault(RecoveryPoint.ResourceGroupName, RecoveryPoint.ResourceName, RecoveryPoint.Location), operationStatus.Jobs).FirstOrDefault());
* */
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<Compile Include="AzureBackupDSCmdletBase.cs" />
<Compile Include="AzureBackupItemCmdletBase.cs" />
<Compile Include="AzureBackupPolicyCmdletBase.cs" />
<Compile Include="AzureBackUpRestoreBase.cs" />
<Compile Include="AzureBackupVaultCmdletBase.cs" />
<Compile Include="AzureBackupCmdletBase.cs" />
<Compile Include="AzureBackupCmdletHelpMessage.cs" />
Expand All @@ -145,6 +146,7 @@
<Compile Include="Cmdlets\ProtectionPolicy\RemoveAzureBackupProtectionPolicy.cs" />
<Compile Include="Cmdlets\ProtectionPolicy\SetAzureBackupProtectionPolicy.cs" />
<Compile Include="Cmdlets\RecoveryPoint\GetAzureBackupRecoveryPoint.cs" />
<Compile Include="Cmdlets\Restore\TriggerRestore.cs" />
<Compile Include="Cmdlets\VaultCredentials\GetAzureBackupVaultCredentials.cs" />
<Compile Include="Cmdlets\Vault\RemoveAzureBackupVault.cs" />
<Compile Include="Cmdlets\Vault\GetAzureBackupVault.cs" />
Expand Down