48
48
using System . Diagnostics ;
49
49
using CM = Microsoft . Azure . Management . Compute . Models ;
50
50
using SM = Microsoft . Azure . PowerShell . Cmdlets . Compute . Helpers . Storage . Models ;
51
+ using Microsoft . Azure . Commands . Compute ;
51
52
52
53
53
54
namespace Microsoft . Azure . Commands . Compute
@@ -443,8 +444,8 @@ public async Task<ResourceConfig<VirtualMachine>> CreateConfigAsync()
443
444
proximityPlacementGroup : ppgSubResourceFunc ) ;
444
445
445
446
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 )
448
449
{
449
450
if ( ImageAndOsType ? . OsType != OperatingSystemTypes . Linux )
450
451
{
@@ -453,12 +454,9 @@ public async Task<ResourceConfig<VirtualMachine>> CreateConfigAsync()
453
454
454
455
string publicKey = _cmdlet . SshKeyForLinux ( ) ;
455
456
SshPublicKey sshPublicKey = new SshPublicKey ( "/home/" + _cmdlet . Credential . UserName + "/.ssh/authorized_keys" , publicKey ) ;
457
+ sshPublicKeyList = new List < SshPublicKey > ( ) ;
456
458
sshPublicKeyList . Add ( sshPublicKey ) ;
457
459
}
458
- else
459
- {
460
- sshPublicKeyList = null ;
461
- }
462
460
463
461
_cmdlet . ConfigAsyncVisited = true ;
464
462
@@ -634,8 +632,7 @@ async Task StrategyExecuteCmdletAsync(IAsyncCmdlet asyncCmdlet)
634
632
//delete the created ssh key resource
635
633
636
634
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 ( ) ;
639
636
// throw exception
640
637
throw ex ;
641
638
}
@@ -1071,7 +1068,7 @@ private static string GetStorageAccountNameFromUriString(string uriStr)
1071
1068
1072
1069
private string SshKeyForLinux ( )
1073
1070
{
1074
- if ( this . ConfigAsyncVisited == true )
1071
+ if ( this . ConfigAsyncVisited )
1075
1072
{
1076
1073
this . GenerateSshKey = false ;
1077
1074
}
@@ -1083,6 +1080,10 @@ private string SshKeyForLinux()
1083
1080
1084
1081
1085
1082
// 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
1086
1087
Microsoft . Azure . Commands . Compute . Automation . NewAzureSshKey sshKeyClass = new Microsoft . Azure . Commands . Compute . Automation . NewAzureSshKey ( ) ;
1087
1088
SshPublicKeyResource SshPublicKey ;
1088
1089
string publicKey = "value" ;
0 commit comments