vagrant-vcloud 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d401c3fdff9b128ececdc4ee0ffbdf66f6210bc
4
- data.tar.gz: 9a07a539ac1f386acb2a838e1c064cc6c64de25d
3
+ metadata.gz: beb3fb2a8c171a33da931289fe566246e416f1bb
4
+ data.tar.gz: 2fbee46af8c1f58713c1279356bdf46ef81f05a8
5
5
  SHA512:
6
- metadata.gz: fa540638ca6eb725d62349b305fe417da030d52ea7e74bb8d9307d01350ac89560e6a241ead5f3ef95dfc1d2d7e28f87d2f2df1adfd30083f7c0810c13df9c42
7
- data.tar.gz: 8fa7216cba76bbfc9787bf8aa025f59c6c1f5851362aed47b3c9c6cad1b7a82dbb3142a71e0c98175ede4b7b78c628b741275cf53c3acec5210c97e0fdbd277a
6
+ metadata.gz: 539d00b06ce68283799b8a41208229649c6067eaa5ad4861e4cd8d4099045133e89fde9c22a71c5f64732e09661eb3471bac2c93f68a4488a52df595b9ec76e6
7
+ data.tar.gz: 49afaa371cc4fc39b3c198d611790f2b1eadc26346ebfcd6a8330690f55e24bd6cb62b4a0f81816dd640ae12bcc5337c98b6f6a1154ff06790958c211a68d1c0
data/.gitignore CHANGED
@@ -4,3 +4,6 @@ Gemfile.lock
4
4
  test-*
5
5
  .yardoc/*
6
6
  doc/*
7
+ Vagrantfile
8
+ puppet/*
9
+ *.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,34 @@
1
+ MethodLength:
2
+ CountComments: false # count full line comments?
3
+ Enabled: false
4
+
5
+ MethodName:
6
+ EnforcedStyle: snake_case
7
+
8
+ AccessorMethodName:
9
+ Description: Check the naming of accessor methods for get_/set_.
10
+ Enabled: false
11
+
12
+ Encoding:
13
+ Description: 'Use UTF-8 as the source file encoding.'
14
+ Enabled: true
15
+
16
+ HashSyntax:
17
+ Description: >-
18
+ Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax
19
+ { :a => 1, :b => 2 }.
20
+ Enabled: false
21
+ EnforcedStyle: hash_rockets
22
+
23
+ LineEndConcatenation:
24
+ Description: 'Use \\ instead of + to concatenate two string literals at line end.'
25
+ Enabled: true
26
+
27
+ LineLength:
28
+ Description: 'Limit lines to 80 characters.'
29
+ Enabled: true
30
+ Max: 80
31
+
32
+ CyclomaticComplexity:
33
+ Description: 'Avoid complex methods.'
34
+ Enabled: false
data/README.md CHANGED
@@ -1,13 +1,30 @@
1
1
  [Vagrant](http://www.vagrantup.com) provider for VMware vCloud Director®
2
2
  =============
3
3
 
4
- [Version 0.1.1](https://github.com/frapposelli/vagrant-vcloud/releases/tag/v0.1.1) has been released!
4
+ [Version 0.2.0](https://github.com/frapposelli/vagrant-vcloud/releases/tag/v0.2.0) has been released!
5
5
  -------------
6
6
 
7
7
  Please note that this software is still Alpha/Beta quality and is not recommended for production usage.
8
8
 
9
9
  Right now a [Precise32](http://vagrant.tsugliani.fr/precise32.box) is available for use, or you can roll your own as you please, make sure to install VMware tools in it.
10
10
 
11
+ Features of Version 0.2.0 are:
12
+
13
+ - It's now possible to connect to an existing VDC network without creating a vShield Edge [ISSUE #23].
14
+ - Added a ```upload_chunksize``` parameter to specify the chunk dimension during box uploads [ISSUE #21].
15
+ - Added support for [vCloud® Hybrid Service™](http://www.vmware.com/products/vcloud-hybrid-service) API version 5.7.
16
+ - Added a new command to vagrant called ```vcloud-status``` that shows the current status of the vCloud instance relative to the Vagrant deployment. *experimental*
17
+ - General code cleanup, code should be more readable and there's a rubocop file for our code conventions.
18
+ - Passwords are now hidden when running in DEBUG mode.
19
+ - Initial support for Vagrant 1.5 (currently not supporting the new "share" features).
20
+ - Lowered Nokogiri requirement to 1.5.5 (you may need to remove a later version if installed).
21
+ - Fixed the Edge Gateway NAT rules creation / deletion.
22
+ - Added debug capabilities down to XML traffic exchanged during the REST calls.
23
+
24
+ Features of Version 0.1.2 are:
25
+
26
+ - Fix ssh_key array for the sync_folder [ISSUE #30 thanks @JMG-OICR]
27
+
11
28
  Features of Version 0.1.1 are:
12
29
 
13
30
  - bugfix multiple sub allocation pools ranges [ISSUE #24]
@@ -101,4 +118,4 @@ Vagrant.configure("2") do |config|
101
118
  end
102
119
  ```
103
120
 
104
- [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/frapposelli/vagrant-vcloud/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
121
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/frapposelli/vagrant-vcloud/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
data/Rakefile CHANGED
@@ -14,4 +14,4 @@ Bundler::GemHelper.install_tasks
14
14
 
15
15
  RSpec::Core::RakeTask.new
16
16
 
17
- task :default => 'spec'
17
+ task :default => 'spec'
@@ -1,24 +1,23 @@
1
- require "pathname"
2
- require "vagrant-vcloud/plugin"
1
+ require 'pathname'
2
+ require 'vagrant-vcloud/plugin'
3
3
 
4
4
  module VagrantPlugins
5
5
  module VCloud
6
- lib_path = Pathname.new(File.expand_path("../vagrant-vcloud", __FILE__))
7
- autoload :Action, lib_path.join("action")
8
- autoload :Errors, lib_path.join("errors")
6
+ lib_path = Pathname.new(File.expand_path('../vagrant-vcloud', __FILE__))
7
+ autoload :Action, lib_path.join('action')
8
+ autoload :Errors, lib_path.join('errors')
9
9
 
10
10
  # This returns the path to the source of this plugin.
11
11
  #
12
12
  # @return [Pathname]
13
13
  def self.source_root
14
- @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
14
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
15
15
  end
16
16
  end
17
17
  end
18
18
 
19
19
  module Vagrant
20
20
  class Machine
21
-
22
21
  attr_reader :vappid
23
22
 
24
23
  def vappid=(value)
@@ -27,13 +26,13 @@ module Vagrant
27
26
  # The file that will store the id if we have one. This allows the
28
27
  # ID to persist across Vagrant runs.
29
28
 
30
- id_file = @data_dir.join("../../../vcloud_vappid")
29
+ id_file = @data_dir.join('../../../vcloud_vappid')
31
30
 
32
31
  ### this should be ./.vagrant/vcloud_vappid
33
32
 
34
33
  if value
35
34
  # Write the "id" file with the id given.
36
- id_file.open("w+") do |f|
35
+ id_file.open('w+') do |f|
37
36
  f.write(value)
38
37
  end
39
38
  else
@@ -46,20 +45,19 @@ module Vagrant
46
45
 
47
46
  # Notify the provider that the ID changed in case it needs to do
48
47
  # any accounting from it.
49
- #@provider.machine_id_changed
48
+ # @provider.machine_id_changed
50
49
  end
51
50
 
52
51
  # This returns the vCloud Director vApp ID.
53
52
  #
54
53
  # @return [vAppId]
55
54
  def get_vapp_id
56
- vappid_file = @data_dir.join("../../../vcloud_vappid")
55
+ vappid_file = @data_dir.join('../../../vcloud_vappid')
57
56
  if vappid_file.file?
58
57
  @vappid = vappid_file.read
59
58
  else
60
59
  nil
61
60
  end
62
61
  end
63
-
64
62
  end
65
- end
63
+ end
@@ -1,5 +1,5 @@
1
- require "pathname"
2
- require "vagrant/action/builder"
1
+ require 'pathname'
2
+ require 'vagrant/action/builder'
3
3
 
4
4
  module VagrantPlugins
5
5
  module VCloud
@@ -11,9 +11,14 @@ module VagrantPlugins
11
11
  # a bootup (i.e. not saved).
12
12
  def self.action_boot
13
13
  Vagrant::Action::Builder.new.tap do |b|
14
+ b.use ConfigValidate
14
15
  b.use PowerOn
15
- b.use HandleNATPortCollisions
16
- b.use ForwardPorts
16
+ b.use Call, IsCreated do |env, b2|
17
+ unless env[:bridged_network]
18
+ b2.use HandleNATPortCollisions
19
+ b2.use ForwardPorts
20
+ end
21
+ end
17
22
  b.use Provision
18
23
  b.use SyncFolders
19
24
  end
@@ -23,7 +28,7 @@ module VagrantPlugins
23
28
  Vagrant::Action::Builder.new.tap do |b|
24
29
  b.use ConfigValidate
25
30
  b.use Call, IsCreated do |env, b2|
26
- if !env[:result]
31
+ unless env[:result]
27
32
  b2.use MessageNotCreated
28
33
  next
29
34
  end
@@ -59,14 +64,15 @@ module VagrantPlugins
59
64
 
60
65
  def self.action_halt
61
66
  Vagrant::Action::Builder.new.tap do |b|
67
+ b.use ConfigValidate
62
68
  b.use ConnectVCloud
63
69
  b.use Call, IsPaused do |env, b2|
64
- if env[:result]
65
- b2.use Resume
66
- end
67
- b2.use UnmapPortForwardings
68
- b2.use PowerOff
70
+ b2.use Resume if env[:result]
69
71
  end
72
+ b.use Call, IsBridged do |env, b2|
73
+ b2.use UnmapPortForwardings unless env[:bridged_network]
74
+ end
75
+ b.use PowerOff
70
76
  end
71
77
  end
72
78
 
@@ -99,11 +105,9 @@ module VagrantPlugins
99
105
  b2.use ConnectVCloud
100
106
  b2.use Call, IsRunning do |env2, b3|
101
107
  # If the VM is running, must power off
102
- if env2[:result]
103
- b3.use action_halt
104
- end
108
+ b3.use action_halt if env2[:result]
105
109
  b3.use Destroy
106
- end
110
+ end
107
111
  else
108
112
  b2.use MessageWillNotDestroy
109
113
  end
@@ -115,7 +119,7 @@ module VagrantPlugins
115
119
  Vagrant::Action::Builder.new.tap do |b|
116
120
  b.use ConfigValidate
117
121
  b.use Call, IsCreated do |env, b2|
118
- if !env[:result]
122
+ unless env[:result]
119
123
  b2.use MessageNotCreated
120
124
  next
121
125
  end
@@ -151,12 +155,12 @@ module VagrantPlugins
151
155
  Vagrant::Action::Builder.new.tap do |b|
152
156
  b.use ConfigValidate
153
157
  b.use Call, IsCreated do |env, b2|
154
- if !env[:result]
158
+ unless env[:result]
155
159
  b2.use MessageNotCreated
156
160
  next
157
161
  end
158
162
  # This calls our helper that announces the IP used to connect
159
- # to the VM, either directly to the vApp vShield or to the Org Edge.
163
+ # to the VM, either directly to the vApp vShield or to the Org Edge
160
164
  b2.use AnnounceSSHExec
161
165
  end
162
166
  end
@@ -166,7 +170,7 @@ module VagrantPlugins
166
170
  Vagrant::Action::Builder.new.tap do |b|
167
171
  b.use ConfigValidate
168
172
  b.use Call, IsCreated do |env, b2|
169
- if !env[:result]
173
+ unless env[:result]
170
174
  b2.use MessageNotCreated
171
175
  next
172
176
  end
@@ -180,13 +184,11 @@ module VagrantPlugins
180
184
  Vagrant::Action::Builder.new.tap do |b|
181
185
  b.use ConfigValidate
182
186
  b.use Call, IsCreated do |env, b2|
183
- if !env[:result]
184
- b2.use HandleBoxUrl
185
- end
187
+ b2.use HandleBox unless env[:result]
186
188
  end
187
189
  b.use ConnectVCloud
188
190
  b.use Call, IsCreated do |env, b2|
189
- if !env[:result]
191
+ unless env[:result]
190
192
  b2.use InventoryCheck
191
193
  b2.use BuildVApp
192
194
  end
@@ -197,30 +199,55 @@ module VagrantPlugins
197
199
  end
198
200
 
199
201
  # The autoload farm
200
- action_root = Pathname.new(File.expand_path("../action", __FILE__))
201
- autoload :AnnounceSSHExec, action_root.join("announce_ssh_exec")
202
- autoload :BuildVApp, action_root.join("build_vapp")
203
- autoload :ConnectVCloud, action_root.join("connect_vcloud")
204
- autoload :Destroy, action_root.join("destroy")
205
- autoload :DisconnectVCloud, action_root.join("disconnect_vcloud")
206
- autoload :ForwardPorts, action_root.join("forward_ports")
207
- autoload :HandleNATPortCollisions, action_root.join("handle_nat_port_collisions")
208
- autoload :InventoryCheck, action_root.join("inventory_check")
209
- autoload :IsCreated, action_root.join("is_created")
210
- autoload :IsPaused, action_root.join("is_paused")
211
- autoload :IsRunning, action_root.join("is_running")
212
- autoload :MessageAlreadyRunning, action_root.join("message_already_running")
213
- autoload :MessageCannotSuspend, action_root.join("message_cannot_suspend")
214
- autoload :MessageNotCreated, action_root.join("message_not_created")
215
- autoload :MessageWillNotDestroy, action_root.join("message_will_not_destroy")
216
- autoload :PowerOff, action_root.join("power_off")
217
- autoload :PowerOn, action_root.join("power_on")
218
- autoload :ReadSSHInfo, action_root.join("read_ssh_info")
219
- autoload :ReadState, action_root.join("read_state")
220
- autoload :Resume, action_root.join("resume")
221
- autoload :Suspend, action_root.join("suspend")
222
- autoload :SyncFolders, action_root.join("sync_folders")
223
- autoload :UnmapPortForwardings, action_root.join("unmap_port_forwardings")
202
+ action_root = Pathname.new(File.expand_path('../action', __FILE__))
203
+ autoload :AnnounceSSHExec,
204
+ action_root.join('announce_ssh_exec')
205
+ autoload :BuildVApp,
206
+ action_root.join('build_vapp')
207
+ autoload :ConnectVCloud,
208
+ action_root.join('connect_vcloud')
209
+ autoload :Destroy,
210
+ action_root.join('destroy')
211
+ autoload :DisconnectVCloud,
212
+ action_root.join('disconnect_vcloud')
213
+ autoload :ForwardPorts,
214
+ action_root.join('forward_ports')
215
+ autoload :HandleNATPortCollisions,
216
+ action_root.join('handle_nat_port_collisions')
217
+ autoload :InventoryCheck,
218
+ action_root.join('inventory_check')
219
+ autoload :IsCreated,
220
+ action_root.join('is_created')
221
+ autoload :IsBridged,
222
+ action_root.join('is_bridged')
223
+ autoload :IsPaused,
224
+ action_root.join('is_paused')
225
+ autoload :IsRunning,
226
+ action_root.join('is_running')
227
+ autoload :MessageAlreadyRunning,
228
+ action_root.join('message_already_running')
229
+ autoload :MessageCannotSuspend,
230
+ action_root.join('message_cannot_suspend')
231
+ autoload :MessageNotCreated,
232
+ action_root.join('message_not_created')
233
+ autoload :MessageWillNotDestroy,
234
+ action_root.join('message_will_not_destroy')
235
+ autoload :PowerOff,
236
+ action_root.join('power_off')
237
+ autoload :PowerOn,
238
+ action_root.join('power_on')
239
+ autoload :ReadSSHInfo,
240
+ action_root.join('read_ssh_info')
241
+ autoload :ReadState,
242
+ action_root.join('read_state')
243
+ autoload :Resume,
244
+ action_root.join('resume')
245
+ autoload :Suspend,
246
+ action_root.join('suspend')
247
+ autoload :SyncFolders,
248
+ action_root.join('sync_folders')
249
+ autoload :UnmapPortForwardings,
250
+ action_root.join('unmap_port_forwardings')
224
251
  end
225
252
  end
226
- end
253
+ end
@@ -7,8 +7,10 @@ module VagrantPlugins
7
7
  end
8
8
 
9
9
  def call(env)
10
- sshInfo = env[:machine].ssh_info
11
- env[:ui].success("External IP for #{env[:machine].name}: #{sshInfo[:host]}")
10
+ ssh_info = env[:machine].ssh_info
11
+ env[:ui].success(
12
+ "External IP for #{env[:machine].name}: #{ssh_info[:host]}"
13
+ )
12
14
  super
13
15
  end
14
16
  end
@@ -1,6 +1,6 @@
1
- require "securerandom"
2
- require "etc"
3
- require "netaddr"
1
+ require 'securerandom'
2
+ require 'etc'
3
+ require 'netaddr'
4
4
 
5
5
  module VagrantPlugins
6
6
  module VCloud
@@ -8,28 +8,26 @@ module VagrantPlugins
8
8
  class BuildVApp
9
9
  def initialize(app, env)
10
10
  @app = app
11
- @logger = Log4r::Logger.new("vagrant_vcloud::action::build_vapp")
11
+ @logger = Log4r::Logger.new('vagrant_vcloud::action::build_vapp')
12
12
  end
13
13
 
14
14
  def call(env)
15
-
16
- # FIXME: we need to find a way to clean things up when a SIGINT get
15
+ # FIXME: we need to find a way to clean things up when a SIGINT get
17
16
  # called... see env[:interrupted] in the vagrant code
18
17
 
19
18
  cfg = env[:machine].provider_config
20
19
  cnx = cfg.vcloud_cnx.driver
21
- vmName = env[:machine].name
20
+ vm_name = env[:machine].name
22
21
 
23
22
  if cfg.ip_dns.nil?
24
- dnsAddress1 = "8.8.8.8"
25
- dnsAddress2 = "8.8.4.4"
23
+ dns_address1 = '8.8.8.8'
24
+ dns_address2 = '8.8.4.4'
26
25
  else
27
- dnsAddress1 = cfg.ip_dns.shift
28
- dnsAddress2 = cfg.ip_dns.shift
26
+ dns_address1 = cfg.ip_dns.shift
27
+ dns_address2 = cfg.ip_dns.shift
29
28
  end
30
29
 
31
30
  if !cfg.ip_subnet.nil?
32
-
33
31
  @logger.debug("Input address: #{cfg.ip_subnet}")
34
32
 
35
33
  begin
@@ -37,159 +35,185 @@ module VagrantPlugins
37
35
  rescue NetAddr::ValidationError
38
36
  raise Errors::InvalidSubnet, :message => cfg.ip_subnet
39
37
  end
40
- if cidr.bits > 30
41
- @logger.debug("Subnet too small!")
42
- raise Errors::SubnetTooSmall, :message => cfg.ip_subnet
43
- end
44
38
 
45
- rangeAddresses = cidr.range(0)
39
+ if cidr.bits > 30
40
+ @logger.debug('Subnet too small!')
41
+ raise Errors::SubnetTooSmall, :message => cfg.ip_subnet
42
+ end
43
+
44
+ range_addresses = cidr.range(0)
46
45
 
47
- @logger.debug("Range: #{rangeAddresses}")
46
+ @logger.debug("Range: #{range_addresses}")
48
47
 
49
- rangeAddresses.shift # Delete the "network" address from the range.
50
- gatewayIp = rangeAddresses.shift # Retrieve the first usable IP, to be used as a gateway.
51
- rangeAddresses.reverse! # Reverse the array in place.
52
- rangeAddresses.shift # Delete the "broadcast" address from the range.
53
- rangeAddresses.reverse! # Reverse back the array.
48
+ # Delete the "network" address from the range.
49
+ range_addresses.shift
50
+ # Retrieve the first usable IP, to be used as a gateway.
51
+ gateway_ip = range_addresses.shift
52
+ # Reverse the array in place.
53
+ range_addresses.reverse!
54
+ # Delete the "broadcast" address from the range.
55
+ range_addresses.shift
56
+ # Reverse back the array.
57
+ range_addresses.reverse!
54
58
 
55
- @logger.debug("Gateway IP: #{gatewayIp.to_s}")
59
+ @logger.debug("Gateway IP: #{gateway_ip.to_s}")
56
60
  @logger.debug("Netmask: #{cidr.wildcard_mask}")
57
- @logger.debug("IP Pool: #{rangeAddresses.first}-#{rangeAddresses.last}")
58
- @logger.debug("DNS1: #{dnsAddress1} DNS2: #{dnsAddress2}")
59
-
60
-
61
- network_options = {
62
- :name => "Vagrant-vApp-Net",
63
- :gateway => gatewayIp.to_s,
64
- :netmask => cidr.wildcard_mask,
65
- :start_address => rangeAddresses.first,
66
- :end_address => rangeAddresses.last,
67
- :fence_mode => "natRouted",
68
- :ip_allocation_mode => "POOL",
69
- :parent_network => cfg.vdc_network_id,
70
- :enable_firewall => "false",
71
- :dns1 => dnsAddress1,
72
- :dns2 => dnsAddress2
61
+ @logger.debug(
62
+ "IP Pool: #{range_addresses.first}-#{range_addresses.last}"
63
+ )
64
+ @logger.debug("DNS1: #{dns_address1} DNS2: #{dns_address2}")
65
+
66
+ network_options = {
67
+ :name => 'Vagrant-vApp-Net',
68
+ :gateway => gateway_ip.to_s,
69
+ :netmask => cidr.wildcard_mask,
70
+ :start_address => range_addresses.first,
71
+ :end_address => range_addresses.last,
72
+ :fence_mode => 'natRouted',
73
+ :ip_allocation_mode => 'POOL',
74
+ :parent_network => cfg.vdc_network_id,
75
+ :enable_firewall => 'false',
76
+ :dns1 => dns_address1,
77
+ :dns2 => dns_address2
73
78
  }
74
79
 
80
+ elsif !cfg.network_bridge.nil?
81
+ # Bridged mode, avoid deploying a vShield Edge altogether.
82
+ network_options = {
83
+ :name => 'Vagrant-vApp-Net',
84
+ :fence_mode => 'bridged',
85
+ :ip_allocation_mode => 'POOL',
86
+ :parent_network => cfg.vdc_network_id
87
+ }
88
+
89
+ env[:bridged_network] = true
90
+
75
91
  else
76
92
 
77
- @logger.debug("DNS1: #{dnsAddress1} DNS2: #{dnsAddress2}")
93
+ @logger.debug("DNS1: #{dns_address1} DNS2: #{dns_address2}")
78
94
  # No IP subnet specified, reverting to defaults
79
- network_options = {
80
- :name => "Vagrant-vApp-Net",
81
- :gateway => "10.1.1.1",
82
- :netmask => "255.255.255.0",
83
- :start_address => "10.1.1.2",
84
- :end_address => "10.1.1.254",
85
- :fence_mode => "natRouted",
86
- :ip_allocation_mode => "POOL",
87
- :parent_network => cfg.vdc_network_id,
88
- :enable_firewall => "false",
89
- :dns1 => dnsAddress1,
90
- :dns2 => dnsAddress2
95
+ network_options = {
96
+ :name => 'Vagrant-vApp-Net',
97
+ :gateway => '10.1.1.1',
98
+ :netmask => '255.255.255.0',
99
+ :start_address => '10.1.1.2',
100
+ :end_address => '10.1.1.254',
101
+ :fence_mode => 'natRouted',
102
+ :ip_allocation_mode => 'POOL',
103
+ :parent_network => cfg.vdc_network_id,
104
+ :enable_firewall => 'false',
105
+ :dns1 => dns_address1,
106
+ :dns2 => dns_address2
91
107
  }
92
108
 
93
109
  end
94
110
 
95
111
  if env[:machine].get_vapp_id.nil?
96
-
97
- env[:ui].info("Building vApp...")
112
+ env[:ui].info('Building vApp...')
98
113
 
99
114
  compose = cnx.compose_vapp_from_vm(
100
- cfg.vdc_id,
101
- "Vagrant-#{Etc.getlogin}-#{Socket.gethostname.downcase}-#{SecureRandom.hex(4)}",
102
- "vApp created by #{Etc.getlogin} running on #{Socket.gethostname.downcase} using vagrant-vcloud on #{Time.now.strftime("%B %d, %Y")}",
103
- {
104
- vmName => cfg.catalog_item[:vms_hash][env[:machine].box.name.to_s][:id]
105
- },
115
+ cfg.vdc_id,
116
+ "Vagrant-#{Etc.getlogin}-#{Socket.gethostname.downcase}-" +
117
+ "#{SecureRandom.hex(4)}",
118
+ "vApp created by #{Etc.getlogin} running on " +
119
+ "#{Socket.gethostname.downcase} using vagrant-vcloud on " +
120
+ "#{Time.now.strftime("%B %d, %Y")}",
121
+ {
122
+ vm_name => cfg.catalog_item[:vms_hash][env[:machine].box.name.to_s][:id]
123
+ },
106
124
  network_options
107
125
  )
108
- @logger.debug("Launched Compose vApp")
126
+ @logger.debug('Launch Compose vApp...')
109
127
  # Wait for the task to finish.
110
128
  wait = cnx.wait_task_completion(compose[:task_id])
111
129
 
112
- if !wait[:errormsg].nil?
113
- raise Errors::ComposeVAppError, :message => wait[:errormsg]
130
+ unless wait[:errormsg].nil?
131
+ fail Errors::ComposeVAppError, :message => wait[:errormsg]
114
132
  end
115
133
 
116
-
117
134
  # Fetch thenewly created vApp ID
118
- vAppId = compose[:vapp_id]
135
+ vapp_id = compose[:vapp_id]
119
136
 
120
137
  # putting the vApp Id in a globally reachable var and file.
121
- env[:machine].vappid = vAppId
138
+ env[:machine].vappid = vapp_id
122
139
 
123
140
  # Fetching new vApp object to check stuff.
124
- newVApp = cnx.get_vapp(vAppId)
141
+ new_vapp = cnx.get_vapp(vapp_id)
125
142
 
126
143
  # FIXME: Add a lot of error handling for each step here !
127
-
128
- if newVApp
129
- env[:ui].success("vApp #{newVApp[:name]} successfully created.")
144
+ if new_vapp
145
+ env[:ui].success("vApp #{new_vapp[:name]} successfully created.")
130
146
 
131
147
  # Add the vm id as machine.id
132
- newVMProperties = newVApp[:vms_hash].fetch(vmName)
133
- env[:machine].id = newVMProperties[:id]
148
+ new_vm_properties = new_vapp[:vms_hash].fetch(vm_name)
149
+ env[:machine].id = new_vm_properties[:id]
134
150
 
135
151
  ### SET GUEST CONFIG
136
-
137
- @logger.info("Setting Guest Customization on ID: [#{vmName}] of vApp [#{newVApp[:name]}]")
138
-
139
- setCustom = cnx.set_vm_guest_customization(newVMProperties[:id], vmName, {
140
- :enabled => true,
141
- :admin_passwd_enabled => false
142
- })
143
- cnx.wait_task_completion(setCustom)
152
+ @logger.info(
153
+ "Setting Guest Customization on ID: [#{vm_name}] " +
154
+ "of vApp [#{new_vapp[:name]}]"
155
+ )
156
+
157
+ set_custom = cnx.set_vm_guest_customization(
158
+ new_vm_properties[:id],
159
+ vm_name,
160
+ {
161
+ :enabled => true,
162
+ :admin_passwd_enabled => false
163
+ }
164
+ )
165
+ cnx.wait_task_completion(set_custom)
144
166
 
145
167
  else
146
- env[:ui].error("vApp #{newVApp[:name]} creation failed!")
168
+ env[:ui].error("vApp #{new_vapp[:name]} creation failed!")
147
169
  raise # FIXME: error handling missing.
148
- end
170
+ end
171
+
149
172
  else
150
- env[:ui].info("Adding VM to existing vApp...")
151
-
173
+ env[:ui].info('Adding VM to existing vApp...')
174
+
152
175
  recompose = cnx.recompose_vapp_from_vm(
153
- env[:machine].get_vapp_id,
154
- {
155
- vmName => cfg.catalog_item[:vms_hash][env[:machine].box.name.to_s][:id]
156
- },
176
+ env[:machine].get_vapp_id,
177
+ {
178
+ vm_name => cfg.catalog_item[:vms_hash][env[:machine].box.name.to_s][:id]
179
+ },
157
180
  network_options
158
181
  )
159
182
 
160
- @logger.info("Waiting for the add to complete ...")
183
+ @logger.info('Waiting for the recompose task to complete ...')
161
184
 
162
185
  # Wait for the task to finish.
163
- wait = cnx.wait_task_completion(recompose[:task_id])
164
-
165
- newVApp = cnx.get_vapp(env[:machine].get_vapp_id)
186
+ cnx.wait_task_completion(recompose[:task_id])
166
187
 
188
+ new_vapp = cnx.get_vapp(env[:machine].get_vapp_id)
167
189
  # FIXME: Add a lot of error handling for each step here !
168
-
169
- if newVApp
170
-
171
- newVMProperties = newVApp[:vms_hash].fetch(vmName)
172
- env[:machine].id = newVMProperties[:id]
190
+ if new_vapp
191
+ new_vm_properties = new_vapp[:vms_hash].fetch(vm_name)
192
+ env[:machine].id = new_vm_properties[:id]
173
193
 
174
194
  ### SET GUEST CONFIG
175
-
176
- @logger.info("Setting Guest Customization on ID: [#{newVMProperties[:id]}] of vApp [#{newVApp[:name]}]")
177
-
178
- setCustom = cnx.set_vm_guest_customization(newVMProperties[:id], vmName, {
179
- :enabled => true,
180
- :admin_passwd_enabled => false
181
- })
182
- cnx.wait_task_completion(setCustom)
195
+ @logger.info(
196
+ 'Setting Guest Customization on ID: ' +
197
+ "[#{new_vm_properties[:id]}] of vApp [#{new_vapp[:name]}]"
198
+ )
199
+
200
+ set_custom = cnx.set_vm_guest_customization(
201
+ new_vm_properties[:id],
202
+ vm_name,
203
+ {
204
+ :enabled => true,
205
+ :admin_passwd_enabled => false
206
+ }
207
+ )
208
+ cnx.wait_task_completion(set_custom)
183
209
 
184
210
  else
185
-
186
- env[:ui].error("VM #{vmName} add to #{newVApp[:name]} failed!")
211
+ env[:ui].error("VM #{vm_name} add to #{new_vapp[:name]} failed!")
187
212
  raise
188
- end
213
+ end
189
214
  end
190
215
 
191
216
  @app.call env
192
-
193
217
  end
194
218
  end
195
219
  end