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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +34 -0
  4. data/README.md +19 -2
  5. data/Rakefile +1 -1
  6. data/lib/vagrant-vcloud.rb +11 -13
  7. data/lib/vagrant-vcloud/action.rb +74 -47
  8. data/lib/vagrant-vcloud/action/announce_ssh_exec.rb +4 -2
  9. data/lib/vagrant-vcloud/action/build_vapp.rb +134 -110
  10. data/lib/vagrant-vcloud/action/connect_vcloud.rb +31 -42
  11. data/lib/vagrant-vcloud/action/destroy.rb +34 -29
  12. data/lib/vagrant-vcloud/action/disconnect_vcloud.rb +7 -5
  13. data/lib/vagrant-vcloud/action/forward_ports.rb +42 -35
  14. data/lib/vagrant-vcloud/action/handle_nat_port_collisions.rb +26 -22
  15. data/lib/vagrant-vcloud/action/inventory_check.rb +79 -52
  16. data/lib/vagrant-vcloud/action/is_bridged.rb +30 -0
  17. data/lib/vagrant-vcloud/action/is_created.rb +13 -14
  18. data/lib/vagrant-vcloud/action/is_paused.rb +0 -2
  19. data/lib/vagrant-vcloud/action/is_running.rb +0 -2
  20. data/lib/vagrant-vcloud/action/message_already_running.rb +1 -1
  21. data/lib/vagrant-vcloud/action/message_cannot_suspend.rb +1 -1
  22. data/lib/vagrant-vcloud/action/message_not_created.rb +1 -1
  23. data/lib/vagrant-vcloud/action/message_will_not_destroy.rb +6 -1
  24. data/lib/vagrant-vcloud/action/power_off.rb +16 -21
  25. data/lib/vagrant-vcloud/action/power_on.rb +64 -28
  26. data/lib/vagrant-vcloud/action/read_ssh_info.rb +44 -28
  27. data/lib/vagrant-vcloud/action/read_state.rb +16 -23
  28. data/lib/vagrant-vcloud/action/resume.rb +5 -13
  29. data/lib/vagrant-vcloud/action/suspend.rb +5 -13
  30. data/lib/vagrant-vcloud/action/sync_folders.rb +82 -48
  31. data/lib/vagrant-vcloud/action/unmap_port_forwardings.rb +27 -29
  32. data/lib/vagrant-vcloud/command.rb +186 -0
  33. data/lib/vagrant-vcloud/config.rb +41 -20
  34. data/lib/vagrant-vcloud/driver/base.rb +170 -121
  35. data/lib/vagrant-vcloud/driver/meta.rb +64 -70
  36. data/lib/vagrant-vcloud/driver/version_5_1.rb +1038 -716
  37. data/lib/vagrant-vcloud/errors.rb +4 -4
  38. data/lib/vagrant-vcloud/model/forwarded_port.rb +4 -2
  39. data/lib/vagrant-vcloud/plugin.rb +30 -20
  40. data/lib/vagrant-vcloud/provider.rb +6 -6
  41. data/lib/vagrant-vcloud/util/compile_forwarded_ports.rb +1 -1
  42. data/lib/vagrant-vcloud/version.rb +1 -1
  43. data/locales/en.yml +6 -5
  44. data/vagrant-vcloud.gemspec +10 -7
  45. 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("vagrant_vcloud::action::is_created")
7
+ @logger = Log4r::Logger.new('vagrant_vcloud::action::is_created')
8
8
  end
9
9
 
10
10
  def call(env)
11
-
12
- vAppId = env[:machine].get_vapp_id
13
-
14
- if vAppId.nil?
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: [#{vAppId}]")
19
-
20
- vmId = env[:machine].id
21
- if vmId
22
- @logger.info("VM has been added to vApp and ID is: [#{vmId}]")
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
- else
25
- @logger.warn("VM has not been added to vApp")
23
+ else
24
+ @logger.warn('VM has not been added to vApp')
26
25
  env[:result] = false
27
- end
26
+ end
28
27
 
29
28
  end
30
29
 
@@ -1,5 +1,3 @@
1
- require "i18n"
2
-
3
1
  module VagrantPlugins
4
2
  module VCloud
5
3
  module Action
@@ -1,5 +1,3 @@
1
- require "i18n"
2
-
3
1
  module VagrantPlugins
4
2
  module VCloud
5
3
  module Action
@@ -8,7 +8,7 @@ module VagrantPlugins
8
8
 
9
9
  def call(env)
10
10
  # FIXME: This error should be categorized
11
- env[:ui].info(I18n.t("vagrant_vcloud.vm_already_running"))
11
+ env[:ui].info(I18n.t('vagrant_vcloud.vm_already_running'))
12
12
  @app.call(env)
13
13
  end
14
14
  end
@@ -8,7 +8,7 @@ module VagrantPlugins
8
8
 
9
9
  def call(env)
10
10
  # FIXME: This error should be categorized
11
- env[:ui].info(I18n.t("vagrant_vcloud.vm_halted_cannot_suspend"))
11
+ env[:ui].info(I18n.t('vagrant_vcloud.vm_halted_cannot_suspend'))
12
12
  @app.call(env)
13
13
  end
14
14
  end
@@ -8,7 +8,7 @@ module VagrantPlugins
8
8
 
9
9
  def call(env)
10
10
  # FIXME: this error should be categorized
11
- env[:ui].info(I18n.t("vcloud.vm_not_created"))
11
+ env[:ui].info(I18n.t('vcloud.vm_not_created'))
12
12
  @app.call(env)
13
13
  end
14
14
  end
@@ -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(I18n.t("vagrant_vcloud.will_not_destroy", name: env[:machine].name))
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("vagrant_vcloud::action::poweroff")
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
- vAppId = env[:machine].get_vapp_id
19
- vmId = env[:machine].id
20
- vmName = env[:machine].name
14
+ vapp_id = env[:machine].get_vapp_id
15
+ vm_id = env[:machine].id
21
16
 
22
- testvApp = cnx.get_vapp(vAppId)
17
+ test_vapp = cnx.get_vapp(vapp_id)
23
18
 
24
- @logger.debug("Number of VMs in the vApp: #{testvApp[:vms_hash].count}")
19
+ @logger.debug(
20
+ "Number of VMs in the vApp: #{test_vapp[:vms_hash].count}"
21
+ )
25
22
 
26
- if testvApp[:vms_hash].count == 1
23
+ if test_vapp[:vms_hash].count == 1
27
24
 
28
25
  # Poweroff vApp
29
- env[:ui].info("Powering off vApp...")
30
- vAppStopTask = cnx.poweroff_vapp(vAppId)
31
- vAppStopWait = cnx.wait_task_completion(vAppStopTask)
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
- if !vAppStopWait[:errormsg].nil?
34
- raise Errors::StopVAppError, :message => vAppStopWait[:errormsg]
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("Powering off VM...")
40
- task_id = cnx.poweroff_vm(vmId)
41
- wait = cnx.wait_task_completion(task_id)
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("vagrant_vcloud::action::power_on")
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
- vmName = env[:machine].name
19
- vAppId = env[:machine].get_vapp_id
20
-
21
- env[:ui].info("Booting VM...")
22
-
23
- testIp = cnx.get_vapp_edge_public_ip(vAppId)
24
-
25
- poweronVM = cnx.poweron_vm(env[:machine].id)
26
- cnx.wait_task_completion(poweronVM)
27
-
28
- if testIp.nil? && cfg.vdc_edge_gateway_ip && cfg.vdc_edge_gateway
29
- @logger.debug("This is our first boot, we should map ports on org edge!")
30
-
31
- env[:ui].info("Creating NAT rules on [#{cfg.vdc_edge_gateway}] for IP [#{cfg.vdc_edge_gateway_ip}].")
32
-
33
- edgeMap = cnx.set_edge_gateway_rules(cfg.vdc_edge_gateway, cfg.vdc_id, cfg.vdc_edge_gateway_ip, vAppId)
34
- cnx.wait_task_completion(edgeMap)
35
- end
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("vagrant_vcloud::action::read_ssh_info")
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
- vmName = env[:machine].name
26
- vAppId = env[:machine].get_vapp_id
22
+ vapp_id = env[:machine].get_vapp_id
23
+ vm_name = env[:machine].name
27
24
 
28
- @logger.debug("Getting vapp info...")
29
- vm = cnx.get_vapp(vAppId)
30
- myhash = vm[:vms_hash][vmName.to_sym]
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 machine can't be found
34
- @logger.info("Machine couldn't be found, assuming it got destroyed.")
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
- @logger.debug("Getting port forwarding rules...")
40
- rules = cnx.get_vapp_port_forwarding_rules(vAppId)
41
-
42
- rules.each do |rule|
43
- if rule[:vapp_scoped_local_id] == myhash[:vapp_scoped_local_id] && rule[:nat_internal_port] == "22"
44
- @externalIP = rule[:nat_external_ip]
45
- @externalPort = rule[:nat_external_port]
46
- break
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
- if cfg.vdc_edge_gateway_ip && cfg.vdc_edge_gateway
51
- @logger.debug("We're running vagrant behind an org edge")
52
- @externalIP = cfg.vdc_edge_gateway_ip
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("Our variables: IP #{@externalIP} and Port #{@externalPort}")
70
+ # @logger.debug(
71
+ # "Our variables: IP #{@external_ip} and Port #{@external_port}"
72
+ # )
57
73
 
58
- return {
59
- # FIXME: these shouldn't be self
60
- :host => @externalIP,
61
- :port => @externalPort
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("vagrant_vcloud::action::read_state")
7
+ @logger = Log4r::Logger.new('vagrant_vcloud::action::read_state')
11
8
  end
12
9
 
13
10
  def call(env)
14
- #env = read_state(env)
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
- vAppId = env[:machine].get_vapp_id
29
- vmName = env[:machine].name
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 [#{vmName}] is not created yet")
25
+ @logger.info("VM [#{vm_name}] is not created yet")
33
26
  return :not_created
34
27
  end
35
28
 
36
- vApp = cnx.get_vapp(vAppId)
37
- vmStatus = vApp[:vms_hash][vmName][:status]
29
+ vapp = cnx.get_vapp(vapp_id)
30
+ vm_status = vapp[:vms_hash][vm_name][:status]
38
31
 
39
- if vmStatus == "stopped"
40
- @logger.info("VM [#{vmName}] is stopped")
32
+ if vm_status == 'stopped'
33
+ @logger.info("VM [#{vm_name}] is stopped")
41
34
  return :stopped
42
- elsif vmStatus == "running"
43
- @logger.info("VM [#{vmName}] is running")
35
+ elsif vm_status == 'running'
36
+ @logger.info("VM [#{vm_name}] is running")
44
37
  return :running
45
- elsif vmStatus == "paused"
46
- @logger.info("VM [#{vmName}] is suspended")
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, :message => e.message
45
+ raise VagrantPlugins::VCloud::Errors::VCloudError,
46
+ :message => e.message
53
47
  end
54
-
55
48
  end
56
49
  end
57
50
  end