vagrant-vcloud 0.1.2 → 0.2.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 +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +34 -0
- data/README.md +19 -2
- data/Rakefile +1 -1
- data/lib/vagrant-vcloud.rb +11 -13
- data/lib/vagrant-vcloud/action.rb +74 -47
- data/lib/vagrant-vcloud/action/announce_ssh_exec.rb +4 -2
- data/lib/vagrant-vcloud/action/build_vapp.rb +134 -110
- data/lib/vagrant-vcloud/action/connect_vcloud.rb +31 -42
- data/lib/vagrant-vcloud/action/destroy.rb +34 -29
- data/lib/vagrant-vcloud/action/disconnect_vcloud.rb +7 -5
- data/lib/vagrant-vcloud/action/forward_ports.rb +42 -35
- data/lib/vagrant-vcloud/action/handle_nat_port_collisions.rb +26 -22
- data/lib/vagrant-vcloud/action/inventory_check.rb +79 -52
- data/lib/vagrant-vcloud/action/is_bridged.rb +30 -0
- data/lib/vagrant-vcloud/action/is_created.rb +13 -14
- data/lib/vagrant-vcloud/action/is_paused.rb +0 -2
- data/lib/vagrant-vcloud/action/is_running.rb +0 -2
- data/lib/vagrant-vcloud/action/message_already_running.rb +1 -1
- data/lib/vagrant-vcloud/action/message_cannot_suspend.rb +1 -1
- data/lib/vagrant-vcloud/action/message_not_created.rb +1 -1
- data/lib/vagrant-vcloud/action/message_will_not_destroy.rb +6 -1
- data/lib/vagrant-vcloud/action/power_off.rb +16 -21
- data/lib/vagrant-vcloud/action/power_on.rb +64 -28
- data/lib/vagrant-vcloud/action/read_ssh_info.rb +44 -28
- data/lib/vagrant-vcloud/action/read_state.rb +16 -23
- data/lib/vagrant-vcloud/action/resume.rb +5 -13
- data/lib/vagrant-vcloud/action/suspend.rb +5 -13
- data/lib/vagrant-vcloud/action/sync_folders.rb +82 -48
- data/lib/vagrant-vcloud/action/unmap_port_forwardings.rb +27 -29
- data/lib/vagrant-vcloud/command.rb +186 -0
- data/lib/vagrant-vcloud/config.rb +41 -20
- data/lib/vagrant-vcloud/driver/base.rb +170 -121
- data/lib/vagrant-vcloud/driver/meta.rb +64 -70
- data/lib/vagrant-vcloud/driver/version_5_1.rb +1038 -716
- data/lib/vagrant-vcloud/errors.rb +4 -4
- data/lib/vagrant-vcloud/model/forwarded_port.rb +4 -2
- data/lib/vagrant-vcloud/plugin.rb +30 -20
- data/lib/vagrant-vcloud/provider.rb +6 -6
- data/lib/vagrant-vcloud/util/compile_forwarded_ports.rb +1 -1
- data/lib/vagrant-vcloud/version.rb +1 -1
- data/locales/en.yml +6 -5
- data/vagrant-vcloud.gemspec +10 -7
- metadata +35 -4
@@ -0,0 +1,30 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module VCloud
|
3
|
+
module Action
|
4
|
+
class IsBridged
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@logger = Log4r::Logger.new("vagrant_vcloud::action::is_bridged")
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
|
12
|
+
vAppId = env[:machine].get_vapp_id
|
13
|
+
|
14
|
+
cfg = env[:machine].provider_config
|
15
|
+
cnx = cfg.vcloud_cnx.driver
|
16
|
+
|
17
|
+
begin
|
18
|
+
@logger.debug("Trying to get the vApp port forwarding rules")
|
19
|
+
cnx.get_vapp_port_forwarding_rules(vAppId)
|
20
|
+
rescue
|
21
|
+
@logger.debug("Setting the bridged_network environment var to true")
|
22
|
+
env[:bridged_network] = true
|
23
|
+
end
|
24
|
+
|
25
|
+
@app.call env
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -4,27 +4,26 @@ module VagrantPlugins
|
|
4
4
|
class IsCreated
|
5
5
|
def initialize(app, env)
|
6
6
|
@app = app
|
7
|
-
@logger = Log4r::Logger.new(
|
7
|
+
@logger = Log4r::Logger.new('vagrant_vcloud::action::is_created')
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(env)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@logger.warn("vApp has not been created")
|
11
|
+
vapp_id = env[:machine].get_vapp_id
|
12
|
+
|
13
|
+
if vapp_id.nil?
|
14
|
+
@logger.warn('vApp has not been created')
|
16
15
|
env[:result] = false
|
17
16
|
else
|
18
|
-
@logger.info("vApp has been created and ID is: [#{
|
19
|
-
|
20
|
-
|
21
|
-
if
|
22
|
-
@logger.info("VM has been added to vApp and ID is: [#{
|
17
|
+
@logger.info("vApp has been created and ID is: [#{vapp_id}]")
|
18
|
+
|
19
|
+
vm_id = env[:machine].id
|
20
|
+
if vm_id
|
21
|
+
@logger.info("VM has been added to vApp and ID is: [#{vm_id}]")
|
23
22
|
env[:result] = true
|
24
|
-
|
25
|
-
@logger.warn(
|
23
|
+
else
|
24
|
+
@logger.warn('VM has not been added to vApp')
|
26
25
|
env[:result] = false
|
27
|
-
|
26
|
+
end
|
28
27
|
|
29
28
|
end
|
30
29
|
|
@@ -8,7 +8,12 @@ module VagrantPlugins
|
|
8
8
|
|
9
9
|
def call(env)
|
10
10
|
# FIXME: This error should be categorized
|
11
|
-
env[:ui].info(
|
11
|
+
env[:ui].info(
|
12
|
+
I18n.t(
|
13
|
+
'vagrant_vcloud.will_not_destroy',
|
14
|
+
name: env[:machine].name
|
15
|
+
)
|
16
|
+
)
|
12
17
|
@app.call(env)
|
13
18
|
end
|
14
19
|
end
|
@@ -1,48 +1,43 @@
|
|
1
|
-
require "i18n"
|
2
|
-
|
3
1
|
module VagrantPlugins
|
4
2
|
module VCloud
|
5
3
|
module Action
|
6
4
|
class PowerOff
|
7
|
-
|
8
5
|
def initialize(app, env)
|
9
6
|
@app = app
|
10
|
-
@logger = Log4r::Logger.new(
|
7
|
+
@logger = Log4r::Logger.new('vagrant_vcloud::action::poweroff')
|
11
8
|
end
|
12
9
|
|
13
10
|
def call(env)
|
14
|
-
|
15
11
|
cfg = env[:machine].provider_config
|
16
12
|
cnx = cfg.vcloud_cnx.driver
|
17
13
|
|
18
|
-
|
19
|
-
|
20
|
-
vmName = env[:machine].name
|
14
|
+
vapp_id = env[:machine].get_vapp_id
|
15
|
+
vm_id = env[:machine].id
|
21
16
|
|
22
|
-
|
17
|
+
test_vapp = cnx.get_vapp(vapp_id)
|
23
18
|
|
24
|
-
@logger.debug(
|
19
|
+
@logger.debug(
|
20
|
+
"Number of VMs in the vApp: #{test_vapp[:vms_hash].count}"
|
21
|
+
)
|
25
22
|
|
26
|
-
if
|
23
|
+
if test_vapp[:vms_hash].count == 1
|
27
24
|
|
28
25
|
# Poweroff vApp
|
29
|
-
env[:ui].info(
|
30
|
-
|
31
|
-
|
26
|
+
env[:ui].info('Powering off vApp...')
|
27
|
+
vapp_stop_task = cnx.poweroff_vapp(vapp_id)
|
28
|
+
vapp_stop_wait = cnx.wait_task_completion(vapp_stop_task)
|
32
29
|
|
33
|
-
|
34
|
-
|
30
|
+
unless vapp_stop_wait[:errormsg].nil?
|
31
|
+
fail Errors::StopVAppError, :message => vapp_stop_wait[:errormsg]
|
35
32
|
end
|
36
33
|
|
37
34
|
else
|
38
35
|
# Poweroff VM
|
39
|
-
env[:ui].info(
|
40
|
-
task_id = cnx.poweroff_vm(
|
41
|
-
|
36
|
+
env[:ui].info('Powering off VM...')
|
37
|
+
task_id = cnx.poweroff_vm(vm_id)
|
38
|
+
cnx.wait_task_completion(task_id)
|
42
39
|
end
|
43
40
|
|
44
|
-
true
|
45
|
-
|
46
41
|
@app.call env
|
47
42
|
end
|
48
43
|
end
|
@@ -1,41 +1,80 @@
|
|
1
|
-
require "i18n"
|
2
|
-
|
3
1
|
module VagrantPlugins
|
4
2
|
module VCloud
|
5
3
|
module Action
|
6
4
|
class PowerOn
|
7
5
|
def initialize(app, env)
|
8
6
|
@app = app
|
9
|
-
@logger = Log4r::Logger.new(
|
7
|
+
@logger = Log4r::Logger.new('vagrant_vcloud::action::power_on')
|
10
8
|
end
|
11
9
|
|
12
10
|
def call(env)
|
13
11
|
@env = env
|
14
12
|
|
15
|
-
|
16
13
|
cfg = env[:machine].provider_config
|
17
14
|
cnx = cfg.vcloud_cnx.driver
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
15
|
+
vapp_id = env[:machine].get_vapp_id
|
16
|
+
|
17
|
+
env[:ui].info('Booting VM...')
|
18
|
+
|
19
|
+
if cfg.network_bridge.nil?
|
20
|
+
test_ip = cnx.get_vapp_edge_public_ip(vapp_id)
|
21
|
+
end
|
22
|
+
|
23
|
+
poweron_vm = cnx.poweron_vm(env[:machine].id)
|
24
|
+
cnx.wait_task_completion(poweron_vm)
|
25
|
+
|
26
|
+
if test_ip.nil? && \
|
27
|
+
cfg.vdc_edge_gateway_ip && \
|
28
|
+
cfg.vdc_edge_gateway && \
|
29
|
+
cfg.network_bridge.nil?
|
30
|
+
|
31
|
+
@logger.debug(
|
32
|
+
'This is our first boot, we should map ports on the ' \
|
33
|
+
'Organization vDC vShield Edge Gateway!'
|
34
|
+
)
|
35
|
+
|
36
|
+
### TMP FIX: tsugliani
|
37
|
+
### We need to verify the vShield Edge Gateway rules don't already
|
38
|
+
### exist.
|
39
|
+
### Removing any rule previously set for that same source IP
|
40
|
+
|
41
|
+
# ----
|
42
|
+
if cfg.vdc_edge_gateway_ip && cfg.vdc_edge_gateway
|
43
|
+
env[:ui].info(
|
44
|
+
"Removing NAT rules on [#{cfg.vdc_edge_gateway}] " +
|
45
|
+
"for IP [#{cfg.vdc_edge_gateway_ip}]."
|
46
|
+
)
|
47
|
+
@logger.debug(
|
48
|
+
'Cleaning possible conflicting Edge Gateway rules - ' +
|
49
|
+
"Organization vDC id: #{cfg.vdc_id}"
|
50
|
+
)
|
51
|
+
|
52
|
+
edge_remove = cnx.remove_edge_gateway_rules(
|
53
|
+
cfg.vdc_edge_gateway,
|
54
|
+
cfg.vdc_id,
|
55
|
+
cfg.vdc_edge_gateway_ip,
|
56
|
+
vapp_id
|
57
|
+
)
|
58
|
+
cnx.wait_task_completion(edge_remove)
|
59
|
+
end
|
60
|
+
# ----
|
61
|
+
|
62
|
+
env[:ui].info(
|
63
|
+
"Creating NAT rules on [#{cfg.vdc_edge_gateway}] " +
|
64
|
+
"for IP [#{cfg.vdc_edge_gateway_ip}]."
|
65
|
+
)
|
66
|
+
|
67
|
+
# Set the vShield Edge Gateway rules
|
68
|
+
edge_map = cnx.set_edge_gateway_rules(
|
69
|
+
cfg.vdc_edge_gateway,
|
70
|
+
cfg.vdc_id,
|
71
|
+
cfg.vdc_edge_gateway_ip,
|
72
|
+
vapp_id
|
73
|
+
)
|
74
|
+
|
75
|
+
# Wait for task to complete.
|
76
|
+
cnx.wait_task_completion(edge_map)
|
77
|
+
end
|
39
78
|
|
40
79
|
@app.call(env)
|
41
80
|
end
|
@@ -43,6 +82,3 @@ module VagrantPlugins
|
|
43
82
|
end
|
44
83
|
end
|
45
84
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
@@ -2,12 +2,10 @@ module VagrantPlugins
|
|
2
2
|
module VCloud
|
3
3
|
module Action
|
4
4
|
class ReadSSHInfo
|
5
|
-
|
6
5
|
# FIXME: More work needed here for vCloud logic (vApp, VM IPs, etc.)
|
7
|
-
|
8
6
|
def initialize(app, env)
|
9
7
|
@app = app
|
10
|
-
@logger = Log4r::Logger.new(
|
8
|
+
@logger = Log4r::Logger.new('vagrant_vcloud::action::read_ssh_info')
|
11
9
|
end
|
12
10
|
|
13
11
|
def call(env)
|
@@ -16,49 +14,67 @@ module VagrantPlugins
|
|
16
14
|
@app.call env
|
17
15
|
end
|
18
16
|
|
19
|
-
|
20
17
|
def read_ssh_info(env)
|
21
18
|
return nil if env[:machine].id.nil?
|
22
19
|
|
23
20
|
cfg = env[:machine].provider_config
|
24
21
|
cnx = cfg.vcloud_cnx.driver
|
25
|
-
|
26
|
-
|
22
|
+
vapp_id = env[:machine].get_vapp_id
|
23
|
+
vm_name = env[:machine].name
|
27
24
|
|
28
|
-
@logger.debug(
|
29
|
-
vm = cnx.get_vapp(
|
30
|
-
myhash = vm[:vms_hash][
|
25
|
+
@logger.debug('Getting vApp information...')
|
26
|
+
vm = cnx.get_vapp(vapp_id)
|
27
|
+
myhash = vm[:vms_hash][vm_name.to_sym]
|
31
28
|
|
32
29
|
if vm.nil?
|
33
|
-
# The
|
34
|
-
@logger.info(
|
30
|
+
# The Virtual Machine couldn't be found.
|
31
|
+
@logger.info(
|
32
|
+
'Machine couldn\'t be found, assuming it got destroyed.'
|
33
|
+
)
|
35
34
|
machine.id = nil
|
36
35
|
return nil
|
37
36
|
end
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
38
|
+
if !cfg.network_bridge.nil?
|
39
|
+
@logger.debug("We're running in bridged mode,
|
40
|
+
fetching the IP directly from the VM")
|
41
|
+
vm_info = cnx.get_vm(env[:machine].id)
|
42
|
+
@logger.debug("IP address for #{vm_name}:
|
43
|
+
#{vm_info[:networks]['Vagrant-vApp-Net'][:ip]}")
|
44
|
+
@external_ip = vm_info[:networks]['Vagrant-vApp-Net'][:ip]
|
45
|
+
@external_port = '22'
|
46
|
+
else
|
47
|
+
|
48
|
+
@logger.debug('Getting port forwarding rules...')
|
49
|
+
rules = cnx.get_vapp_port_forwarding_rules(vAppId)
|
50
|
+
|
51
|
+
rules.each do |rule|
|
52
|
+
if rule[:vapp_scoped_local_id] == myhash[:vapp_scoped_local_id] \
|
53
|
+
&& rule[:nat_internal_port] == '22'
|
54
|
+
|
55
|
+
@external_ip = rule[:nat_external_ip]
|
56
|
+
@external_port = rule[:nat_external_port]
|
57
|
+
break
|
58
|
+
|
59
|
+
end
|
47
60
|
end
|
48
|
-
end
|
49
61
|
|
50
|
-
|
51
|
-
|
52
|
-
|
62
|
+
if cfg.vdc_edge_gateway_ip && cfg.vdc_edge_gateway
|
63
|
+
@logger.debug("We're running vagrant behind an Organization vDC
|
64
|
+
edge")
|
65
|
+
@external_ip = cfg.vdc_edge_gateway_ip
|
66
|
+
end
|
53
67
|
end
|
54
68
|
|
55
69
|
# FIXME: fix the selfs and create a meaningful info message
|
56
|
-
# @logger.debug(
|
70
|
+
# @logger.debug(
|
71
|
+
# "Our variables: IP #{@external_ip} and Port #{@external_port}"
|
72
|
+
# )
|
57
73
|
|
58
|
-
|
59
|
-
|
60
|
-
:host => @
|
61
|
-
:port => @
|
74
|
+
{
|
75
|
+
# FIXME: these shouldn't be self
|
76
|
+
:host => @external_ip,
|
77
|
+
:port => @external_port
|
62
78
|
}
|
63
79
|
end
|
64
80
|
end
|
@@ -1,57 +1,50 @@
|
|
1
|
-
require "log4r"
|
2
|
-
|
3
1
|
module VagrantPlugins
|
4
2
|
module VCloud
|
5
3
|
module Action
|
6
4
|
class ReadState
|
7
|
-
|
8
5
|
def initialize(app, env)
|
9
6
|
@app = app
|
10
|
-
@logger = Log4r::Logger.new(
|
7
|
+
@logger = Log4r::Logger.new('vagrant_vcloud::action::read_state')
|
11
8
|
end
|
12
9
|
|
13
10
|
def call(env)
|
14
|
-
|
15
|
-
|
16
|
-
env[:machine_state_id] = read_state(env)
|
17
|
-
|
11
|
+
env[:machine_state_id] = read_state(env)
|
12
|
+
|
18
13
|
@app.call env
|
19
14
|
end
|
20
15
|
|
21
16
|
def read_state(env)
|
22
|
-
|
23
17
|
# FIXME: this part needs some cleanup
|
24
|
-
|
25
18
|
begin
|
26
19
|
cfg = env[:machine].provider_config
|
27
20
|
cnx = cfg.vcloud_cnx.driver
|
28
|
-
|
29
|
-
|
21
|
+
vapp_id = env[:machine].get_vapp_id
|
22
|
+
vm_name = env[:machine].name
|
30
23
|
|
31
24
|
if env[:machine].id.nil?
|
32
|
-
@logger.info("VM [#{
|
25
|
+
@logger.info("VM [#{vm_name}] is not created yet")
|
33
26
|
return :not_created
|
34
27
|
end
|
35
28
|
|
36
|
-
|
37
|
-
|
29
|
+
vapp = cnx.get_vapp(vapp_id)
|
30
|
+
vm_status = vapp[:vms_hash][vm_name][:status]
|
38
31
|
|
39
|
-
if
|
40
|
-
@logger.info("VM [#{
|
32
|
+
if vm_status == 'stopped'
|
33
|
+
@logger.info("VM [#{vm_name}] is stopped")
|
41
34
|
return :stopped
|
42
|
-
elsif
|
43
|
-
@logger.info("VM [#{
|
35
|
+
elsif vm_status == 'running'
|
36
|
+
@logger.info("VM [#{vm_name}] is running")
|
44
37
|
return :running
|
45
|
-
elsif
|
46
|
-
@logger.info("VM [#{
|
38
|
+
elsif vm_status == 'paused'
|
39
|
+
@logger.info("VM [#{vm_name}] is suspended")
|
47
40
|
return :suspended
|
48
41
|
end
|
49
42
|
rescue Exception => e
|
50
43
|
### When bad credentials, we get here.
|
51
44
|
@logger.debug("Couldn't Read VM State: #{e.message}")
|
52
|
-
raise VagrantPlugins::VCloud::Errors::VCloudError,
|
45
|
+
raise VagrantPlugins::VCloud::Errors::VCloudError,
|
46
|
+
:message => e.message
|
53
47
|
end
|
54
|
-
|
55
48
|
end
|
56
49
|
end
|
57
50
|
end
|