File tree Expand file tree Collapse file tree 8 files changed +44
-41
lines changed
src/ResourceManager/Compute
Commands.Compute.Test/ScenarioTests Expand file tree Collapse file tree 8 files changed +44
-41
lines changed Original file line number Diff line number Diff line change @@ -67,13 +67,13 @@ function Test-AddVhd
67
67
68
68
$vhdDownloadPath = $vhdLocalPath + " -download.vhd" ;
69
69
70
- $vhdDownloadContext = Save-AzureRmVhd - ResourceGroupName $rgname - Source $vhdDestUri - LocalFilePath $vhdDownloadPath ;
70
+ $vhdDownloadContext = Save-AzureRmVhd - ResourceGroupName $rgname - SourceUri $vhdDestUri - LocalFilePath $vhdDownloadPath ;
71
71
Write-Output (" Source :" + $vhdDownloadContext.Source );
72
72
Write-Output (" LocalFilePath :" + $vhdDownloadContext.LocalFilePath );
73
73
Assert-AreEqual $vhdDestUri $vhdDownloadContext.Source ;
74
74
Assert-AreEqual $vhdDownloadPath $vhdDownloadContext.LocalFilePath ;
75
75
76
- $vhdDownloadContext = Save-AzureRmVhd - ResourceGroupName $rgname - Source $vhdDestUri - LocalFilePath $vhdDownloadPath - Overwrite;
76
+ $vhdDownloadContext = Save-AzureRmVhd - ResourceGroupName $rgname - SourceUri $vhdDestUri - LocalFilePath $vhdDownloadPath - Overwrite;
77
77
Assert-AreEqual $vhdDestUri $vhdDownloadContext.Source ;
78
78
Assert-AreEqual $vhdDownloadPath $vhdDownloadContext.LocalFilePath ;
79
79
}
Original file line number Diff line number Diff line change @@ -475,8 +475,9 @@ function Get-SubscriptionIdFromResourceGroup
475
475
476
476
$rgid = $rg.ResourceId ;
477
477
478
+ # ResouceId is a form of "/subscriptions/<subId>/resourceGroups/<resourgGroupName>"
479
+ # So return the second part to get subscription Id
478
480
$first = $rgid.IndexOf (' /' , 1 );
479
481
$last = $rgid.IndexOf (' /' , $first + 1 );
480
-
481
482
return $rgid.Substring ($first + 1 , $last - $first - 1 );
482
483
}
Original file line number Diff line number Diff line change 310
310
<Compile Include =" VirtualMachine\Config\SetAzureVMOperatingSystemCommand.cs" />
311
311
<Compile Include =" VirtualMachine\Config\AddAzureVMDataDiskCommand.cs" />
312
312
<Compile Include =" VirtualMachine\Config\AddAzureVMNetworkInterfaceCommand.cs" />
313
+ <Compile Include =" VirtualMachine\VirtualMachineCmdletHelper.cs" />
313
314
</ItemGroup >
314
315
<ItemGroup >
315
316
<ProjectReference Include =" ..\..\..\Common\Commands.Common.Storage\Commands.Common.Storage.csproj" >
Original file line number Diff line number Diff line change @@ -69,8 +69,8 @@ public static class ProfileNouns
69
69
public const string DataDisk = "AzureRmVMDataDisk" ;
70
70
public const string OSDisk = "AzureRmVMOSDisk" ;
71
71
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 " ;
74
74
75
75
public const string NetworkInterface = "AzureRmVMNetworkInterface" ;
76
76
@@ -79,7 +79,7 @@ public static class ProfileNouns
79
79
public const string VirtualMachineCustomScriptExtension = "AzureRmVMCustomScriptExtension" ;
80
80
public const string VirtualMachineAccessExtension = "AzureRmVMAccessExtension" ;
81
81
public const string VirtualMachineDiagnosticsExtension = "AzureRmVMDiagnosticsExtension" ;
82
- public const string VirtualMachineExtensionImage = "AzureRmVMExtensionImage " ;
82
+ public const string VirtualMachineExtensionImage = "AzureRmVmExtensionImage " ;
83
83
public const string VirtualMachineExtensionImageVersion = "AzureRmVMExtensionImageVersion" ;
84
84
public const string VirtualMachineExtensionImageType = "AzureRmVMExtensionImageType" ;
85
85
Original file line number Diff line number Diff line change @@ -46,36 +46,24 @@ public class SaveAzureVhdCommand : ComputeClientBaseCmdlet
46
46
HelpMessage = "Key of the storage account" ) ]
47
47
[ ValidateNotNullOrEmpty ]
48
48
[ Alias ( "sk" ) ]
49
- public string StorageKey
50
- {
51
- get ;
52
- set ;
53
- }
49
+ public string StorageKey { get ; set ; }
54
50
55
51
[ Parameter (
56
52
Position = 1 ,
57
53
Mandatory = true ,
58
54
ValueFromPipelineByPropertyName = true ,
59
55
HelpMessage = "Uri to blob" ) ]
60
56
[ ValidateNotNullOrEmpty ]
61
- [ Alias ( "src" ) ]
62
- public Uri Source
63
- {
64
- get ;
65
- set ;
66
- }
57
+ [ Alias ( "src" , "Source" ) ]
58
+ public Uri SourceUri { get ; set ; }
67
59
68
60
[ Parameter (
69
61
Position = 2 ,
70
62
Mandatory = true ,
71
63
HelpMessage = "Local path of the vhd file" ) ]
72
64
[ ValidateNotNullOrEmpty ]
73
65
[ Alias ( "lf" ) ]
74
- public FileInfo LocalFilePath
75
- {
76
- get ;
77
- set ;
78
- }
66
+ public FileInfo LocalFilePath { get ; set ; }
79
67
80
68
private int numberOfThreads = DefaultNumberOfUploaderThreads ;
81
69
@@ -98,17 +86,13 @@ public int NumberOfThreads
98
86
HelpMessage = "Delete the local file if already exists" ) ]
99
87
[ ValidateNotNullOrEmpty ]
100
88
[ Alias ( "o" ) ]
101
- public SwitchParameter OverWrite
102
- {
103
- get ;
104
- set ;
105
- }
89
+ public SwitchParameter OverWrite { get ; set ; }
106
90
107
91
protected override void ProcessRecord ( )
108
92
{
109
93
var result = DownloadFromBlobUri (
110
94
this ,
111
- this . Source ,
95
+ this . SourceUri ,
112
96
this . LocalFilePath ,
113
97
this . StorageKey ,
114
98
this . ResourceGroupName ,
Original file line number Diff line number Diff line change @@ -85,7 +85,6 @@ protected override void ProcessRecord()
85
85
ExecuteClientAction ( ( ) =>
86
86
{
87
87
var result = this . VirtualMachineClient . GetWithInstanceView ( this . ResourceGroupName , this . Name ) ;
88
- var output = new VhdDownloadContext ( ) ;
89
88
if ( result == null || result . VirtualMachine == null )
90
89
{
91
90
ThrowTerminatingError
@@ -153,7 +152,6 @@ protected override void ProcessRecord()
153
152
154
153
WriteObject ( sb . ToString ( ) ) ;
155
154
}
156
- WriteObject ( output ) ;
157
155
} ) ;
158
156
}
159
157
Original file line number Diff line number Diff line change @@ -196,9 +196,9 @@ private string GetRandomStorageAccountName(int interation)
196
196
const int maxResLength = 6 ;
197
197
const int maxVMLength = 4 ;
198
198
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 ) ;
202
202
var datetimestr = DateTime . Now . ToString ( "MMddHHmm" ) ;
203
203
204
204
var output = subscriptionName + resourcename + vmname + datetimestr + interation ;
@@ -208,14 +208,6 @@ private string GetRandomStorageAccountName(int interation)
208
208
return output . ToLowerInvariant ( ) ;
209
209
}
210
210
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
-
219
211
private static string GetStorageAccountNameFromUriString ( string uriStr )
220
212
{
221
213
Uri uri ;
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments