vagrant-actionio 0.0.9

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 (54) hide show
  1. data/.env-example +4 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +7 -0
  5. data/LICENSE +10 -0
  6. data/README.md +110 -0
  7. data/Rakefile +21 -0
  8. data/a.rb +1 -0
  9. data/actionio-dummy.box +0 -0
  10. data/data/cacert.pem +3895 -0
  11. data/example_box/README.md +13 -0
  12. data/example_box/metadata.json +3 -0
  13. data/lib/vagrant-actionio.rb +18 -0
  14. data/lib/vagrant-actionio/action.rb +152 -0
  15. data/lib/vagrant-actionio/action/connect_actionio.rb +31 -0
  16. data/lib/vagrant-actionio/action/is_created.rb +18 -0
  17. data/lib/vagrant-actionio/action/is_running.rb +18 -0
  18. data/lib/vagrant-actionio/action/is_stopped.rb +18 -0
  19. data/lib/vagrant-actionio/action/is_terminated.rb +18 -0
  20. data/lib/vagrant-actionio/action/message_already_created.rb +16 -0
  21. data/lib/vagrant-actionio/action/message_already_terminated.rb +16 -0
  22. data/lib/vagrant-actionio/action/message_cannot_terminate.rb +16 -0
  23. data/lib/vagrant-actionio/action/message_not_created.rb +16 -0
  24. data/lib/vagrant-actionio/action/message_not_running.rb +16 -0
  25. data/lib/vagrant-actionio/action/message_provisioning_not_yet_supported.rb +16 -0
  26. data/lib/vagrant-actionio/action/read_ssh_info.rb +53 -0
  27. data/lib/vagrant-actionio/action/read_state.rb +36 -0
  28. data/lib/vagrant-actionio/action/remove_machine_id.rb +19 -0
  29. data/lib/vagrant-actionio/action/run_instance.rb +94 -0
  30. data/lib/vagrant-actionio/action/start_instance.rb +56 -0
  31. data/lib/vagrant-actionio/action/stop_instance.rb +56 -0
  32. data/lib/vagrant-actionio/action/sync_folders.rb +57 -0
  33. data/lib/vagrant-actionio/action/terminate_instance.rb +57 -0
  34. data/lib/vagrant-actionio/action/timed_provision.rb +21 -0
  35. data/lib/vagrant-actionio/action/warn_networks.rb +19 -0
  36. data/lib/vagrant-actionio/config.rb +75 -0
  37. data/lib/vagrant-actionio/connection.rb +70 -0
  38. data/lib/vagrant-actionio/errors.rb +35 -0
  39. data/lib/vagrant-actionio/plugin.rb +73 -0
  40. data/lib/vagrant-actionio/provider.rb +50 -0
  41. data/lib/vagrant-actionio/util/env.rb +12 -0
  42. data/lib/vagrant-actionio/util/timer.rb +17 -0
  43. data/lib/vagrant-actionio/version.rb +5 -0
  44. data/locales/en.yml +121 -0
  45. data/spec/vagrant-actionio/action/read_ssh_info_spec.rb +58 -0
  46. data/spec/vagrant-actionio/action/read_state_spec.rb +46 -0
  47. data/spec/vagrant-actionio/action/run_instance_spec.rb +24 -0
  48. data/spec/vagrant-actionio/action/start_instance_spec.rb +21 -0
  49. data/spec/vagrant-actionio/action/stop_instance_spec.rb +21 -0
  50. data/spec/vagrant-actionio/action/terminate_instance_spec.rb +21 -0
  51. data/spec/vagrant-actionio/config_spec.rb +47 -0
  52. data/spec/vagrant-actionio/connection_spec.rb +105 -0
  53. data/vagrant-actionio.gemspec +59 -0
  54. metadata +2882 -0
@@ -0,0 +1,13 @@
1
+ # Vagrant Action.IO 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 `actionio` provider.
5
+ To turn this into a `.box` file:
6
+
7
+ ```
8
+ $ tar cvzf actionio.box ./metadata.json ./Vagrantfile
9
+ ```
10
+
11
+ This box works by using Vagrant's built-in Vagrantfile merging to setup
12
+ defaults for Action.IO These defaults can easily be overwritten by
13
+ higher-level Vagrantfiles (such as project root Vagrantfiles).
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "actionio"
3
+ }
@@ -0,0 +1,18 @@
1
+ require 'pathname'
2
+
3
+ require 'vagrant-actionio/plugin'
4
+
5
+ module VagrantPlugins
6
+ module ActionIO
7
+ lib_path = Pathname.new(File.expand_path('../vagrant-actionio', __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,152 @@
1
+ require 'pathname'
2
+
3
+ require 'vagrant/action/builder'
4
+
5
+ module VagrantPlugins
6
+ module ActionIO
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 ConnectActionIO
16
+ b.use Call, IsTerminated do |env, b2|
17
+ if env[:result]
18
+ b2.use MessageAlreadyTerminated
19
+ b2.use RemoveMachineId
20
+ next
21
+ end
22
+
23
+ b2.use Call, IsRunning do |env, b3|
24
+ if env[:result]
25
+ b3.use StopInstance
26
+ end
27
+
28
+ b3.use Call, IsStopped do |env, b4|
29
+ if !env[:result]
30
+ b4.use MessageCannotTerminate
31
+ next
32
+ end
33
+ b4.use TerminateInstance
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ # This action is called when `vagrant provision` is called.
41
+ def self.action_provision
42
+ Vagrant::Action::Builder.new.tap do |b|
43
+ b.use MessageProvisioningNotYetSupported
44
+ #b.use ConfigValidate
45
+ #b.use Call, IsCreated do |env, b2|
46
+ #if !env[:result]
47
+ #b2.use MessageNotCreated
48
+ #next
49
+ #end
50
+
51
+ #b2.use Provision
52
+ #b2.use SyncFolders
53
+ #end
54
+ end
55
+ end
56
+
57
+ # This action is called to read the SSH info of the machine. The
58
+ # resulting state is expected to be put into the `:machine_ssh_info`
59
+ # key.
60
+ def self.action_read_ssh_info
61
+ Vagrant::Action::Builder.new.tap do |b|
62
+ b.use ConfigValidate
63
+ b.use ConnectActionIO
64
+ b.use ReadSSHInfo
65
+ end
66
+ end
67
+
68
+ # This action is called to read the state of the machine. The
69
+ # resulting state is expected to be put into the `:machine_state_id`
70
+ # key.
71
+ def self.action_read_state
72
+ Vagrant::Action::Builder.new.tap do |b|
73
+ b.use ConfigValidate
74
+ b.use ConnectActionIO
75
+ b.use ReadState
76
+ end
77
+ end
78
+
79
+ # This action is called to SSH into the machine.
80
+ def self.action_ssh
81
+ Vagrant::Action::Builder.new.tap do |b|
82
+ b.use ConfigValidate
83
+ b.use Call, IsCreated do |env, b2|
84
+ if !env[:result]
85
+ b2.use MessageNotCreated
86
+ next
87
+ end
88
+
89
+ b2.use Call, IsRunning do |env, b3|
90
+ if !env[:result]
91
+ b3.use MessageNotRunning
92
+ next
93
+ end
94
+
95
+ b3.use SSHExec
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ # This action is called to bring the box up from nothing.
102
+ def self.action_up
103
+ Vagrant::Action::Builder.new.tap do |b|
104
+ b.use ConfigValidate
105
+ b.use ConnectActionIO
106
+
107
+ b.use Call, IsCreated do |env, b2|
108
+ if env[:result]
109
+ b2.use MessageAlreadyCreated
110
+ b2.use Call, IsStopped do |env, b3|
111
+ if env[:result]
112
+ b3.use StartInstance
113
+ end
114
+ end
115
+ next
116
+ end
117
+
118
+ #b2.use TimedProvision
119
+ b2.use SyncFolders
120
+ b2.use WarnNetworks
121
+ b2.use RunInstance
122
+ b2.use MessageProvisioningNotYetSupported
123
+ end
124
+ end
125
+ end
126
+
127
+ # The autoload farm
128
+ action_root = Pathname.new(File.expand_path('../action', __FILE__))
129
+ autoload :ConnectActionIO, action_root.join('connect_actionio')
130
+ autoload :IsCreated, action_root.join('is_created')
131
+ autoload :IsRunning, action_root.join('is_running')
132
+ autoload :IsStopped, action_root.join('is_stopped')
133
+ autoload :IsTerminated, action_root.join('is_terminated')
134
+ autoload :MessageAlreadyCreated, action_root.join('message_already_created')
135
+ autoload :MessageAlreadyTerminated, action_root.join('message_already_terminated')
136
+ autoload :MessageCannotTerminate, action_root.join('message_cannot_terminate')
137
+ autoload :MessageNotCreated, action_root.join('message_not_created')
138
+ autoload :MessageNotRunning, action_root.join('message_not_running')
139
+ autoload :MessageProvisioningNotYetSupported, action_root.join('message_provisioning_not_yet_supported')
140
+ autoload :ReadSSHInfo, action_root.join('read_ssh_info')
141
+ autoload :ReadState, action_root.join('read_state')
142
+ autoload :RunInstance, action_root.join('run_instance')
143
+ autoload :RemoveMachineId, action_root.join('remove_machine_id')
144
+ autoload :StartInstance, action_root.join('start_instance')
145
+ autoload :StopInstance, action_root.join('stop_instance')
146
+ autoload :SyncFolders, action_root.join('sync_folders')
147
+ autoload :TerminateInstance, action_root.join("terminate_instance")
148
+ autoload :TimedProvision, action_root.join('timed_provision')
149
+ autoload :WarnNetworks, action_root.join('warn_networks')
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,31 @@
1
+ require 'log4r'
2
+ require 'vagrant-actionio/connection'
3
+ require 'vagrant-actionio/errors'
4
+
5
+ module VagrantPlugins
6
+ module ActionIO
7
+ module Action
8
+ # This action connects to ActionIO, verifies credentials work, and
9
+ # puts the ActionIO connection object into the `:actionio` key
10
+ # in the environment.
11
+ class ConnectActionIO
12
+
13
+ def initialize(app, env)
14
+ @app = app
15
+ @logger = Log4r::Logger.new('vagrant_actionio::action::connect_actionio')
16
+ end
17
+
18
+ def call(env)
19
+ connection = Connection.new(env[:machine].provider_config.access_token)
20
+
21
+ @logger.info('Verifying Access Token...')
22
+ connection.verify_access_token
23
+
24
+ env[:actionio] = connection
25
+
26
+ @app.call(env)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module ActionIO
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 ActionIO
3
+ module Action
4
+ # This can be used with "Call" built-in to check if the machine
5
+ # is running and branch in the middleware.
6
+ class IsRunning
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env[:result] = env[:machine].state.id == :running
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module ActionIO
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,18 @@
1
+ module VagrantPlugins
2
+ module ActionIO
3
+ module Action
4
+ # This can be used with "Call" built-in to check if the machine
5
+ # is terminated and branch in the middleware.
6
+ class IsTerminated
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env[:result] = [:terminated, :terminating].include?(env[:machine].state.id)
13
+ @app.call(env)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module ActionIO
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_actionio.already_created'))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module ActionIO
3
+ module Action
4
+ class MessageAlreadyTerminated
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t('vagrant_actionio.already_terminated'))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module ActionIO
3
+ module Action
4
+ class MessageCannotTerminate
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t('vagrant_actionio.cannot_terminate'))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module ActionIO
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_actionio.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 ActionIO
3
+ module Action
4
+ class MessageNotRunning
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t('vagrant_actionio.not_running'))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module ActionIO
3
+ module Action
4
+ class MessageProvisioningNotYetSupported
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t('vagrant_actionio.provisioning_not_yet_supported'))
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 ActionIO
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_actionio::action::read_ssh_info")
12
+ end
13
+
14
+ def call(env)
15
+ env[:machine_ssh_info] = read_ssh_info(env[:actionio], env[:machine])
16
+
17
+ @app.call(env)
18
+ end
19
+
20
+ def read_ssh_info(actionio, machine)
21
+ return nil if machine.id.nil?
22
+
23
+ # Find the box
24
+ begin
25
+ response = actionio.request(:get, "/boxes/#{machine.id}")
26
+ rescue => e
27
+ if e.respond_to?(:response) && e.response.status == 404
28
+ # The machine can't be found
29
+ @logger.info("Box not found on Action.IO, assuming it got destroyed.")
30
+ machine.id = nil
31
+ return nil
32
+ else
33
+ raise e
34
+ end
35
+ end
36
+
37
+ box_info = response.parsed['box']
38
+
39
+ # Get the configuration
40
+ config = machine.provider_config
41
+
42
+ # Read the info
43
+ return {
44
+ host: box_info['host'],
45
+ port: box_info['port'].to_s,
46
+ private_key_path: config.ssh_private_key_path,
47
+ username: 'action'
48
+ }
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end