diff --git a/AzurePowershell.Test.targets b/AzurePowershell.Test.targets index 02c15e5f4083..ab6484c15da1 100644 --- a/AzurePowershell.Test.targets +++ b/AzurePowershell.Test.targets @@ -216,7 +216,7 @@ - + - + - + - + - + - + - + - + @@ -337,7 +337,7 @@ ContinueOnError="false" /> - + @@ -346,7 +346,7 @@ ContinueOnError="true" /> - + @@ -355,7 +355,7 @@ ContinueOnError="false" /> - + @@ -364,7 +364,7 @@ ContinueOnError="false" /> - + @@ -373,7 +373,7 @@ ContinueOnError="false" /> - + @@ -382,7 +382,7 @@ ContinueOnError="false" /> - + @@ -391,7 +391,7 @@ ContinueOnError="false" /> - + @@ -403,7 +403,7 @@ ContinueOnError="false" /> - + - + - + + + + diff --git a/src/ResourceManager/Compute/Commands.Compute/Common/ConstantStringTypes.cs b/src/ResourceManager/Compute/Commands.Compute/Common/ConstantStringTypes.cs index 7eda1594b52f..eb62eeea1d86 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Common/ConstantStringTypes.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Common/ConstantStringTypes.cs @@ -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 diff --git a/src/ResourceManager/Compute/Commands.Compute/Models/VhdDownloadContext.cs b/src/ResourceManager/Compute/Commands.Compute/Models/VhdDownloadContext.cs new file mode 100644 index 000000000000..6b460684400e --- /dev/null +++ b/src/ResourceManager/Compute/Commands.Compute/Models/VhdDownloadContext.cs @@ -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; } + } +} diff --git a/src/ResourceManager/Compute/Commands.Compute/Models/VhdDownloaderModel.cs b/src/ResourceManager/Compute/Commands.Compute/Models/VhdDownloaderModel.cs new file mode 100644 index 000000000000..5ab1443c3087 --- /dev/null +++ b/src/ResourceManager/Compute/Commands.Compute/Models/VhdDownloaderModel.cs @@ -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 + }; + } + } +} diff --git a/src/ResourceManager/Compute/Commands.Compute/StorageServices/AddAzureVhdCommand.cs b/src/ResourceManager/Compute/Commands.Compute/StorageServices/AddAzureVhdCommand.cs index 77d355dc62c7..c01f610f2236 100644 --- a/src/ResourceManager/Compute/Commands.Compute/StorageServices/AddAzureVhdCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/StorageServices/AddAzureVhdCommand.cs @@ -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())); @@ -147,7 +147,7 @@ public UploadParameters ValidateParameters() return parameters; } - private StorageCredentialsFactory CreateStorageCredentialsFactory(BlobUri destinationUri) + private StorageCredentialsFactory CreateStorageCredentialsFactory() { StorageCredentialsFactory storageCredentialsFactory; diff --git a/src/ResourceManager/Compute/Commands.Compute/StorageServices/SaveAzureVhdCommand.cs b/src/ResourceManager/Compute/Commands.Compute/StorageServices/SaveAzureVhdCommand.cs new file mode 100644 index 000000000000..87fd946dc2ea --- /dev/null +++ b/src/ResourceManager/Compute/Commands.Compute/StorageServices/SaveAzureVhdCommand.cs @@ -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( + 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); + } + } +} diff --git a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/AddAzureVMDataDiskCommand.cs b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/AddAzureVMDataDiskCommand.cs index 5737db843271..59d83e64c760 100644 --- a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/AddAzureVMDataDiskCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/AddAzureVMDataDiskCommand.cs @@ -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( diff --git a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/SetAzureVMDataDiskCommand.cs b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/SetAzureVMDataDiskCommand.cs index 0b330cc5dc4d..83403242bd2a 100644 --- a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/SetAzureVMDataDiskCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/SetAzureVMDataDiskCommand.cs @@ -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( diff --git a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/SetAzureVMOSDiskCommand.cs b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/SetAzureVMOSDiskCommand.cs index 1226f5500a93..b29fd2277b6b 100644 --- a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/SetAzureVMOSDiskCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/SetAzureVMOSDiskCommand.cs @@ -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")] diff --git a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs index 59f4bffb3244..310a285af452 100644 --- a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs @@ -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; @@ -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)] @@ -61,7 +62,8 @@ protected override void ProcessRecord() }; var op = this.VirtualMachineClient.CreateOrUpdate(this.ResourceGroupName, parameters); - WriteObject(op); + var result = Mapper.Map(op); + WriteObject(result); }); } } diff --git a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/UpdateAzureVMCommand.cs b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/UpdateAzureVMCommand.cs index 7f2f5bfe3f9e..51c184741750 100644 --- a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/UpdateAzureVMCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/UpdateAzureVMCommand.cs @@ -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; @@ -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")] @@ -53,7 +54,8 @@ protected override void ProcessRecord() }; var op = this.VirtualMachineClient.CreateOrUpdate(this.ResourceGroupName, parameters); - WriteObject(op); + var result = Mapper.Map(op); + WriteObject(result); }); } } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/BVTTest.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/BVTTest.cs index 520fc058609e..9e891962b837 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/BVTTest.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/BVTTest.cs @@ -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); diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/CredentialHelper.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/CredentialHelper.cs index d7d2bcb8296b..c04882e8c968 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/CredentialHelper.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/CredentialHelper.cs @@ -12,15 +12,17 @@ // limitations under the License. // ---------------------------------------------------------------------------------- +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.WindowsAzure.Commands.ServiceManagement.Test.Properties; +using Microsoft.WindowsAzure.Commands.Storage.Common; +using Microsoft.WindowsAzure.Storage.Auth; +using Microsoft.WindowsAzure.Storage.Blob; using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Microsoft.WindowsAzure.Commands.ServiceManagement.Test.Properties; -using Microsoft.WindowsAzure.Storage.Auth; -using Microsoft.WindowsAzure.Storage.Blob; +using System.Management.Automation; namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests { @@ -263,12 +265,14 @@ public static void CopyTestData(string srcContainer, string srcBlob, string dest // Create a container try { - vmPowershellCmdlets.RunPSScript("Get-AzureStorageContainer -Name " + destContainer); + vmPowershellCmdlets.RunPSScript(String.Format("{0}-{1} -Name {2}", + VerbsCommon.Get, StorageNouns.Container, destContainer)); } catch { // Create a container. - vmPowershellCmdlets.RunPSScript("New-AzureStorageContainer -Name " + destContainer); + vmPowershellCmdlets.RunPSScript(String.Format("{0}-{1} -Name {2}", + VerbsCommon.New, StorageNouns.Container, destContainer)); } // Make SAS Uri for the source blob. @@ -276,12 +280,14 @@ public static void CopyTestData(string srcContainer, string srcBlob, string dest if (string.IsNullOrEmpty(destBlob)) { - vmPowershellCmdlets.RunPSScript(string.Format("Start-AzureStorageBlobCopy -SrcContainer {0} -SrcBlob {1} -DestContainer {2} -Force", srcContainer, srcBlob, destContainer)); + vmPowershellCmdlets.RunPSScript(string.Format("{0}-{1} -SrcContainer {2} -SrcBlob {3} -DestContainer {4} -Force", + VerbsLifecycle.Start, StorageNouns.CopyBlob, srcContainer, srcBlob, destContainer)); destBlob = srcBlob; } else { - vmPowershellCmdlets.RunPSScript(string.Format("Start-AzureStorageBlobCopy -SrcUri \"{0}\" -DestContainer {1} -DestBlob {2} -Force", srcSasUri, destContainer, destBlob)); + vmPowershellCmdlets.RunPSScript(string.Format("{0}-{1} -SrcUri \"{2}\" -DestContainer {3} -DestBlob {4} -Force", + VerbsLifecycle.Start, StorageNouns.CopyBlob, srcSasUri, destContainer, destBlob)); } for (int i = 0; i < 60; i++) diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTestCommonVhd.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTestCommonVhd.cs index f7c661787d10..9863677cd6f6 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTestCommonVhd.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTestCommonVhd.cs @@ -12,14 +12,15 @@ // limitations under the License. // ---------------------------------------------------------------------------------- - +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.WindowsAzure.Commands.ServiceManagement.Model; +using Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests.ConfigDataInfo; +using Microsoft.WindowsAzure.Commands.Storage.Common; using System; using System.IO; using System.Linq; +using System.Management.Automation; using System.Reflection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Microsoft.WindowsAzure.Commands.ServiceManagement.Model; -using Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests.ConfigDataInfo; namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests { @@ -166,7 +167,8 @@ public void AzureDiskTest() private void CopyCommonVhd(string vhdContainerName, string vhdName, string myVhdName) { - vmPowershellCmdlets.RunPSScript(string.Format("Start-AzureStorageBlobCopy -SrcContainer {0} -SrcBlob {1} -DestContainer {2} -DestBlob {3}", vhdContainerName, vhdName, vhdContainerName, myVhdName)); + vmPowershellCmdlets.RunPSScript(string.Format("{0}-{1} -SrcContainer {2} -SrcBlob {3} -DestContainer {4} -DestBlob {5}", + VerbsLifecycle.Start, StorageNouns.CopyBlob, vhdContainerName, vhdName, vhdContainerName, myVhdName)); } [TestMethod(), TestCategory(Category.Functional), TestCategory(Category.BVT), TestProperty("Feature", "IAAS"), Priority(1), Owner("hylee"), Description("Test the cmdlet ((Add,Get,Save,Update,Remove)-AzureVMImage)")] diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/RemoveAzureVMCmdletInfo.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/RemoveAzureVMCmdletInfo.cs index 8048c1ad0736..39632cbd2990 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/RemoveAzureVMCmdletInfo.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/IaasCmdletInfo/RemoveAzureVMCmdletInfo.cs @@ -19,7 +19,7 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests { public class RemoveAzureVMCmdletInfo : CmdletsInfo { - public RemoveAzureVMCmdletInfo(string vmName, string serviceName, bool deleteVhd) + public RemoveAzureVMCmdletInfo(string vmName, string serviceName, bool deleteVhd, bool whatif) { this.cmdletName = Utilities.RemoveAzureVMCmdletName; this.cmdletParams.Add(new CmdletParam("Name", vmName)); @@ -29,6 +29,11 @@ public RemoveAzureVMCmdletInfo(string vmName, string serviceName, bool deleteVhd { this.cmdletParams.Add(new CmdletParam("DeleteVhd")); } + + if (whatif) + { + this.cmdletParams.Add(new CmdletParam("WhatIf")); + } } } } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs index bddb03530864..f474d6f9d12b 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/ServiceManagementCmdletTestHelper.cs @@ -33,6 +33,7 @@ using Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests.PIRCmdletInfo; using Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests.NetworkCmdletInfo; using Microsoft.WindowsAzure.Commands.ServiceManagement.Test.FunctionalTests.SubscriptionCmdletInfo; +using Microsoft.WindowsAzure.Commands.Storage.Common; using Microsoft.WindowsAzure.Commands.Utilities.Common; using Microsoft.WindowsAzure.Management.Network.Models; using Microsoft.WindowsAzure.Storage.Blob; @@ -176,7 +177,8 @@ private Collection RunPSCmdletAndReturnAllHelper(PowershellCore.CmdletsInf public CopyState CheckCopyBlobStatus(string destContainer, string destBlob, bool debug = false) { List st = new List(); - st.Add(string.Format("Get-AzureStorageBlobCopyState -Container {0} -Blob {1}", destContainer, destBlob)); + st.Add(string.Format("{0}-{1} -Container {2} -Blob {3}", + VerbsCommon.Get, StorageNouns.CopyBlobStatus, destContainer, destBlob)); WindowsAzurePowershellScript azurePowershellCmdlet = new WindowsAzurePowershellScript(st); return (CopyState)azurePowershellCmdlet.Run(debug)[0].BaseObject; @@ -1446,9 +1448,9 @@ public SM.PersistentVMRoleContext GetAzureVM(string vmName, string serviceName) return RunPSCmdletAndReturnFirst(new GetAzureVMCmdletInfo(vmName, serviceName)); } - public ManagementOperationContext RemoveAzureVM(string vmName, string serviceName, bool deleteVhd = false) + public ManagementOperationContext RemoveAzureVM(string vmName, string serviceName, bool deleteVhd = false, bool whatif = false) { - return RunPSCmdletAndReturnFirst(new RemoveAzureVMCmdletInfo(vmName, serviceName, deleteVhd)); + return RunPSCmdletAndReturnFirst(new RemoveAzureVMCmdletInfo(vmName, serviceName, deleteVhd, whatif)); } public ManagementOperationContext StartAzureVM(string vmName, string serviceName) @@ -1594,14 +1596,16 @@ public string GetAzureVMImageName(string[] keywords, bool exactMatch = true, int Collection vmImages = GetAzureVMImage(); foreach (SM.OSImageContext image in vmImages) { - if (Utilities.MatchKeywords(image.ImageName, keywords, exactMatch) >= 0 && - ((diskSize == null) || (image.LogicalSizeInGB <= diskSize))) + if (Utilities.MatchKeywords(image.ImageName, keywords, exactMatch) >= 0 + && ((diskSize == null) || (image.LogicalSizeInGB <= diskSize)) + && image.Location.Contains(CredentialHelper.Location)) return image.ImageName; } foreach (SM.OSImageContext image in vmImages) { - if (Utilities.MatchKeywords(image.OS, keywords, exactMatch) >= 0 && - ((diskSize == null) || (image.LogicalSizeInGB <= diskSize))) + if (Utilities.MatchKeywords(image.OS, keywords, exactMatch) >= 0 + && ((diskSize == null) || (image.LogicalSizeInGB <= diskSize)) + && image.Location.Contains(CredentialHelper.Location)) return image.ImageName; } return null; diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/PersistentVMs/RemoveAzureVM.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/PersistentVMs/RemoveAzureVM.cs index 5784f1d24125..c5a8d5df9322 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/PersistentVMs/RemoveAzureVM.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/PersistentVMs/RemoveAzureVM.cs @@ -23,7 +23,7 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS { - [Cmdlet(VerbsCommon.Remove, "AzureVM"), OutputType(typeof(ManagementOperationContext))] + [Cmdlet(VerbsCommon.Remove, "AzureVM", SupportsShouldProcess = true), OutputType(typeof(ManagementOperationContext))] public class RemoveAzureVMCommand : IaaSDeploymentManagementCmdletBase { [Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the role to remove.")] @@ -43,38 +43,41 @@ public SwitchParameter DeleteVHD protected override void ExecuteCommand() { - ServiceManagementProfile.Initialize(); - - base.ExecuteCommand(); - if (CurrentDeploymentNewSM == null) + if (this.ShouldProcess(String.Format("Service: {0}, VM: {1}", this.ServiceName, this.Name), Resources.RemoveAzureVMShouldProcessAction)) { - return; - } + ServiceManagementProfile.Initialize(); - DeploymentGetResponse deploymentGetResponse = this.ComputeClient.Deployments.GetBySlot(this.ServiceName, DeploymentSlot.Production); - if (deploymentGetResponse.Roles.FirstOrDefault(r => r.RoleName.Equals(Name, StringComparison.InvariantCultureIgnoreCase)) == null) - { - throw new ArgumentOutOfRangeException(String.Format(Resources.RoleInstanceCanNotBeFoundWithName, Name)); - } + base.ExecuteCommand(); + if (CurrentDeploymentNewSM == null) + { + return; + } - if (deploymentGetResponse.RoleInstances.Count > 1) - { - ExecuteClientActionNewSM( - null, - CommandRuntime.ToString(), - () => this.ComputeClient.VirtualMachines.Delete(this.ServiceName, CurrentDeploymentNewSM.Name, Name, DeleteVHD.IsPresent)); - } - else - { - if (deploymentGetResponse != null && !string.IsNullOrEmpty(deploymentGetResponse.ReservedIPName)) + DeploymentGetResponse deploymentGetResponse = this.ComputeClient.Deployments.GetBySlot(this.ServiceName, DeploymentSlot.Production); + if (deploymentGetResponse.Roles.FirstOrDefault(r => r.RoleName.Equals(Name, StringComparison.InvariantCultureIgnoreCase)) == null) { - WriteVerboseWithTimestamp(string.Format(Resources.ReservedIPNameNoLongerInUseByDeletingLastVMButStillBeingReserved, deploymentGetResponse.ReservedIPName)); + throw new ArgumentOutOfRangeException(String.Format(Resources.RoleInstanceCanNotBeFoundWithName, Name)); } - ExecuteClientActionNewSM( - null, - CommandRuntime.ToString(), - () => this.ComputeClient.Deployments.DeleteByName(this.ServiceName, CurrentDeploymentNewSM.Name, DeleteVHD.IsPresent)); + if (deploymentGetResponse.RoleInstances.Count > 1) + { + ExecuteClientActionNewSM( + null, + CommandRuntime.ToString(), + () => this.ComputeClient.VirtualMachines.Delete(this.ServiceName, CurrentDeploymentNewSM.Name, Name, DeleteVHD.IsPresent)); + } + else + { + if (deploymentGetResponse != null && !string.IsNullOrEmpty(deploymentGetResponse.ReservedIPName)) + { + WriteVerboseWithTimestamp(string.Format(Resources.ReservedIPNameNoLongerInUseByDeletingLastVMButStillBeingReserved, deploymentGetResponse.ReservedIPName)); + } + + ExecuteClientActionNewSM( + null, + CommandRuntime.ToString(), + () => this.ComputeClient.Deployments.DeleteByName(this.ServiceName, CurrentDeploymentNewSM.Name, DeleteVHD.IsPresent)); + } } } } diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/Properties/Resources.Designer.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/Properties/Resources.Designer.cs index f3cb57a9fed3..61587543ea21 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/Properties/Resources.Designer.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34014 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -1429,6 +1429,15 @@ public static string RemoveAzureDnsServerWarning { } } + /// + /// Looks up a localized string similar to Deleting VM. + /// + public static string RemoveAzureVMShouldProcessAction { + get { + return ResourceManager.GetString("RemoveAzureVMShouldProcessAction", resourceCulture); + } + } + /// /// Looks up a localized string similar to Remove Reserved IP Association. /// diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/Properties/Resources.resx b/src/ServiceManagement/Compute/Commands.ServiceManagement/Properties/Resources.resx index 143942ad19e9..8a6ca4ac560c 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/Properties/Resources.resx +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/Properties/Resources.resx @@ -753,4 +753,7 @@ Upload '{0}' {0} is the name of an storage blob + + Deleting VM + \ No newline at end of file