-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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 #37 from hyonholee/dev
Test fixes
- Loading branch information
Showing
19 changed files
with
305 additions
and
55 deletions.
There are no files selected for viewing
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
25 changes: 25 additions & 0 deletions
25
src/ResourceManager/Compute/Commands.Compute/Models/VhdDownloadContext.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,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; } | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/ResourceManager/Compute/Commands.Compute/Models/VhdDownloaderModel.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,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 | ||
}; | ||
} | ||
} | ||
} |
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
144 changes: 144 additions & 0 deletions
144
src/ResourceManager/Compute/Commands.Compute/StorageServices/SaveAzureVhdCommand.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,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); | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.