-
Notifications
You must be signed in to change notification settings - Fork 4k
[Do not Mege] Updated Set-AzureRmVMChefExtension cmd #1676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f78bf28
Updated Set-AzureRmVMChefExtension cmd implementation to pass setting…
7f89c7a
Fixed client.rb file parsing error
c7e39ab
Fixed parsing issues when options like chef_server_url and validation…
2d2bd72
Added tests without recording
5e0bb00
Added Remove-AzureRmVMChefExtension command in ARM
7ba829b
Implemented Get-AzureRmVMChefExtension command
6274863
Updated specs to test Remove-AzureRmVMChefExtension and Get-AzureRmVM…
c0db9a5
Added BootstrapVersion and UninstallChefClient options
3a1604b
Fetching latest extension version
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/ChefExtensionTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Microsoft.WindowsAzure.Commands.ScenarioTest; | ||
using Xunit; | ||
|
||
namespace Microsoft.Azure.Commands.Compute.Test.ScenarioTests | ||
{ | ||
public class ChefExtensionTests | ||
{ | ||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void TestChefExtensionBasic() | ||
{ | ||
ComputeTestController.NewInstance.RunPsTest("Test-SetChefExtensionBasic"); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/ChefExtensionTests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# | ||
# ChefExtensionTests.ps1 | ||
# | ||
|
||
<# | ||
.SYNOPSIS | ||
Test the usage of the Set virtual machine chef extension command | ||
#> | ||
function Test-SetChefExtensionBasic | ||
{ | ||
$rgname = Get-ComputeTestResourceName | ||
$loc = Get-ComputeVMLocation | ||
|
||
try | ||
{ | ||
# Create Virtual Machine | ||
$vm = Create-VirtualMachine -rgname $rgname -loc $loc | ||
$vmname = $vm.Name | ||
$version = "1210.12" | ||
$client_rb = ".\Templates\client.rb"; | ||
$validationPemFile = ".\Templates\tstorgnztn-validator.pem"; | ||
|
||
# Set Chef extension | ||
Set-AzureRmVMChefExtension -ResourceGroupName $rgname -VMName $vmname -TypeHandlerVersion $version -ClientRb $client.rb -ValidationPem $validationPemFile -Windows | ||
$extension = Get-AzureRmVMChefExtension -ResourceGroupName $rgname -VMName $vmname | ||
|
||
Assert-NotNull $extension | ||
Assert-AreEqual $extension.Publisher 'Chef.Bootstrap.WindowsAzure' | ||
Assert-AreEqual $extension.ExtensionType 'ChefClient' | ||
Assert-AreEqual $extension.Name 'ChefClient' | ||
$settings = $extension.PublicSettings | ConvertFrom-Json | ||
Assert-AreEqual $settings.autoUpdateClient "false" | ||
Assert-AreEqual $settings.deleteChefConfig "false" | ||
|
||
# Test Remove command. | ||
Remove-AzureRmVMChefExtension -ResourceGroupName $rgname -VMName $vmname | ||
$extension = Get-AzureRmVMChefExtension -ResourceGroupName $rgname -VMName $vmname | ||
Assert-Null $extension | ||
} | ||
finally | ||
{ | ||
# Cleanup | ||
Clean-ResourceGroup $rgname | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/ResourceManager/Compute/Commands.Compute.Test/Templates/client.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
log_level :debug | ||
chef_server_url "https://api.chef.io/organizations/tstorgnztn" | ||
validation_client_name "tstorgnztn-validator" |
27 changes: 27 additions & 0 deletions
27
src/ResourceManager/Compute/Commands.Compute.Test/Templates/tstorgnztn-validator.pem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIEpAIBAAKCAQEAuxOLMJhoDZXc2WsRGPjj6UTw67Q1l0qdm8Zd/TQ092OCogbm | ||
Azk/84FdtMlZLCneZLkshn1l+KiD3W+lz4JG/We3SpDfO+pGDkVfHrwpiX6amMfo | ||
B4trELFo02oyzffO2LieInDqEldxId2c7LO3DpDlN0E3t3U0QYhs70Zd1kpHjFgO | ||
Zwzl9CZRt/eC4fU1b1upVhXdTEAkGTf6E2xF4IhXl5gJZBe6xPM+p5cX7IAHSHIJ | ||
2qVkVIT9TzkTJ/Tn1dOpye7E8bv6WxggQsFZg36MEEeebL3ra7OyTiiVLljs93YA | ||
oufYdsvsRhoi0W0tt9G+V2GbQjIaO6HzwiyCrQIDAQABAoIBADni/0PnNPNXNwJT | ||
vfOjOCq7OW1F0vtgjEpiZDzwRZ9zPD3UsqG2ulIn6o4Ba8Vdo0I5hkyLSt1Zj4wa | ||
ew0tu7e3uyComVrZ0BmkX52MDbJM6Zty6BpFiricnNomV1giYO/wmIYBuHw6cHhR | ||
MbiQl4k7TqH9XTc4XhYVF9gmRu0CgTa+/RmaSE37nWas27IF6KUYGs2WB2aOa+6/ | ||
BahZKGYYjEx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== | ||
-----END RSA PRIVATE KEY----- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
src/ResourceManager/Compute/Commands.Compute/Extension/Chef/GetAzureRmVMChefExtension.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Management.Automation; | ||
using Microsoft.Azure.Commands.Compute.Common; | ||
using Microsoft.Azure.Commands.Compute.Models; | ||
using Microsoft.Azure.Management.Compute; | ||
using Microsoft.Azure.Management.Compute.Models; | ||
using Microsoft.Rest.Azure; | ||
|
||
namespace Microsoft.Azure.Commands.Compute.Extension.Chef | ||
{ | ||
[Cmdlet( | ||
VerbsCommon.Get, | ||
ProfileNouns.VirtualMachineChefExtension), | ||
OutputType( | ||
typeof(PSVirtualMachineExtension))] | ||
public class GetAzureRmVMChefExtension : VirtualMachineExtensionBaseCmdlet | ||
{ | ||
private string ExtensionDefaultPublisher = "Chef.Bootstrap.WindowsAzure"; | ||
private string ExtensionDefaultName = "ChefClient"; | ||
private string LinuxExtensionName = "LinuxChefClient"; | ||
|
||
protected const string LinuxParameterSetName = "Linux"; | ||
protected const string WindowsParameterSetName = "Windows"; | ||
|
||
[Parameter( | ||
Mandatory = true, | ||
Position = 0, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = "The resource group name.")] | ||
[ValidateNotNullOrEmpty] | ||
public string ResourceGroupName { get; set; } | ||
|
||
[Alias("ResourceName")] | ||
[Parameter( | ||
Mandatory = true, | ||
Position = 1, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = "The virtual machine name.")] | ||
[ValidateNotNullOrEmpty] | ||
public string VMName { get; set; } | ||
|
||
[Alias("ExtensionName")] | ||
[Parameter( | ||
Mandatory = false, | ||
Position = 2, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = "Extension Name.")] | ||
public string Name { get; set; } | ||
|
||
[Parameter( | ||
Position = 3, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = "To show the status.")] | ||
[ValidateNotNullOrEmpty] | ||
public SwitchParameter Status { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = true, | ||
ParameterSetName = LinuxParameterSetName, | ||
HelpMessage = "Set extension for Linux.")] | ||
public SwitchParameter Linux { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = true, | ||
ParameterSetName = WindowsParameterSetName, | ||
HelpMessage = "Set extension for Windows.")] | ||
public SwitchParameter Windows { get; set; } | ||
|
||
public override void ExecuteCmdlet() | ||
{ | ||
base.ExecuteCmdlet(); | ||
|
||
if (this.Linux.IsPresent) | ||
{ | ||
this.Name = LinuxExtensionName; | ||
} | ||
else if (this.Windows.IsPresent) | ||
{ | ||
this.Name = ExtensionDefaultName; | ||
} | ||
|
||
ExecuteClientAction(() => | ||
{ | ||
if (string.IsNullOrEmpty(this.Name)) | ||
{ | ||
var virtualMachine = ComputeClient.ComputeManagementClient.VirtualMachines.Get(this.ResourceGroupName, this.VMName); | ||
var chefExtension = virtualMachine.Resources != null | ||
? virtualMachine.Resources.FirstOrDefault(extension => | ||
extension.Publisher.Equals(ExtensionDefaultPublisher, StringComparison.InvariantCultureIgnoreCase) && | ||
extension.VirtualMachineExtensionType.Equals(this.Name, StringComparison.InvariantCultureIgnoreCase)) | ||
: null; | ||
|
||
if (chefExtension == null) | ||
{ | ||
WriteObject(null); | ||
return; | ||
} | ||
else | ||
{ | ||
this.Name = chefExtension.Name; | ||
} | ||
} | ||
|
||
AzureOperationResponse<VirtualMachineExtension> virtualMachineExtensionGetResponse = null; | ||
if (Status.IsPresent) | ||
{ | ||
virtualMachineExtensionGetResponse = | ||
this.VirtualMachineExtensionClient.GetWithInstanceView(this.ResourceGroupName, | ||
this.VMName, this.Name); | ||
} | ||
else | ||
{ | ||
virtualMachineExtensionGetResponse = this.VirtualMachineExtensionClient.GetWithHttpMessagesAsync( | ||
this.ResourceGroupName, | ||
this.VMName, | ||
this.Name).GetAwaiter().GetResult(); | ||
} | ||
|
||
var returnedExtension = virtualMachineExtensionGetResponse.ToPSVirtualMachineExtension(this.ResourceGroupName); | ||
WriteObject(returnedExtension); | ||
}); | ||
} | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
src/ResourceManager/Compute/Commands.Compute/Extension/Chef/RemoveAzureRmVMChefExtension.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Management.Automation; | ||
using Microsoft.Azure.Commands.Compute.Common; | ||
using Microsoft.Azure.Management.Compute; | ||
using System.Globalization; | ||
using AutoMapper; | ||
using Microsoft.Azure.Commands.Compute.Models; | ||
using Microsoft.Azure.Management.Compute.Models; | ||
|
||
namespace Microsoft.Azure.Commands.Compute.Extension.Chef | ||
{ | ||
[Cmdlet( | ||
VerbsCommon.Remove, | ||
ProfileNouns.VirtualMachineChefExtension)] | ||
[OutputType(typeof(PSAzureOperationResponse))] | ||
public class RemoveAzureRmVMChefExtension : VirtualMachineExtensionBaseCmdlet | ||
{ | ||
private string ExtensionDefaultPublisher = "Chef.Bootstrap.WindowsAzure"; | ||
private string ExtensionDefaultName = "ChefClient"; | ||
private string LinuxExtensionName = "LinuxChefClient"; | ||
|
||
protected const string LinuxParameterSetName = "Linux"; | ||
protected const string WindowsParameterSetName = "Windows"; | ||
|
||
[Parameter( | ||
Mandatory = true, | ||
Position = 0, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = "The resource group name.")] | ||
[ValidateNotNullOrEmpty] | ||
public string ResourceGroupName { get; set; } | ||
|
||
[Alias("ResourceName")] | ||
[Parameter( | ||
Mandatory = true, | ||
Position = 1, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = "The virtual machine name.")] | ||
[ValidateNotNullOrEmpty] | ||
public string VMName { get; set; } | ||
|
||
[Alias("ExtensionName")] | ||
[Parameter( | ||
Mandatory = false, | ||
Position = 2, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = "Extension Name.")] | ||
public string Name | ||
{ | ||
get | ||
{ | ||
return this.ExtensionDefaultName; | ||
} | ||
set | ||
{ | ||
this.ExtensionDefaultName = value; | ||
} | ||
} | ||
|
||
[Parameter( | ||
Mandatory = true, | ||
ParameterSetName = LinuxParameterSetName, | ||
HelpMessage = "Set extension for Linux.")] | ||
public SwitchParameter Linux { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = true, | ||
ParameterSetName = WindowsParameterSetName, | ||
HelpMessage = "Set extension for Windows.")] | ||
public SwitchParameter Windows { get; set; } | ||
|
||
public override void ExecuteCmdlet() | ||
{ | ||
base.ExecuteCmdlet(); | ||
|
||
if (this.Linux.IsPresent) | ||
{ | ||
this.Name = LinuxExtensionName; | ||
} | ||
else if (this.Windows.IsPresent) | ||
{ | ||
this.Name = ExtensionDefaultName; | ||
} | ||
|
||
ExecuteClientAction(() => | ||
{ | ||
if (string.IsNullOrEmpty(this.Name)) | ||
{ | ||
VirtualMachine virtualMachine = ComputeClient.ComputeManagementClient.VirtualMachines.Get( | ||
this.ResourceGroupName, this.VMName); | ||
var chefExtension = virtualMachine.Resources != null | ||
? virtualMachine.Resources.FirstOrDefault(extension => | ||
extension.Publisher.Equals(ExtensionDefaultPublisher, StringComparison.InvariantCultureIgnoreCase) && | ||
extension.VirtualMachineExtensionType.Equals(this.Name, StringComparison.InvariantCultureIgnoreCase)) | ||
: null; | ||
|
||
if (chefExtension == null) | ||
{ | ||
WriteWarning(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ChefExtensionNotFound, this.ResourceGroupName, this.VMName)); | ||
return; | ||
} | ||
else | ||
{ | ||
this.Name = chefExtension.Name; | ||
} | ||
} | ||
|
||
var op = this.VirtualMachineExtensionClient.DeleteWithHttpMessagesAsync( | ||
this.ResourceGroupName, | ||
this.VMName, | ||
this.Name).GetAwaiter().GetResult(); | ||
var result = Mapper.Map<PSAzureOperationResponse>(op); | ||
WriteObject(result); | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please align the white-spaces in this file.