Skip to content

Commit cc94edd

Browse files
committed
Merge pull request Azure#321 from ClogenyTechnologies/sid-chef-extension-bootstrap-opts
Implemented bootstrap option for chef extension
2 parents e7ee318 + 858709c commit cc94edd

File tree

3 files changed

+98
-9
lines changed

3 files changed

+98
-9
lines changed

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/Chef/SetAzureVMChefExtension.cs

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ public class SetAzureVMChefExtensionCommand : VirtualMachineChefExtensionCmdletB
5353
[ValidateNotNullOrEmpty]
5454
public string ClientRb { get; set; }
5555

56+
[Parameter(
57+
ValueFromPipelineByPropertyName = true,
58+
HelpMessage = "The Chef Client bootstrap options in JSON format.")]
59+
[ValidateNotNullOrEmpty]
60+
public string BootstrapOptions { get; set; }
61+
5662
[Parameter(
5763
ValueFromPipelineByPropertyName = true,
5864
HelpMessage = "The Chef Server Node Runlist.")]
@@ -84,6 +90,12 @@ public class SetAzureVMChefExtensionCommand : VirtualMachineChefExtensionCmdletB
8490
[ValidateNotNullOrEmpty]
8591
public SwitchParameter AutoUpdateChefClient { get; set; }
8692

93+
[Parameter(
94+
ValueFromPipelineByPropertyName = true,
95+
HelpMessage = "Delete the chef config files during update/uninstall extension. Default is false.")]
96+
[ValidateNotNullOrEmpty]
97+
public SwitchParameter DeleteChefConfig { get; set; }
98+
8799
[Parameter(
88100
Mandatory = true,
89101
ParameterSetName = LinuxParameterSetName,
@@ -152,7 +164,9 @@ private void SetPublicConfig()
152164
bool IsChefServerUrlEmpty = string.IsNullOrEmpty(this.ChefServerUrl);
153165
bool IsValidationClientNameEmpty = string.IsNullOrEmpty(this.ValidationClientName);
154166
bool IsRunListEmpty = string.IsNullOrEmpty(this.RunList);
167+
bool IsBootstrapOptionsEmpty = string.IsNullOrEmpty(this.BootstrapOptions);
155168
string AutoUpdateChefClient = this.AutoUpdateChefClient.IsPresent ? "true" : "false";
169+
string DeleteChefConfig = this.DeleteChefConfig.IsPresent ? "true" : "false";
156170

157171
//Cases handled:
158172
// 1. When clientRb given by user and:
@@ -204,17 +218,43 @@ private void SetPublicConfig()
204218

205219
if (IsRunListEmpty)
206220
{
207-
this.PublicConfiguration = string.Format("{{{0},{1}}}",
208-
string.Format(AutoUpdateTemplate, AutoUpdateChefClient),
209-
string.Format(ClientRbTemplate, ClientConfig));
221+
if (IsBootstrapOptionsEmpty)
222+
{
223+
this.PublicConfiguration = string.Format("{{{0},{1},{2}}}",
224+
string.Format(AutoUpdateTemplate, AutoUpdateChefClient),
225+
string.Format(DeleteChefConfigTemplate, DeleteChefConfig),
226+
string.Format(ClientRbTemplate, ClientConfig));
227+
}
228+
else
229+
{
230+
this.PublicConfiguration = string.Format("{{{0},{1},{2},{3}}}",
231+
string.Format(AutoUpdateTemplate, AutoUpdateChefClient),
232+
string.Format(DeleteChefConfigTemplate, DeleteChefConfig),
233+
string.Format(ClientRbTemplate, ClientConfig),
234+
string.Format(BootStrapOptionsTemplate, this.BootstrapOptions));
235+
}
210236
}
211237
else
212238
{
213-
this.PublicConfiguration = string.Format("{{{0},{1},{2}}}",
214-
string.Format(AutoUpdateTemplate, AutoUpdateChefClient),
215-
string.Format(ClientRbTemplate, ClientConfig),
216-
string.Format(RunListTemplate, this.RunList));
239+
if (IsBootstrapOptionsEmpty)
240+
{
241+
this.PublicConfiguration = string.Format("{{{0},{1},{2},{3}}}",
242+
string.Format(AutoUpdateTemplate, AutoUpdateChefClient),
243+
string.Format(DeleteChefConfigTemplate, DeleteChefConfig),
244+
string.Format(ClientRbTemplate, ClientConfig),
245+
string.Format(RunListTemplate, this.RunList));
246+
}
247+
else
248+
{
249+
this.PublicConfiguration = string.Format("{{{0},{1},{2},{3},{4}}",
250+
string.Format(AutoUpdateTemplate, AutoUpdateChefClient),
251+
string.Format(DeleteChefConfigTemplate, DeleteChefConfig),
252+
string.Format(ClientRbTemplate, ClientConfig),
253+
string.Format(RunListTemplate, this.RunList),
254+
string.Format(BootStrapOptionsTemplate, this.BootstrapOptions));
255+
}
217256
}
257+
218258
}
219259

220260
protected override void ValidateParameters()

src/ServiceManagement/Compute/Commands.ServiceManagement/IaaS/Extensions/Chef/VirtualMachineChefExtensionCmdletBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public class VirtualMachineChefExtensionCmdletBase : VirtualMachineExtensionCmdl
2323
protected const string LinuxExtensionName = "LinuxChefClient";
2424
protected const string PrivateConfigurationTemplate = "{{\"validation_key\":\"{0}\"}}";
2525
protected const string AutoUpdateTemplate = "\"autoUpdateClient\":\"{0}\"";
26+
protected const string DeleteChefConfigTemplate = "\"deleteChefConfig\":\"{0}\"";
2627
protected const string ClientRbTemplate = "\"client_rb\":\"{0}\"";
28+
protected const string BootStrapOptionsTemplate = "\"bootstrap_options\":{0}";
2729
protected const string RunListTemplate = "\"runlist\": \"\\\"{0}\\\"\"";
2830

2931
public VirtualMachineChefExtensionCmdletBase()

src/ServiceManagement/Compute/Commands.ServiceManagement/Microsoft.WindowsAzure.Commands.ServiceManagement.dll-Help.xml

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34584,6 +34584,29 @@ PS C:\> Get-AzureVM -ServiceName "ContosoService03" -Name "Con
3458434584
</dev:type>
3458534585
<dev:defaultValue></dev:defaultValue>
3458634586
</command:parameter>
34587+
<command:parameter required="false" variableLength="false" globbing="false" position="named">
34588+
<maml:name>DeleteChefConfig</maml:name>
34589+
<maml:description>
34590+
<maml:para>DeleteChefConfig Options determines whether Chef configuration files removed when Azure removes the Chef resource extension from the VM. This options is useful during extension update and uninstall process. Default is false</maml:para>
34591+
</maml:description>
34592+
<dev:type>
34593+
<maml:name>Boolean</maml:name>
34594+
<maml:uri/>
34595+
</dev:type>
34596+
<dev:defaultValue>false</dev:defaultValue>
34597+
</command:parameter>
34598+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="named">
34599+
<maml:name>BootstrapOptions</maml:name>
34600+
<maml:description>
34601+
<maml:para>Bootstrap Options in JSON Format</maml:para>
34602+
</maml:description>
34603+
<command:parameterValue required="false" variableLength="false">BootstrapOptions</command:parameterValue>
34604+
<dev:type>
34605+
<maml:name>String</maml:name>
34606+
<maml:uri/>
34607+
</dev:type>
34608+
<dev:defaultValue></dev:defaultValue>
34609+
</command:parameter>
3458734610
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="named">
3458834611
<maml:name>ValidationClientName</maml:name>
3458934612
<maml:description>
@@ -34716,14 +34739,38 @@ PS C:\&gt; Get-AzureVM -ServiceName &quot;ContosoService03&quot; -Name &quot;Con
3471634739
</command:commandLine>
3471734740
</command:commandLines>
3471834741
</command:example>
34719-
3472034742
<command:example>
3472134743
<maml:title>
3472234744
-------------------------- EXAMPLE 2 --------------------------
3472334745
</maml:title>
3472434746
<maml:introduction>
3472534747
<maml:para>C:\PS&gt;</maml:para>
3472634748
</maml:introduction>
34749+
<dev:code>
34750+
Set-AzureVMChefExtension -VM $vm -ValidationPem "C:\\myorg-validator.pem" -BootstrapOptions '{"chef_node_name":"your_node_name","chef_server_url":"https://api.opscode.com/organizations/some-org", "validation_client_name":"some-org-validator"}' -RunList "apache" -Windows;
34751+
</dev:code>
34752+
<dev:remarks>
34753+
<maml:para>Description</maml:para>
34754+
<maml:para>-----------</maml:para>
34755+
<maml:para>This cmdlet adds the Chef extension to a windows VM.</maml:para>
34756+
<maml:para>When the VM comes up, it will be bootstrapped with Chef and have apache running on it, while bootstraping it will refer 'BootstrapOptions' specified in JSON format.</maml:para>
34757+
<maml:para></maml:para>
34758+
<maml:para></maml:para>
34759+
<maml:para></maml:para>
34760+
</dev:remarks>
34761+
<command:commandLines>
34762+
<command:commandLine>
34763+
<command:commandText></command:commandText>
34764+
</command:commandLine>
34765+
</command:commandLines>
34766+
</command:example>
34767+
<command:example>
34768+
<maml:title>
34769+
-------------------------- EXAMPLE 3 --------------------------
34770+
</maml:title>
34771+
<maml:introduction>
34772+
<maml:para>C:\PS&gt;</maml:para>
34773+
</maml:introduction>
3472734774
<dev:code>
3472834775
Set-AzureVMChefExtension -VM $vm -ValidationPem "C:\\myorg-validator.pem" -ChefServerUrl "http://ipaddress:port" -ValidationClientName "myorg-validator" -RunList "apache, git" -Windows;
3472934776
</dev:code>
@@ -34745,7 +34792,7 @@ PS C:\&gt; Get-AzureVM -ServiceName &quot;ContosoService03&quot; -Name &quot;Con
3474534792

3474634793
<command:example>
3474734794
<maml:title>
34748-
-------------------------- EXAMPLE 3 --------------------------
34795+
-------------------------- EXAMPLE 4 --------------------------
3474934796
</maml:title>
3475034797
<maml:introduction>
3475134798
<maml:para>C:\PS&gt;</maml:para>

0 commit comments

Comments
 (0)