vagrant-aws 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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/lib/vagrant_init.rb DELETED
@@ -1,4 +0,0 @@
1
- # This file is automatically loaded by Vagrant to load any
2
- # plugins. This file kicks off this plugin.
3
-
4
- require 'vagrant-aws'
data/test/test_helper.rb DELETED
@@ -1,24 +0,0 @@
1
- require 'test/unit'
2
- require 'contest'
3
- require 'mocha'
4
- require 'vagrant-aws'
5
-
6
- Fog.mock!
7
-
8
- module Vagrant
9
- module TestHelpers
10
-
11
- # Creates and _loads_ a Vagrant environment at the given path.
12
- # If no path is given, then a default {#vagrantfile} is used.
13
- def vagrant_env(*args)
14
- path = args.shift if Pathname === args.first
15
- path ||= vagrantfile
16
- VagrantAWS::Environment.new(:cwd => path).load!
17
- end
18
-
19
- end
20
- end
21
-
22
- class Test::Unit::TestCase
23
- include Vagrant::TestHelpers
24
- end
@@ -1,63 +0,0 @@
1
- require 'test_helper'
2
-
3
- class CreateImageTest < Test::Unit::TestCase
4
-
5
- setup do
6
- @app, @env = action_env
7
-
8
- @env.env.vm = VagrantAWS::VM.new(:env => @env.env, :name => "default")
9
- @middleware = VagrantAWS::Action::CreateImage.new(@app, @env)
10
-
11
- @env["vm"].expects(:created?).returns(true)
12
-
13
- @env["vm"].vm = @env["vm"].connection.servers.create
14
- @env["vm"].vm.root_device_type = "ebs" # Fog mock instances are "instance-store" by default
15
-
16
- @env["vm"].connection.data[:images] = { "notused" => { "imageId" => @env["vm"].vm.image_id }}
17
- end
18
-
19
- should "return error if instance not running" do
20
- @env["vm"].vm.stubs(:running?).returns(false)
21
- assert_raise(Vagrant::Errors::VMNotRunningError) do
22
- @middleware.call(@env)
23
- end
24
- end
25
-
26
- context "instance running" do
27
- setup do
28
- @env["vm"].vm.stubs(:running?).returns(true)
29
- end
30
-
31
- should "not create image unless register specified" do
32
- @env["vm"].connection.expects(:create_image).never
33
- @middleware.call(@env)
34
- end
35
-
36
- should "create image if register specified" do
37
- @env["vm"].connection.expects(:create_image => @env["vm"].connection.create_image(@env["vm"].vm.id, "test", "test"))
38
- @env["image.register"] = true
39
- @middleware.call(@env)
40
- end
41
-
42
- context "recovery" do
43
- setup do
44
- @internal_image = @env["vm"].connection.create_image(@env["vm"].vm.id, "test", "test")
45
- @env["vm"].connection.stubs(:create_image).returns(@internal_image)
46
- end
47
-
48
- should "deregister if error during registration" do
49
- @env["image.register"] = true
50
- @middleware.call(@env)
51
- @middleware.image.expects(:deregister).with(true)
52
- @middleware.recover(@env)
53
- end
54
-
55
- end
56
-
57
- should "call the next app" do
58
- @app.expects(:call).once
59
- @middleware.call(@env)
60
- end
61
- end
62
-
63
- end
@@ -1,43 +0,0 @@
1
- require 'test_helper'
2
-
3
- class CreateSSHKeyActionTest < Test::Unit::TestCase
4
- setup do
5
- @app, @env = action_env
6
-
7
- @env.env.vm = VagrantAWS::VM.new(:env => @env.env, :name => "default")
8
- @connection = @env["vm"].connection # We need to trigger the connection creation to load FOG models
9
-
10
- @middleware = VagrantAWS::Action::CreateSSHKey.new(@app, @env)
11
-
12
- @env["config"].aws.key_name = "default"
13
- end
14
-
15
- should "call the next app" do
16
- @app.expects(:call).once
17
- @middleware.call(@env)
18
- end
19
-
20
- should "not do anything if key name is provided" do
21
- @env["vm"].connection.expects(:key_pairs).never
22
- @middleware.call(@env)
23
- end
24
-
25
- context "no key specified" do
26
- setup do
27
- @env["config"].aws.key_name = nil
28
- end
29
-
30
- should "use pre-existing key pair if available" do
31
- @env.env.expects(:ssh_keys).returns(["existing_key"])
32
- @connection.data[:key_pairs] = { "notused" => { "keyName" => "existing_key"} }
33
- @middleware.call(@env)
34
- end
35
-
36
- should "create key pair if none available" do
37
- @env.env.expects(:ssh_keys).returns([])
38
- File.stubs(:open).with(@env.env.ssh_keys_path.join("vagrantaws_#{Mac.addr.gsub(':','')}"), File::WRONLY|File::TRUNC|File::CREAT, 0600).returns(nil)
39
- @middleware.call(@env)
40
- end
41
- end
42
-
43
- end
@@ -1,65 +0,0 @@
1
- require 'test_helper'
2
-
3
- class CreateActionTest < Test::Unit::TestCase
4
- setup do
5
- @app, @env = action_env
6
-
7
- @env.env.vm = VagrantAWS::VM.new(:env => @env.env, :name => "default")
8
- @connection = @env["vm"].connection # We need to trigger the connection creation to load FOG models
9
-
10
- @middleware = VagrantAWS::Action::Create.new(@app, @env)
11
-
12
- # Setup FOG mocks
13
- @env["config"].aws.key_name = "default"
14
- @connection.data[:key_pairs] = { "notused" => { "keyName" => "default"} }
15
- @connection.data[:images] = { "default" => { "imageId" => @env["config"].aws.image, "imageState" => 'available' } }
16
- end
17
-
18
- should "call the next app" do
19
- @app.expects(:call).once
20
- @middleware.call(@env)
21
- end
22
-
23
- should "create running AWS server" do
24
- @middleware.call(@env)
25
-
26
- assert_not_nil @env["vm"].vm
27
- assert_instance_of Fog::Compute::AWS::Server, @env["vm"].vm
28
- assert @env["vm"].vm.running?
29
- end
30
-
31
-
32
- should "mark environment erroneous and not continue chain on failure" do
33
- Fog::Compute::AWS::Servers.any_instance.stubs(:create).returns(nil)
34
- @app.expects(:call).never
35
- assert_raises(VagrantAWS::Errors::VMCreateFailure) {
36
- @middleware.call(@env)
37
- }
38
- end
39
-
40
- context "recovery" do
41
- setup do
42
- @env["vm"].stubs(:created?).returns(true)
43
- end
44
-
45
- should "not run the destroy action on recover if error is a VagrantError" do
46
- @env["vagrant.error"] = Vagrant::Errors::VMImportFailure.new
47
- @env.env.actions.expects(:run).never
48
- @middleware.recover(@env)
49
- end
50
-
51
- should "not run the destroy action on recover if VM is not created" do
52
- @env.env.vm.stubs(:created?).returns(false)
53
- @env.env.actions.expects(:run).never
54
- @middleware.recover(@env)
55
- end
56
-
57
- should "run the destroy action on recover" do
58
- @env.env.vm.stubs(:created?).returns(true)
59
- @env.env.actions.expects(:run).with(:aws_destroy).once
60
- @middleware.recover(@env)
61
- end
62
- end
63
-
64
- end
65
-
@@ -1,20 +0,0 @@
1
- require "test_helper"
2
-
3
- class TerminateActionTest < Test::Unit::TestCase
4
- setup do
5
- @app, @env = action_env
6
- @env.env.vm = VagrantAWS::VM.new(:env => @env.env, :name => "default")
7
- @middleware = VagrantAWS::Action::Terminate.new(@app, @env)
8
-
9
- @internal_vm = mock("internal")
10
- @env.env.vm.stubs(:vm).returns(@internal_vm)
11
- end
12
-
13
- should "destroy VM and attached images" do
14
- @internal_vm.expects(:destroy).once
15
- @env["vm"].expects(:vm=).with(nil).once
16
- @app.expects(:call).with(@env).once
17
- @middleware.call(@env)
18
- end
19
-
20
- end
@@ -1,21 +0,0 @@
1
- require 'test_helper'
2
-
3
- class CommandTest < Test::Unit::TestCase
4
- setup do
5
- @env = vagrant_env
6
- end
7
-
8
- context "up" do
9
-
10
- should "run aws_up" do
11
- @env.config.aws.key_name = "default"
12
- @env.vms.values.each do |vm|
13
- vm.env.actions.expects(:run).with(:aws_up, {'provision.enabled' => true}).once
14
- end
15
- @env.cli("aws","up")
16
- end
17
-
18
- end
19
-
20
- end
21
-
@@ -1,14 +0,0 @@
1
- require "test_helper"
2
-
3
- class ConfigTest < Test::Unit::TestCase
4
- setup do
5
- @config = VagrantAWS::Config.new
6
- @errors = Vagrant::Config::ErrorRecorder.new
7
- end
8
-
9
- should "be valid by default" do
10
- @config.validate(@errors)
11
- assert @errors.errors.empty?
12
- end
13
-
14
- end