Skip to content

Commit

Permalink
Merge pull request #37 from hyonholee/dev
Browse files Browse the repository at this point in the history
Test fixes
  • Loading branch information
AzureRT committed Sep 22, 2015
2 parents 2d643e9 + 94916b9 commit 0e64614
Show file tree
Hide file tree
Showing 19 changed files with 305 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,15 @@
<Compile Include="Models\PSVirtualMachineSize.cs" />
<Compile Include="Common\LocationStringExtensions.cs" />
<Compile Include="Models\UploadParameters.cs" />
<Compile Include="Models\VhdDownloadContext.cs" />
<Compile Include="Models\VhdDownloaderModel.cs" />
<Compile Include="Models\VhdUploadContext.cs" />
<Compile Include="Models\VhdUploaderModel.cs" />
<Compile Include="RemoteDesktop\VirtualMachineRemoteDesktopBaseCmdlet.cs" />
<Compile Include="RemoteDesktop\GetAzureRemoteDesktopFileCommand.cs" />
<Compile Include="StorageServices\AddAzureVhdCommand.cs" />
<Compile Include="StorageServices\CloudPageBlobObjectFactory.cs" />
<Compile Include="StorageServices\SaveAzureVhdCommand.cs" />
<Compile Include="StorageServices\StorageCredentialsFactory.cs" />
<Compile Include="Usage\GetAzureVMUsageCommand.cs" />
<Compile Include="Usage\VirtualMachineUsageBaseCmdlet.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static class ValidateSetValues
{
public const string ReadOnly = "ReadOnly";
public const string ReadWrite = "ReadWrite";
public const string None = "None";
}

public static class ProfileNouns
Expand Down
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.
// ----------------------------------------------------------------------------------

using System;
using System.IO;

namespace Microsoft.Azure.Commands.Compute.Models
{
public class VhdDownloadContext
{
public FileInfo LocalFilePath { get; set; }
public Uri Source { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// ----------------------------------------------------------------------------------
//
// 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.WindowsAzure.Commands.Sync;
using Microsoft.WindowsAzure.Commands.Sync.Download;
using System.IO;

namespace Microsoft.Azure.Commands.Compute.Models
{
public class VhdDownloaderModel
{
public static VhdDownloadContext Download(DownloaderParameters downloadParameters, ComputeClientBaseCmdlet cmdlet)
{
Program.SyncOutput = new PSSyncOutputEvents(cmdlet);

downloadParameters.ProgressDownloadComplete = Program.SyncOutput.ProgressDownloadComplete;
downloadParameters.ProgressDownloadStatus = Program.SyncOutput.ProgressDownloadStatus;

var downloader = new Downloader(downloadParameters);
downloader.Download();

return new VhdDownloadContext
{
LocalFilePath = new FileInfo(downloadParameters.LocalFilePath),
Source = downloadParameters.BlobUri.Uri
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public UploadParameters ValidateParameters()
}
}

var storageCredentialsFactory = CreateStorageCredentialsFactory(destinationUri);
var storageCredentialsFactory = CreateStorageCredentialsFactory();

PathIntrinsics currentPath = SessionState.Path;
var filePath = new FileInfo(currentPath.GetUnresolvedProviderPathFromPSPath(LocalFilePath.ToString()));
Expand All @@ -147,7 +147,7 @@ public UploadParameters ValidateParameters()
return parameters;
}

private StorageCredentialsFactory CreateStorageCredentialsFactory(BlobUri destinationUri)
private StorageCredentialsFactory CreateStorageCredentialsFactory()
{
StorageCredentialsFactory storageCredentialsFactory;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// ----------------------------------------------------------------------------------
//
// 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.Commands.Compute.Common;
using Microsoft.Azure.Commands.Compute.Models;
using Microsoft.Azure.Common.Authentication;
using Microsoft.Azure.Common.Authentication.Models;
using Microsoft.Azure.Management.Storage;
using Microsoft.WindowsAzure.Commands.Sync.Download;
using System;
using System.IO;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Compute.StorageServices
{
[Cmdlet(VerbsData.Save, ProfileNouns.Vhd), OutputType(typeof(VhdDownloadContext))]
public class SaveAzureVhdCommand : ComputeClientBaseCmdlet
{
private const int DefaultNumberOfUploaderThreads = 8;
private const string ResourceGroupParameterSet = "ResourceGroupParameterSetName";
private const string StorageKeyParameterSet = "StorageKeyParameterSetName";

[Parameter(
Position = 0,
Mandatory = true,
ParameterSetName = ResourceGroupParameterSet,
ValueFromPipelineByPropertyName = true)]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Parameter(
Position = 0,
Mandatory = true,
ParameterSetName = StorageKeyParameterSet,
HelpMessage = "Key of the storage account")]
[ValidateNotNullOrEmpty]
[Alias("sk")]
public string StorageKey
{
get;
set;
}

[Parameter(
Position = 1,
Mandatory = true,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Uri to blob")]
[ValidateNotNullOrEmpty]
[Alias("src")]
public Uri Source
{
get;
set;
}

[Parameter(
Position = 2,
Mandatory = true,
HelpMessage = "Local path of the vhd file")]
[ValidateNotNullOrEmpty]
[Alias("lf")]
public FileInfo LocalFilePath
{
get;
set;
}

private int numberOfThreads = DefaultNumberOfUploaderThreads;

[Parameter(
Position = 3,
Mandatory = false,
HelpMessage = "Number of downloader threads")]
[ValidateNotNullOrEmpty]
[ValidateRange(1, 64)]
[Alias("th")]
public int NumberOfThreads
{
get { return this.numberOfThreads; }
set { this.numberOfThreads = value; }
}

[Parameter(
Position = 4,
Mandatory = false,
HelpMessage = "Delete the local file if already exists")]
[ValidateNotNullOrEmpty]
[Alias("o")]
public SwitchParameter OverWrite
{
get;
set;
}

protected override void ProcessRecord()
{
BlobUri blobUri;
if (!BlobUri.TryParseUri(Source, out blobUri))
{
throw new ArgumentOutOfRangeException("Source", Source.ToString());
}

var storageKey = this.StorageKey;
if (this.StorageKey == null)
{
var storageClient = AzureSession.ClientFactory.CreateClient<StorageManagementClient>(
DefaultProfile.Context, AzureEnvironment.Endpoint.ResourceManager);


var storageService = storageClient.StorageAccounts.GetProperties(this.ResourceGroupName, blobUri.StorageAccountName);
if (storageService != null)
{
var storageKeys = storageClient.StorageAccounts.ListKeys(this.ResourceGroupName, storageService.StorageAccount.Name);
storageKey = storageKeys.StorageAccountKeys.Key1;
}
}

var downloaderParameters = new DownloaderParameters
{
BlobUri = blobUri,
LocalFilePath = LocalFilePath.FullName,
ConnectionLimit = NumberOfThreads,
StorageAccountKey = storageKey,
ValidateFreeDiskSpace = true,
OverWrite = OverWrite
};

var vhdDownloadContext = VhdDownloaderModel.Download(downloaderParameters, this);
WriteObject(vhdDownloadContext);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class AddAzureVMDataDiskCommand : Microsoft.Azure.Commands.ResourceManage
ValueFromPipelineByPropertyName = true,
HelpMessage = HelpMessages.VMDataDiskCaching)]
[ValidateNotNullOrEmpty]
[ValidateSet(ValidateSetValues.ReadOnly, ValidateSetValues.ReadWrite)]
[ValidateSet(ValidateSetValues.ReadOnly, ValidateSetValues.ReadWrite, ValidateSetValues.None)]
public string Caching { get; set; }

[Parameter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class SetAzureVMDataDiskCommand : Microsoft.Azure.Commands.ResourceManage
ValueFromPipelineByPropertyName = true,
HelpMessage = HelpMessages.VMDataDiskCaching)]
[ValidateNotNullOrEmpty]
[ValidateSet(ValidateSetValues.ReadOnly, ValidateSetValues.ReadWrite)]
[ValidateSet(ValidateSetValues.ReadOnly, ValidateSetValues.ReadWrite, ValidateSetValues.None)]
public string Caching { get; set; }

[Parameter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class SetAzureVMOSDiskCommand : Microsoft.Azure.Commands.ResourceManager.
ValueFromPipelineByPropertyName = true,
HelpMessage = HelpMessages.VMOSDiskCaching)]
[ValidateNotNullOrEmpty]
[ValidateSet(ValidateSetValues.ReadOnly, ValidateSetValues.ReadWrite)]
[ValidateSet(ValidateSetValues.ReadOnly, ValidateSetValues.ReadWrite, ValidateSetValues.None)]
public string Caching { get; set; }

[Alias("SourceImage")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using AutoMapper;
using Microsoft.Azure.Commands.Compute.Common;
using Microsoft.Azure.Commands.Compute.Models;
using Microsoft.Azure.Commands.Tags.Model;
using Microsoft.Azure.Management.Compute;
using Microsoft.Azure.Management.Compute.Models;
using System.Collections;
Expand All @@ -23,6 +23,7 @@
namespace Microsoft.Azure.Commands.Compute
{
[Cmdlet(VerbsCommon.New, ProfileNouns.VirtualMachine)]
[OutputType(typeof(PSComputeLongRunningOperation))]
public class NewAzureVMCommand : VirtualMachineBaseCmdlet
{
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true)]
Expand Down Expand Up @@ -61,7 +62,8 @@ protected override void ProcessRecord()
};

var op = this.VirtualMachineClient.CreateOrUpdate(this.ResourceGroupName, parameters);
WriteObject(op);
var result = Mapper.Map<PSComputeLongRunningOperation>(op);
WriteObject(result);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// limitations under the License.
// ----------------------------------------------------------------------------------


using AutoMapper;
using Microsoft.Azure.Commands.Compute.Common;
using Microsoft.Azure.Commands.Compute.Models;
using Microsoft.Azure.Management.Compute;
Expand All @@ -22,7 +22,8 @@

namespace Microsoft.Azure.Commands.Compute
{
[Cmdlet(VerbsData.Update, ProfileNouns.VirtualMachine, DefaultParameterSetName = ResourceGroupNameParameterSet)]
[Cmdlet(VerbsData.Update, ProfileNouns.VirtualMachine, DefaultParameterSetName = ResourceGroupNameParameterSet)]
[OutputType(typeof(PSComputeLongRunningOperation))]
public class UpdateAzureVMCommand : VirtualMachineActionBaseCmdlet
{
[Alias("VMProfile")]
Expand Down Expand Up @@ -53,7 +54,8 @@ protected override void ProcessRecord()
};

var op = this.VirtualMachineClient.CreateOrUpdate(this.ResourceGroupName, parameters);
WriteObject(op);
var result = Mapper.Map<PSComputeLongRunningOperation>(op);
WriteObject(result);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ public void AzureIaaSBVT()
//
// Remove-AzureVM
//
vmPowershellCmdlets.RemoveAzureVM(newAzureVMName, serviceName, false, true);
Assert.AreNotEqual(null, vmPowershellCmdlets.GetAzureVM(newAzureVMName, serviceName));

vmPowershellCmdlets.RemoveAzureVM(newAzureVMName, serviceName);

RecordTimeTaken(ref prevTime);
Expand Down
Loading

0 comments on commit 0e64614

Please sign in to comment.