@@ -58,7 +58,6 @@ public class SetAzureVMChefExtensionCommand : VirtualMachineExtensionBaseCmdlet
58
58
59
59
[ Alias ( "HandlerVersion" , "Version" ) ]
60
60
[ Parameter (
61
- Mandatory = true ,
62
61
Position = 9 ,
63
62
ValueFromPipelineByPropertyName = true ,
64
63
HelpMessage = "The extension version." ) ]
@@ -224,7 +223,7 @@ private Hashtable PublicConfiguration
224
223
bool IsBootstrapOptionsEmpty = string . IsNullOrEmpty ( this . BootstrapOptions ) ;
225
224
string AutoUpdateChefClient = this . AutoUpdateChefClient . IsPresent ? "true" : "false" ;
226
225
string DeleteChefConfig = this . DeleteChefConfig . IsPresent ? "true" : "false" ;
227
- string BootstrapVersion = this . BootstrapVersion ;
226
+ string BootstrapVersion = string . IsNullOrEmpty ( this . BootstrapVersion ) ? "" : this . BootstrapVersion ;
228
227
string UninstallChefClient = this . UninstallChefClient . IsPresent ? "true" : "false" ;
229
228
230
229
//Cases handled:
@@ -389,15 +388,30 @@ private void SetDefault()
389
388
this . Name = ExtensionDefaultName ;
390
389
}
391
390
392
- //Uncomment this when GetLatestChefExtensionVersion() is implemented
393
- //this.TypeHandlerVersion = this.TypeHandlerVersion ?? GetLatestChefExtensionVersion();
391
+ this . TypeHandlerVersion = this . TypeHandlerVersion ?? GetLatestChefExtensionVersion ( ) ;
394
392
}
395
393
396
394
private string GetLatestChefExtensionVersion ( )
397
- {
398
- //Right now chef extension's major version is freezed as 1210.
399
- //Todo: Implement proper logic to fetch the current major.minor version number
400
- return "1210.12" ;
395
+ {
396
+ var result = ComputeClient . ComputeManagementClient . VirtualMachineExtensionImages . ListVersionsWithHttpMessagesAsync ( this . Location , ExtensionDefaultPublisher , this . Name ) . GetAwaiter ( ) . GetResult ( ) ;
397
+
398
+ var images = from r in result . Body
399
+ select new PSVirtualMachineExtensionImage
400
+ {
401
+ RequestId = result . RequestId ,
402
+ StatusCode = result . Response . StatusCode ,
403
+ Id = r . Id ,
404
+ Location = r . Location ,
405
+ Version = r . Name ,
406
+ PublisherName = ExtensionDefaultPublisher ,
407
+ Type = this . Name
408
+ } ;
409
+
410
+ var maxVersion = images . Max ( extension => extension . Version ) ;
411
+ string [ ] separators = { "." } ;
412
+ string [ ] splitVersion = maxVersion . Split ( separators , StringSplitOptions . None ) ;
413
+ string majorMinorVersion = splitVersion [ 0 ] + "." + splitVersion [ 1 ] ;
414
+ return majorMinorVersion ;
401
415
}
402
416
403
417
private void ValidateParameters ( )
0 commit comments