Skip to content

Commit 8f44634

Browse files
in progress
1 parent f272be6 commit 8f44634

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/Compute/Compute/Strategies/ComputeRp/VirtualMachineStrategy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig(
7474
OsProfile = new OSProfile
7575
{
7676
ComputerName = name,
77-
WindowsConfiguration = imageAndOsType.CreateWindowsConfiguration(),
77+
WindowsConfiguration = imageAndOsType?.CreateWindowsConfiguration(),
7878
LinuxConfiguration = (imageAndOsType?.OsType != OperatingSystemTypes.Linux) ? null : new LinuxConfiguration
7979
{
8080
Ssh = new SshConfiguration(sshPublicKeys)

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
using System.Diagnostics;
4949
using CM = Microsoft.Azure.Management.Compute.Models;
5050
using SM = Microsoft.Azure.PowerShell.Cmdlets.Compute.Helpers.Storage.Models;
51+
using Microsoft.Azure.Commands.Compute;
5152

5253

5354
namespace Microsoft.Azure.Commands.Compute
@@ -443,8 +444,8 @@ public async Task<ResourceConfig<VirtualMachine>> CreateConfigAsync()
443444
proximityPlacementGroup: ppgSubResourceFunc);
444445

445446

446-
List<SshPublicKey> sshPublicKeyList = new List<SshPublicKey>();
447-
if (_cmdlet.SshKeyName != null || _cmdlet.GenerateSshKey == true)
447+
List<SshPublicKey> sshPublicKeyList = null;
448+
if ( !String.IsNullOrEmpty(_cmdlet.SshKeyName) || _cmdlet.GenerateSshKey)
448449
{
449450
if (ImageAndOsType?.OsType != OperatingSystemTypes.Linux)
450451
{
@@ -453,12 +454,9 @@ public async Task<ResourceConfig<VirtualMachine>> CreateConfigAsync()
453454

454455
string publicKey = _cmdlet.SshKeyForLinux();
455456
SshPublicKey sshPublicKey = new SshPublicKey("/home/" + _cmdlet.Credential.UserName + "/.ssh/authorized_keys", publicKey);
457+
sshPublicKeyList = new List<SshPublicKey>();
456458
sshPublicKeyList.Add(sshPublicKey);
457459
}
458-
else
459-
{
460-
sshPublicKeyList = null;
461-
}
462460

463461
_cmdlet.ConfigAsyncVisited = true;
464462

@@ -634,8 +632,7 @@ async Task StrategyExecuteCmdletAsync(IAsyncCmdlet asyncCmdlet)
634632
//delete the created ssh key resource
635633

636634
WriteInformation("VM creation failed. Deleting the SSH key resource that was created.", new string[] { "PSHOST" });
637-
Microsoft.Azure.Commands.Compute.Automation.NewAzureSshKey sshKeyClass = new Microsoft.Azure.Commands.Compute.Automation.NewAzureSshKey();
638-
sshKeyClass.SshPublicKeyClient.Delete(this.ResourceGroupName, this.SshKeyName);
635+
SshPublicKeyClient.DeleteWithHttpMessagesAsync(this.ResourceGroupName, this.SshKeyName).GetAwaiter().GetResult();
639636
// throw exception
640637
throw ex;
641638
}
@@ -1071,7 +1068,7 @@ private static string GetStorageAccountNameFromUriString(string uriStr)
10711068

10721069
private string SshKeyForLinux()
10731070
{
1074-
if (this.ConfigAsyncVisited == true)
1071+
if (this.ConfigAsyncVisited)
10751072
{
10761073
this.GenerateSshKey = false;
10771074
}
@@ -1083,6 +1080,10 @@ private string SshKeyForLinux()
10831080

10841081

10851082
// check if -SshKeyName exists in azure
1083+
// TODO
1084+
//ComputeClient computeClinet = new ComputeClient(this.DefaultContext);
1085+
//computeClinet.ComputeManagementClient.SshPublicKeys sshPublicKeys
1086+
//ISshPublicKeysOperation sshKeyClass = Microsoft.Azure.Commands.Compute.Automation.ComputeAutomationBaseCmdlet.SshPublicKeyClient
10861087
Microsoft.Azure.Commands.Compute.Automation.NewAzureSshKey sshKeyClass = new Microsoft.Azure.Commands.Compute.Automation.NewAzureSshKey();
10871088
SshPublicKeyResource SshPublicKey;
10881089
string publicKey = "value";

0 commit comments

Comments
 (0)