vagrant-vcloudair 0.5.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.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +34 -0
  3. data/.rubocop.yml +34 -0
  4. data/Gemfile +7 -0
  5. data/LICENSE +21 -0
  6. data/README.md +109 -0
  7. data/lib/vagrant-vcloudair.rb +63 -0
  8. data/lib/vagrant-vcloudair/action.rb +298 -0
  9. data/lib/vagrant-vcloudair/action/announce_ssh_exec.rb +22 -0
  10. data/lib/vagrant-vcloudair/action/build_vapp.rb +235 -0
  11. data/lib/vagrant-vcloudair/action/connect_vcloud.rb +54 -0
  12. data/lib/vagrant-vcloudair/action/destroy_vapp.rb +54 -0
  13. data/lib/vagrant-vcloudair/action/destroy_vm.rb +37 -0
  14. data/lib/vagrant-vcloudair/action/disconnect_vcloud.rb +31 -0
  15. data/lib/vagrant-vcloudair/action/forward_ports.rb +132 -0
  16. data/lib/vagrant-vcloudair/action/handle_nat_port_collisions.rb +153 -0
  17. data/lib/vagrant-vcloudair/action/inventory_check.rb +210 -0
  18. data/lib/vagrant-vcloudair/action/is_bridged.rb +29 -0
  19. data/lib/vagrant-vcloudair/action/is_created.rb +35 -0
  20. data/lib/vagrant-vcloudair/action/is_last_vm.rb +31 -0
  21. data/lib/vagrant-vcloudair/action/is_paused.rb +20 -0
  22. data/lib/vagrant-vcloudair/action/is_running.rb +20 -0
  23. data/lib/vagrant-vcloudair/action/message_already_running.rb +16 -0
  24. data/lib/vagrant-vcloudair/action/message_cannot_suspend.rb +16 -0
  25. data/lib/vagrant-vcloudair/action/message_not_created.rb +16 -0
  26. data/lib/vagrant-vcloudair/action/message_not_running.rb +16 -0
  27. data/lib/vagrant-vcloudair/action/message_will_not_destroy.rb +21 -0
  28. data/lib/vagrant-vcloudair/action/power_off.rb +33 -0
  29. data/lib/vagrant-vcloudair/action/power_off_vapp.rb +40 -0
  30. data/lib/vagrant-vcloudair/action/power_on.rb +39 -0
  31. data/lib/vagrant-vcloudair/action/read_ssh_info.rb +153 -0
  32. data/lib/vagrant-vcloudair/action/read_state.rb +51 -0
  33. data/lib/vagrant-vcloudair/action/resume.rb +25 -0
  34. data/lib/vagrant-vcloudair/action/suspend.rb +25 -0
  35. data/lib/vagrant-vcloudair/action/unmap_port_forwardings.rb +74 -0
  36. data/lib/vagrant-vcloudair/cap/forwarded_ports.rb +38 -0
  37. data/lib/vagrant-vcloudair/cap/public_address.rb +18 -0
  38. data/lib/vagrant-vcloudair/cap/rdp_info.rb +18 -0
  39. data/lib/vagrant-vcloudair/cap/winrm_info.rb +15 -0
  40. data/lib/vagrant-vcloudair/command.rb +285 -0
  41. data/lib/vagrant-vcloudair/config.rb +205 -0
  42. data/lib/vagrant-vcloudair/driver/base.rb +643 -0
  43. data/lib/vagrant-vcloudair/driver/meta.rb +202 -0
  44. data/lib/vagrant-vcloudair/driver/version_5_1.rb +2019 -0
  45. data/lib/vagrant-vcloudair/errors.rb +77 -0
  46. data/lib/vagrant-vcloudair/model/forwarded_port.rb +66 -0
  47. data/lib/vagrant-vcloudair/plugin.rb +111 -0
  48. data/lib/vagrant-vcloudair/provider.rb +41 -0
  49. data/lib/vagrant-vcloudair/util/compile_forwarded_ports.rb +34 -0
  50. data/lib/vagrant-vcloudair/version.rb +5 -0
  51. data/locales/en.yml +169 -0
  52. data/vagrant-vcloudair.gemspec +33 -0
  53. metadata +266 -0
@@ -0,0 +1,20 @@
1
+ module VagrantPlugins
2
+ module VCloudAir
3
+ module Action
4
+ class IsPaused
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ # Set the result to be true if the machine is suspended.
11
+ env[:result] = env[:machine].state.id == :suspended
12
+
13
+ # Call the next if we have one (but we shouldn't, since this
14
+ # middleware is built to run with the Call-type middlewares)
15
+ @app.call(env)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module VagrantPlugins
2
+ module VCloudAir
3
+ module Action
4
+ class IsRunning
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ # Set the result to be true if the machine is running.
11
+ env[:result] = env[:machine].state.id == :running
12
+
13
+ # Call the next if we have one (but we shouldn't, since this
14
+ # middleware is built to run with the Call-type middlewares)
15
+ @app.call(env)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module VCloudAir
3
+ module Action
4
+ class MessageAlreadyRunning
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t('vagrant_vcloudair.vm.vm_already_running'))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module VCloudAir
3
+ module Action
4
+ class MessageCannotSuspend
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t('vagrant_vcloudair.vm.vm_halted_cannot_suspend'))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module VagrantPlugins
2
+ module VCloudAir
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_vcloudair.vm.vm_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 VCloudAir
3
+ module Action
4
+ class MessageNotRunning
5
+ def initialize(app, env)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env[:ui].info(I18n.t('vagrant_vcloudair.vm.vm_not_running'))
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ module VagrantPlugins
2
+ module VCloudAir
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(
11
+ I18n.t(
12
+ 'vagrant_vcloudair.vm.will_not_destroy',
13
+ name: env[:machine].name
14
+ )
15
+ )
16
+ @app.call(env)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ module VagrantPlugins
2
+ module VCloudAir
3
+ module Action
4
+ class PowerOff
5
+ def initialize(app, env)
6
+ @app = app
7
+ @logger = Log4r::Logger.new('vagrant_vcloudair::action::poweroff')
8
+ end
9
+
10
+ def call(env)
11
+ cfg = env[:machine].provider_config
12
+ cnx = cfg.vcloudair_cnx.driver
13
+
14
+ vapp_id = env[:machine].get_vapp_id
15
+ vm_id = env[:machine].id
16
+
17
+ test_vapp = cnx.get_vapp(vapp_id)
18
+
19
+ @logger.debug(
20
+ "Number of VMs in the vApp: #{test_vapp[:vms_hash].count}"
21
+ )
22
+
23
+ # Poweroff VM
24
+ env[:ui].info(I18n.t('vagrant_vcloudair.vm.poweroff_vm'))
25
+ task_id = cnx.poweroff_vm(vm_id)
26
+ cnx.wait_task_completion(task_id)
27
+
28
+ @app.call env
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,40 @@
1
+ module VagrantPlugins
2
+ module VCloudAir
3
+ module Action
4
+ class PowerOffVApp
5
+ def initialize(app, env)
6
+ @app = app
7
+ @logger = Log4r::Logger.new('vagrant_vcloudair::action::poweroff_vapp')
8
+ end
9
+
10
+ def call(env)
11
+ cfg = env[:machine].provider_config
12
+ cnx = cfg.vcloudair_cnx.driver
13
+
14
+ vapp_id = env[:machine].get_vapp_id
15
+
16
+ test_vapp = cnx.get_vapp(vapp_id)
17
+
18
+ @logger.debug(
19
+ "Number of VMs in the vApp: #{test_vapp[:vms_hash].count}"
20
+ )
21
+
22
+ # this is a helper to get vapp_edge_ip into cache for later destroy
23
+ # of edge gateway rules
24
+ vapp_edge_ip = cnx.get_vapp_edge_public_ip(vapp_id) if cfg.network_bridge.nil?
25
+
26
+ # Poweroff vApp
27
+ env[:ui].info(I18n.t('vagrant_vcloudair.vapp.poweroff_vapp'))
28
+ vapp_stop_task = cnx.poweroff_vapp(vapp_id)
29
+ vapp_stop_wait = cnx.wait_task_completion(vapp_stop_task)
30
+
31
+ unless vapp_stop_wait[:errormsg].nil?
32
+ fail Errors::StopVAppError, :message => vapp_stop_wait[:errormsg]
33
+ end
34
+
35
+ @app.call env
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,39 @@
1
+ module VagrantPlugins
2
+ module VCloudAir
3
+ module Action
4
+ class PowerOn
5
+ def initialize(app, env)
6
+ @app = app
7
+ @logger = Log4r::Logger.new('vagrant_vcloudair::action::power_on')
8
+ end
9
+
10
+ def call(env)
11
+ @env = env
12
+
13
+ cfg = env[:machine].provider_config
14
+ cnx = cfg.vcloudair_cnx.driver
15
+
16
+ env[:ui].info(I18n.t('vagrant_vcloudair.vm.setting_vm_hardware'))
17
+
18
+ set_vm_hardware = cnx.set_vm_hardware(env[:machine].id, cfg)
19
+ cnx.wait_task_completion(set_vm_hardware) if set_vm_hardware
20
+
21
+ env[:ui].info(I18n.t('vagrant_vcloudair.vm.poweron_vm'))
22
+
23
+ unless cfg.nested_hypervisor.nil?
24
+ set_vm_nested_hypervisor = cnx.set_vm_nested_hypervisor(
25
+ env[:machine].id, cfg.nested_hypervisor)
26
+ if set_vm_nested_hypervisor
27
+ cnx.wait_task_completion(set_vm_nested_hypervisor)
28
+ end
29
+ end
30
+
31
+ poweron_vm = cnx.poweron_vm(env[:machine].id)
32
+ cnx.wait_task_completion(poweron_vm)
33
+
34
+ @app.call(env)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,153 @@
1
+ module VagrantPlugins
2
+ module VCloudAir
3
+ module Action
4
+ class ReadSSHInfo
5
+ def initialize(app, env, port = 22)
6
+ @app = app
7
+ @port = port
8
+ @logger = Log4r::Logger.new('vagrant_vcloudair::action::read_ssh_info')
9
+ end
10
+
11
+ def call(env)
12
+ env[:machine_ssh_info] = read_ssh_info(env)
13
+
14
+ @app.call env
15
+ end
16
+
17
+ # Small method to check the tcp connection to an ip:port works.
18
+ # Return false if anything fails, and true if it succeeded.
19
+ def check_for_port(ip, port, port_name)
20
+ begin
21
+ Timeout::timeout(1) do
22
+ begin
23
+ s = TCPSocket.new(ip, port)
24
+ s.close
25
+ @logger.debug("#{port_name} Connection successful !")
26
+ return true
27
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::EHOSTDOWN
28
+ @logger.debug("#{port_name} Connection Refused/Host Unreachable...")
29
+ return false
30
+ end
31
+ end
32
+ rescue Timeout::Error
33
+ @logger.debug("#{port_name} Connection Timeout...")
34
+ end
35
+
36
+ return false
37
+ end
38
+
39
+ def read_ssh_info(env)
40
+ return nil if env[:machine].id.nil?
41
+
42
+ cfg = env[:machine].provider_config
43
+ cnx = cfg.vcloudair_cnx.driver
44
+ vapp_id = env[:machine].get_vapp_id
45
+ vm_name = env[:machine].name
46
+
47
+ @logger.debug('Getting vApp information...')
48
+ vm = cnx.get_vapp(vapp_id)
49
+ myhash = vm[:vms_hash][vm_name.to_sym]
50
+
51
+ if vm.nil?
52
+ # The Virtual Machine couldn't be found.
53
+ @logger.info(
54
+ 'Machine couldn\'t be found, assuming it got destroyed.'
55
+ )
56
+ machine.id = nil
57
+ return nil
58
+ end
59
+
60
+ if !cfg.network_bridge.nil?
61
+ @logger.debug(
62
+ 'We\'re running in bridged mode, ' \
63
+ 'fetching the IP directly from the VM'
64
+ )
65
+ vm_info = cnx.get_vm(env[:machine].id)
66
+ @logger.debug(
67
+ "IP address for #{vm_name}: " \
68
+ "#{vm_info[:networks]['Vagrant-vApp-Net'][:ip]}"
69
+ )
70
+
71
+ @external_ip = vm_info[:networks]['Vagrant-vApp-Net'][:ip]
72
+ @external_port = "#{@port}"
73
+ else
74
+
75
+ @logger.debug('Getting port forwarding rules...')
76
+ rules = cnx.get_vapp_port_forwarding_rules(vapp_id)
77
+
78
+ rules.each do |rule|
79
+ if rule[:vapp_scoped_local_id] == myhash[:vapp_scoped_local_id] && rule[:nat_internal_port] == "#{@port}"
80
+ @external_ip = rule[:nat_external_ip]
81
+ @external_port = rule[:nat_external_port]
82
+ break
83
+
84
+ end
85
+ end
86
+
87
+ if cfg.vdc_edge_gateway_ip && cfg.vdc_edge_gateway
88
+ @logger.debug(
89
+ "We're running vagrant behind an Organization vDC Edge"
90
+ )
91
+
92
+ #
93
+ # Add config.ssh.host support
94
+ # http://docs.vagrantup.com/v2/vagrantfile/ssh_settings.html
95
+ #
96
+ if env[:machine].config.ssh.host
97
+ @logger.debug(
98
+ 'SSH Host setting configured too: ' \
99
+ "#{env[:machine].config.ssh.host}"
100
+ )
101
+ @external_ip = env[:machine].config.ssh.host
102
+ else
103
+ @logger.debug(
104
+ "Using Edge Gateway IP: #{cfg.vdc_edge_gateway_ip}"
105
+ )
106
+ @external_ip = cfg.vdc_edge_gateway_ip
107
+ end
108
+ end
109
+ end
110
+
111
+ port_name = 'SSH'
112
+ port_name = 'WinRM' if @port == 5985
113
+
114
+ @logger.debug(
115
+ "#{port_name} INFO: IP #{@external_ip} and Port #{@external_port}"
116
+ )
117
+
118
+ # FIXME:
119
+ # tsugliani: Temporary Fix for Issue #56
120
+ # SSH unavailable makes the deployment fails.
121
+ # Wait infinitely right now for SSH...
122
+ # sleep_counter incremented by 1s each loop.
123
+ #
124
+ # This should be fixed with implementing Vagrant::Util::Retryable
125
+ # and something like:
126
+ #
127
+ # retryable(:on => Vagrant::SSHSomething, :tries => 10, :sleep => 5) do
128
+ # check_for_port(ip, port, "SSH", :error_class => Vagrant::SSHSomething)
129
+ # end
130
+ #
131
+ sleep_counter = 5
132
+
133
+ if @port == 22 || @port == 5985
134
+ while check_for_port(@external_ip, @external_port, port_name) == false
135
+ env[:ui].info(I18n.t('vagrant_vcloudair.vm.waiting_for_ssh',
136
+ port_name: port_name,
137
+ external_ip: @external_ip,
138
+ external_port: @external_port))
139
+ sleep sleep_counter
140
+ sleep_counter += 1
141
+ end
142
+ end
143
+
144
+ # If we are here, then SSH is ready, continue
145
+ {
146
+ :host => @external_ip,
147
+ :port => @external_port
148
+ }
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,51 @@
1
+ module VagrantPlugins
2
+ module VCloudAir
3
+ module Action
4
+ class ReadState
5
+ def initialize(app, env)
6
+ @app = app
7
+ @logger = Log4r::Logger.new('vagrant_vcloudair::action::read_state')
8
+ end
9
+
10
+ def call(env)
11
+ env[:machine_state_id] = read_state(env)
12
+
13
+ @app.call env
14
+ end
15
+
16
+ def read_state(env)
17
+ # FIXME: this part needs some cleanup
18
+ begin
19
+ cfg = env[:machine].provider_config
20
+ cnx = cfg.vcloudair_cnx.driver
21
+ vapp_id = env[:machine].get_vapp_id
22
+ vm_name = env[:machine].name
23
+
24
+ if env[:machine].id.nil?
25
+ @logger.info("VM [#{vm_name}] is not created yet")
26
+ return :not_created
27
+ end
28
+
29
+ vapp = cnx.get_vapp(vapp_id)
30
+ vm_status = vapp[:vms_hash][vm_name][:status]
31
+
32
+ if vm_status == 'stopped'
33
+ @logger.info("VM [#{vm_name}] is stopped")
34
+ return :stopped
35
+ elsif vm_status == 'running'
36
+ @logger.info("VM [#{vm_name}] is running")
37
+ return :running
38
+ elsif vm_status == 'paused'
39
+ @logger.info("VM [#{vm_name}] is suspended")
40
+ return :suspended
41
+ end
42
+ rescue Exception => e
43
+ ### When bad credentials, we get here.
44
+ @logger.debug("Couldn't Read VM State: #{e.message}")
45
+ raise Errors::VCloudAirGenericError, :message => e.message
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end