Skip to content
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

Add support for Linode StackScripts via the stackscript/stackscriptid attributes #60

Merged
merged 1 commit into from
Jun 14, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 37 additions & 1 deletion lib/vagrant-linode/actions/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ def call(env)
root_pass = Digest::SHA2.new.update(@machine.provider_config.api_key).to_s
end

if @machine.provider_config.stackscript
stackscripts = @client.stackscript.list + @client.avail.stackscripts
stackscript = stackscripts.find { |s| s.label.downcase == @machine.provider_config.stackscript.to_s.downcase }
Copy link
Owner

@displague displague May 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see us find from the private list, then find from the public list if there was no private match.

fail(Errors::StackscriptMatch, stackscript: @machine.provider_config.stackscript.to_s) if stackscript.nil?
stackscript_id = stackscript.stackscriptid || nil
else
stackscript_id = @machine.provider_config.stackscriptid
end

stackscript_udf_responses = @machine.provider_config.stackscript_udf_responses

if stackscript_udf_responses and !stackscript_udf_responses.is_a?(Hash)
fail(Errors::StackscriptUDFFormat, format: stackscript_udf_responses.class.to_s)
else
stackscript_udf_responses = { }
end

if @machine.provider_config.distribution
distributions = @client.avail.distributions
distribution = distributions.find { |d| d.label.downcase.include? @machine.provider_config.distribution.downcase }
Expand Down Expand Up @@ -114,7 +131,26 @@ def call(env)
# assign the machine id for reference in other commands
@machine.id = result['linodeid'].to_s

if distribution_id
if stackscript_id
swap = @client.linode.disk.create(
linodeid: result['linodeid'],
label: 'Vagrant swap',
type: 'swap',
size: swap_size
)

disk = @client.linode.disk.createfromstackscript(
linodeid: result['linodeid'],
stackscriptid: stackscript_id,
stackscriptudfresponses: JSON.dump(stackscript_udf_responses),
distributionid: distribution_id,
label: 'Vagrant Disk Distribution ' + distribution_id.to_s + ' Linode ' + result['linodeid'].to_s,
type: 'ext4',
size: xvda_size,
rootsshkey: pubkey,
rootpass: root_pass
)
elsif distribution_id
swap = @client.linode.disk.create(
linodeid: result['linodeid'],
label: 'Vagrant swap',
Expand Down
13 changes: 13 additions & 0 deletions lib/vagrant-linode/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class Config < Vagrant.plugin('2', :config)
attr_accessor :ca_path
attr_accessor :ssh_key_name
attr_accessor :setup
attr_accessor :stackscriptid
attr_accessor :stackscript
attr_accessor :stackscript_udf_responses
attr_accessor :xvda_size
attr_accessor :swap_size
attr_accessor :kernelid
Expand All @@ -34,6 +37,9 @@ def initialize
@api_url = UNSET_VALUE
@distributionid = UNSET_VALUE
@distribution = UNSET_VALUE
@stackscriptid = UNSET_VALUE
@stackscript = UNSET_VALUE
@stackscript_udf_responses = UNSET_VALUE
@imageid = UNSET_VALUE
@image = UNSET_VALUE
@datacenterid = UNSET_VALUE
Expand Down Expand Up @@ -63,6 +69,9 @@ def finalize!
@distributionid = nil if @distributionid == UNSET_VALUE
@distribution = nil if @distribution == UNSET_VALUE
@distribution = 'Ubuntu 14.04 LTS' if @distribution.nil? and @distributionid.nil? and @imageid.nil? and @image.nil?
@stackscriptid = nil if @stackscriptid == UNSET_VALUE
@stackscript = nil if @stackscript == UNSET_VALUE
@stackscript_udf_responses = nil if @stackscript_udf_responses == UNSET_VALUE
@datacenterid = nil if @datacenterid == UNSET_VALUE
@datacenter = nil if @datacenter == UNSET_VALUE
@datacenter = 'dallas' if @datacenter.nil? and @datacenterid.nil?
Expand Down Expand Up @@ -101,6 +110,10 @@ def validate(machine)
errors << I18n.t('vagrant_linode.config.distributionid_or_distribution')
end

if @stackscriptid and @stackscript
errors << I18n.t('vagrant_linode.config.stackscriptid_or_stackscript')
end

if @datacenterid and @datacenter
errors << I18n.t('vagrant_linode.config.datacenterid_or_datacenter')
end
Expand Down
8 changes: 8 additions & 0 deletions lib/vagrant-linode/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ class PublicKeyError < LinodeError
class RsyncError < LinodeError
error_key(:rsync)
end

class StackscriptMatch < LinodeError
error_key(:stackscript_match)
end

class StackscriptUDFFormat < LinodeError
error_key(:stackscript_udf_responses)
end
end
end
end
6 changes: 6 additions & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ en:
disk_too_large: "Disk Images use more drive space than plan allocates"
planid_or_plan: "Use either planid or plan, not both"
distributionid_or_distribution: "Use either distributionid or distribution, not both"
stackscriptid_or_stackscript: "Use either stackscriptid or stackscript, not both"
datacenterid_or_datacenter: "Use either datacenterid or datacenter, not both"
kernelid_or_kernel: "Use either kernelid or kernel, not both"
imageid_or_image: "Use either imageid or image, not both"
Expand Down Expand Up @@ -126,3 +127,8 @@ en:
plan_id: !-
The plan which you have specified ( %{plan} ) is not available at this time,
for more information regarding plans review the following url - https://www.linode.com/pricing
stackscript_match: !-
The provider does not have your chosen Stackscript ( %{stackscript} ).
Supported distributions can be found at the following url - https://manager.linode.com/stackscripts
stackscript_udf_responses: !-
The stackscript UDF responses object provided is of the wrong type. It should be a Hash.