vagrant-mos 0.8.39

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/CHANGELOG.md +92 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE +8 -0
  6. data/README.md +292 -0
  7. data/Rakefile +21 -0
  8. data/Vagrantfile +1 -0
  9. data/dummy.box +0 -0
  10. data/example_box/README.md +13 -0
  11. data/example_box/Vagrantfile +8 -0
  12. data/example_box/metadata.json +3 -0
  13. data/lib/vagrant-mos.rb +18 -0
  14. data/lib/vagrant-mos/action.rb +212 -0
  15. data/lib/vagrant-mos/action/connect_mos.rb +51 -0
  16. data/lib/vagrant-mos/action/elb_deregister_instance.rb +24 -0
  17. data/lib/vagrant-mos/action/elb_register_instance.rb +24 -0
  18. data/lib/vagrant-mos/action/is_created.rb +18 -0
  19. data/lib/vagrant-mos/action/is_stopped.rb +19 -0
  20. data/lib/vagrant-mos/action/message_already_created.rb +16 -0
  21. data/lib/vagrant-mos/action/message_not_created.rb +16 -0
  22. data/lib/vagrant-mos/action/message_will_not_destroy.rb +16 -0
  23. data/lib/vagrant-mos/action/package_instance.rb +192 -0
  24. data/lib/vagrant-mos/action/read_ssh_info.rb +64 -0
  25. data/lib/vagrant-mos/action/read_state.rb +46 -0
  26. data/lib/vagrant-mos/action/run_instance.rb +287 -0
  27. data/lib/vagrant-mos/action/start_instance.rb +82 -0
  28. data/lib/vagrant-mos/action/stop_instance.rb +29 -0
  29. data/lib/vagrant-mos/action/terminate_instance.rb +52 -0
  30. data/lib/vagrant-mos/action/timed_provision.rb +21 -0
  31. data/lib/vagrant-mos/action/wait_for_state.rb +41 -0
  32. data/lib/vagrant-mos/action/warn_networks.rb +19 -0
  33. data/lib/vagrant-mos/config.rb +405 -0
  34. data/lib/vagrant-mos/errors.rb +43 -0
  35. data/lib/vagrant-mos/plugin.rb +73 -0
  36. data/lib/vagrant-mos/provider.rb +53 -0
  37. data/lib/vagrant-mos/util/elb.rb +56 -0
  38. data/lib/vagrant-mos/util/timer.rb +17 -0
  39. data/lib/vagrant-mos/version.rb +5 -0
  40. data/locales/en.yml +153 -0
  41. data/mos.box +0 -0
  42. data/spec/spec_helper.rb +1 -0
  43. data/spec/vagrant-mos/config_spec.rb +225 -0
  44. data/templates/metadata.json.erb +3 -0
  45. data/templates/vagrant-aws_package_Vagrantfile.erb +5 -0
  46. data/vagrant-mos.gemspec +60 -0
  47. metadata +172 -0
data/dummy.box ADDED
Binary file
@@ -0,0 +1,13 @@
1
+ # Vagrant MOS 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 `mos` provider.
5
+ To turn this into a box:
6
+
7
+ ```
8
+ $ tar cvzf mos.box ./metadata.json ./Vagrantfile
9
+ ```
10
+
11
+ This box works by using Vagrant's built-in Vagrantfile merging to setup
12
+ defaults for MOS. These defaults can easily be overwritten by higher-level
13
+ Vagrantfiles (such as project root Vagrantfiles).
@@ -0,0 +1,8 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.provider :mos do |mos|
6
+ mos.ami = "fa1026fe-c082-4ead-8458-802bf65ca64c"
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ {
2
+ "provider": "mos"
3
+ }
@@ -0,0 +1,18 @@
1
+ require "pathname"
2
+
3
+ require "vagrant-mos/plugin"
4
+
5
+ module VagrantPlugins
6
+ module MOS
7
+ lib_path = Pathname.new(File.expand_path("../vagrant-mos", __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,212 @@
1
+ require "pathname"
2
+
3
+ require "vagrant/action/builder"
4
+
5
+ module VagrantPlugins
6
+ module MOS
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
+ def self.action_package
12
+ Vagrant::Action::Builder.new.tap do |b|
13
+ b.use Call, IsCreated do |env, b2|
14
+ if !env[:result]
15
+ b2.use MessageNotCreated
16
+ next
17
+ end
18
+
19
+ # Connect to MOS and then Create a package from the server instance
20
+ b2.use ConnectMOS
21
+ b2.use PackageInstance
22
+ end
23
+ end
24
+ end
25
+
26
+ # This action is called to halt the remote machine.
27
+ def self.action_halt
28
+ Vagrant::Action::Builder.new.tap do |b|
29
+ b.use ConfigValidate
30
+ b.use Call, IsCreated do |env, b2|
31
+ if !env[:result]
32
+ b2.use MessageNotCreated
33
+ next
34
+ end
35
+
36
+ b2.use ConnectMOS
37
+ b2.use StopInstance
38
+ end
39
+ end
40
+ end
41
+
42
+ # This action is called to terminate the remote machine.
43
+ def self.action_destroy
44
+ Vagrant::Action::Builder.new.tap do |b|
45
+ b.use Call, DestroyConfirm do |env, b2|
46
+ if env[:result]
47
+ b2.use ConfigValidate
48
+ b2.use Call, IsCreated do |env2, b3|
49
+ if !env2[:result]
50
+ b3.use MessageNotCreated
51
+ next
52
+ end
53
+ b3.use ConnectMOS
54
+ b3.use ElbDeregisterInstance
55
+ b3.use TerminateInstance
56
+ b3.use ProvisionerCleanup if defined?(ProvisionerCleanup)
57
+ end
58
+ else
59
+ b2.use MessageWillNotDestroy
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ # This action is called when `vagrant provision` is called.
66
+ def self.action_provision
67
+ Vagrant::Action::Builder.new.tap do |b|
68
+ b.use ConfigValidate
69
+ b.use Call, IsCreated do |env, b2|
70
+ if !env[:result]
71
+ b2.use MessageNotCreated
72
+ next
73
+ end
74
+
75
+ b2.use Provision
76
+ b2.use SyncedFolders
77
+ end
78
+ end
79
+ end
80
+
81
+ # This action is called to read the SSH info of the machine. The
82
+ # resulting state is expected to be put into the `:machine_ssh_info`
83
+ # key.
84
+ def self.action_read_ssh_info
85
+ Vagrant::Action::Builder.new.tap do |b|
86
+ b.use ConfigValidate
87
+ b.use ConnectMOS
88
+ b.use ReadSSHInfo
89
+ end
90
+ end
91
+
92
+ # This action is called to read the state of the machine. The
93
+ # resulting state is expected to be put into the `:machine_state_id`
94
+ # key.
95
+ def self.action_read_state
96
+ Vagrant::Action::Builder.new.tap do |b|
97
+ b.use ConfigValidate
98
+ b.use ConnectMOS
99
+ b.use ReadState
100
+ end
101
+ end
102
+
103
+ # This action is called to SSH into the machine.
104
+ def self.action_ssh
105
+ Vagrant::Action::Builder.new.tap do |b|
106
+ b.use ConfigValidate
107
+ b.use Call, IsCreated do |env, b2|
108
+ if !env[:result]
109
+ b2.use MessageNotCreated
110
+ next
111
+ end
112
+
113
+ b2.use SSHExec
114
+ end
115
+ end
116
+ end
117
+
118
+ def self.action_ssh_run
119
+ Vagrant::Action::Builder.new.tap do |b|
120
+ b.use ConfigValidate
121
+ b.use Call, IsCreated do |env, b2|
122
+ if !env[:result]
123
+ b2.use MessageNotCreated
124
+ next
125
+ end
126
+
127
+ b2.use SSHRun
128
+ end
129
+ end
130
+ end
131
+
132
+ def self.action_prepare_boot
133
+ Vagrant::Action::Builder.new.tap do |b|
134
+ b.use Provision
135
+ b.use SyncedFolders
136
+ b.use WarnNetworks
137
+ #b.use ElbRegisterInstance
138
+ end
139
+ end
140
+
141
+ # This action is called to bring the box up from nothing.
142
+ def self.action_up
143
+ Vagrant::Action::Builder.new.tap do |b|
144
+ b.use HandleBox
145
+ b.use ConfigValidate
146
+ b.use BoxCheckOutdated
147
+ b.use ConnectMOS
148
+ b.use Call, IsCreated do |env1, b1|
149
+ if env1[:result]
150
+ b1.use Call, IsStopped do |env2, b2|
151
+ if env2[:result]
152
+ b2.use action_prepare_boot
153
+ b2.use StartInstance # restart this instance
154
+ else
155
+ b2.use MessageAlreadyCreated # TODO write a better message
156
+ end
157
+ end
158
+ else
159
+ b1.use action_prepare_boot
160
+ b1.use RunInstance # launch a new instance
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ def self.action_reload
167
+ Vagrant::Action::Builder.new.tap do |b|
168
+ b.use ConfigValidate
169
+ b.use ConnectMOS
170
+ b.use Call, IsCreated do |env, b2|
171
+ if !env[:result]
172
+ b2.use MessageNotCreated
173
+ next
174
+ end
175
+
176
+ b2.use action_halt
177
+ b2.use Call, WaitForState, "ready", 120 do |env2, b3|
178
+ if env2[:result]
179
+ #b3.use action_up
180
+ b3.use StartInstance
181
+ else
182
+ # TODO we couldn't reach :stopped, what now?
183
+ b3.use StartInstance
184
+ end
185
+ end
186
+ end
187
+ end
188
+ end
189
+
190
+ # The autoload farm
191
+ action_root = Pathname.new(File.expand_path("../action", __FILE__))
192
+ autoload :ConnectMOS, action_root.join("connect_mos")
193
+ autoload :IsCreated, action_root.join("is_created")
194
+ autoload :IsStopped, action_root.join("is_stopped")
195
+ autoload :MessageAlreadyCreated, action_root.join("message_already_created")
196
+ autoload :MessageNotCreated, action_root.join("message_not_created")
197
+ autoload :MessageWillNotDestroy, action_root.join("message_will_not_destroy")
198
+ autoload :PackageInstance, action_root.join("package_instance")
199
+ autoload :ReadSSHInfo, action_root.join("read_ssh_info")
200
+ autoload :ReadState, action_root.join("read_state")
201
+ autoload :RunInstance, action_root.join("run_instance")
202
+ autoload :StartInstance, action_root.join("start_instance")
203
+ autoload :StopInstance, action_root.join("stop_instance")
204
+ autoload :TerminateInstance, action_root.join("terminate_instance")
205
+ autoload :TimedProvision, action_root.join("timed_provision") # some plugins now expect this action to exist
206
+ autoload :WaitForState, action_root.join("wait_for_state")
207
+ autoload :WarnNetworks, action_root.join("warn_networks")
208
+ autoload :ElbRegisterInstance, action_root.join("elb_register_instance")
209
+ autoload :ElbDeregisterInstance, action_root.join("elb_deregister_instance")
210
+ end
211
+ end
212
+ end
@@ -0,0 +1,51 @@
1
+ require "fog"
2
+ require "mos_sdk"
3
+ require "log4r"
4
+
5
+ module VagrantPlugins
6
+ module MOS
7
+ module Action
8
+ # This action connects to MOS, verifies credentials work, and
9
+ # puts the MOS connection object into the `:mos_compute` key
10
+ # in the environment.
11
+ class ConnectMOS
12
+ def initialize(app, env)
13
+ @app = app
14
+ @logger = Log4r::Logger.new("vagrant_mos::action::connect_mos")
15
+ end
16
+
17
+ def call(env)
18
+ # Get the region we're going to booting up in
19
+ region = env[:machine].provider_config.region
20
+
21
+ # Get the configs
22
+ region_config = env[:machine].provider_config.get_region_config(region)
23
+
24
+ # Build the fog config
25
+ fog_config = {
26
+ :provider => :mos,
27
+ :region => region
28
+ }
29
+ if region_config.use_iam_profile
30
+ fog_config[:use_iam_profile] = true
31
+ else
32
+ fog_config[:mos_access_key_id] = region_config.access_key_id
33
+ fog_config[:mos_secret_access_key] = region_config.secret_access_key
34
+ fog_config[:mos_secret_url] = region_config.secret_access_url
35
+ #fog_config[:mos_session_token] = region_config.session_token
36
+ end
37
+
38
+ fog_config[:endpoint] = region_config.endpoint if region_config.endpoint
39
+ fog_config[:version] = region_config.version if region_config.version
40
+
41
+ @logger.info("Connecting to MOS...")
42
+ #env[:mos_compute] = Fog::Compute.new(fog_config)
43
+ env[:mos_compute] = MosSdk::Client.new(region_config.access_key_id, region_config.secret_access_key, region_config.secret_access_url)
44
+ # env[:mos_elb] = Fog::MOS::ELB.new(fog_config.except(:provider, :endpoint))
45
+
46
+ @app.call(env)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,24 @@
1
+ require 'vagrant-mos/util/elb'
2
+
3
+ module VagrantPlugins
4
+ module MOS
5
+ module Action
6
+ # This registers instance in ELB
7
+ class ElbDeregisterInstance
8
+ include ElasticLoadBalancer
9
+
10
+ def initialize(app, env)
11
+ @app = app
12
+ @logger = Log4r::Logger.new("vagrant_mos::action::elb_deregister_instance")
13
+ end
14
+
15
+ def call(env)
16
+ if elb_name = env[:machine].provider_config.elb
17
+ deregister_instance env, elb_name, env[:machine].id
18
+ end
19
+ @app.call(env)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'vagrant-mos/util/elb'
2
+
3
+ module VagrantPlugins
4
+ module MOS
5
+ module Action
6
+ # This registers instance in ELB
7
+ class ElbRegisterInstance
8
+ include ElasticLoadBalancer
9
+
10
+ def initialize(app, env)
11
+ @app = app
12
+ @logger = Log4r::Logger.new("vagrant_mos::action::elb_register_instance")
13
+ end
14
+
15
+ def call(env)
16
+ @app.call(env)
17
+ if elb_name = env[:machine].provider_config.elb
18
+ register_instance env, elb_name, env[:machine].id
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ module VagrantPlugins
2
+ module MOS
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,19 @@
1
+ module VagrantPlugins
2
+ module MOS
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
+ puts env[:machine].state.id
13
+ env[:result] = env[:machine].state.id == "ready"
14
+ @app.call(env)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module MOS
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_mos.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 MOS
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_mos.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 MOS
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_mos.will_not_destroy", name: env[:machine].name))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end