Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
Allow package command to just take a snapshot
Browse files Browse the repository at this point in the history
Currently, the snapshot sub-command is not supported
for this provider, but the ability to take ami snapshots
is supported inside of the package command.

This patch adds an option: `package_only_snapshot`
that allows you to use the package option to only
take a snapshot.
  • Loading branch information
bodepd committed Aug 2, 2016
1 parent 770627c commit d962eb2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ This provider exposes quite a few provider-specific configuration options:
* `tenancy` - When running in a VPC configure the tenancy of the instance. Supports 'default' and 'dedicated'.
* `tags` - A hash of tags to set on the machine.
* `package_tags` - A hash of tags to set on the ami generated during the package operation.
* `package_only_snapshot` - A boolean that indicates whether the package command should only
create an AMI snapshop. Defaults to false.
* `use_iam_profile` - If true, will use [IAM profiles](http://docs.aws.amazon.com/IAM/latest/UserGuide/instance-profiles.html)
for credentials.
* `block_device_mapping` - Amazon EC2 Block Device Mapping Property
Expand Down
44 changes: 24 additions & 20 deletions lib/vagrant-aws/action/package_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,30 @@ def call(env)
raise Errors::FogError, :message => e.message
end

# Handles inclusions from --include and --vagrantfile options
setup_package_files(env)

# Setup the temporary directory for the tarball files
@temp_dir = env[:tmp_path].join(Time.now.to_i.to_s)
env["export.temp_dir"] = @temp_dir
FileUtils.mkpath(env["export.temp_dir"])

# Create the Vagrantfile and metadata.json files from templates to go in the box
create_vagrantfile(env)
create_metadata_file(env)

# Just match up a couple environmental variables so that
# the superclass will do the right thing. Then, call the
# superclass to actually create the tarball (.box file)
env["package.directory"] = env["export.temp_dir"]
general_call(env)

# Always call recover to clean up the temp dir
clean_temp_dir
region=env[:machine].provider_config.region
region_config=env[:machine].provider_config.get_region_config(region)
if !region_config.package_only_snapshot
# Handles inclusions from --include and --vagrantfile options
setup_package_files(env)

# Setup the temporary directory for the tarball files
@temp_dir = env[:tmp_path].join(Time.now.to_i.to_s)
env["export.temp_dir"] = @temp_dir
FileUtils.mkpath(env["export.temp_dir"])

# Create the Vagrantfile and metadata.json files from templates to go in the box
create_vagrantfile(env)
create_metadata_file(env)

# Just match up a couple environmental variables so that
# the superclass will do the right thing. Then, call the
# superclass to actually create the tarball (.box file)
env["package.directory"] = env["export.temp_dir"]
general_call(env)

# Always call recover to clean up the temp dir
clean_temp_dir
end
end

protected
Expand Down
7 changes: 7 additions & 0 deletions lib/vagrant-aws/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ class Config < Vagrant.plugin("2", :config)
# @return [Hash<String, String>]
attr_accessor :package_tags

# Whether to create a vagrant package or just take a snapshot when running
# the package subcommand.
#
# @return [Boolean]
attr_accessor :package_only_snapshot

# Use IAM Instance Role for authentication to AWS instead of an
# explicit access_id and secret_access_key
#
Expand Down Expand Up @@ -215,6 +221,7 @@ def initialize(region_specific=false)
@subnet_id = UNSET_VALUE
@tags = {}
@package_tags = {}
@package_only_snapshot = false
@user_data = UNSET_VALUE
@use_iam_profile = UNSET_VALUE
@block_device_mapping = []
Expand Down
1 change: 1 addition & 0 deletions spec/vagrant-aws/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
its("iam_instance_profile_name") { should be_nil }
its("tags") { should == {} }
its("package_tags") { should == {} }
its("package_only_snapshot") { should == false }
its("user_data") { should be_nil }
its("use_iam_profile") { should be false }
its("block_device_mapping") {should == [] }
Expand Down

0 comments on commit d962eb2

Please sign in to comment.