vagrant-aws 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/.gitignore +11 -2
  2. data/CHANGELOG.md +3 -0
  3. data/Gemfile +8 -2
  4. data/LICENSE +8 -0
  5. data/README.md +192 -65
  6. data/Rakefile +18 -7
  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.rb +17 -13
  11. data/lib/vagrant-aws/action.rb +107 -0
  12. data/lib/vagrant-aws/action/connect_aws.rb +38 -0
  13. data/lib/vagrant-aws/action/is_created.rb +18 -0
  14. data/lib/vagrant-aws/action/message_already_created.rb +16 -0
  15. data/lib/vagrant-aws/action/message_not_created.rb +16 -0
  16. data/lib/vagrant-aws/action/read_ssh_info.rb +47 -0
  17. data/lib/vagrant-aws/action/read_state.rb +38 -0
  18. data/lib/vagrant-aws/action/run_instance.rb +148 -0
  19. data/lib/vagrant-aws/action/sync_folders.rb +57 -0
  20. data/lib/vagrant-aws/action/terminate_instance.rb +26 -0
  21. data/lib/vagrant-aws/action/timed_provision.rb +21 -0
  22. data/lib/vagrant-aws/action/warn_networks.rb +19 -0
  23. data/lib/vagrant-aws/config.rb +253 -38
  24. data/lib/vagrant-aws/errors.rb +15 -25
  25. data/lib/vagrant-aws/plugin.rb +73 -0
  26. data/lib/vagrant-aws/provider.rb +50 -0
  27. data/lib/vagrant-aws/util/timer.rb +17 -0
  28. data/lib/vagrant-aws/version.rb +4 -2
  29. data/locales/en.yml +65 -61
  30. data/spec/vagrant-aws/config_spec.rb +161 -0
  31. data/vagrant-aws.gemspec +54 -25
  32. metadata +79 -86
  33. data/lib/vagrant-aws/action/create.rb +0 -56
  34. data/lib/vagrant-aws/action/create_image.rb +0 -106
  35. data/lib/vagrant-aws/action/create_sshkey.rb +0 -39
  36. data/lib/vagrant-aws/action/deregister_image.rb +0 -27
  37. data/lib/vagrant-aws/action/populate_ssh.rb +0 -41
  38. data/lib/vagrant-aws/action/prepare_provisioners.rb +0 -127
  39. data/lib/vagrant-aws/action/resume.rb +0 -20
  40. data/lib/vagrant-aws/action/suspend.rb +0 -20
  41. data/lib/vagrant-aws/action/terminate.rb +0 -21
  42. data/lib/vagrant-aws/box.rb +0 -20
  43. data/lib/vagrant-aws/box_collection.rb +0 -15
  44. data/lib/vagrant-aws/command.rb +0 -186
  45. data/lib/vagrant-aws/environment.rb +0 -79
  46. data/lib/vagrant-aws/middleware.rb +0 -53
  47. data/lib/vagrant-aws/system.rb +0 -24
  48. data/lib/vagrant-aws/vm.rb +0 -94
  49. data/lib/vagrant_init.rb +0 -4
  50. data/test/test_helper.rb +0 -24
  51. data/test/vagrant-aws/action/create_image_test.rb +0 -63
  52. data/test/vagrant-aws/action/create_ssh_key_test.rb +0 -43
  53. data/test/vagrant-aws/action/create_test.rb +0 -65
  54. data/test/vagrant-aws/action/terminate_test.rb +0 -20
  55. data/test/vagrant-aws/command_test.rb +0 -21
  56. data/test/vagrant-aws/config_test.rb +0 -14
data/.gitignore CHANGED
@@ -1,5 +1,14 @@
1
+ # OS-specific
2
+ .DS_Store
3
+
4
+ # Bundler/Rubygems
1
5
  *.gem
2
6
  .bundle
3
- Gemfile.lock
4
7
  pkg/*
5
- .rvmrc
8
+ tags
9
+ Gemfile.lock
10
+
11
+ # Vagrant
12
+ .vagrant
13
+ Vagrantfile
14
+ !example_box/Vagrantfile
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.1.0 (March 14, 2013)
2
+
3
+ * Initial release.
data/Gemfile CHANGED
@@ -1,4 +1,10 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in vagrant-aws.gemspec
4
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) 2013 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 CHANGED
@@ -1,65 +1,192 @@
1
- # vagrant-aws
2
-
3
- `vagrant-aws` is a plugin for [Vagrant](http://vagrantup.com) which allows the user
4
- to instantiate the Vagrant environment on Amazon AWS (using EC2). This document assumes
5
- you are familiar with Vagrant, if not, the project has excellent [documentation](http://vagrantup.com/docs/index.html).
6
-
7
- **NOTE:** This plugin is "pre-alpha", see below for the caveats
8
-
9
- ## Installing / Getting Started
10
-
11
- To use this plugin, first install Vagrant, then install the plugin gem. It should be
12
- picked up automatically by vagrant. You can then use the `vagrant aws` commands.
13
-
14
- `vagrant-aws` uses [fog](https://github.com/geemus/fog) internally, and you will need to
15
- specify your Amazon AWS credentials in a "fog" file. Create `~/.fog` with:
16
-
17
- ---
18
- default:
19
- aws_access_key_id: <YOUR ACCESS KEY>
20
- aws_secret_access_key: <YOUR SECRET KEY>
21
-
22
- If you already have an Amazon key pair (created when you signed-up, or
23
- someother time), you can specify the key name and the path the associated
24
- private key. Alternately, if no key name is specified, `vagrant-aws` will
25
- automatically create and register a key pair for you with the name
26
- `vagrant_<MAC ADDRESS>`. If you want to use your pre-existing key, you can
27
- specify the key name and path on a per-environment basis (i.e., in each
28
- Vagrantfile) or in a single Vagrantfile in your `~/.vagrant` directory. In the
29
- latter case, create `~/.vagrant/Vagrantfile` with:
30
-
31
- Vagrant::Config.run do |config|
32
- config.aws.key_name = "<KEY NAME>"
33
- config.aws.private_key_path = "<PATH/TO/KEY>"
34
- end
35
-
36
- With the above in place you should be ready instantiate your Vagrant environment on
37
- Amazon AWS. See below for additional information on configuration, caveats, etc..
38
-
39
- ## Configuration and Image Boxes
40
-
41
- `vagrant-aws` defines a new configuration class for use in your Vagrantfile. An example
42
- usage (showing the defaults) would be:
43
-
44
- Vagrant::Config.run do |config|
45
- config.aws.region = "us-east-1"
46
- config.aws.availability_zone = nil # Let AWS choose
47
- config.aws.image = "ami-2ec83147" # EBS-backed Ubuntu 10.04 64-bit
48
- config.aws.username = "ubuntu"
49
- config.aws.security_groups = ["default"]
50
- config.aws.flavor = "t1.micro"
51
- end
52
-
53
- Alternately you can work with "image boxes" using the `vagrant aws box_*` commands. These are
54
- similar to Vagrant's native boxes, and have a similar API, but wrap AWS ami IDs. The major
55
- difference is that box creation and removal can optionally reregister and deregister AMIs
56
- with AWS. Note that AMI creation is only supported for EBS-backed instances.
57
-
58
- ## Caveats
59
-
60
- `vagrant-aws` is "pre-alpha" and currently only supports creation, suspension, resumption
61
- and descruction of the Vagrant environment. Provisioning should be supported for shell,
62
- chef-server and chef-solo, but has only been tested with chef-solo and on an Ubuntu guest.
63
- Only a subset of Vagrant features are supported. Currently port forwarding and shared
64
- directories are not implemented, nor is host networking (although that is less relevant for AWS).
65
- `vagrant-aws` in general has only been tested for a single VM, on OSX 10.6, with chef-solo.
1
+ # Vagrant AWS Provider
2
+
3
+ This is a [Vagrant](http://www.vagrantup.com) 1.1+ plugin that adds an [AWS](http://aws.amazon.com)
4
+ provider to Vagrant, allowing Vagrant to control and provision machines in
5
+ EC2 and VPC.
6
+
7
+ **NOTE:** This plugin requires Vagrant 1.1+,
8
+
9
+ ## Features
10
+
11
+ * Boot EC2 or VPC instances.
12
+ * SSH into the instances.
13
+ * Provision the instances with any built-in Vagrant provisioner.
14
+ * Minimal synced folder support via `rsync`.
15
+ * Define region-specifc configurations so Vagrant can manage machines
16
+ in multiple regions.
17
+
18
+ ## Usage
19
+
20
+ Install using standard Vagrant 1.1+ plugin installation methods. After
21
+ installing, `vagrant up` and specify the `aws` provider. An example is
22
+ shown below.
23
+
24
+ ```
25
+ $ vagrant plugin install vagrant-aws
26
+ ...
27
+ $ vagrant up --provider=aws
28
+ ...
29
+ ```
30
+
31
+ Of course prior to doing this, you'll need to obtain an AWS-compatible
32
+ box file for Vagrant.
33
+
34
+ ## Quick Start
35
+
36
+ After installing the plugin (instructions above), the quickest way to get
37
+ started is to actually use a dummy AWS box and specify all the details
38
+ manually within a `config.vm.provider` block. So first, add the dummy
39
+ box using any name you want:
40
+
41
+ ```
42
+ $ vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box
43
+ ...
44
+ ```
45
+
46
+ And then make a Vagrantfile that looks like the following, filling in
47
+ your information where necessary.
48
+
49
+ ```
50
+ Vagrant.configure("2") do |config|
51
+ config.vm.box = "dummy"
52
+
53
+ config.vm.provider :aws do |aws|
54
+ aws.access_key_id = "YOUR KEY"
55
+ aws.secret_access_key = "YOUR SECRET KEY"
56
+ aws.keypair_name = "KEYPAIR NAME"
57
+ aws.ssh_private_key_path = "PATH TO YOUR PRIVATE KEY"
58
+
59
+ aws.ami = "ami-7747d01e"
60
+ aws.ssh_username = "ubuntu"
61
+ end
62
+ end
63
+ ```
64
+
65
+ And then run `vagrant up --provider=aws`.
66
+
67
+ This will start an Ubuntu 12.04 instance in the us-east-1 region within
68
+ your account. And assuming your SSH information was filled in properly
69
+ within your Vagrantfile, SSH and provisioning will work as well.
70
+
71
+ Note that normally a lot of this boilerplate is encoded within the box
72
+ file, but the box file used for the quick start, the "dummy" box, has
73
+ no preconfigured defaults.
74
+
75
+ ## Box Format
76
+
77
+ Every provider in Vagrant must introduce a custom box format. This
78
+ provider introduces `aws` boxes. You can view an example box in
79
+ the [example_box/ directory](https://github.com/mitchellh/vagrant-aws/tree/master/example_box).
80
+ That directory also contains instructions on how to build a box.
81
+
82
+ The box format is basically just the required `metadata.json` file
83
+ along with a `Vagrantfile` that does default settings for the
84
+ provider-specific configuration for this provider.
85
+
86
+ ## Configuration
87
+
88
+ This provider exposes quite a few provider-specific configuration options:
89
+
90
+ * `access_key_id` - The access key for accessing AWS
91
+ * `ami` - The AMI id to boot, such as "ami-12345678"
92
+ * `availability_zone` - The availability zone within the region to launch
93
+ the instance. If nil, it will use the default set by Amazon.
94
+ * `instance_type` - The type of instance, such as "m1.small"
95
+ * `keypair_name` - The name of the keypair to use to bootstrap AMIs
96
+ which support it.
97
+ * `private_ip_address` - The private IP address to assign to an instance
98
+ within a [VPC](http://aws.amazon.com/vpc/)
99
+ * `region` - The region to start the instance in, such as "us-east-1"
100
+ * `secret_access_key` - The secret access key for accessing AWS
101
+ * `ssh_private_key_path` - The path to the SSH private key. This overrides
102
+ `config.ssh.private_key_path`.
103
+ * `ssh_username` - The SSH username, which overrides `config.ssh.username`.
104
+ * `security_groups` - An array of security groups for the instance. If this
105
+ instance will be launched in VPC, this must be a list of security group
106
+ IDs.
107
+ * `subnet_id` - The subnet to boot the instance into, for VPC.
108
+ * `tags` - A hash of tags to set on the machine.
109
+
110
+ These can be set like typical provider-specific configuration:
111
+
112
+ ```ruby
113
+ Vagrant.configure("2") do |config|
114
+ # ... other stuff
115
+
116
+ config.vm.provider :aws do |aws|
117
+ aws.access_key_id = "foo"
118
+ aws.secret_access_key = "bar"
119
+ end
120
+ end
121
+ ```
122
+
123
+ In addition to the above top-level configs, you can use the `region_config`
124
+ method to specify region-specific overrides within your Vagrantfile. Note
125
+ that the top-level `region` config must always be specified to choose which
126
+ region you want to actually use, however. This looks like this:
127
+
128
+ ```ruby
129
+ Vagrant.configure("2") do |config|
130
+ # ... other stuff
131
+
132
+ config.vm.provider :aws do |aws|
133
+ aws.access_key_id = "foo"
134
+ aws.secret_access_key = "bar"
135
+ aws.region = "us-east-1"
136
+
137
+ # Simply region config
138
+ aws.region_config "us-east-1", :ami => "ami-12345678"
139
+
140
+ # More comprehensive region config
141
+ aws.region_config "us-west-2" do |region|
142
+ region.ami = "ami-87654321"
143
+ region.keypair_name = "company-west"
144
+ end
145
+ end
146
+ end
147
+ ```
148
+
149
+ The region-specific configurations will override the top-level
150
+ configurations when that region is used. They otherwise inherit
151
+ the top-level configurations, as you would probably expect.
152
+
153
+ ## Networks
154
+
155
+ Networking features in the form of `config.vm.network` are not
156
+ supported with `vagrant-aws`, currently. If any of these are
157
+ specified, Vagrant will emit a warning, but will otherwise boot
158
+ the AWS machine.
159
+
160
+ ## Synced Folders
161
+
162
+ There is minimal support for synced folders. Upon `vagrant up`,
163
+ `vagrant reload`, and `vagrant provision`, the AWS provider will use
164
+ `rsync` (if available) to uni-directionally sync the folder to
165
+ the remote machine over SSH.
166
+
167
+ This is good enough for all built-in Vagrant provisioners (shell,
168
+ chef, and puppet) to work!
169
+
170
+ ## Development
171
+
172
+ To work on the `vagrant-aws` plugin, clone this repository out, and use
173
+ [Bundler](http://gembundler.com) to get the dependencies:
174
+
175
+ ```
176
+ $ bundle
177
+ ```
178
+
179
+ Once you have the dependencies, verify the unit tests pass with `rake`:
180
+
181
+ ```
182
+ $ bundle exec rake
183
+ ```
184
+
185
+ If those pass, you're ready to start developing the plugin. You can test
186
+ the plugin without installing it into your Vagrant environment by just
187
+ creating a `Vagrantfile` in the top level of this directory (it is gitignored)
188
+ that uses it, and uses bundler to execute Vagrant:
189
+
190
+ ```
191
+ $ bundle exec vagrant up --provider=aws
192
+ ```
data/Rakefile CHANGED
@@ -1,10 +1,21 @@
1
- require 'bundler/gem_tasks'
2
- require 'rake/testtask'
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec/core/rake_task'
3
4
 
4
- task :default => :test
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
5
9
 
6
- Rake::TestTask.new do |t|
7
- t.libs << "test"
8
- t.pattern = 'test/**/*_test.rb'
9
- end
10
+ # Change to the directory of this file.
11
+ Dir.chdir(File.expand_path("../", __FILE__))
10
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
+ }
data/lib/vagrant-aws.rb CHANGED
@@ -1,14 +1,18 @@
1
- require 'vagrant'
2
- require 'vagrant-aws/version'
3
- require 'vagrant-aws/errors'
4
- require 'vagrant-aws/environment'
5
- require 'vagrant-aws/vm'
6
- require 'vagrant-aws/config'
7
- require 'vagrant-aws/middleware'
8
- require 'vagrant-aws/command'
9
- require 'vagrant-aws/system'
10
- require 'vagrant-aws/box'
11
- require 'vagrant-aws/box_collection'
1
+ require "pathname"
12
2
 
13
- # Add our custom translations to the load path
14
- I18n.load_path << File.expand_path("../../locales/en.yml", __FILE__)
3
+ require "vagrant-aws/plugin"
4
+
5
+ module VagrantPlugins
6
+ module AWS
7
+ lib_path = Pathname.new(File.expand_path("../vagrant-aws", __FILE__))
8
+ autoload :Action, lib_path.join("action")
9
+ autoload :Errors, lib_path.join("errors")
10
+
11
+ # This returns the path to the source of this plugin.
12
+ #
13
+ # @return [Pathname]
14
+ def self.source_root
15
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,107 @@
1
+ require "pathname"
2
+
3
+ require "vagrant/action/builder"
4
+
5
+ module VagrantPlugins
6
+ module AWS
7
+ module Action
8
+ # Include the built-in modules so we can use them as top-level things.
9
+ include Vagrant::Action::Builtin
10
+
11
+ # This action is called to terminate the remote machine.
12
+ def self.action_destroy
13
+ Vagrant::Action::Builder.new.tap do |b|
14
+ b.use ConfigValidate
15
+ b.use ConnectAWS
16
+ b.use TerminateInstance
17
+ end
18
+ end
19
+
20
+ # This action is called when `vagrant provision` is called.
21
+ def self.action_provision
22
+ Vagrant::Action::Builder.new.tap do |b|
23
+ b.use ConfigValidate
24
+ b.use Call, IsCreated do |env, b2|
25
+ if !env[:result]
26
+ b2.use MessageNotCreated
27
+ next
28
+ end
29
+
30
+ b2.use Provision
31
+ b2.use SyncFolders
32
+ end
33
+ end
34
+ end
35
+
36
+ # This action is called to read the SSH info of the machine. The
37
+ # resulting state is expected to be put into the `:machine_ssh_info`
38
+ # key.
39
+ def self.action_read_ssh_info
40
+ Vagrant::Action::Builder.new.tap do |b|
41
+ b.use ConfigValidate
42
+ b.use ConnectAWS
43
+ b.use ReadSSHInfo
44
+ end
45
+ end
46
+
47
+ # This action is called to read the state of the machine. The
48
+ # resulting state is expected to be put into the `:machine_state_id`
49
+ # key.
50
+ def self.action_read_state
51
+ Vagrant::Action::Builder.new.tap do |b|
52
+ b.use ConfigValidate
53
+ b.use ConnectAWS
54
+ b.use ReadState
55
+ end
56
+ end
57
+
58
+ # This action is called to SSH into the machine.
59
+ def self.action_ssh
60
+ Vagrant::Action::Builder.new.tap do |b|
61
+ b.use ConfigValidate
62
+ b.use Call, IsCreated do |env, b2|
63
+ if !env[:result]
64
+ b2.use MessageNotCreated
65
+ next
66
+ end
67
+
68
+ b2.use SSHExec
69
+ end
70
+ end
71
+ end
72
+
73
+ # This action is called to bring the box up from nothing.
74
+ def self.action_up
75
+ Vagrant::Action::Builder.new.tap do |b|
76
+ b.use ConfigValidate
77
+ b.use ConnectAWS
78
+ b.use Call, IsCreated do |env, b2|
79
+ if env[:result]
80
+ b2.use MessageAlreadyCreated
81
+ next
82
+ end
83
+
84
+ b2.use TimedProvision
85
+ b2.use SyncFolders
86
+ b2.use WarnNetworks
87
+ b2.use RunInstance
88
+ end
89
+ end
90
+ end
91
+
92
+ # The autoload farm
93
+ action_root = Pathname.new(File.expand_path("../action", __FILE__))
94
+ autoload :ConnectAWS, action_root.join("connect_aws")
95
+ autoload :IsCreated, action_root.join("is_created")
96
+ autoload :MessageAlreadyCreated, action_root.join("message_already_created")
97
+ autoload :MessageNotCreated, action_root.join("message_not_created")
98
+ autoload :ReadSSHInfo, action_root.join("read_ssh_info")
99
+ autoload :ReadState, action_root.join("read_state")
100
+ autoload :RunInstance, action_root.join("run_instance")
101
+ autoload :SyncFolders, action_root.join("sync_folders")
102
+ autoload :TimedProvision, action_root.join("timed_provision")
103
+ autoload :WarnNetworks, action_root.join("warn_networks")
104
+ autoload :TerminateInstance, action_root.join("terminate_instance")
105
+ end
106
+ end
107
+ end