Skip to content

Commit ac26cd9

Browse files
committed
Merge pull request Azure#1576 from huangpf/clu
AzureRT - VM Creation Update & Tests
2 parents 93cbccd + 3cee9e7 commit ac26cd9

20 files changed

+177
-26
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Param(
2+
[string]$resourceGroupName,
3+
[string]$resourceGroupLocation
4+
)
5+
6+
Write-Host "Skip"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
set -e
3+
printf "\n=== Managing Virtual Machine Creation in Azure Compute ===\n"
4+
5+
printf "\n1. Creating a new resource group: %s and location: %s.\n" "$groupName" "$location"
6+
azure group create -n "$groupName" --location "$location"
7+
8+
printf "\n2. Creating a new storage account '%s' in type '%s'.\n" "$storageAccountName" "$storageAccountType"
9+
azure storage account new --resourcegroupname "$groupName" --name "$storageAccountName" --location "$location" --type "$storageAccountType"
10+
11+
printf "\n3. Create virtual network.\n"
12+
result=`azure virtual network create --resourcegroupname "$groupName" --name test --location "$location" --addressprefix "[\"10.0.0.0/16\"]" --subnet "[{\"Name\":\"test\",\"AddressPrefix\":\"10.0.0.0/24\"}]" --force`
13+
14+
contextResult=`azure context get`
15+
16+
subId=`echo $contextResult | jq '.Subscription.SubscriptionId' --raw-output`
17+
18+
subnetId="/subscriptions/$subId/resourceGroups/$groupName/providers/Microsoft.Network/virtualNetworks/test/subnets/test"
19+
20+
printf "\n4. Create network interface with:\r\nsubId='%s' \r\n& \r\nsubnetId='$subnetId'.\n" "$subId"
21+
export MSYS_NO_PATHCONV=1
22+
azure network interface create --name test --resourcegroupname "$groupName" --location "$location" --subnetid "$subnetId"
23+
export MSYS_NO_PATHCONV=
24+
25+
nicId="/subscriptions/$subId/resourceGroups/$groupName/providers/Microsoft.Network/networkInterfaces/test"
26+
27+
vhdUri="https://$storageAccountName.blob.core.windows.net/$storageAccountName/$storageAccountName.vhd"
28+
29+
vmStr="{\"Name\":\"test\",\"HardwareProfile\":{\"VmSize\":\"Standard_A1\"},\"NetworkProfile\":{\"NetworkInterfaces\":[{\"Id\":\"$nicId\"}]},\"OSProfile\":{\"ComputerName\":\"test\",\"AdminPassword\":\"BaR@1234\",\"AdminUsername\":\"Foo12\"},\"StorageProfile\":{\"ImageReference\":{\"Offer\":\"WindowsServer\",\"Publisher\":\"MicrosoftWindowsServer\",\"Sku\":\"2008-R2-SP1\",\"Version\":\"latest\"},\"OSDisk\":{\"Caching\":\"ReadWrite\",\"CreateOption\":\"FromImage\",\"Name\":\"osDisk\",\"Vhd\":{\"Uri\":\"$vhdUri\"}}}}"
30+
31+
printf "\n5. Create virtual machine with\r\nnicId='%s'\r\nvhdUri='%s'\r\nvmStr='%s'\n" "$nicId" "$vhdUri" "$vmStr"
32+
33+
azure vm new --resourcegroupname "$groupName" --location "$location" --vmprofile "$vmStr"
34+
35+
printf "\n6. Removing resource group: %s.\n" "$groupName"
36+
azure group remove -n "$groupName" -f

src/CLU/Commands.Common.ScenarioTest/SampleTest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,12 @@ public void VirtualMachineSizeTest()
4545
var helper = _collectionState.GetRunner("compute-management");
4646
helper.RunScript("01-VirtualMachineSizes");
4747
}
48+
49+
[Fact]
50+
public void VirtualMachineCreationTest()
51+
{
52+
var helper = _collectionState.GetRunner("compute-management");
53+
helper.RunScript("02-VirtualMachineCreation");
54+
}
4855
}
4956
}

src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/RemoveAzureVMCustomScriptExtensionCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected override void ProcessRecord()
5959

6060
ExecuteClientAction(() =>
6161
{
62-
if (this.Force.IsPresent || this.ShouldContinue(Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("VirtualMachineExtensionRemovalConfirmation"), Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("VirtualMachineExtensionRemovalCaption")))
62+
if (this.Force.IsPresent || this.ShouldContinue(Microsoft.Azure.Commands.Compute.Properties.Resources.VirtualMachineExtensionRemovalConfirmation, Microsoft.Azure.Commands.Compute.Properties.Resources.VirtualMachineExtensionRemovalCaption))
6363
{
6464
this.VirtualMachineExtensionClient.Delete(this.ResourceGroupName, this.VMName, this.Name);
6565
}

src/CLU/Microsoft.Azure.Commands.Compute/Extension/CustomScript/SetAzureVMCustomScriptExtensionCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ protected override void ProcessRecord()
197197

198198
if (string.IsNullOrEmpty(this.Run))
199199
{
200-
WriteWarning(Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("CustomScriptExtensionTryToUseTheFirstSpecifiedFileAsRunScript"));
200+
WriteWarning(Microsoft.Azure.Commands.Compute.Properties.Resources.CustomScriptExtensionTryToUseTheFirstSpecifiedFileAsRunScript);
201201
this.Run = this.FileName[0];
202202
}
203203
}

src/CLU/Microsoft.Azure.Commands.Compute/Extension/RemoveAzureVMExtensionCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected override void ProcessRecord()
6060

6161
ExecuteClientAction(() =>
6262
{
63-
if (this.Force.IsPresent || this.ShouldContinue(Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("VirtualMachineExtensionRemovalConfirmation"), Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("VirtualMachineExtensionRemovalCaption")))
63+
if (this.Force.IsPresent || this.ShouldContinue(Microsoft.Azure.Commands.Compute.Properties.Resources.VirtualMachineExtensionRemovalConfirmation, Microsoft.Azure.Commands.Compute.Properties.Resources.VirtualMachineExtensionRemovalCaption))
6464
{
6565
this.VirtualMachineExtensionClient.Delete(this.ResourceGroupName, this.VMName, this.Name);
6666
}

src/CLU/Microsoft.Azure.Commands.Compute/Extension/SetAzureVMExtensionCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ protected override void ProcessRecord()
151151
this.Name,
152152
parameters);
153153

154-
var result = Mapper.Map<PSComputeLongRunningOperation>(op);
154+
// TODO: CLU
155+
var result = op;
156+
//var result = Mapper.Map<PSComputeLongRunningOperation>(op);
155157
WriteObject(result);
156158
});
157159
}

src/CLU/Microsoft.Azure.Commands.Compute/Extension/VMAccess/RemoveAzureVMAccessExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected override void ProcessRecord()
5959

6060
ExecuteClientAction(() =>
6161
{
62-
if (this.Force.IsPresent || this.ShouldContinue(Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("VirtualMachineExtensionRemovalConfirmation"), Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("VirtualMachineExtensionRemovalCaption")))
62+
if (this.Force.IsPresent || this.ShouldContinue(Microsoft.Azure.Commands.Compute.Properties.Resources.VirtualMachineExtensionRemovalConfirmation, Microsoft.Azure.Commands.Compute.Properties.Resources.VirtualMachineExtensionRemovalCaption))
6363
{
6464
this.VirtualMachineExtensionClient.Delete(this.ResourceGroupName, this.VMName, this.Name);
6565
}

src/CLU/Microsoft.Azure.Commands.Compute/Properties/Resources.resx

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,4 +375,98 @@ The file needs to be a PowerShell script (.ps1 or .psm1).</value>
375375
<value>Configuration published to {0}</value>
376376
<comment>{0} is an URI</comment>
377377
</data>
378+
<data name="PublishVMDscExtensionCopyFileVerbose1" xml:space="preserve">
379+
<value>Copy '{0}' to '{1}'.</value>
380+
<comment>{0} = source, {1} = destination</comment>
381+
</data>
382+
<data name="PublishVMDscExtensionCopyModuleVerbose1" xml:space="preserve">
383+
<value>Copy the module '{0}' to '{1}'.</value>
384+
<comment>{0} = source, {1} = destination</comment>
385+
</data>
386+
<data name="PublishVMDscExtensionCreateArchiveConfigFileInvalidExtension1" xml:space="preserve">
387+
<value>Invalid configuration file: {0}.
388+
The file needs to be a PowerShell script (.ps1 or .psm1).</value>
389+
<comment>0 = path to the configuration file</comment>
390+
</data>
391+
<data name="PublishVMDscExtensionDeletedFileMessage1" xml:space="preserve">
392+
<value>Deleted '{0}'</value>
393+
<comment>{0} is the path of a file</comment>
394+
</data>
395+
<data name="PublishVMDscExtensionDeleteErrorMessage1" xml:space="preserve">
396+
<value>Cannot delete '{0}': {1}</value>
397+
<comment>{0} is the path of a file, {1} is an error message</comment>
398+
</data>
399+
<data name="PublishVMDscExtensionDirectoryNotExist" xml:space="preserve">
400+
<value>Path '{0}' not found.</value>
401+
<comment>0 = path to the additional content file/directory</comment>
402+
</data>
403+
<data name="PublishVMDscExtensionGetDscResourceFailed1" xml:space="preserve">
404+
<value>Cannot get module for DscResource '{0}'. Possible solutions:
405+
1) Specify -ModuleName for Import-DscResource in your configuration.
406+
2) Unblock module that contains resource.
407+
3) Move Import-DscResource inside Node block.
408+
</value>
409+
<comment>0 = name of DscResource</comment>
410+
</data>
411+
<data name="PublishVMDscExtensionRequiredModulesVerbose1" xml:space="preserve">
412+
<value>List of required modules: [{0}].</value>
413+
<comment>{0} = list of modules</comment>
414+
</data>
415+
<data name="PublishVMDscExtensionRequiredPsVersion1" xml:space="preserve">
416+
<value>Your current PowerShell version {1} is less then required by this cmdlet {0}. Consider download and install latest PowerShell version.</value>
417+
<comment>{0} = minimal required PS version, {1} = current PS version</comment>
418+
</data>
419+
<data name="PublishVMDscExtensionStorageParserErrors1" xml:space="preserve">
420+
<value>Configuration script '{0}' contained parse errors:
421+
{1}</value>
422+
<comment>0 = path to the configuration script, 1 = parser errors</comment>
423+
</data>
424+
<data name="PublishVMDscExtensionTempFolderVerbose1" xml:space="preserve">
425+
<value>Temp folder '{0}' created.</value>
426+
<comment>{0} = temp folder path</comment>
427+
</data>
428+
<data name="PublishVMDscExtensionUploadArchiveConfigFileInvalidExtension1" xml:space="preserve">
429+
<value>Invalid configuration file: {0}.
430+
The file needs to be a PowerShell script (.ps1 or .psm1) or a ZIP archive (.zip).</value>
431+
<comment>0 = path to the configuration file</comment>
432+
</data>
433+
<data name="PublishVMDscExtensionUploadArchiveConfigFileNotExist1" xml:space="preserve">
434+
<value>Configuration file '{0}' not found.</value>
435+
<comment>0 = path to the configuration file</comment>
436+
</data>
437+
<data name="PremiumStorageAccountForBootDiagnostics" xml:space="preserve">
438+
<value>Storage account, {0}, is a premium account. You cannot specify a premium storage account for boot diagnostics</value>
439+
</data>
440+
<data name="BootDiagnosticsNoStorageAccountError" xml:space="preserve">
441+
<value>Storage account name for boot diagnostics is not given.</value>
442+
</data>
443+
<data name="CreatingStorageAccountForBootDiagnostics" xml:space="preserve">
444+
<value>Since the VM is created using premium storage, new standard storage account, {0}, is created for boot diagnostics.</value>
445+
<comment>{0} = new standard storage account name</comment>
446+
</data>
447+
<data name="ErrorDuringCreatingStorageAccountForBootDiagnostics" xml:space="preserve">
448+
<value>Error occurred when creating storage account for boot diagnostics. Keep creating a VM with disabling boot diagnostics. : {0}</value>
449+
<comment>{0} = exception</comment>
450+
</data>
451+
<data name="UsingExistingStorageAccountForBootDiagnostics" xml:space="preserve">
452+
<value>Since the VM is created using premium storage, existing standard storage account, {0}, is used for boot diagnostics.</value>
453+
<comment>{0} = existing standard storage account name</comment>
454+
</data>
455+
<data name="EnableAzureDiskEncryptionCaption" xml:space="preserve">
456+
<value>Enable AzureDiskEncryption on the VM</value>
457+
</data>
458+
<data name="EnableAzureDiskEncryptionConfirmation" xml:space="preserve">
459+
<value>This cmdlet prepares the VM and enables encryption which may reboot the machine and takes 10-15 minutes to finish. Please save your work on the VM before confirming. Do you want to continue?</value>
460+
</data>
461+
<data name="ErrorDuringGettingStorageAccountForBootDiagnostics" xml:space="preserve">
462+
<value>Error occurred when getting storage account, {0}, for boot diagnostics: {1}</value>
463+
<comment>{0} = storage account name, {1} = error message</comment>
464+
</data>
465+
<data name="StorageAccountNotFoundForBootDiagnostics" xml:space="preserve">
466+
<value>Storage account, {0}, is not found. The OS disk may be in a different storage group.</value>
467+
<comment>{0} = storage account name</comment>
468+
</data>
469+
<data name="VMOSDiskDiskEncryptionBothKekVaultIdAndKekUrlRequired" xml:space="preserve">
470+
<value>You have to specify either both of KeyEncryptionKeyVaultId and KeyEncryptionKeyUrl or none of them.</value>
471+
</data>
378472
</root>

src/CLU/Microsoft.Azure.Commands.Compute/StorageServices/AddAzureVhdCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public UploadParameters ValidateParameters()
124124

125125
if (!String.IsNullOrEmpty(destinationUri.Uri.Query))
126126
{
127-
var message = String.Format(Rsrc.ResourceManager.GetString("AddAzureVhdCommandSASUriNotSupportedInPatchMode"), destinationUri.Uri);
127+
var message = String.Format(Rsrc.AddAzureVhdCommandSASUriNotSupportedInPatchMode, destinationUri.Uri);
128128
throw new ArgumentOutOfRangeException("Destination", message);
129129
}
130130
}

src/CLU/Microsoft.Azure.Commands.Compute/StorageServices/StorageCredentialsFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public StorageCredentials Create(BlobUri destination)
5050
{
5151
if (currentSubscription == null)
5252
{
53-
throw new ArgumentException(Rsrc.ResourceManager.GetString("StorageCredentialsFactoryCurrentSubscriptionNotSet"), "SubscriptionId");
53+
throw new ArgumentException(Rsrc.StorageCredentialsFactoryCurrentSubscriptionNotSet, "currentSubscription");
5454
}
5555
var storageKeys = this.client.StorageAccounts.ListKeys(this.resourceGroupName, destination.StorageAccountName);
5656
return new StorageCredentials(destination.StorageAccountName, storageKeys.Key1);

src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Action/SaveAzureVMImageCommand.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,13 @@ protected override void ProcessRecord()
8484
this.Name,
8585
parameters);
8686

87-
var result = Mapper.Map<PSComputeLongRunningOperation>(op);
87+
// TODO: CLU
88+
var result = op;
89+
//var result = Mapper.Map<PSComputeLongRunningOperation>(op);
8890

8991
if (!string.IsNullOrWhiteSpace(this.Path))
9092
{
91-
File.WriteAllText(this.Path, result.Output);
93+
File.WriteAllText(this.Path, result.Output == null ? null : result.Output.ToString());
9294
}
9395

9496
WriteObject(result);

src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/AddAzureVMSshPublicKeyCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected override void ProcessRecord()
7070
}
7171
else if (this.VM.OSProfile.WindowsConfiguration != null && this.VM.OSProfile.LinuxConfiguration == null)
7272
{
73-
throw new ArgumentException(Resources.ResourceManager.GetString("BothWindowsAndLinuxConfigurationsSpecified"));
73+
throw new ArgumentException(Compute.Properties.Resources.BothWindowsAndLinuxConfigurationsSpecified);
7474
}
7575

7676
if (this.VM.OSProfile.LinuxConfiguration.Ssh == null)

src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMBootDiagnosticsCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ protected override void ProcessRecord()
9999
}
100100
else
101101
{
102-
var storageClient = ClientFactory.CreateClient<StorageManagementClient>(
102+
var storageClient = ClientFactory.CreateArmClient<StorageManagementClient>(
103103
DefaultProfile.Context, AzureEnvironment.Endpoint.ResourceManager);
104104
var storageAccount = storageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.StorageAccountName);
105105

@@ -122,7 +122,7 @@ private void ThrowPremiumStorageError(string storageAccountName)
122122
ThrowTerminatingError
123123
(new ErrorRecord(
124124
new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
125-
Resources.ResourceManager.GetString("PremiumStorageAccountForBootDiagnostics"), storageAccountName)),
125+
Compute.Properties.Resources.PremiumStorageAccountForBootDiagnostics, storageAccountName)),
126126
string.Empty,
127127
ErrorCategory.InvalidData,
128128
null));
@@ -132,7 +132,7 @@ private void ThrowNoStorageAccount()
132132
{
133133
ThrowTerminatingError
134134
(new ErrorRecord(
135-
new InvalidOperationException(Resources.ResourceManager.GetString("BootDiagnosticsNoStorageAccountError")),
135+
new InvalidOperationException(Compute.Properties.Resources.BootDiagnosticsNoStorageAccountError),
136136
string.Empty,
137137
ErrorCategory.InvalidData,
138138
null));

src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMDataDiskCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private void ThrowDataDiskNotExistError()
123123
ThrowTerminatingError
124124
(new ErrorRecord(
125125
new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
126-
Resources.ResourceManager.GetString("DataDiskNotAssignedForVM"), missingDisk)),
126+
Resources.DataDiskNotAssignedForVM, missingDisk)),
127127
string.Empty,
128128
ErrorCategory.InvalidData,
129129
null));

src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMOSDiskCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ protected override void ProcessRecord()
179179
|| (!string.IsNullOrEmpty(this.KeyEncryptionKeyVaultId) && string.IsNullOrEmpty(this.KeyEncryptionKeyUrl)))
180180
{
181181
WriteError(new ErrorRecord(
182-
new Exception(Properties.Resources.ResourceManager.GetString("VMOSDiskDiskEncryptionBothKekVaultIdAndKekUrlRequired")),
182+
new Exception(Properties.Resources.VMOSDiskDiskEncryptionBothKekVaultIdAndKekUrlRequired),
183183
string.Empty, ErrorCategory.InvalidArgument, null));
184184
}
185185

src/CLU/Microsoft.Azure.Commands.Compute/VirtualMachine/Config/SetAzureVMOperatingSystemCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ protected override void ProcessRecord()
163163
{
164164
if (this.VM.OSProfile.WindowsConfiguration != null)
165165
{
166-
throw new ArgumentException(Resources.ResourceManager.GetString("BothWindowsAndLinuxConfigurationsSpecified"));
166+
throw new ArgumentException(Resources.BothWindowsAndLinuxConfigurationsSpecified);
167167
}
168168

169169
if (this.VM.OSProfile.LinuxConfiguration == null)
@@ -180,7 +180,7 @@ protected override void ProcessRecord()
180180
{
181181
if (this.VM.OSProfile.LinuxConfiguration != null)
182182
{
183-
throw new ArgumentException(Resources.ResourceManager.GetString("BothWindowsAndLinuxConfigurationsSpecified"));
183+
throw new ArgumentException(Resources.BothWindowsAndLinuxConfigurationsSpecified);
184184
}
185185

186186
if (this.VM.OSProfile.WindowsConfiguration == null)

0 commit comments

Comments
 (0)