vagrant-aws_stsmith 0.5.0.dev

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/.gitignore +21 -0
  2. data/CHANGELOG.md +76 -0
  3. data/Gemfile +10 -0
  4. data/LICENSE +8 -0
  5. data/README.md +251 -0
  6. data/Rakefile +21 -0
  7. data/dummy.box +0 -0
  8. data/example_box/README.md +13 -0
  9. data/example_box/metadata.json +3 -0
  10. data/lib/vagrant-aws/action/connect_aws.rb +46 -0
  11. data/lib/vagrant-aws/action/is_created.rb +18 -0
  12. data/lib/vagrant-aws/action/is_stopped.rb +18 -0
  13. data/lib/vagrant-aws/action/message_already_created.rb +16 -0
  14. data/lib/vagrant-aws/action/message_not_created.rb +16 -0
  15. data/lib/vagrant-aws/action/message_will_not_destroy.rb +16 -0
  16. data/lib/vagrant-aws/action/read_ssh_info.rb +53 -0
  17. data/lib/vagrant-aws/action/read_state.rb +38 -0
  18. data/lib/vagrant-aws/action/run_instance.rb +247 -0
  19. data/lib/vagrant-aws/action/start_instance.rb +81 -0
  20. data/lib/vagrant-aws/action/stop_instance.rb +28 -0
  21. data/lib/vagrant-aws/action/sync_folders.rb +118 -0
  22. data/lib/vagrant-aws/action/terminate_instance.rb +47 -0
  23. data/lib/vagrant-aws/action/timed_provision.rb +21 -0
  24. data/lib/vagrant-aws/action/wait_for_state.rb +41 -0
  25. data/lib/vagrant-aws/action/warn_networks.rb +19 -0
  26. data/lib/vagrant-aws/action.rb +190 -0
  27. data/lib/vagrant-aws/config.rb +372 -0
  28. data/lib/vagrant-aws/errors.rb +31 -0
  29. data/lib/vagrant-aws/plugin.rb +73 -0
  30. data/lib/vagrant-aws/provider.rb +50 -0
  31. data/lib/vagrant-aws/util/timer.rb +17 -0
  32. data/lib/vagrant-aws/version.rb +5 -0
  33. data/lib/vagrant-aws.rb +18 -0
  34. data/locales/en.yml +122 -0
  35. data/spec/vagrant-aws/config_spec.rb +216 -0
  36. data/vagrant-aws.gemspec +59 -0
  37. metadata +139 -0
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ # OS-specific
2
+ .DS_Store
3
+
4
+ # editors
5
+ *.swp
6
+
7
+ # Bundler/Rubygems
8
+ *.gem
9
+ .bundle
10
+ pkg/*
11
+ tags
12
+ Gemfile.lock
13
+
14
+ # Vagrant
15
+ .vagrant
16
+ Vagrantfile
17
+ !example_box/Vagrantfile
18
+
19
+ # RVM files for gemset/ruby setting
20
+ .ruby-*
21
+ .rvmrc
data/CHANGELOG.md ADDED
@@ -0,0 +1,76 @@
1
+ # 0.5.0 (unreleased)
2
+
3
+ # 0.4.1 (December 17, 2013)
4
+
5
+ * Update fog.io to 1.18.0
6
+ * Fix sync folder user permissions (GH #175)
7
+ * Fix vagrant < 1.3.0 provisioner compatibility (GH #173)
8
+ * Add vagrant 1.4.0 multiple SSH key support (GH #172)
9
+ * Fix EIP deallocation bug (GH #164)
10
+ * Add (per shared folder) rsync exclude flag (GH #156)
11
+
12
+ # 0.4.0 (October 11, 2013)
13
+
14
+ * Handle EIP allocation error (GH #134)
15
+ * Implement halt and reload (GH #31)
16
+ * rsync ignores Vagrantfile
17
+ * warn if none of the security groups allows incoming SSH
18
+ * bump fog.io to 1.15.0
19
+ * Fix rsync on windows (GH #77)
20
+ * Add `ssh_host_attribute` config (GH #143)
21
+
22
+ # 0.3.0 (September 2, 2013)
23
+
24
+ * Parallelize multi-machine up on Vagrant 1.2+
25
+ * Show proper configuration errors if an invalid configuration key
26
+ is used.
27
+ * Request confirmation on `vagrant destroy`, like normal VirtualBox + Vagrant.
28
+ * If user data is configured, output is shown on "vagrant up" that
29
+ it is being set.
30
+ * Add EIP support (GH #65)
31
+ * Add block device mapping support (GH #93)
32
+ * README improvements (GH #120)
33
+ * Fix missing locale message (GH #73)
34
+ * SyncFolders creates hostpath if it doesn't exist and `:create` option is set (GH #17)
35
+ * Add IAM Instance Profile support (GH #68)
36
+ * Add shutdown behavior support (GH #125,#131)
37
+
38
+ # 0.2.2 (April 18, 2013)
39
+
40
+ * Fix crashing bug with incorrect provisioner arguments.
41
+
42
+ # 0.2.1 (April 16, 2013)
43
+
44
+ * Got rid of extranneous references to old SSH settings.
45
+
46
+ # 0.2.0 (April 16, 2013)
47
+
48
+ * Add support for `vagrant ssh -c` [GH-42]
49
+ * Ability to specify a timeout for waiting for instances to become ready. [GH-44]
50
+ * Better error message if instance didn't become ready in time.
51
+ * Connection can now be done using IAM profiles. [GH-41]
52
+
53
+ # 0.1.3 (April 9, 2013)
54
+
55
+ * The `AWS_ACCESS_KEY` and `AWS_SECRET_KEY` will be used if available
56
+ and no specific keys are set in the Vagrantfile. [GH-33]
57
+ * Fix issues with SSH on VPCs, the correct IP is used. [GH-30]
58
+ * Exclude the ".vagrant" directory from rsync.
59
+ * Implement `:disabled` flag support for shared folders. [GH-29]
60
+ * `aws.user_data` to specify user data on the instance. [GH-26]
61
+
62
+ # 0.1.2 (March 22, 2013)
63
+
64
+ * Choose the proper region when connecting to AWS. [GH-9]
65
+ * Configurable SSH port. [GH-13]
66
+ * Support other AWS-compatible API endpoints with `config.endpoint`
67
+ and `config.version`. [GH-6]
68
+ * Disable strict host key checking on rsync so known hosts aren't an issue. [GH-7]
69
+
70
+ # 0.1.1 (March 18, 2013)
71
+
72
+ * Up fog dependency for Vagrant 1.1.1
73
+
74
+ # 0.1.0 (March 14, 2013)
75
+
76
+ * Initial release.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ # We depend on Vagrant for development, but we don't add it as a
7
+ # gem dependency because we expect to be installed within the
8
+ # Vagrant environment itself using `vagrant plugin`.
9
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
10
+ end
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2014 Mitchell Hashimoto
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,251 @@
1
+ # Vagrant AWS Provider
2
+
3
+ <span class="badges">
4
+ [![Gem Version](https://badge.fury.io/rb/vagrant-aws.png)][gem]
5
+ [![Dependency Status](https://gemnasium.com/mitchellh/vagrant-aws.png)][gemnasium]
6
+ </span>
7
+
8
+ [gem]: https://rubygems.org/gems/vagrant-aws
9
+ [gemnasium]: https://gemnasium.com/mitchellh/vagrant-aws
10
+
11
+ This is a [Vagrant](http://www.vagrantup.com) 1.2+ plugin that adds an [AWS](http://aws.amazon.com)
12
+ provider to Vagrant, allowing Vagrant to control and provision machines in
13
+ EC2 and VPC.
14
+
15
+ **NOTE:** This plugin requires Vagrant 1.2+,
16
+
17
+ ## Features
18
+
19
+ * Boot EC2 or VPC instances.
20
+ * SSH into the instances.
21
+ * Provision the instances with any built-in Vagrant provisioner.
22
+ * Minimal synced folder support via `rsync`.
23
+ * Define region-specifc configurations so Vagrant can manage machines
24
+ in multiple regions.
25
+
26
+ ## Usage
27
+
28
+ Install using standard Vagrant 1.1+ plugin installation methods. After
29
+ installing, `vagrant up` and specify the `aws` provider. An example is
30
+ shown below.
31
+
32
+ ```
33
+ $ vagrant plugin install vagrant-aws
34
+ ...
35
+ $ vagrant up --provider=aws
36
+ ...
37
+ ```
38
+
39
+ Of course prior to doing this, you'll need to obtain an AWS-compatible
40
+ box file for Vagrant.
41
+
42
+ ## Quick Start
43
+
44
+ After installing the plugin (instructions above), the quickest way to get
45
+ started is to actually use a dummy AWS box and specify all the details
46
+ manually within a `config.vm.provider` block. So first, add the dummy
47
+ box using any name you want:
48
+
49
+ ```
50
+ $ vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box
51
+ ...
52
+ ```
53
+
54
+ And then make a Vagrantfile that looks like the following, filling in
55
+ your information where necessary.
56
+
57
+ ```
58
+ Vagrant.configure("2") do |config|
59
+ config.vm.box = "dummy"
60
+
61
+ config.vm.provider :aws do |aws, override|
62
+ aws.access_key_id = "YOUR KEY"
63
+ aws.secret_access_key = "YOUR SECRET KEY"
64
+ aws.keypair_name = "KEYPAIR NAME"
65
+
66
+ aws.ami = "ami-7747d01e"
67
+
68
+ override.ssh.username = "ubuntu"
69
+ override.ssh.private_key_path = "PATH TO YOUR PRIVATE KEY"
70
+ end
71
+ end
72
+ ```
73
+
74
+ And then run `vagrant up --provider=aws`.
75
+
76
+ This will start an Ubuntu 12.04 instance in the us-east-1 region within
77
+ your account. And assuming your SSH information was filled in properly
78
+ within your Vagrantfile, SSH and provisioning will work as well.
79
+
80
+ Note that normally a lot of this boilerplate is encoded within the box
81
+ file, but the box file used for the quick start, the "dummy" box, has
82
+ no preconfigured defaults.
83
+
84
+ If you have issues with SSH connecting, make sure that the instances
85
+ are being launched with a security group that allows SSH access.
86
+
87
+ ## Box Format
88
+
89
+ Every provider in Vagrant must introduce a custom box format. This
90
+ provider introduces `aws` boxes. You can view an example box in
91
+ the [example_box/ directory](https://github.com/mitchellh/vagrant-aws/tree/master/example_box).
92
+ That directory also contains instructions on how to build a box.
93
+
94
+ The box format is basically just the required `metadata.json` file
95
+ along with a `Vagrantfile` that does default settings for the
96
+ provider-specific configuration for this provider.
97
+
98
+ ## Configuration
99
+
100
+ This provider exposes quite a few provider-specific configuration options:
101
+
102
+ * `access_key_id` - The access key for accessing AWS
103
+ * `ami` - The AMI id to boot, such as "ami-12345678"
104
+ * `availability_zone` - The availability zone within the region to launch
105
+ the instance. If nil, it will use the default set by Amazon.
106
+ * `instance_ready_timeout` - The number of seconds to wait for the instance
107
+ to become "ready" in AWS. Defaults to 120 seconds.
108
+ * `instance_type` - The type of instance, such as "m1.small". The default
109
+ value of this if not specified is "m1.small".
110
+ * `keypair_name` - The name of the keypair to use to bootstrap AMIs
111
+ which support it.
112
+ * `private_ip_address` - The private IP address to assign to an instance
113
+ within a [VPC](http://aws.amazon.com/vpc/)
114
+ * `region` - The region to start the instance in, such as "us-east-1"
115
+ * `secret_access_key` - The secret access key for accessing AWS
116
+ * `security_groups` - An array of security groups for the instance. If this
117
+ instance will be launched in VPC, this must be a list of security group
118
+ IDs.
119
+ * `iam_instance_profile_arn` - The Amazon resource name (ARN) of the IAM Instance
120
+ Profile to associate with the instance
121
+ * `iam_instance_profile_name` - The name of the IAM Instance Profile to associate
122
+ with the instance
123
+ * `subnet_id` - The subnet to boot the instance into, for VPC.
124
+ * `associate_public_ip` - If true, will associate a public IP address to an instance in a VPC.
125
+ * `tags` - A hash of tags to set on the machine.
126
+ * `use_iam_profile` - If true, will use [IAM profiles](http://docs.aws.amazon.com/IAM/latest/UserGuide/instance-profiles.html)
127
+ for credentials.
128
+
129
+ These can be set like typical provider-specific configuration:
130
+
131
+ ```ruby
132
+ Vagrant.configure("2") do |config|
133
+ # ... other stuff
134
+
135
+ config.vm.provider :aws do |aws|
136
+ aws.access_key_id = "foo"
137
+ aws.secret_access_key = "bar"
138
+ end
139
+ end
140
+ ```
141
+
142
+ In addition to the above top-level configs, you can use the `region_config`
143
+ method to specify region-specific overrides within your Vagrantfile. Note
144
+ that the top-level `region` config must always be specified to choose which
145
+ region you want to actually use, however. This looks like this:
146
+
147
+ ```ruby
148
+ Vagrant.configure("2") do |config|
149
+ # ... other stuff
150
+
151
+ config.vm.provider :aws do |aws|
152
+ aws.access_key_id = "foo"
153
+ aws.secret_access_key = "bar"
154
+ aws.region = "us-east-1"
155
+
156
+ # Simple region config
157
+ aws.region_config "us-east-1", :ami => "ami-12345678"
158
+
159
+ # More comprehensive region config
160
+ aws.region_config "us-west-2" do |region|
161
+ region.ami = "ami-87654321"
162
+ region.keypair_name = "company-west"
163
+ end
164
+ end
165
+ end
166
+ ```
167
+
168
+ The region-specific configurations will override the top-level
169
+ configurations when that region is used. They otherwise inherit
170
+ the top-level configurations, as you would probably expect.
171
+
172
+ ## Networks
173
+
174
+ Networking features in the form of `config.vm.network` are not
175
+ supported with `vagrant-aws`, currently. If any of these are
176
+ specified, Vagrant will emit a warning, but will otherwise boot
177
+ the AWS machine.
178
+
179
+ ## Synced Folders
180
+
181
+ There is minimal support for synced folders. Upon `vagrant up`,
182
+ `vagrant reload`, and `vagrant provision`, the AWS provider will use
183
+ `rsync` (if available) to uni-directionally sync the folder to
184
+ the remote machine over SSH.
185
+
186
+ This is good enough for all built-in Vagrant provisioners (shell,
187
+ chef, and puppet) to work!
188
+
189
+ ## Other Examples
190
+
191
+ ### Tags
192
+
193
+ To use tags, simply define a hash of key/value for the tags you want to associate to your instance, like:
194
+
195
+ ```ruby
196
+ Vagrant.configure("2") do |config|
197
+ # ... other stuff
198
+
199
+ config.vm.provider "aws" do |aws|
200
+ aws.tags = {
201
+ 'Name' => 'Some Name',
202
+ 'Some Key' => 'Some Value'
203
+ }
204
+ end
205
+ end
206
+ ```
207
+
208
+ ### User data
209
+
210
+ You can specify user data for the instance being booted.
211
+
212
+ ```ruby
213
+ Vagrant.configure("2") do |config|
214
+ # ... other stuff
215
+
216
+ config.vm.provider "aws" do |aws|
217
+ # Option 1: a single string
218
+ aws.user_data = "#!/bin/bash\necho 'got user data' > /tmp/user_data.log\necho"
219
+
220
+ # Option 2: use a file
221
+ aws.user_data = File.read("user_data.txt")
222
+ end
223
+ end
224
+ ```
225
+
226
+ ## Development
227
+
228
+ To work on the `vagrant-aws` plugin, clone this repository out, and use
229
+ [Bundler](http://gembundler.com) to get the dependencies:
230
+
231
+ ```
232
+ $ bundle
233
+ ```
234
+
235
+ Once you have the dependencies, verify the unit tests pass with `rake`:
236
+
237
+ ```
238
+ $ bundle exec rake
239
+ ```
240
+
241
+ If those pass, you're ready to start developing the plugin. You can test
242
+ the plugin without installing it into your Vagrant environment by just
243
+ creating a `Vagrantfile` in the top level of this directory (it is gitignored)
244
+ and add the following line to your `Vagrantfile`
245
+ ```ruby
246
+ Vagrant.require_plugin "vagrant-aws"
247
+ ```
248
+ Use bundler to execute Vagrant:
249
+ ```
250
+ $ bundle exec vagrant up --provider=aws
251
+ ```
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec/core/rake_task'
4
+
5
+ # Immediately sync all stdout so that tools like buildbot can
6
+ # immediately load in the output.
7
+ $stdout.sync = true
8
+ $stderr.sync = true
9
+
10
+ # Change to the directory of this file.
11
+ Dir.chdir(File.expand_path("../", __FILE__))
12
+
13
+ # This installs the tasks that help with gem creation and
14
+ # publishing.
15
+ Bundler::GemHelper.install_tasks
16
+
17
+ # Install the `spec` task so that we can run tests.
18
+ RSpec::Core::RakeTask.new
19
+
20
+ # Default task is to run the unit tests
21
+ task :default => "spec"
data/dummy.box ADDED
Binary file
@@ -0,0 +1,13 @@
1
+ # Vagrant AWS Example Box
2
+
3
+ Vagrant providers each require a custom provider-specific box format.
4
+ This folder shows the example contents of a box for the `aws` provider.
5
+ To turn this into a box:
6
+
7
+ ```
8
+ $ tar cvzf aws.box ./metadata.json ./Vagrantfile
9
+ ```
10
+
11
+ This box works by using Vagrant's built-in Vagrantfile merging to setup
12
+ defaults for AWS. These defaults can easily be overwritten by higher-level
13
+ Vagrantfiles (such as project root Vagrantfiles).
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "aws"
3
+ }
@@ -0,0 +1,46 @@
1
+ require "fog"
2
+ require "log4r"
3
+
4
+ module VagrantPlugins
5
+ module AWS
6
+ module Action
7
+ # This action connects to AWS, verifies credentials work, and
8
+ # puts the AWS connection object into the `:aws_compute` key
9
+ # in the environment.
10
+ class ConnectAWS
11
+ def initialize(app, env)
12
+ @app = app
13
+ @logger = Log4r::Logger.new("vagrant_aws::action::connect_aws")
14
+ end
15
+
16
+ def call(env)
17
+ # Get the region we're going to booting up in
18
+ region = env[:machine].provider_config.region
19
+
20
+ # Get the configs
21
+ region_config = env[:machine].provider_config.get_region_config(region)
22
+
23
+ # Build the fog config
24
+ fog_config = {
25
+ :provider => :aws,
26
+ :region => region
27
+ }
28
+ if region_config.use_iam_profile
29
+ fog_config[:use_iam_profile] = true
30
+ else
31
+ fog_config[:aws_access_key_id] = region_config.access_key_id
32
+ fog_config[:aws_secret_access_key] = region_config.secret_access_key
33
+ end
34
+
35
+ fog_config[:endpoint] = region_config.endpoint if region_config.endpoint
36
+ fog_config[:version] = region_config.version if region_config.version
37
+
38
+ @logger.info("Connecting to AWS...")
39
+ env[:aws_compute] = Fog::Compute.new(fog_config)
40
+
41
+ @app.call(env)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module AWS
3
+ module Action
4
+ # This can be used with "Call" built-in to check if the machine
5
+ # is created and branch in the middleware.
6
+ class IsCreated
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env[:result] = env[:machine].state.id != :not_created
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module AWS
3
+ module Action
4
+ # This can be used with "Call" built-in to check if the machine
5
+ # is stopped and branch in the middleware.
6
+ class IsStopped
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env[:result] = env[:machine].state.id == :stopped
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module AWS
3
+ module Action
4
+ class MessageAlreadyCreated
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_aws.already_status", :status => "created"))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module AWS
3
+ module Action
4
+ class MessageNotCreated
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_aws.not_created"))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module AWS
3
+ module Action
4
+ class MessageWillNotDestroy
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t("vagrant_aws.will_not_destroy", name: env[:machine].name))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,53 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module AWS
5
+ module Action
6
+ # This action reads the SSH info for the machine and puts it into the
7
+ # `:machine_ssh_info` key in the environment.
8
+ class ReadSSHInfo
9
+ def initialize(app, env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new("vagrant_aws::action::read_ssh_info")
12
+ end
13
+
14
+ def call(env)
15
+ env[:machine_ssh_info] = read_ssh_info(env[:aws_compute], env[:machine])
16
+
17
+ @app.call(env)
18
+ end
19
+
20
+ def read_ssh_info(aws, machine)
21
+ return nil if machine.id.nil?
22
+
23
+ # Find the machine
24
+ server = aws.servers.get(machine.id)
25
+ if server.nil?
26
+ # The machine can't be found
27
+ @logger.info("Machine couldn't be found, assuming it got destroyed.")
28
+ machine.id = nil
29
+ return nil
30
+ end
31
+
32
+ # read attribute override
33
+ ssh_host_attribute = machine.provider_config.
34
+ get_region_config(machine.provider_config.region).ssh_host_attribute
35
+ # default host attributes to try. NOTE: Order matters!
36
+ ssh_attrs = [:public_ip_address, :dns_name, :private_ip_address]
37
+ ssh_attrs = (Array(ssh_host_attribute) + ssh_attrs).uniq if ssh_host_attribute
38
+ # try each attribute, get out on first value
39
+ host_value = nil
40
+ while !host_value and attr_name = ssh_attrs.shift
41
+ begin
42
+ host_value = server.send(attr_name)
43
+ rescue NoMethodError
44
+ @logger.info("SSH host attribute not found #{attr_name}")
45
+ end
46
+ end
47
+
48
+ return { :host => host_value, :port => 22 }
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,38 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module AWS
5
+ module Action
6
+ # This action reads the state of the machine and puts it in the
7
+ # `:machine_state_id` key in the environment.
8
+ class ReadState
9
+ def initialize(app, env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new("vagrant_aws::action::read_state")
12
+ end
13
+
14
+ def call(env)
15
+ env[:machine_state_id] = read_state(env[:aws_compute], env[:machine])
16
+
17
+ @app.call(env)
18
+ end
19
+
20
+ def read_state(aws, machine)
21
+ return :not_created if machine.id.nil?
22
+
23
+ # Find the machine
24
+ server = aws.servers.get(machine.id)
25
+ if server.nil? || [:"shutting-down", :terminated].include?(server.state.to_sym)
26
+ # The machine can't be found
27
+ @logger.info("Machine not found or terminated, assuming it got destroyed.")
28
+ machine.id = nil
29
+ return :not_created
30
+ end
31
+
32
+ # Return the state
33
+ return server.state.to_sym
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end