vagrant-softlayer 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,208 +1,242 @@
1
- require "pathname"
2
- require "vagrant-softlayer/util/load_balancer"
3
- require "vagrant-softlayer/util/network"
4
- require "vagrant-softlayer/util/warden"
5
-
6
- module VagrantPlugins
7
- module SoftLayer
8
- module Action
9
- # Include the built-in modules so we can use them as top-level things.
10
- include Vagrant::Action::Builtin
11
-
12
- # This action is called to terminate the remote machine.
13
- def self.action_destroy
14
- Vagrant::Action::Builder.new.tap do |b|
15
- b.use Call, DestroyConfirm do |env, b2|
16
- if env[:result]
17
- b2.use ConfigValidate
18
- b.use Call, Is, :not_created do |env2, b3|
19
- if env2[:result]
20
- b3.use Message, :error, "vagrant_softlayer.vm.not_created"
21
- next
22
- end
23
- end
24
- b2.use SetupSoftLayer
25
- b2.use UpdateDNS
26
- b2.use DestroyInstance
27
- b2.use LoadBalancerCleanup
28
- b2.use ProvisionerCleanup
29
- else
30
- b2.use Message, :warn, "vagrant_softlayer.vm.not_destroying"
31
- end
32
- end
33
- end
34
- end
35
-
36
- # This action is called to halt the remote machine.
37
- def self.action_halt
38
- Vagrant::Action::Builder.new.tap do |b|
39
- b.use ConfigValidate
40
- b.use Call, Is, :running do |env, b2|
41
- if !env[:result]
42
- b2.use Message, :error, "vagrant_softlayer.vm.not_running"
43
- next
44
- end
45
-
46
- b2.use SetupSoftLayer
47
- b2.use StopInstance
48
- end
49
- end
50
- end
51
-
52
- # This action is called to run provisioners on the machine.
53
- def self.action_provision
54
- Vagrant::Action::Builder.new.tap do |b|
55
- b.use ConfigValidate
56
- b.use Call, Is, :running do |env, b2|
57
- if !env[:result]
58
- b2.use Message, :error, "vagrant_softlayer.vm.not_running"
59
- next
60
- end
61
-
62
- b2.use Provision
63
- b2.use SyncFolders
64
- end
65
- end
66
- end
67
-
68
- # This action is called to read the SSH info of the machine. The
69
- # resulting state is expected to be put into the `:machine_ssh_info`
70
- # key.
71
- def self.action_read_ssh_info
72
- Vagrant::Action::Builder.new.tap do |b|
73
- b.use ConfigValidate
74
- b.use SetupSoftLayer
75
- b.use ReadSSHInfo
76
- end
77
- end
78
-
79
- # This action is called to read the state of the machine. The
80
- # resulting state is expected to be put into the `:machine_state_id`
81
- # key.
82
- def self.action_read_state
83
- Vagrant::Action::Builder.new.tap do |b|
84
- b.use ConfigValidate
85
- b.use SetupSoftLayer
86
- b.use ReadState
87
- end
88
- end
89
-
90
- # This action is called to rebuild the machine OS from scratch.
91
- def self.action_rebuild
92
- Vagrant::Action::Builder.new.tap do |b|
93
- b.use Call, Confirm, I18n.t("vagrant_softlayer.vm.rebuild_confirmation"), :force_rebuild do |env, b2|
94
- if env[:result]
95
- b2.use ConfigValidate
96
- b.use Call, Is, :not_created do |env2, b3|
97
- if env2[:result]
98
- b3.use Message, :error, "vagrant_softlayer.vm.not_created"
99
- next
100
- end
101
- end
102
- b2.use SetupSoftLayer
103
- b2.use RebuildInstance
104
- b2.use Provision
105
- b2.use SyncFolders
106
- b2.use WaitForRebuild
107
- b2.use WaitForCommunicator
108
- else
109
- b2.use Message, :warn, "vagrant_softlayer.vm.not_rebuilding"
110
- end
111
- end
112
- end
113
- end
114
-
115
- # This action is called to reload the machine.
116
- def self.action_reload
117
- Vagrant::Action::Builder.new.tap do |b|
118
- b.use action_halt
119
- b.use action_up
120
- end
121
- end
122
-
123
- # This action is called to SSH into the machine.
124
- def self.action_ssh
125
- Vagrant::Action::Builder.new.tap do |b|
126
- b.use ConfigValidate
127
- b.use Call, Is, :running do |env, b2|
128
- if !env[:result]
129
- b2.use Message, :error, "vagrant_softlayer.vm.not_running"
130
- next
131
- end
132
-
133
- b2.use SSHExec
134
- end
135
- end
136
- end
137
-
138
- def self.action_ssh_run
139
- Vagrant::Action::Builder.new.tap do |b|
140
- b.use ConfigValidate
141
- b.use Call, Is, :running do |env, b2|
142
- if !env[:result]
143
- b2.use Message, :error, "vagrant_softlayer.vm.not_running"
144
- next
145
- end
146
-
147
- b2.use SSHRun
148
- end
149
- end
150
- end
151
-
152
- # This action is called to bring the box up from nothing.
153
- def self.action_up
154
- Vagrant::Action::Builder.new.tap do |b|
155
- b.use HandleBoxUrl
156
- b.use ConfigValidate
157
- b.use SetupSoftLayer
158
- b.use Call, Is, :not_created do |env1, b1|
159
- if env1[:result]
160
- b1.use SetupSoftLayer
161
- b1.use Provision
162
- b1.use SyncFolders
163
- b1.use CreateInstance
164
- b1.use WaitForProvision
165
- b1.use UpdateDNS
166
- b1.use JoinLoadBalancer
167
- b1.use WaitForCommunicator
168
- else
169
- b1.use Call, Is, :halted do |env2, b2|
170
- if env2[:result]
171
- b2.use SetupSoftLayer
172
- b2.use Provision
173
- b2.use SyncFolders
174
- b2.use StartInstance
175
- b2.use UpdateDNS
176
- b2.use JoinLoadBalancer
177
- b2.use WaitForCommunicator
178
- else
179
- b2.use Message, :warn, "vagrant_softlayer.vm.already_running"
180
- end
181
- end
182
- end
183
- end
184
- end
185
- end
186
-
187
- # The autoload farm
188
- action_root = Pathname.new(File.expand_path("../action", __FILE__))
189
-
190
- autoload :CreateInstance, action_root.join("create_instance")
191
- autoload :DestroyInstance, action_root.join("destroy_instance")
192
- autoload :Is, action_root.join("is")
193
- autoload :JoinLoadBalancer, action_root.join("join_load_balancer")
194
- autoload :LoadBalancerCleanup, action_root.join("load_balancer_cleanup")
195
- autoload :Message, action_root.join("message")
196
- autoload :ReadSSHInfo, action_root.join("read_ssh_info")
197
- autoload :ReadState, action_root.join("read_state")
198
- autoload :RebuildInstance, action_root.join("rebuild_instance")
199
- autoload :SetupSoftLayer, action_root.join("setup_softlayer")
200
- autoload :StartInstance, action_root.join("start_instance")
201
- autoload :StopInstance, action_root.join("stop_instance")
202
- autoload :SyncFolders, action_root.join("sync_folders")
203
- autoload :UpdateDNS, action_root.join("update_dns")
204
- autoload :WaitForProvision, action_root.join("wait_for_provision")
205
- autoload :WaitForRebuild, action_root.join("wait_for_rebuild")
206
- end
207
- end
208
- end
1
+ require "pathname"
2
+ require "vagrant-softlayer/util/load_balancer"
3
+ require "vagrant-softlayer/util/network"
4
+ require "vagrant-softlayer/util/warden"
5
+
6
+ module VagrantPlugins
7
+ module SoftLayer
8
+ module Action
9
+ # Include the built-in modules so we can use them as top-level things.
10
+ include Vagrant::Action::Builtin
11
+
12
+ # This action is called to terminate the remote machine.
13
+ def self.action_destroy
14
+ Vagrant::Action::Builder.new.tap do |b|
15
+ b.use Call, DestroyConfirm do |env, b2|
16
+ if env[:result]
17
+ b2.use ConfigValidate
18
+ b.use Call, Is, :not_created do |env2, b3|
19
+ if env2[:result]
20
+ b3.use Message, :error, "vagrant_softlayer.vm.not_created"
21
+ next
22
+ end
23
+ end
24
+ b2.use SetupSoftLayer
25
+ b2.use UpdateDNS
26
+ b2.use DestroyInstance
27
+ b2.use LoadBalancerCleanup
28
+ b2.use ProvisionerCleanup
29
+ else
30
+ b2.use Message, :warn, "vagrant_softlayer.vm.not_destroying"
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ # This action is called to halt the remote machine.
37
+ def self.action_halt
38
+ Vagrant::Action::Builder.new.tap do |b|
39
+ b.use ConfigValidate
40
+ b.use Call, Is, :running do |env, b2|
41
+ if !env[:result]
42
+ b2.use Message, :error, "vagrant_softlayer.vm.not_running"
43
+ next
44
+ end
45
+
46
+ b2.use SetupSoftLayer
47
+ b2.use StopInstance
48
+ end
49
+ end
50
+ end
51
+
52
+ # This action is called to run provisioners on the machine.
53
+ def self.action_provision
54
+ Vagrant::Action::Builder.new.tap do |b|
55
+ b.use ConfigValidate
56
+ b.use Call, Is, :running do |env, b2|
57
+ if !env[:result]
58
+ b2.use Message, :error, "vagrant_softlayer.vm.not_running"
59
+ next
60
+ end
61
+
62
+ b2.use Provision
63
+ b2.use SyncFolders
64
+ end
65
+ end
66
+ end
67
+
68
+ # This action is called to read the SSH info of the machine. The
69
+ # resulting state is expected to be put into the `:machine_ssh_info`
70
+ # key.
71
+ def self.action_read_ssh_info
72
+ Vagrant::Action::Builder.new.tap do |b|
73
+ b.use ConfigValidate
74
+ b.use SetupSoftLayer
75
+ b.use ReadSSHInfo
76
+ end
77
+ end
78
+
79
+ # This action is called to read the state of the machine. The
80
+ # resulting state is expected to be put into the `:machine_state_id`
81
+ # key.
82
+ def self.action_read_state
83
+ Vagrant::Action::Builder.new.tap do |b|
84
+ b.use ConfigValidate
85
+ b.use SetupSoftLayer
86
+ b.use ReadState
87
+ end
88
+ end
89
+
90
+ # This action is called to rebuild the machine OS from scratch.
91
+ def self.action_rebuild
92
+ Vagrant::Action::Builder.new.tap do |b|
93
+ b.use Call, Confirm, I18n.t("vagrant_softlayer.vm.rebuild_confirmation"), :force_rebuild do |env, b2|
94
+ if env[:result]
95
+ b2.use ConfigValidate
96
+ b.use Call, Is, :not_created do |env2, b3|
97
+ if env2[:result]
98
+ b3.use Message, :error, "vagrant_softlayer.vm.not_created"
99
+ next
100
+ end
101
+ end
102
+ b2.use SetupSoftLayer
103
+ b2.use RebuildInstance
104
+ b2.use Provision
105
+ b2.use SyncFolders
106
+ b2.use WaitForRebuild
107
+ b2.use WaitForCommunicator
108
+ else
109
+ b2.use Message, :warn, "vagrant_softlayer.vm.not_rebuilding"
110
+ end
111
+ end
112
+ end
113
+ end
114
+
115
+ # This action is called to reload the machine.
116
+ def self.action_reload
117
+ Vagrant::Action::Builder.new.tap do |b|
118
+ b.use action_halt
119
+ b.use action_up
120
+ end
121
+ end
122
+
123
+ # This action is called to resume the remote machine.
124
+ def self.action_resume
125
+ Vagrant::Action::Builder.new.tap do |b|
126
+ b.use ConfigValidate
127
+ b.use Call, Is, :paused do |env, b2|
128
+ if !env[:result]
129
+ b2.use Message, :error, "vagrant_softlayer.vm.not_paused"
130
+ next
131
+ end
132
+
133
+ b2.use SetupSoftLayer
134
+ b2.use ResumeInstance
135
+ end
136
+ end
137
+ end
138
+
139
+ # This action is called to SSH into the machine.
140
+ def self.action_ssh
141
+ Vagrant::Action::Builder.new.tap do |b|
142
+ b.use ConfigValidate
143
+ b.use Call, Is, :running do |env, b2|
144
+ if !env[:result]
145
+ b2.use Message, :error, "vagrant_softlayer.vm.not_running"
146
+ next
147
+ end
148
+
149
+ b2.use SSHExec
150
+ end
151
+ end
152
+ end
153
+
154
+ def self.action_ssh_run
155
+ Vagrant::Action::Builder.new.tap do |b|
156
+ b.use ConfigValidate
157
+ b.use Call, Is, :running do |env, b2|
158
+ if !env[:result]
159
+ b2.use Message, :error, "vagrant_softlayer.vm.not_running"
160
+ next
161
+ end
162
+
163
+ b2.use SSHRun
164
+ end
165
+ end
166
+ end
167
+
168
+ # This action is called to suspend the remote machine.
169
+ def self.action_suspend
170
+ Vagrant::Action::Builder.new.tap do |b|
171
+ b.use ConfigValidate
172
+ b.use Call, Is, :running do |env, b2|
173
+ if !env[:result]
174
+ b2.use Message, :error, "vagrant_softlayer.vm.not_running"
175
+ next
176
+ end
177
+
178
+ b2.use SetupSoftLayer
179
+ b2.use SuspendInstance
180
+ end
181
+ end
182
+ end
183
+
184
+ # This action is called to bring the box up from nothing.
185
+ def self.action_up
186
+ Vagrant::Action::Builder.new.tap do |b|
187
+ b.use HandleBoxUrl
188
+ b.use ConfigValidate
189
+ b.use SetupSoftLayer
190
+ b.use Call, Is, :not_created do |env1, b1|
191
+ if env1[:result]
192
+ b1.use SetupSoftLayer
193
+ b1.use Provision
194
+ b1.use SyncFolders
195
+ b1.use CreateInstance
196
+ b1.use WaitForProvision
197
+ b1.use UpdateDNS
198
+ b1.use JoinLoadBalancer
199
+ b1.use WaitForCommunicator
200
+ else
201
+ b1.use Call, Is, :halted do |env2, b2|
202
+ if env2[:result]
203
+ b2.use SetupSoftLayer
204
+ b2.use Provision
205
+ b2.use SyncFolders
206
+ b2.use StartInstance
207
+ b2.use UpdateDNS
208
+ b2.use JoinLoadBalancer
209
+ b2.use WaitForCommunicator
210
+ else
211
+ b2.use Message, :warn, "vagrant_softlayer.vm.already_running"
212
+ end
213
+ end
214
+ end
215
+ end
216
+ end
217
+ end
218
+
219
+ # The autoload farm
220
+ action_root = Pathname.new(File.expand_path("../action", __FILE__))
221
+
222
+ autoload :CreateInstance, action_root.join("create_instance")
223
+ autoload :DestroyInstance, action_root.join("destroy_instance")
224
+ autoload :Is, action_root.join("is")
225
+ autoload :JoinLoadBalancer, action_root.join("join_load_balancer")
226
+ autoload :LoadBalancerCleanup, action_root.join("load_balancer_cleanup")
227
+ autoload :Message, action_root.join("message")
228
+ autoload :ReadSSHInfo, action_root.join("read_ssh_info")
229
+ autoload :ReadState, action_root.join("read_state")
230
+ autoload :RebuildInstance, action_root.join("rebuild_instance")
231
+ autoload :ResumeInstance, action_root.join("resume_instance")
232
+ autoload :SetupSoftLayer, action_root.join("setup_softlayer")
233
+ autoload :StartInstance, action_root.join("start_instance")
234
+ autoload :StopInstance, action_root.join("stop_instance")
235
+ autoload :SuspendInstance, action_root.join("suspend_instance")
236
+ autoload :SyncFolders, action_root.join("sync_folders")
237
+ autoload :UpdateDNS, action_root.join("update_dns")
238
+ autoload :WaitForProvision, action_root.join("wait_for_provision")
239
+ autoload :WaitForRebuild, action_root.join("wait_for_rebuild")
240
+ end
241
+ end
242
+ end