vagrant-cloudstack 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +18 -19
- data/.ruby-version +1 -1
- data/.travis.yml +19 -19
- data/CHANGELOG.md +179 -171
- data/Docker/.dockerignore +2 -0
- data/Docker/Dockerfile +51 -0
- data/Docker/Dockerfile.chefdk_0_17 +49 -0
- data/Docker/Dockerfile.latest_dependencies +49 -0
- data/Docker/README.md +67 -0
- data/Docker/vac.ps1 +29 -0
- data/Docker/vac.sh +30 -0
- data/Gemfile +20 -20
- data/LICENSE +8 -8
- data/README.md +416 -416
- data/Rakefile +106 -99
- data/bootstrap.key +27 -0
- data/build_rpm.sh +7 -7
- data/functional-tests/basic/Vagrantfile.basic_networking +45 -45
- data/functional-tests/basic/basic_spec.rb +21 -21
- data/functional-tests/networking/Vagrantfile.advanced_networking +119 -102
- data/functional-tests/networking/networking_spec.rb +14 -0
- data/functional-tests/rsync/Vagrantfile.advanced_networking +39 -56
- data/functional-tests/rsync/rsync_spec.rb +9 -9
- data/functional-tests/vmlifecycle/Vagrantfile.advanced_networking +66 -82
- data/functional-tests/vmlifecycle/vmlifecycle_spec.rb +13 -13
- data/lib/vagrant-cloudstack/action/connect_cloudstack.rb +47 -47
- data/lib/vagrant-cloudstack/action/is_created.rb +18 -18
- data/lib/vagrant-cloudstack/action/is_stopped.rb +18 -18
- data/lib/vagrant-cloudstack/action/message_already_created.rb +16 -16
- data/lib/vagrant-cloudstack/action/message_not_created.rb +16 -16
- data/lib/vagrant-cloudstack/action/message_will_not_destroy.rb +16 -16
- data/lib/vagrant-cloudstack/action/read_rdp_info.rb +76 -76
- data/lib/vagrant-cloudstack/action/read_ssh_info.rb +104 -87
- data/lib/vagrant-cloudstack/action/read_state.rb +38 -38
- data/lib/vagrant-cloudstack/action/read_winrm_info.rb +103 -103
- data/lib/vagrant-cloudstack/action/run_instance.rb +798 -703
- data/lib/vagrant-cloudstack/action/start_instance.rb +81 -81
- data/lib/vagrant-cloudstack/action/stop_instance.rb +28 -28
- data/lib/vagrant-cloudstack/action/terminate_instance.rb +269 -224
- data/lib/vagrant-cloudstack/action/timed_provision.rb +21 -21
- data/lib/vagrant-cloudstack/action/wait_for_state.rb +41 -41
- data/lib/vagrant-cloudstack/action/warn_networks.rb +19 -19
- data/lib/vagrant-cloudstack/action.rb +210 -210
- data/lib/vagrant-cloudstack/capabilities/rdp.rb +12 -12
- data/lib/vagrant-cloudstack/capabilities/winrm.rb +12 -12
- data/lib/vagrant-cloudstack/config.rb +566 -548
- data/lib/vagrant-cloudstack/errors.rb +27 -27
- data/lib/vagrant-cloudstack/exceptions/exceptions.rb +10 -10
- data/lib/vagrant-cloudstack/model/cloudstack_resource.rb +51 -33
- data/lib/vagrant-cloudstack/plugin.rb +82 -82
- data/lib/vagrant-cloudstack/provider.rb +58 -58
- data/lib/vagrant-cloudstack/service/cloudstack_resource_service.rb +64 -58
- data/lib/vagrant-cloudstack/util/timer.rb +17 -17
- data/lib/vagrant-cloudstack/version.rb +5 -5
- data/lib/vagrant-cloudstack.rb +17 -17
- data/locales/en.yml +131 -123
- data/spec/spec_helper.rb +8 -6
- data/spec/vagrant-cloudstack/action/read_ssh_info_spec.rb +80 -0
- data/spec/vagrant-cloudstack/config_spec.rb +355 -355
- data/spec/vagrant-cloudstack/model/cloudstack_resource_spec.rb +95 -73
- data/spec/vagrant-cloudstack/service/cloudstack_resource_service_spec.rb +43 -43
- data/spec/vagrant-cloudstack/support/be_a_resource.rb +6 -0
- data/vagrant-cloudstack.gemspec +59 -59
- data/vagrant-cloudstack.spec +42 -42
- metadata +14 -7
- data/dummy.box +0 -0
- data/example_box/README.md +0 -13
- data/example_box/metadata.json +0 -3
- data/functional-tests/networking/rsync_spec.rb +0 -12
@@ -1,16 +1,16 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module Cloudstack
|
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_cloudstack.already_status", :status => "created"))
|
11
|
-
@app.call(env)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
1
|
+
module VagrantPlugins
|
2
|
+
module Cloudstack
|
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_cloudstack.already_status", :status => "created"))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module Cloudstack
|
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_cloudstack.not_created"))
|
11
|
-
@app.call(env)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
1
|
+
module VagrantPlugins
|
2
|
+
module Cloudstack
|
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_cloudstack.not_created"))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module Cloudstack
|
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_cloudstack.will_not_destroy", name: env[:machine].name))
|
11
|
-
@app.call(env)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
1
|
+
module VagrantPlugins
|
2
|
+
module Cloudstack
|
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_cloudstack.will_not_destroy", name: env[:machine].name))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,76 +1,76 @@
|
|
1
|
-
require 'log4r'
|
2
|
-
|
3
|
-
module VagrantPlugins
|
4
|
-
module Cloudstack
|
5
|
-
module Action
|
6
|
-
# This action reads the WinRM info for the machine and puts it into the
|
7
|
-
# `:machine_winrm_info` key in the environment.
|
8
|
-
class ReadRdpInfo
|
9
|
-
def initialize(app, env)
|
10
|
-
@app = app
|
11
|
-
@logger = Log4r::Logger.new("vagrant_cloudstack::action::read_rdp_info")
|
12
|
-
end
|
13
|
-
|
14
|
-
def call(env)
|
15
|
-
env[:machine_rdp_info] = read_rdp_info(env[:cloudstack_compute], env[:machine])
|
16
|
-
|
17
|
-
@app.call(env)
|
18
|
-
end
|
19
|
-
|
20
|
-
def read_rdp_info(cloudstack, machine)
|
21
|
-
return nil if machine.id.nil?
|
22
|
-
|
23
|
-
# Find the machine
|
24
|
-
server = cloudstack.servers.get(machine.id)
|
25
|
-
if server.nil?
|
26
|
-
# The machine can't be found
|
27
|
-
@logger.info("Machine couldn't be found, assuming it got destroyed.")
|
28
|
-
machine.id = nil
|
29
|
-
return nil
|
30
|
-
end
|
31
|
-
|
32
|
-
# Get the Port forwarding config
|
33
|
-
domain = machine.provider_config.domain_id
|
34
|
-
domain_config = machine.provider_config.get_domain_config(domain)
|
35
|
-
|
36
|
-
pf_ip_address_id = domain_config.pf_ip_address_id
|
37
|
-
pf_ip_address = domain_config.pf_ip_address
|
38
|
-
pf_public_rdp_port = domain_config.pf_public_rdp_port
|
39
|
-
|
40
|
-
if pf_public_rdp_port.nil?
|
41
|
-
pf_public_rdp_port_file = machine.data_dir.join('pf_public_rdp_port')
|
42
|
-
if pf_public_rdp_port_file.file?
|
43
|
-
File.read(pf_public_rdp_port_file).each_line do |line|
|
44
|
-
pf_public_rdp_port = line.strip
|
45
|
-
end
|
46
|
-
domain_config.pf_public_rdp_port = pf_public_rdp_port
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
if not pf_ip_address and pf_ip_address_id and pf_public_rdp_port
|
51
|
-
begin
|
52
|
-
response = cloudstack.list_public_ip_addresses({:id => pf_ip_address_id})
|
53
|
-
rescue Fog::Compute::Cloudstack::Error => e
|
54
|
-
raise Errors::FogError, :message => e.message
|
55
|
-
end
|
56
|
-
|
57
|
-
if response["listpublicipaddressesresponse"]["count"] == 0
|
58
|
-
@logger.info("IP address #{pf_ip_address_id} not exists.")
|
59
|
-
env[:ui].info(I18n.t("IP address #{pf_ip_address_id} not exists."))
|
60
|
-
pf_ip_address = nil
|
61
|
-
else
|
62
|
-
pf_ip_address = response["listpublicipaddressesresponse"]["publicipaddress"][0]["ipaddress"]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
rdp_info = {
|
67
|
-
:host => pf_ip_address || server.nics[0]['ipaddress'],
|
68
|
-
:port => pf_public_rdp_port
|
69
|
-
}
|
70
|
-
|
71
|
-
rdp_info
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Cloudstack
|
5
|
+
module Action
|
6
|
+
# This action reads the WinRM info for the machine and puts it into the
|
7
|
+
# `:machine_winrm_info` key in the environment.
|
8
|
+
class ReadRdpInfo
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@logger = Log4r::Logger.new("vagrant_cloudstack::action::read_rdp_info")
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:machine_rdp_info] = read_rdp_info(env[:cloudstack_compute], env[:machine])
|
16
|
+
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
def read_rdp_info(cloudstack, machine)
|
21
|
+
return nil if machine.id.nil?
|
22
|
+
|
23
|
+
# Find the machine
|
24
|
+
server = cloudstack.servers.get(machine.id)
|
25
|
+
if server.nil?
|
26
|
+
# The machine can't be found
|
27
|
+
@logger.info("Machine couldn't be found, assuming it got destroyed.")
|
28
|
+
machine.id = nil
|
29
|
+
return nil
|
30
|
+
end
|
31
|
+
|
32
|
+
# Get the Port forwarding config
|
33
|
+
domain = machine.provider_config.domain_id
|
34
|
+
domain_config = machine.provider_config.get_domain_config(domain)
|
35
|
+
|
36
|
+
pf_ip_address_id = domain_config.pf_ip_address_id
|
37
|
+
pf_ip_address = domain_config.pf_ip_address
|
38
|
+
pf_public_rdp_port = domain_config.pf_public_rdp_port
|
39
|
+
|
40
|
+
if pf_public_rdp_port.nil?
|
41
|
+
pf_public_rdp_port_file = machine.data_dir.join('pf_public_rdp_port')
|
42
|
+
if pf_public_rdp_port_file.file?
|
43
|
+
File.read(pf_public_rdp_port_file).each_line do |line|
|
44
|
+
pf_public_rdp_port = line.strip
|
45
|
+
end
|
46
|
+
domain_config.pf_public_rdp_port = pf_public_rdp_port
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
if not pf_ip_address and pf_ip_address_id and pf_public_rdp_port
|
51
|
+
begin
|
52
|
+
response = cloudstack.list_public_ip_addresses({:id => pf_ip_address_id})
|
53
|
+
rescue Fog::Compute::Cloudstack::Error => e
|
54
|
+
raise Errors::FogError, :message => e.message
|
55
|
+
end
|
56
|
+
|
57
|
+
if response["listpublicipaddressesresponse"]["count"] == 0
|
58
|
+
@logger.info("IP address #{pf_ip_address_id} not exists.")
|
59
|
+
env[:ui].info(I18n.t("IP address #{pf_ip_address_id} not exists."))
|
60
|
+
pf_ip_address = nil
|
61
|
+
else
|
62
|
+
pf_ip_address = response["listpublicipaddressesresponse"]["publicipaddress"][0]["ipaddress"]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
rdp_info = {
|
67
|
+
:host => pf_ip_address || server.nics[0]['ipaddress'],
|
68
|
+
:port => pf_public_rdp_port
|
69
|
+
}
|
70
|
+
|
71
|
+
rdp_info
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -1,87 +1,104 @@
|
|
1
|
-
require 'log4r'
|
2
|
-
|
3
|
-
module VagrantPlugins
|
4
|
-
module Cloudstack
|
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_cloudstack::action::read_ssh_info")
|
12
|
-
end
|
13
|
-
|
14
|
-
def call(env)
|
15
|
-
env[:machine_ssh_info] = read_ssh_info(env[:cloudstack_compute], env[:machine])
|
16
|
-
|
17
|
-
@app.call(env)
|
18
|
-
end
|
19
|
-
|
20
|
-
def read_ssh_info(cloudstack, machine)
|
21
|
-
return nil if machine.id.nil?
|
22
|
-
|
23
|
-
# Find the machine
|
24
|
-
server = cloudstack.servers.get(machine.id)
|
25
|
-
if server.nil?
|
26
|
-
# The machine can't be found
|
27
|
-
@logger.info("Machine couldn't be found, assuming it got destroyed.")
|
28
|
-
machine.id = nil
|
29
|
-
return nil
|
30
|
-
end
|
31
|
-
|
32
|
-
# Get the Port forwarding config
|
33
|
-
domain = machine.provider_config.domain_id
|
34
|
-
domain_config = machine.provider_config.get_domain_config(domain)
|
35
|
-
|
36
|
-
pf_ip_address_id = domain_config.pf_ip_address_id
|
37
|
-
pf_ip_address = domain_config.pf_ip_address
|
38
|
-
pf_public_port = domain_config.pf_public_port
|
39
|
-
|
40
|
-
if pf_public_port.nil?
|
41
|
-
pf_public_port_file = machine.data_dir.join('pf_public_port')
|
42
|
-
if pf_public_port_file.file?
|
43
|
-
File.read(pf_public_port_file).each_line do |line|
|
44
|
-
pf_public_port = line.strip
|
45
|
-
end
|
46
|
-
domain_config.pf_public_port = pf_public_port
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
if not pf_ip_address and pf_ip_address_id and pf_public_port
|
51
|
-
begin
|
52
|
-
response = cloudstack.list_public_ip_addresses({:id => pf_ip_address_id})
|
53
|
-
rescue Fog::Compute::Cloudstack::Error => e
|
54
|
-
raise Errors::FogError, :message => e.message
|
55
|
-
end
|
56
|
-
|
57
|
-
if response["listpublicipaddressesresponse"]["count"] == 0
|
58
|
-
@logger.info("IP address #{pf_ip_address_id} not exists.")
|
59
|
-
env[:ui].info(I18n.t("IP address #{pf_ip_address_id} not exists."))
|
60
|
-
pf_ip_address = nil
|
61
|
-
else
|
62
|
-
pf_ip_address = response["listpublicipaddressesresponse"]["publicipaddress"][0]["ipaddress"]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
if domain_config.keypair.nil? && domain_config.ssh_key.nil?
|
67
|
-
sshkeyfile_file = machine.data_dir.join('sshkeyfile')
|
68
|
-
if sshkeyfile_file.file?
|
69
|
-
domain_config.ssh_key = sshkeyfile_file.to_s
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Cloudstack
|
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_cloudstack::action::read_ssh_info")
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:machine_ssh_info] = read_ssh_info(env[:cloudstack_compute], env[:machine])
|
16
|
+
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
def read_ssh_info(cloudstack, machine)
|
21
|
+
return nil if machine.id.nil?
|
22
|
+
|
23
|
+
# Find the machine
|
24
|
+
server = cloudstack.servers.get(machine.id)
|
25
|
+
if server.nil?
|
26
|
+
# The machine can't be found
|
27
|
+
@logger.info("Machine couldn't be found, assuming it got destroyed.")
|
28
|
+
machine.id = nil
|
29
|
+
return nil
|
30
|
+
end
|
31
|
+
|
32
|
+
# Get the Port forwarding config
|
33
|
+
domain = machine.provider_config.domain_id
|
34
|
+
domain_config = machine.provider_config.get_domain_config(domain)
|
35
|
+
|
36
|
+
pf_ip_address_id = domain_config.pf_ip_address_id
|
37
|
+
pf_ip_address = domain_config.pf_ip_address
|
38
|
+
pf_public_port = domain_config.pf_public_port
|
39
|
+
|
40
|
+
if pf_public_port.nil?
|
41
|
+
pf_public_port_file = machine.data_dir.join('pf_public_port')
|
42
|
+
if pf_public_port_file.file?
|
43
|
+
File.read(pf_public_port_file).each_line do |line|
|
44
|
+
pf_public_port = line.strip
|
45
|
+
end
|
46
|
+
domain_config.pf_public_port = pf_public_port
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
if not pf_ip_address and pf_ip_address_id and pf_public_port
|
51
|
+
begin
|
52
|
+
response = cloudstack.list_public_ip_addresses({:id => pf_ip_address_id})
|
53
|
+
rescue Fog::Compute::Cloudstack::Error => e
|
54
|
+
raise Errors::FogError, :message => e.message
|
55
|
+
end
|
56
|
+
|
57
|
+
if response["listpublicipaddressesresponse"]["count"] == 0
|
58
|
+
@logger.info("IP address #{pf_ip_address_id} not exists.")
|
59
|
+
env[:ui].info(I18n.t("IP address #{pf_ip_address_id} not exists."))
|
60
|
+
pf_ip_address = nil
|
61
|
+
else
|
62
|
+
pf_ip_address = response["listpublicipaddressesresponse"]["publicipaddress"][0]["ipaddress"]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
if domain_config.keypair.nil? && domain_config.ssh_key.nil?
|
67
|
+
sshkeyfile_file = machine.data_dir.join('sshkeyfile')
|
68
|
+
if sshkeyfile_file.file?
|
69
|
+
domain_config.ssh_key = sshkeyfile_file.to_s
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
nic_ip_address = fetch_nic_ip_address(server.nics, domain_config)
|
74
|
+
|
75
|
+
ssh_info = {
|
76
|
+
:host => pf_ip_address || nic_ip_address,
|
77
|
+
:port => pf_public_port
|
78
|
+
}
|
79
|
+
ssh_info = ssh_info.merge({
|
80
|
+
:private_key_path => domain_config.ssh_key,
|
81
|
+
:password => nil
|
82
|
+
}) unless domain_config.ssh_key.nil?
|
83
|
+
ssh_info = ssh_info.merge({ :username => domain_config.ssh_user }) unless domain_config.ssh_user.nil?
|
84
|
+
ssh_info
|
85
|
+
end
|
86
|
+
|
87
|
+
def fetch_nic_ip_address(nics, domain_config)
|
88
|
+
ssh_nic =
|
89
|
+
if !domain_config.ssh_network_id.nil?
|
90
|
+
nics.find { |nic| nic["networkid"] == domain_config.ssh_network_id }
|
91
|
+
elsif !domain_config.ssh_network_name.nil?
|
92
|
+
nics.find { |nic| nic["networkname"] == domain_config.ssh_network_name }
|
93
|
+
else
|
94
|
+
# When without neither ssh_network_id and ssh_network_name, use 1st nic
|
95
|
+
nics[0]
|
96
|
+
end
|
97
|
+
|
98
|
+
ssh_nic ||= nics[0]
|
99
|
+
ssh_nic["ipaddress"]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -1,38 +1,38 @@
|
|
1
|
-
require "log4r"
|
2
|
-
|
3
|
-
module VagrantPlugins
|
4
|
-
module Cloudstack
|
5
|
-
module Action
|
6
|
-
# This action reads the state of the machine and puts it in the
|
7
|
-
# `:machine_state_id` key in the environment.
|
8
|
-
class ReadState
|
9
|
-
def initialize(app, env)
|
10
|
-
@app = app
|
11
|
-
@logger = Log4r::Logger.new("vagrant_cloudstack::action::read_state")
|
12
|
-
end
|
13
|
-
|
14
|
-
def call(env)
|
15
|
-
env[:machine_state_id] = read_state(env[:cloudstack_compute], env[:machine])
|
16
|
-
|
17
|
-
@app.call(env)
|
18
|
-
end
|
19
|
-
|
20
|
-
def read_state(cloudstack, machine)
|
21
|
-
return :not_created if machine.id.nil?
|
22
|
-
|
23
|
-
# Find the machine
|
24
|
-
server = cloudstack.servers.get(machine.id)
|
25
|
-
if server.nil? || [:"shutting-down", :terminated].include?(server.state.downcase.to_sym)
|
26
|
-
# The machine can't be found
|
27
|
-
@logger.info("Machine not found or terminated, assuming it got destroyed.")
|
28
|
-
machine.id = nil
|
29
|
-
return :not_created
|
30
|
-
end
|
31
|
-
|
32
|
-
# Return the state
|
33
|
-
server.state.downcase.to_sym
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Cloudstack
|
5
|
+
module Action
|
6
|
+
# This action reads the state of the machine and puts it in the
|
7
|
+
# `:machine_state_id` key in the environment.
|
8
|
+
class ReadState
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@logger = Log4r::Logger.new("vagrant_cloudstack::action::read_state")
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:machine_state_id] = read_state(env[:cloudstack_compute], env[:machine])
|
16
|
+
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
def read_state(cloudstack, machine)
|
21
|
+
return :not_created if machine.id.nil?
|
22
|
+
|
23
|
+
# Find the machine
|
24
|
+
server = cloudstack.servers.get(machine.id)
|
25
|
+
if server.nil? || [:"shutting-down", :terminated].include?(server.state.downcase.to_sym)
|
26
|
+
# The machine can't be found
|
27
|
+
@logger.info("Machine not found or terminated, assuming it got destroyed.")
|
28
|
+
machine.id = nil
|
29
|
+
return :not_created
|
30
|
+
end
|
31
|
+
|
32
|
+
# Return the state
|
33
|
+
server.state.downcase.to_sym
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|