Skip to content

Commit f4c9564

Browse files
committed
Update according to PR comments
1 parent 0525010 commit f4c9564

File tree

8 files changed

+44
-41
lines changed

8 files changed

+44
-41
lines changed

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/AddVhdTests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ function Test-AddVhd
6767

6868
$vhdDownloadPath = $vhdLocalPath + "-download.vhd";
6969

70-
$vhdDownloadContext = Save-AzureRmVhd -ResourceGroupName $rgname -Source $vhdDestUri -LocalFilePath $vhdDownloadPath;
70+
$vhdDownloadContext = Save-AzureRmVhd -ResourceGroupName $rgname -SourceUri $vhdDestUri -LocalFilePath $vhdDownloadPath;
7171
Write-Output ("Source :" +$vhdDownloadContext.Source);
7272
Write-Output ("LocalFilePath :" +$vhdDownloadContext.LocalFilePath);
7373
Assert-AreEqual $vhdDestUri $vhdDownloadContext.Source;
7474
Assert-AreEqual $vhdDownloadPath $vhdDownloadContext.LocalFilePath;
7575

76-
$vhdDownloadContext = Save-AzureRmVhd -ResourceGroupName $rgname -Source $vhdDestUri -LocalFilePath $vhdDownloadPath -Overwrite;
76+
$vhdDownloadContext = Save-AzureRmVhd -ResourceGroupName $rgname -SourceUri $vhdDestUri -LocalFilePath $vhdDownloadPath -Overwrite;
7777
Assert-AreEqual $vhdDestUri $vhdDownloadContext.Source;
7878
Assert-AreEqual $vhdDownloadPath $vhdDownloadContext.LocalFilePath;
7979
}

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/ComputeTestCommon.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,9 @@ function Get-SubscriptionIdFromResourceGroup
475475

476476
$rgid = $rg.ResourceId;
477477

478+
# ResouceId is a form of "/subscriptions/<subId>/resourceGroups/<resourgGroupName>"
479+
# So return the second part to get subscription Id
478480
$first = $rgid.IndexOf('/', 1);
479481
$last = $rgid.IndexOf('/', $first + 1);
480-
481482
return $rgid.Substring($first + 1, $last - $first - 1);
482483
}

src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@
310310
<Compile Include="VirtualMachine\Config\SetAzureVMOperatingSystemCommand.cs" />
311311
<Compile Include="VirtualMachine\Config\AddAzureVMDataDiskCommand.cs" />
312312
<Compile Include="VirtualMachine\Config\AddAzureVMNetworkInterfaceCommand.cs" />
313+
<Compile Include="VirtualMachine\VirtualMachineCmdletHelper.cs" />
313314
</ItemGroup>
314315
<ItemGroup>
315316
<ProjectReference Include="..\..\..\Common\Commands.Common.Storage\Commands.Common.Storage.csproj">

src/ResourceManager/Compute/Commands.Compute/Common/ConstantStringTypes.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public static class ProfileNouns
6969
public const string DataDisk = "AzureRmVMDataDisk";
7070
public const string OSDisk = "AzureRmVMOSDisk";
7171
public const string SourceImage = "AzureRmVMSourceImage";
72-
public const string BootDiagnostics = "AzureRMVMBootDiagnostics";
73-
public const string BootDiagnosticsData = "AzureRMVMBootDiagnosticsData";
72+
public const string BootDiagnostics = "AzureRmVMBootDiagnostics";
73+
public const string BootDiagnosticsData = "AzureRmVMBootDiagnosticsData";
7474

7575
public const string NetworkInterface = "AzureRmVMNetworkInterface";
7676

@@ -79,7 +79,7 @@ public static class ProfileNouns
7979
public const string VirtualMachineCustomScriptExtension = "AzureRmVMCustomScriptExtension";
8080
public const string VirtualMachineAccessExtension = "AzureRmVMAccessExtension";
8181
public const string VirtualMachineDiagnosticsExtension = "AzureRmVMDiagnosticsExtension";
82-
public const string VirtualMachineExtensionImage = "AzureRmVMExtensionImage";
82+
public const string VirtualMachineExtensionImage = "AzureRmVmExtensionImage";
8383
public const string VirtualMachineExtensionImageVersion = "AzureRmVMExtensionImageVersion";
8484
public const string VirtualMachineExtensionImageType = "AzureRmVMExtensionImageType";
8585

src/ResourceManager/Compute/Commands.Compute/StorageServices/SaveAzureVhdCommand.cs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,36 +46,24 @@ public class SaveAzureVhdCommand : ComputeClientBaseCmdlet
4646
HelpMessage = "Key of the storage account")]
4747
[ValidateNotNullOrEmpty]
4848
[Alias("sk")]
49-
public string StorageKey
50-
{
51-
get;
52-
set;
53-
}
49+
public string StorageKey { get; set; }
5450

5551
[Parameter(
5652
Position = 1,
5753
Mandatory = true,
5854
ValueFromPipelineByPropertyName = true,
5955
HelpMessage = "Uri to blob")]
6056
[ValidateNotNullOrEmpty]
61-
[Alias("src")]
62-
public Uri Source
63-
{
64-
get;
65-
set;
66-
}
57+
[Alias("src", "Source")]
58+
public Uri SourceUri { get; set; }
6759

6860
[Parameter(
6961
Position = 2,
7062
Mandatory = true,
7163
HelpMessage = "Local path of the vhd file")]
7264
[ValidateNotNullOrEmpty]
7365
[Alias("lf")]
74-
public FileInfo LocalFilePath
75-
{
76-
get;
77-
set;
78-
}
66+
public FileInfo LocalFilePath { get; set; }
7967

8068
private int numberOfThreads = DefaultNumberOfUploaderThreads;
8169

@@ -98,17 +86,13 @@ public int NumberOfThreads
9886
HelpMessage = "Delete the local file if already exists")]
9987
[ValidateNotNullOrEmpty]
10088
[Alias("o")]
101-
public SwitchParameter OverWrite
102-
{
103-
get;
104-
set;
105-
}
89+
public SwitchParameter OverWrite { get; set; }
10690

10791
protected override void ProcessRecord()
10892
{
10993
var result = DownloadFromBlobUri(
11094
this,
111-
this.Source,
95+
this.SourceUri,
11296
this.LocalFilePath,
11397
this.StorageKey,
11498
this.ResourceGroupName,

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/GetAzureVMBootDiagnosticsDataCommand.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ protected override void ProcessRecord()
8585
ExecuteClientAction(() =>
8686
{
8787
var result = this.VirtualMachineClient.GetWithInstanceView(this.ResourceGroupName, this.Name);
88-
var output = new VhdDownloadContext();
8988
if (result == null || result.VirtualMachine == null)
9089
{
9190
ThrowTerminatingError
@@ -153,7 +152,6 @@ protected override void ProcessRecord()
153152

154153
WriteObject(sb.ToString());
155154
}
156-
WriteObject(output);
157155
});
158156
}
159157

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ private string GetRandomStorageAccountName(int interation)
196196
const int maxResLength = 6;
197197
const int maxVMLength = 4;
198198

199-
var subscriptionName = GetTruncatedStr(this.DefaultContext.Subscription.Name, maxSubLength);
200-
var resourcename = GetTruncatedStr(this.ResourceGroupName, maxResLength);
201-
var vmname = GetTruncatedStr(this.VM.Name, maxVMLength);
199+
var subscriptionName = VirtualMachineCmdletHelper.GetTruncatedStr(this.DefaultContext.Subscription.Name, maxSubLength);
200+
var resourcename = VirtualMachineCmdletHelper.GetTruncatedStr(this.ResourceGroupName, maxResLength);
201+
var vmname = VirtualMachineCmdletHelper.GetTruncatedStr(this.VM.Name, maxVMLength);
202202
var datetimestr = DateTime.Now.ToString("MMddHHmm");
203203

204204
var output = subscriptionName + resourcename + vmname + datetimestr + interation;
@@ -208,14 +208,6 @@ private string GetRandomStorageAccountName(int interation)
208208
return output.ToLowerInvariant();
209209
}
210210

211-
private static string GetTruncatedStr(string inputStr, int maxLength)
212-
{
213-
if (inputStr == null) return string.Empty;
214-
return (inputStr.Length > maxLength)
215-
? inputStr.Substring(0, maxLength)
216-
: inputStr;
217-
}
218-
219211
private static string GetStorageAccountNameFromUriString(string uriStr)
220212
{
221213
Uri uri;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.Compute
16+
{
17+
public class VirtualMachineCmdletHelper
18+
{
19+
public static string GetTruncatedStr(string inputStr, int maxLength)
20+
{
21+
if (inputStr == null) return string.Empty;
22+
return (inputStr.Length > maxLength)
23+
? inputStr.Substring(0, maxLength)
24+
: inputStr;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)