Skip to content

Piyushka #1

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
merged 3 commits into from
May 27, 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
8 changes: 7 additions & 1 deletion src/AzurePowershell.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
# Visual Studio Express 2013 for Web
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8531411A-0137-4E27-9C5E-49E07C245048}"
Expand Down Expand Up @@ -210,6 +210,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.ApiManagement", "R
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.ApiManagement.Test", "ResourceManager\ApiManagement\Commands.ApiManagement.Test\Commands.ApiManagement.Test.csproj", "{BEC9ECE9-A3D6-4B24-A682-1FA890647D9D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.AzureBackup", "ResourceManager\AzureBackup\Commands.AzureBackup\Commands.AzureBackup.csproj", "{6C8D2337-C9D1-4F52-94B3-AB63A19F3453}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -512,6 +514,10 @@ Global
{BEC9ECE9-A3D6-4B24-A682-1FA890647D9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEC9ECE9-A3D6-4B24-A682-1FA890647D9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BEC9ECE9-A3D6-4B24-A682-1FA890647D9D}.Release|Any CPU.Build.0 = Release|Any CPU
{6C8D2337-C9D1-4F52-94B3-AB63A19F3453}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C8D2337-C9D1-4F52-94B3-AB63A19F3453}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C8D2337-C9D1-4F52-94B3-AB63A19F3453}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C8D2337-C9D1-4F52-94B3-AB63A19F3453}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
22 changes: 22 additions & 0 deletions src/ResourceManager.AzureBackup.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 2013 for Web
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.AzureBackup", "ResourceManager\AzureBackup\Commands.AzureBackup\Commands.AzureBackup.csproj", "{6C8D2337-C9D1-4F52-94B3-AB63A19F3453}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6C8D2337-C9D1-4F52-94B3-AB63A19F3453}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C8D2337-C9D1-4F52-94B3-AB63A19F3453}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C8D2337-C9D1-4F52-94B3-AB63A19F3453}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C8D2337-C9D1-4F52-94B3-AB63A19F3453}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
// ----------------------------------------------------------------------------------
//
// 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.WindowsAzure.Management.Scheduler;
using Microsoft.Azure.Management.BackupServices;
using Microsoft.Azure.Management.BackupServices.Models;

namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
{
public abstract class AzureBackupCmdletBase : AzurePSCmdlet
{
/// <summary>
/// ResourceGroup context for the operation
/// </summary>
private string resourceGroupName { get; set; }

/// <summary>
/// Resource context for the operation
/// </summary>
private string resourceName { get; set; }

/// <summary>
/// Client request id.
/// </summary>
private string clientRequestId;

/// <summary>
/// Azure backup client.
/// </summary>
private BackupServicesManagementClient azureBackupClient;

/// <summary>
/// Cancellation Token Source
/// </summary>
private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
protected CancellationToken CmdletCancellationToken;

/// <summary>
/// Get Azure backup client.
/// </summary>
protected BackupServicesManagementClient AzureBackupClient
{
get
{
if (this.azureBackupClient == null)
{
// Temp code to be able to test internal env.
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

var cloudServicesClient = AzureSession.ClientFactory.CreateClient<CloudServiceManagementClient>(Profile, Profile.Context.Subscription, AzureEnvironment.Endpoint.ResourceManager);
this.azureBackupClient = AzureSession.ClientFactory.CreateCustomClient<BackupServicesManagementClient>(resourceName, resourceGroupName, cloudServicesClient.Credentials, cloudServicesClient.BaseUri);
}

return this.azureBackupClient;
}
}

public void InitializeAzureBackupCmdlet(string rgName, string rName)
{
resourceGroupName = rgName;
resourceName = rName;

clientRequestId = Guid.NewGuid().ToString() + "-" + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ssZ") + "-PS";

WriteDebug(string.Format("Initialized AzureBackup Cmdlet, ClientRequestId: {0}, ResourceGroupName: {1}, ResourceName : {2}", this.clientRequestId, resourceGroupName, resourceName));

CmdletCancellationToken = cancellationTokenSource.Token;
}

protected void ExecutionBlock(Action execAction)
{
try
{
execAction();
}
catch (Exception exception)
{
WriteDebug(String.Format("Caught exception, type: {0}", exception.GetType()));
HandleException(exception);
}
}

/// <summary>
/// Handles set of exceptions thrown by client
/// </summary>
/// <param name="ex"></param>
private void HandleException(Exception exception)
{
if (exception is AggregateException && ((AggregateException)exception).InnerExceptions != null
&& ((AggregateException)exception).InnerExceptions.Count != 0)
{
WriteDebug("Handling aggregate exception");
foreach (var innerEx in ((AggregateException)exception).InnerExceptions)
{
HandleException(innerEx);
}
}
else
{
Exception targetEx = exception;
string targetErrorId = String.Empty;
ErrorCategory targetErrorCategory = ErrorCategory.NotSpecified;

if (exception is CloudException)
{
var cloudEx = exception as CloudException;
if (cloudEx.Response != null && cloudEx.Response.StatusCode == HttpStatusCode.NotFound)
{
WriteDebug(String.Format("Received CloudException, StatusCode: {0}", cloudEx.Response.StatusCode));

targetEx = new Exception(Resources.ResourceNotFoundMessage);
targetErrorCategory = ErrorCategory.InvalidArgument;
}
else if (cloudEx.Error != null)
{
WriteDebug(String.Format("Received CloudException, ErrorCode: {0}, Message: {1}", cloudEx.Error.Code, cloudEx.Error.Message));

targetErrorId = cloudEx.Error.Code;
targetErrorCategory = ErrorCategory.InvalidOperation;
}
}
else if (exception is WebException)
{
var webEx = exception as WebException;
WriteDebug(string.Format("Received WebException, Response: {0}, Status: {1}", webEx.Response, webEx.Status));

targetErrorCategory = ErrorCategory.ConnectionError;
}
else if (exception is ArgumentException || exception is ArgumentNullException)
{
WriteDebug(string.Format("Received ArgumentException"));
targetErrorCategory = ErrorCategory.InvalidArgument;
}

var errorRecord = new ErrorRecord(targetEx, targetErrorId, targetErrorCategory, null);
WriteError(errorRecord);
}
}

protected CustomRequestHeaders GetCustomRequestHeaders()
{
var hdrs = new CustomRequestHeaders()
{
// ClientRequestId is a unique ID for every request to backend service.
ClientRequestId = this.clientRequestId,
};

return hdrs;
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ----------------------------------------------------------------------------------
//
// 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.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
{

internal static class AzureBackupCmdletHelpMessage
{
public const string Vault = "The vault details";
public const string PolicyName = "The protection policy name.";
public const string ResourceGroupName = "The ResourceGroup name.";
public const string ResourceName = "The Resource name.";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// ----------------------------------------------------------------------------------
//
// 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 AzureBackupVaultCmdletBase : AzureBackupCmdletBase
{
[Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ResourceGroupName, ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Parameter(Position = 1, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ResourceName, ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
public string ResourceName { get; set; }


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

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

InitializeAzureBackupCmdlet(ResourceGroupName, ResourceName);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ----------------------------------------------------------------------------------
//
// 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;

namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
{
/// <summary>
/// Get list of containers
/// </summary>
[Cmdlet(VerbsCommon.Get, "AzureBackupJob"), OutputType(typeof(string))]
public class GetAzureBackupJob : AzureBackupCmdletBase
{
public override void ExecuteCmdlet()
{
}
}
}

Loading