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

Commit 08633c8

Browse files
committed
Allow package command to just take a snapshot
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.
1 parent 770627c commit 08633c8

File tree

4 files changed

+34
-20
lines changed

4 files changed

+34
-20
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ This provider exposes quite a few provider-specific configuration options:
161161
* `tenancy` - When running in a VPC configure the tenancy of the instance. Supports 'default' and 'dedicated'.
162162
* `tags` - A hash of tags to set on the machine.
163163
* `package_tags` - A hash of tags to set on the ami generated during the package operation.
164+
* `package_only_snapshot` - A boolean that indicates whether the package command should only
165+
create an AMI snapshot and not create a vagrant box. Defaults to false.
164166
* `use_iam_profile` - If true, will use [IAM profiles](http://docs.aws.amazon.com/IAM/latest/UserGuide/instance-profiles.html)
165167
for credentials.
166168
* `block_device_mapping` - Amazon EC2 Block Device Mapping Property

lib/vagrant-aws/action/package_instance.rb

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,30 @@ def call(env)
9292
raise Errors::FogError, :message => e.message
9393
end
9494

95-
# Handles inclusions from --include and --vagrantfile options
96-
setup_package_files(env)
97-
98-
# Setup the temporary directory for the tarball files
99-
@temp_dir = env[:tmp_path].join(Time.now.to_i.to_s)
100-
env["export.temp_dir"] = @temp_dir
101-
FileUtils.mkpath(env["export.temp_dir"])
102-
103-
# Create the Vagrantfile and metadata.json files from templates to go in the box
104-
create_vagrantfile(env)
105-
create_metadata_file(env)
106-
107-
# Just match up a couple environmental variables so that
108-
# the superclass will do the right thing. Then, call the
109-
# superclass to actually create the tarball (.box file)
110-
env["package.directory"] = env["export.temp_dir"]
111-
general_call(env)
112-
113-
# Always call recover to clean up the temp dir
114-
clean_temp_dir
95+
region=env[:machine].provider_config.region
96+
region_config=env[:machine].provider_config.get_region_config(region)
97+
if !region_config.package_only_snapshot
98+
# Handles inclusions from --include and --vagrantfile options
99+
setup_package_files(env)
100+
101+
# Setup the temporary directory for the tarball files
102+
@temp_dir = env[:tmp_path].join(Time.now.to_i.to_s)
103+
env["export.temp_dir"] = @temp_dir
104+
FileUtils.mkpath(env["export.temp_dir"])
105+
106+
# Create the Vagrantfile and metadata.json files from templates to go in the box
107+
create_vagrantfile(env)
108+
create_metadata_file(env)
109+
110+
# Just match up a couple environmental variables so that
111+
# the superclass will do the right thing. Then, call the
112+
# superclass to actually create the tarball (.box file)
113+
env["package.directory"] = env["export.temp_dir"]
114+
general_call(env)
115+
116+
# Always call recover to clean up the temp dir
117+
clean_temp_dir
118+
end
115119
end
116120

117121
protected

lib/vagrant-aws/config.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ class Config < Vagrant.plugin("2", :config)
114114
# @return [Hash<String, String>]
115115
attr_accessor :package_tags
116116

117+
# Whether to create a vagrant package or just take a snapshot when running
118+
# the package subcommand.
119+
#
120+
# @return [Boolean]
121+
attr_accessor :package_only_snapshot
122+
117123
# Use IAM Instance Role for authentication to AWS instead of an
118124
# explicit access_id and secret_access_key
119125
#
@@ -215,6 +221,7 @@ def initialize(region_specific=false)
215221
@subnet_id = UNSET_VALUE
216222
@tags = {}
217223
@package_tags = {}
224+
@package_only_snapshot = false
218225
@user_data = UNSET_VALUE
219226
@use_iam_profile = UNSET_VALUE
220227
@block_device_mapping = []

spec/vagrant-aws/config_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
its("iam_instance_profile_name") { should be_nil }
4747
its("tags") { should == {} }
4848
its("package_tags") { should == {} }
49+
its("package_only_snapshot") { should == false }
4950
its("user_data") { should be_nil }
5051
its("use_iam_profile") { should be false }
5152
its("block_device_mapping") {should == [] }

0 commit comments

Comments
 (0)