Skip to content

Implemented bootstrap option for chef extension #321

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

Merged
merged 3 commits into from
May 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public class SetAzureVMChefExtensionCommand : VirtualMachineChefExtensionCmdletB
[ValidateNotNullOrEmpty]
public string ClientRb { get; set; }

[Parameter(
ValueFromPipelineByPropertyName = true,
HelpMessage = "The Chef Client bootstrap options in JSON format.")]
[ValidateNotNullOrEmpty]
public string BootstrapOptions { get; set; }

[Parameter(
ValueFromPipelineByPropertyName = true,
HelpMessage = "The Chef Server Node Runlist.")]
Expand Down Expand Up @@ -84,6 +90,12 @@ public class SetAzureVMChefExtensionCommand : VirtualMachineChefExtensionCmdletB
[ValidateNotNullOrEmpty]
public SwitchParameter AutoUpdateChefClient { get; set; }

[Parameter(
ValueFromPipelineByPropertyName = true,
HelpMessage = "Delete the chef config files during update/uninstall extension. Default is false.")]
[ValidateNotNullOrEmpty]
public SwitchParameter DeleteChefConfig { get; set; }

[Parameter(
Mandatory = true,
ParameterSetName = LinuxParameterSetName,
Expand Down Expand Up @@ -152,7 +164,9 @@ private void SetPublicConfig()
bool IsChefServerUrlEmpty = string.IsNullOrEmpty(this.ChefServerUrl);
bool IsValidationClientNameEmpty = string.IsNullOrEmpty(this.ValidationClientName);
bool IsRunListEmpty = string.IsNullOrEmpty(this.RunList);
bool IsBootstrapOptionsEmpty = string.IsNullOrEmpty(this.BootstrapOptions);
string AutoUpdateChefClient = this.AutoUpdateChefClient.IsPresent ? "true" : "false";
string DeleteChefConfig = this.DeleteChefConfig.IsPresent ? "true" : "false";

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

if (IsRunListEmpty)
{
this.PublicConfiguration = string.Format("{{{0},{1}}}",
string.Format(AutoUpdateTemplate, AutoUpdateChefClient),
string.Format(ClientRbTemplate, ClientConfig));
if (IsBootstrapOptionsEmpty)
{
this.PublicConfiguration = string.Format("{{{0},{1},{2}}}",
string.Format(AutoUpdateTemplate, AutoUpdateChefClient),
string.Format(DeleteChefConfigTemplate, DeleteChefConfig),
string.Format(ClientRbTemplate, ClientConfig));
}
else
{
this.PublicConfiguration = string.Format("{{{0},{1},{2},{3}}}",
string.Format(AutoUpdateTemplate, AutoUpdateChefClient),
string.Format(DeleteChefConfigTemplate, DeleteChefConfig),
string.Format(ClientRbTemplate, ClientConfig),
string.Format(BootStrapOptionsTemplate, this.BootstrapOptions));
}
}
else
{
this.PublicConfiguration = string.Format("{{{0},{1},{2}}}",
string.Format(AutoUpdateTemplate, AutoUpdateChefClient),
string.Format(ClientRbTemplate, ClientConfig),
string.Format(RunListTemplate, this.RunList));
if (IsBootstrapOptionsEmpty)
{
this.PublicConfiguration = string.Format("{{{0},{1},{2},{3}}}",
string.Format(AutoUpdateTemplate, AutoUpdateChefClient),
string.Format(DeleteChefConfigTemplate, DeleteChefConfig),
string.Format(ClientRbTemplate, ClientConfig),
string.Format(RunListTemplate, this.RunList));
}
else
{
this.PublicConfiguration = string.Format("{{{0},{1},{2},{3},{4}}",
string.Format(AutoUpdateTemplate, AutoUpdateChefClient),
string.Format(DeleteChefConfigTemplate, DeleteChefConfig),
string.Format(ClientRbTemplate, ClientConfig),
string.Format(RunListTemplate, this.RunList),
string.Format(BootStrapOptionsTemplate, this.BootstrapOptions));
}
}

}

protected override void ValidateParameters()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public class VirtualMachineChefExtensionCmdletBase : VirtualMachineExtensionCmdl
protected const string LinuxExtensionName = "LinuxChefClient";
protected const string PrivateConfigurationTemplate = "{{\"validation_key\":\"{0}\"}}";
protected const string AutoUpdateTemplate = "\"autoUpdateClient\":\"{0}\"";
protected const string DeleteChefConfigTemplate = "\"deleteChefConfig\":\"{0}\"";
protected const string ClientRbTemplate = "\"client_rb\":\"{0}\"";
protected const string BootStrapOptionsTemplate = "\"bootstrap_options\":{0}";
protected const string RunListTemplate = "\"runlist\": \"\\\"{0}\\\"\"";

public VirtualMachineChefExtensionCmdletBase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33690,6 +33690,29 @@ PS C:\> Get-AzureVM -ServiceName "ContosoService03" -Name "Con
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" position="named">
<maml:name>DeleteChefConfig</maml:name>
<maml:description>
<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>
</maml:description>
<dev:type>
<maml:name>Boolean</maml:name>
<maml:uri/>
</dev:type>
<dev:defaultValue>false</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="named">
<maml:name>BootstrapOptions</maml:name>
<maml:description>
<maml:para>Bootstrap Options in JSON Format</maml:para>
</maml:description>
<command:parameterValue required="false" variableLength="false">BootstrapOptions</command:parameterValue>
<dev:type>
<maml:name>String</maml:name>
<maml:uri/>
</dev:type>
<dev:defaultValue></dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="named">
<maml:name>ValidationClientName</maml:name>
<maml:description>
Expand Down Expand Up @@ -33822,14 +33845,38 @@ PS C:\&gt; Get-AzureVM -ServiceName &quot;ContosoService03&quot; -Name &quot;Con
</command:commandLine>
</command:commandLines>
</command:example>

<command:example>
<maml:title>
-------------------------- EXAMPLE 2 --------------------------
</maml:title>
<maml:introduction>
<maml:para>C:\PS&gt;</maml:para>
</maml:introduction>
<dev:code>
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;
</dev:code>
<dev:remarks>
<maml:para>Description</maml:para>
<maml:para>-----------</maml:para>
<maml:para>This cmdlet adds the Chef extension to a windows VM.</maml:para>
<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>
<maml:para></maml:para>
<maml:para></maml:para>
<maml:para></maml:para>
</dev:remarks>
<command:commandLines>
<command:commandLine>
<command:commandText></command:commandText>
</command:commandLine>
</command:commandLines>
</command:example>
<command:example>
<maml:title>
-------------------------- EXAMPLE 3 --------------------------
</maml:title>
<maml:introduction>
<maml:para>C:\PS&gt;</maml:para>
</maml:introduction>
<dev:code>
Set-AzureVMChefExtension -VM $vm -ValidationPem "C:\\myorg-validator.pem" -ChefServerUrl "http://ipaddress:port" -ValidationClientName "myorg-validator" -RunList "apache, git" -Windows;
</dev:code>
Expand All @@ -33851,7 +33898,7 @@ PS C:\&gt; Get-AzureVM -ServiceName &quot;ContosoService03&quot; -Name &quot;Con

<command:example>
<maml:title>
-------------------------- EXAMPLE 3 --------------------------
-------------------------- EXAMPLE 4 --------------------------
</maml:title>
<maml:introduction>
<maml:para>C:\PS&gt;</maml:para>
Expand Down