vagrant-cosmic 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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/CHANGELOG.md +8 -0
- data/Docker/.dockerignore +2 -0
- data/Docker/Dockerfile +48 -0
- data/Docker/Dockerfile.chefdk_0_17 +49 -0
- data/Docker/Dockerfile.latest_dependencies +49 -0
- data/Docker/README.md +95 -0
- data/Docker/vac.ps1 +29 -0
- data/Docker/vac.sh +30 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +187 -0
- data/LICENSE +8 -0
- data/README.md +409 -0
- data/Rakefile +106 -0
- data/build_rpm.sh +7 -0
- data/functional-tests/basic/Vagrantfile.basic_networking +34 -0
- data/functional-tests/basic/basic_spec.rb +15 -0
- data/functional-tests/networking/Vagrantfile.advanced_networking +106 -0
- data/functional-tests/networking/networking_spec.rb +14 -0
- data/functional-tests/rsync/Vagrantfile.advanced_networking +40 -0
- data/functional-tests/rsync/rsync_spec.rb +9 -0
- data/functional-tests/vmlifecycle/Vagrantfile.advanced_networking +64 -0
- data/functional-tests/vmlifecycle/vmlifecycle_spec.rb +25 -0
- data/lib/vagrant-cosmic/action/connect_cosmic.rb +47 -0
- data/lib/vagrant-cosmic/action/is_created.rb +18 -0
- data/lib/vagrant-cosmic/action/is_stopped.rb +18 -0
- data/lib/vagrant-cosmic/action/message_already_created.rb +16 -0
- data/lib/vagrant-cosmic/action/message_not_created.rb +16 -0
- data/lib/vagrant-cosmic/action/message_will_not_destroy.rb +16 -0
- data/lib/vagrant-cosmic/action/read_rdp_info.rb +42 -0
- data/lib/vagrant-cosmic/action/read_ssh_info.rb +70 -0
- data/lib/vagrant-cosmic/action/read_state.rb +38 -0
- data/lib/vagrant-cosmic/action/read_transport_info.rb +59 -0
- data/lib/vagrant-cosmic/action/read_winrm_info.rb +69 -0
- data/lib/vagrant-cosmic/action/run_instance.rb +819 -0
- data/lib/vagrant-cosmic/action/start_instance.rb +81 -0
- data/lib/vagrant-cosmic/action/stop_instance.rb +28 -0
- data/lib/vagrant-cosmic/action/terminate_instance.rb +208 -0
- data/lib/vagrant-cosmic/action/timed_provision.rb +21 -0
- data/lib/vagrant-cosmic/action/wait_for_state.rb +41 -0
- data/lib/vagrant-cosmic/action/warn_networks.rb +19 -0
- data/lib/vagrant-cosmic/action.rb +210 -0
- data/lib/vagrant-cosmic/capabilities/rdp.rb +12 -0
- data/lib/vagrant-cosmic/capabilities/winrm.rb +12 -0
- data/lib/vagrant-cosmic/config.rb +422 -0
- data/lib/vagrant-cosmic/errors.rb +27 -0
- data/lib/vagrant-cosmic/exceptions/exceptions.rb +15 -0
- data/lib/vagrant-cosmic/model/cosmic_resource.rb +51 -0
- data/lib/vagrant-cosmic/plugin.rb +82 -0
- data/lib/vagrant-cosmic/provider.rb +58 -0
- data/lib/vagrant-cosmic/service/cosmic_resource_service.rb +76 -0
- data/lib/vagrant-cosmic/util/timer.rb +17 -0
- data/lib/vagrant-cosmic/version.rb +5 -0
- data/lib/vagrant-cosmic.rb +17 -0
- data/locales/en.yml +131 -0
- data/spec/spec_helper.rb +53 -0
- data/spec/vagrant-cosmic/action/read_ssh_info_spec.rb +80 -0
- data/spec/vagrant-cosmic/action/retrieve_public_ip_port_spec.rb +94 -0
- data/spec/vagrant-cosmic/action/run_instance_spec.rb +573 -0
- data/spec/vagrant-cosmic/action/terminate_instance_spec.rb +207 -0
- data/spec/vagrant-cosmic/config_spec.rb +340 -0
- data/spec/vagrant-cosmic/model/cosmic_resource_spec.rb +95 -0
- data/spec/vagrant-cosmic/service/cosmic_resource_service_spec.rb +43 -0
- data/spec/vagrant-cosmic/support/be_a_resource.rb +6 -0
- data/vagrant-cosmic.gemspec +59 -0
- data/vagrant-cosmic.spec +42 -0
- metadata +218 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
require "log4r"
|
2
|
+
require "vagrant/util/retryable"
|
3
|
+
require "vagrant-cosmic/util/timer"
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module Cosmic
|
7
|
+
module Action
|
8
|
+
# This starts a stopped instance.
|
9
|
+
class StartInstance
|
10
|
+
include Vagrant::Util::Retryable
|
11
|
+
|
12
|
+
def initialize(app, env)
|
13
|
+
@app = app
|
14
|
+
@logger = Log4r::Logger.new("vagrant_cosmic::action::start_instance")
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
# Initialize metrics if they haven't been
|
19
|
+
env[:metrics] ||= {}
|
20
|
+
|
21
|
+
server = env[:cosmic_compute].servers.get(env[:machine].id)
|
22
|
+
|
23
|
+
env[:ui].info(I18n.t("vagrant_cosmic.starting"))
|
24
|
+
|
25
|
+
begin
|
26
|
+
server.start
|
27
|
+
|
28
|
+
domain = env[:machine].provider_config.domain_id
|
29
|
+
domain_config = env[:machine].provider_config.get_domain_config(domain)
|
30
|
+
|
31
|
+
# Wait for the instance to be ready first
|
32
|
+
env[:metrics]["instance_ready_time"] = Util::Timer.time do
|
33
|
+
tries = domain_config.instance_ready_timeout / 2
|
34
|
+
|
35
|
+
env[:ui].info(I18n.t("vagrant_cosmic.waiting_for_ready"))
|
36
|
+
begin
|
37
|
+
retryable(:on => Fog::Errors::TimeoutError, :tries => tries) do
|
38
|
+
# If we're interrupted don't worry about waiting
|
39
|
+
next if env[:interrupted]
|
40
|
+
|
41
|
+
# Wait for the server to be ready
|
42
|
+
server.wait_for(2) { ready? }
|
43
|
+
end
|
44
|
+
rescue Fog::Errors::TimeoutError
|
45
|
+
# Notify the user
|
46
|
+
raise Errors::InstanceReadyTimeout,
|
47
|
+
:timeout => domain_config.instance_ready_timeout
|
48
|
+
end
|
49
|
+
end
|
50
|
+
rescue Fog::Cosmic::Compute::Error => e
|
51
|
+
raise Errors::FogError, :message => e.message
|
52
|
+
end
|
53
|
+
|
54
|
+
@logger.info("Time to instance ready: #{env[:metrics]["instance_ready_time"]}")
|
55
|
+
|
56
|
+
if !env[:interrupted]
|
57
|
+
env[:metrics]["instance_ssh_time"] = Util::Timer.time do
|
58
|
+
# Wait for communicator to be ready.
|
59
|
+
communicator = env[:machine].config.vm.communicator
|
60
|
+
communicator = "SSH" if communicator.nil?
|
61
|
+
env[:ui].info(I18n.t("vagrant_cosmic.waiting_for_communicator", :communicator => communicator.to_s.upcase))
|
62
|
+
while true
|
63
|
+
# If we're interrupted then just back out
|
64
|
+
break if env[:interrupted]
|
65
|
+
break if env[:machine].communicate.ready?
|
66
|
+
sleep 2
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
@logger.info("Time for SSH ready: #{env[:metrics]["instance_ssh_time"]}")
|
71
|
+
|
72
|
+
# Ready and booted!
|
73
|
+
env[:ui].info(I18n.t("vagrant_cosmic.ready"))
|
74
|
+
end
|
75
|
+
|
76
|
+
@app.call(env)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Cosmic
|
5
|
+
module Action
|
6
|
+
# This stops the running instance.
|
7
|
+
class StopInstance
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
@logger = Log4r::Logger.new("vagrant_cosmic::action::stop_instance")
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
server = env[:cosmic_compute].servers.get(env[:machine].id)
|
15
|
+
|
16
|
+
if env[:machine].state.id == :stopped
|
17
|
+
env[:ui].info(I18n.t("vagrant_cosmic.already_status", :status => env[:machine].state.id))
|
18
|
+
else
|
19
|
+
env[:ui].info(I18n.t("vagrant_cosmic.stopping"))
|
20
|
+
server.stop({'force' => !!env[:force_halt]})
|
21
|
+
end
|
22
|
+
|
23
|
+
@app.call(env)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,208 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Cosmic
|
5
|
+
module Action
|
6
|
+
# This terminates the running instance.
|
7
|
+
class TerminateInstance
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
@logger = Log4r::Logger.new('vagrant_cosmic::action::terminate_instance')
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
# Delete the Firewall rule
|
15
|
+
remove_firewall_rules(env)
|
16
|
+
|
17
|
+
# Disable Static NAT
|
18
|
+
remove_static_nat(env)
|
19
|
+
|
20
|
+
# Delete the Port forwarding rule
|
21
|
+
remove_portforwarding(env)
|
22
|
+
|
23
|
+
# Destroy the server and remove the tracking ID
|
24
|
+
if env[:machine].id.nil?
|
25
|
+
env[:ui].info(I18n.t('vagrant_cosmic.no_instance_found'))
|
26
|
+
return
|
27
|
+
else
|
28
|
+
server = env[:cosmic_compute].servers.get(env[:machine].id)
|
29
|
+
|
30
|
+
env[:ui].info(I18n.t('vagrant_cosmic.terminating'))
|
31
|
+
|
32
|
+
domain = env[:machine].provider_config.domain_id
|
33
|
+
domain_config = env[:machine].provider_config.get_domain_config(domain)
|
34
|
+
expunge_on_destroy = domain_config.expunge_on_destroy
|
35
|
+
|
36
|
+
options = {}
|
37
|
+
options['expunge'] = expunge_on_destroy
|
38
|
+
|
39
|
+
job = server.destroy(options)
|
40
|
+
wait_for_job_ready(env, job.id, 'Waiting for instance to be deleted')
|
41
|
+
end
|
42
|
+
|
43
|
+
remove_volumes(env)
|
44
|
+
|
45
|
+
# Delete the vmcredentials file
|
46
|
+
remove_stored_credentials(env)
|
47
|
+
|
48
|
+
# Remove keyname from cosmic
|
49
|
+
remove_generated_ssh_key(env)
|
50
|
+
|
51
|
+
env[:machine].id = nil
|
52
|
+
|
53
|
+
env[:ui].info(I18n.t('vagrant_cosmic.terminateinstance_done'))
|
54
|
+
@app.call(env)
|
55
|
+
end
|
56
|
+
|
57
|
+
def remove_volumes(env)
|
58
|
+
volumes_file = env[:machine].data_dir.join('volumes')
|
59
|
+
if volumes_file.file?
|
60
|
+
env[:ui].info(I18n.t('vagrant_cosmic.deleting_volumes'))
|
61
|
+
File.read(volumes_file).each_line do |line|
|
62
|
+
volume_id = line.strip
|
63
|
+
begin
|
64
|
+
resp = env[:cosmic_compute].detach_volume({:id => volume_id})
|
65
|
+
job_id = resp['detachvolumeresponse']['jobid']
|
66
|
+
wait_for_job_ready(env, job_id)
|
67
|
+
rescue Fog::Cosmic::Compute::Error => e
|
68
|
+
if e.message =~ /Unable to execute API command detachvolume.*entity does not exist/
|
69
|
+
env[:ui].warn(I18n.t('vagrant_cosmic.detach_volume_failed', message: e.message))
|
70
|
+
else
|
71
|
+
raise Errors::FogError, :message => e.message
|
72
|
+
end
|
73
|
+
end
|
74
|
+
resp = env[:cosmic_compute].delete_volume({:id => volume_id})
|
75
|
+
env[:ui].warn(I18n.t('vagrant_cosmic.detach_volume_failed', volume_id: volume_id)) unless resp['deletevolumeresponse']['success'] == 'true'
|
76
|
+
end
|
77
|
+
volumes_file.delete
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def remove_generated_ssh_key(env)
|
82
|
+
sshkeyname_file = env[:machine].data_dir.join('sshkeyname')
|
83
|
+
if sshkeyname_file.file?
|
84
|
+
env[:ui].info(I18n.t('vagrant_cosmic.ssh_key_pair_removing'))
|
85
|
+
sshkeyname = ''
|
86
|
+
File.read(sshkeyname_file).each_line do |line|
|
87
|
+
sshkeyname = line.strip
|
88
|
+
end
|
89
|
+
|
90
|
+
begin
|
91
|
+
response = env[:cosmic_compute].delete_ssh_key_pair(name: sshkeyname)
|
92
|
+
env[:ui].warn(I18n.t('vagrant_cosmic.ssh_key_pair_no_success_removing', name: sshkeyname)) unless response['deletesshkeypairresponse']['success'] == 'true'
|
93
|
+
rescue Fog::Cosmic::Compute::Error => e
|
94
|
+
env[:ui].warn(I18n.t('vagrant_cosmic.errors.fog_error', :message => e.message))
|
95
|
+
end
|
96
|
+
sshkeyname_file.delete
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def remove_stored_credentials(env)
|
101
|
+
vmcredentials_file = env[:machine].data_dir.join('vmcredentials')
|
102
|
+
vmcredentials_file.delete if vmcredentials_file.file?
|
103
|
+
end
|
104
|
+
|
105
|
+
def remove_portforwarding(env)
|
106
|
+
env[:ui].info(I18n.t('vagrant_cosmic.deleting_port_forwarding_rule'))
|
107
|
+
port_forwarding_file = env[:machine].data_dir.join('port_forwarding')
|
108
|
+
if port_forwarding_file.file?
|
109
|
+
File.read(port_forwarding_file).each_line do |line|
|
110
|
+
rule_id = line.strip
|
111
|
+
begin
|
112
|
+
resp = env[:cosmic_compute].delete_port_forwarding_rule({:id => rule_id})
|
113
|
+
job_id = resp['deleteportforwardingruleresponse']['jobid']
|
114
|
+
wait_for_job_ready(env, job_id)
|
115
|
+
rescue Fog::Cosmic::Compute::Error => e
|
116
|
+
if e.message =~ /Unable to execute API command deleteportforwardingrule.*entity does not exist/
|
117
|
+
env[:ui].warn(" -- Failed to delete portforwarding rule: #{e.message}")
|
118
|
+
else
|
119
|
+
raise Errors::FogError, :message => e.message
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
124
|
+
port_forwarding_file.delete
|
125
|
+
end
|
126
|
+
|
127
|
+
# Delete the Communicator Port forwording public port file
|
128
|
+
# Delete the RDP Port forwording public port file
|
129
|
+
%w(pf_public_port pf_public_rdp_port).each do |pf_filename|
|
130
|
+
pf_file = env[:machine].data_dir.join(pf_filename)
|
131
|
+
pf_file.delete if pf_file.file?
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def remove_static_nat(env)
|
136
|
+
env[:ui].info(I18n.t('vagrant_cosmic.disabling_static_nat'))
|
137
|
+
static_nat_file = env[:machine].data_dir.join('static_nat')
|
138
|
+
if static_nat_file.file?
|
139
|
+
File.read(static_nat_file).each_line do |line|
|
140
|
+
ip_address_id = line.strip
|
141
|
+
begin
|
142
|
+
options = {
|
143
|
+
:command => 'disableStaticNat',
|
144
|
+
:ipaddressid => ip_address_id
|
145
|
+
}
|
146
|
+
resp = env[:cosmic_compute].request(options)
|
147
|
+
job_id = resp['disablestaticnatresponse']['jobid']
|
148
|
+
wait_for_job_ready(env, job_id)
|
149
|
+
rescue Fog::Cosmic::Compute::Error => e
|
150
|
+
raise Errors::FogError, :message => e.message
|
151
|
+
end
|
152
|
+
end
|
153
|
+
static_nat_file.delete
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def remove_firewall_rules(env)
|
158
|
+
env[:ui].info(I18n.t('vagrant_cosmic.deleting_firewall_rule'))
|
159
|
+
firewall_file = env[:machine].data_dir.join('firewall')
|
160
|
+
if firewall_file.file?
|
161
|
+
File.read(firewall_file).each_line do |line|
|
162
|
+
line_items=line.split(",").collect(&:strip)
|
163
|
+
rule_id = line_items[0]
|
164
|
+
type_string = line_items[1]
|
165
|
+
|
166
|
+
if type_string == 'firewallrule'
|
167
|
+
command_string = 'deleteFirewallRule'
|
168
|
+
response_string = 'deletefirewallruleresponse'
|
169
|
+
else
|
170
|
+
command_string = 'deleteNetworkACL'
|
171
|
+
response_string = 'deletenetworkaclresponse'
|
172
|
+
end
|
173
|
+
|
174
|
+
begin
|
175
|
+
options = {
|
176
|
+
command: command_string,
|
177
|
+
id: rule_id
|
178
|
+
}
|
179
|
+
resp = env[:cosmic_compute].request(options)
|
180
|
+
job_id = resp[response_string]['jobid']
|
181
|
+
wait_for_job_ready(env, job_id)
|
182
|
+
rescue Fog::Cosmic::Compute::Error => e
|
183
|
+
if e.message =~ /Unable to execute API command deletefirewallrule.*entity does not exist/
|
184
|
+
env[:ui].warn(" -- Failed to delete #{type_string}: #{e.message}")
|
185
|
+
else
|
186
|
+
raise Errors::FogError, :message => e.message
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
firewall_file.delete
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def wait_for_job_ready(env, job_id, message=nil)
|
195
|
+
while true
|
196
|
+
response = env[:cosmic_compute].query_async_job_result({:jobid => job_id})
|
197
|
+
if response['queryasyncjobresultresponse']['jobstatus'] != 0
|
198
|
+
break
|
199
|
+
else
|
200
|
+
env[:ui].info(message) if message
|
201
|
+
sleep 2
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "vagrant-cosmic/util/timer"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Cosmic
|
5
|
+
module Action
|
6
|
+
# This is the same as the builtin provision except it times the
|
7
|
+
# provisioner runs.
|
8
|
+
class TimedProvision < Vagrant::Action::Builtin::Provision
|
9
|
+
def run_provisioner(env, pname, p)
|
10
|
+
timer = Util::Timer.time do
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
env[:metrics] ||= {}
|
15
|
+
env[:metrics]["provisioner_times"] ||= []
|
16
|
+
env[:metrics]["provisioner_times"] << [p.class.to_s, timer]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "log4r"
|
2
|
+
require "timeout"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module Cosmic
|
6
|
+
module Action
|
7
|
+
# This action will wait for a machine to reach a specific state or quit by timeout
|
8
|
+
class WaitForState
|
9
|
+
# env[:result] will be false in case of timeout.
|
10
|
+
# @param [Symbol] state Target machine state.
|
11
|
+
# @param [Number] timeout Timeout in seconds.
|
12
|
+
def initialize(app, env, state, timeout)
|
13
|
+
@app = app
|
14
|
+
@logger = Log4r::Logger.new("vagrant_cosmic::action::wait_for_state")
|
15
|
+
@state = state
|
16
|
+
@timeout = timeout
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
env[:result] = true
|
21
|
+
if env[:machine].state.id == @state
|
22
|
+
@logger.info(I18n.t("vagrant_cosmic.already_status", :status => @state))
|
23
|
+
else
|
24
|
+
@logger.info("Waiting for machine to reach state #{@state}")
|
25
|
+
begin
|
26
|
+
Timeout.timeout(@timeout) do
|
27
|
+
until env[:machine].state.id == @state
|
28
|
+
sleep 2
|
29
|
+
end
|
30
|
+
end
|
31
|
+
rescue Timeout::Error
|
32
|
+
env[:result] = false # couldn't reach state in time
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
@app.call(env)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Cosmic
|
3
|
+
module Action
|
4
|
+
class WarnNetworks
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
if env[:machine].config.vm.networks.length > 0
|
11
|
+
env[:ui].warn(I18n.t("vagrant_cosmic.warn_networks"))
|
12
|
+
end
|
13
|
+
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require "pathname"
|
2
|
+
require "vagrant/action/builder"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module Cosmic
|
6
|
+
module Action
|
7
|
+
# Include the built-in modules so we can use them as top-level things.
|
8
|
+
include Vagrant::Action::Builtin
|
9
|
+
|
10
|
+
# This action is called to halt the remote machine.
|
11
|
+
def self.action_halt
|
12
|
+
Vagrant::Action::Builder.new.tap do |b|
|
13
|
+
b.use ConfigValidate
|
14
|
+
b.use Call, IsCreated do |env, b2|
|
15
|
+
if !env[:result]
|
16
|
+
b2.use MessageNotCreated
|
17
|
+
next
|
18
|
+
end
|
19
|
+
|
20
|
+
b2.use ConnectCosmic
|
21
|
+
b2.use StopInstance
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# This action is called to terminate the remote machine.
|
27
|
+
def self.action_destroy
|
28
|
+
Vagrant::Action::Builder.new.tap do |b|
|
29
|
+
b.use Call, DestroyConfirm do |env, b2|
|
30
|
+
if env[:result]
|
31
|
+
b2.use ConfigValidate
|
32
|
+
b.use Call, IsCreated do |env2, b3|
|
33
|
+
if !env2[:result]
|
34
|
+
b3.use MessageNotCreated
|
35
|
+
next
|
36
|
+
end
|
37
|
+
end
|
38
|
+
b2.use ConnectCosmic
|
39
|
+
b2.use TerminateInstance
|
40
|
+
else
|
41
|
+
b2.use MessageWillNotDestroy
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# This action is called when `vagrant provision` is called.
|
48
|
+
def self.action_provision
|
49
|
+
Vagrant::Action::Builder.new.tap do |b|
|
50
|
+
b.use ConfigValidate
|
51
|
+
b.use Call, IsCreated do |env, b2|
|
52
|
+
if !env[:result]
|
53
|
+
b2.use MessageNotCreated
|
54
|
+
next
|
55
|
+
end
|
56
|
+
|
57
|
+
b2.use Provision
|
58
|
+
b2.use SyncedFolders
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# This action is called to read the WinRM info of the machine. The
|
64
|
+
# resulting state is expected to be put into the `:machine_winrm_info`
|
65
|
+
# key.
|
66
|
+
def self.action_read_rdp_info
|
67
|
+
Vagrant::Action::Builder.new.tap do |b|
|
68
|
+
b.use ConfigValidate
|
69
|
+
b.use ConnectCosmic
|
70
|
+
b.use ReadRdpInfo
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# This action is called to read the WinRM info of the machine. The
|
75
|
+
# resulting state is expected to be put into the `:machine_winrm_info`
|
76
|
+
# key.
|
77
|
+
def self.action_read_winrm_info
|
78
|
+
Vagrant::Action::Builder.new.tap do |b|
|
79
|
+
b.use ConfigValidate
|
80
|
+
b.use ConnectCosmic
|
81
|
+
b.use ReadWinrmInfo
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# This action is called to read the SSH info of the machine. The
|
86
|
+
# resulting state is expected to be put into the `:machine_ssh_info`
|
87
|
+
# key.
|
88
|
+
def self.action_read_ssh_info
|
89
|
+
Vagrant::Action::Builder.new.tap do |b|
|
90
|
+
b.use ConfigValidate
|
91
|
+
b.use ConnectCosmic
|
92
|
+
b.use ReadSSHInfo
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# This action is called to read the state of the machine. The
|
97
|
+
# resulting state is expected to be put into the `:machine_state_id`
|
98
|
+
# key.
|
99
|
+
def self.action_read_state
|
100
|
+
Vagrant::Action::Builder.new.tap do |b|
|
101
|
+
b.use ConfigValidate
|
102
|
+
b.use ConnectCosmic
|
103
|
+
b.use ReadState
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# This action is called to SSH into the machine.
|
108
|
+
def self.action_ssh
|
109
|
+
Vagrant::Action::Builder.new.tap do |b|
|
110
|
+
b.use ConfigValidate
|
111
|
+
b.use Call, IsCreated do |env, b2|
|
112
|
+
if !env[:result]
|
113
|
+
b2.use MessageNotCreated
|
114
|
+
next
|
115
|
+
end
|
116
|
+
|
117
|
+
b2.use SSHExec
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.action_ssh_run
|
123
|
+
Vagrant::Action::Builder.new.tap do |b|
|
124
|
+
b.use ConfigValidate
|
125
|
+
b.use Call, IsCreated do |env, b2|
|
126
|
+
if !env[:result]
|
127
|
+
b2.use MessageNotCreated
|
128
|
+
next
|
129
|
+
end
|
130
|
+
|
131
|
+
b2.use SSHRun
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def self.action_prepare_boot
|
137
|
+
Vagrant::Action::Builder.new.tap do |b|
|
138
|
+
b.use Provision
|
139
|
+
b.use SyncedFolders
|
140
|
+
b.use WarnNetworks
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# This action is called to bring the box up from nothing.
|
145
|
+
def self.action_up
|
146
|
+
Vagrant::Action::Builder.new.tap do |b|
|
147
|
+
b.use ConfigValidate
|
148
|
+
b.use ConnectCosmic
|
149
|
+
b.use Call, IsCreated do |env1, b1|
|
150
|
+
if env1[:result]
|
151
|
+
b1.use Call, IsStopped do |env2, b2|
|
152
|
+
if env2[:result]
|
153
|
+
b2.use action_prepare_boot
|
154
|
+
b2.use StartInstance # restart this instance
|
155
|
+
else
|
156
|
+
b2.use MessageAlreadyCreated # TODO write a better message
|
157
|
+
end
|
158
|
+
end
|
159
|
+
else
|
160
|
+
b1.use action_prepare_boot
|
161
|
+
b1.use RunInstance # launch a new instance
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def self.action_reload
|
168
|
+
Vagrant::Action::Builder.new.tap do |b|
|
169
|
+
b.use ConfigValidate
|
170
|
+
b.use ConnectCosmic
|
171
|
+
b.use Call, IsCreated do |env, b2|
|
172
|
+
if !env[:result]
|
173
|
+
b2.use MessageNotCreated
|
174
|
+
next
|
175
|
+
end
|
176
|
+
|
177
|
+
b2.use action_halt
|
178
|
+
b2.use Call, WaitForState, :stopped, 120 do |env2, b3|
|
179
|
+
if env2[:result]
|
180
|
+
b3.use action_up
|
181
|
+
else
|
182
|
+
# TODO we couldn't reach :stopped, what now?
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
# The autoload farm
|
190
|
+
action_root = Pathname.new(File.expand_path("../action", __FILE__))
|
191
|
+
autoload :ConnectCosmic, action_root.join("connect_cosmic")
|
192
|
+
autoload :IsCreated, action_root.join("is_created")
|
193
|
+
autoload :IsStopped, action_root.join("is_stopped")
|
194
|
+
autoload :MessageAlreadyCreated, action_root.join("message_already_created")
|
195
|
+
autoload :MessageNotCreated, action_root.join("message_not_created")
|
196
|
+
autoload :MessageWillNotDestroy, action_root.join("message_will_not_destroy")
|
197
|
+
autoload :ReadSSHInfo, action_root.join("read_ssh_info")
|
198
|
+
autoload :ReadWinrmInfo, action_root.join("read_winrm_info")
|
199
|
+
autoload :ReadRdpInfo, action_root.join("read_rdp_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 :TimedProvision, action_root.join("timed_provision")
|
205
|
+
autoload :WaitForState, action_root.join("wait_for_state")
|
206
|
+
autoload :WarnNetworks, action_root.join("warn_networks")
|
207
|
+
autoload :TerminateInstance, action_root.join("terminate_instance")
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|