vagrant-vcloud 0.4.4 → 0.4.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c063c6be550a2cc4edc377537aa3131e5151b7be
4
- data.tar.gz: 6dc78ac5e15f8a82dd04cc096e309fa82f20665e
3
+ metadata.gz: b9c4c78e1a1282b1aac96e39cfcea24b36847340
4
+ data.tar.gz: afc6fc6fa406254848db0d871b5f014b0d72f193
5
5
  SHA512:
6
- metadata.gz: fa89f867841f3aa6c3db196be9ba3731bef0387958c5c1de89f6bfc0dcb3bd657d351199deb70a7ed2ed93a1ab828d2b3bc5f36428767d2c327c7e704cb20f6a
7
- data.tar.gz: 045e357b328c4ec61015865353009d2fec8fc4cc4b1f54b489fe9fc402510a0d2a64d1bc8af5973d93f94ccc94f57aa840d91785f7f9981750b14e31241055a2
6
+ metadata.gz: 6d53ac5b55cd8060e0d73c5168d56ca21793cadcef767bdf0abde2ecd25091eec362a0d6eec4500cbff64e0d16ea77391ba9d5e8759c139a708502b86633bb92
7
+ data.tar.gz: 29fb9185c93f55efdcd1bf787dc3c67e898231370477e0fed5969509598305d1c289186f77de60e24dc808dfd8902464ad868bf536a3a0be946cf96567043bed
data/README.md CHANGED
@@ -1,44 +1,84 @@
1
- [Vagrant](http://www.vagrantup.com) provider for VMware vCloud Director® [![Gem Version](https://badge.fury.io/rb/vagrant-vcloud.svg)](http://badge.fury.io/rb/vagrant-vcloud) [![Code Climate](https://codeclimate.com/github/frapposelli/vagrant-vcloud/badges/gpa.svg)](https://codeclimate.com/github/frapposelli/vagrant-vcloud)
2
- =============
1
+ [Vagrant](http://www.vagrantup.com) provider for VMware vCloud Director® [![Gem Version](https://badge.fury.io/rb/vagrant-vcloud.svg)](http://badge.fury.io/rb/vagrant-vcloud) [![Code Climate](https://codeclimate.com/github/frapposelli/vagrant-vcloud/badges/gpa.svg)](https://codeclimate.com/github/frapposelli/vagrant-vcloud) [![Dependency Status](https://gemnasium.com/frapposelli/vagrant-vcloud.svg)](https://gemnasium.com/frapposelli/vagrant-vcloud) [![Join the chat at https://gitter.im/frapposelli/vagrant-vcloud](https://badges.gitter.im/frapposelli/vagrant-vcloud.svg)](https://gitter.im/frapposelli/vagrant-vcloud?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
2
+ ========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
3
3
 
4
4
  Please note that this software is still Alpha/Beta quality and is not recommended for production usage.
5
5
 
6
6
  We have a wide array of boxes available at [Vagrant Cloud](https://vagrantcloud.com/gosddc) you can use them directly or you can roll your own as you please, make sure to install VMware tools in it.
7
7
 
8
- Starting from [version 0.4.2](../../releases/tag/v0.4.2), this plugin supports the universal [```vmware_ovf``` box format](https://github.com/gosddc/packer-post-processor-vagrant-vmware-ovf/wiki/vmware_ovf-Box-Format), that is 100% portable between [vagrant-vcloud](https://github.com/frapposelli/vagrant-vcloud), [vagrant-vcenter](https://github.com/gosddc/vagrant-vcenter) and [vagrant-vcloudair](https://github.com/gosddc/vagrant-vcloudair), no more double boxes!.
8
+ Starting from [version 0.4.2](../../releases/tag/v0.4.2), this plugin supports the universal [`vmware_ovf` box format](https://github.com/gosddc/packer-post-processor-vagrant-vmware-ovf/wiki/vmware_ovf-Box-Format), that is 100% portable between [vagrant-vcloud](https://github.com/frapposelli/vagrant-vcloud), [vagrant-vcenter](https://github.com/gosddc/vagrant-vcenter) and [vagrant-vcloudair](https://github.com/gosddc/vagrant-vcloudair), no more double boxes!.
9
9
 
10
10
  If you're unsure about what are the correct network settings for your Vagrantfile make sure to check out the [Network Deployment Options](https://github.com/frapposelli/vagrant-vcloud/wiki/Network-Deployment-Options) wiki page.
11
11
 
12
12
  Check the full releases changelog [here](../../releases)
13
13
 
14
14
  Install
15
- -------------
15
+ -------
16
16
 
17
- Latest version can be easily installed by running the following command:
17
+ Latest version can be installed by running the following command:
18
18
 
19
- ```vagrant plugin install vagrant-vcloud```
19
+ `vagrant plugin install vagrant-vcloud`
20
20
 
21
21
  Vagrant will download all the required gems during the installation process.
22
22
 
23
- After the install has completed a ```vagrant up --provider=vcloud``` will trigger the newly installed provider.
23
+ After the install has completed a `vagrant up --provider=vcloud` will trigger the newly installed provider.
24
24
 
25
25
  Upgrade
26
- -------------
26
+ -------
27
27
 
28
28
  If you already have vagrant-vcloud installed you can update to the latest version available by issuing:
29
29
 
30
- ```vagrant plugin update vagrant-vcloud```
30
+ `vagrant plugin update vagrant-vcloud`
31
31
 
32
32
  Vagrant will take care of the upgrade process.
33
33
 
34
34
  Configuration
35
35
  -------------
36
36
 
37
- Here's a sample Multi-VM Vagrantfile, please note that ```vcloud.vdc_edge_gateway``` and ```vcloud.vdc_edge_gateway_ip``` are required only when you cannot access ```vcloud.vdc_network_name``` directly and there's an Organization Edge between your workstation and the vCloud Network.
37
+ Here's a sample Multi-VM Vagrantfile, please note that `vcloud.vdc_edge_gateway` and `vcloud.vdc_edge_gateway_ip` are required when you cannot access `vcloud.vdc_network_name` directly and there's an Organization Edge between your workstation and the vCloud Network.
38
38
 
39
39
  ```ruby
40
+ vapp = {
41
+ name: 'My vApp name',
42
+ org_name: 'OrganizationName',
43
+ orgvdc_name: 'vDC_Name',
44
+ orgvdccatalog_name: 'Vagrant',
45
+ metadata: [ [ 'key', 'value' ] ],
46
+ advanced_networking: true,
47
+ networks: {
48
+ org: [ 'Org_VDC_Network' ],
49
+ vapp: [
50
+ {
51
+ name: 'MyNetwork',
52
+ ip_subnet: '10.10.10.10/255.255.255.0'
53
+ }
54
+ ]
55
+ }
56
+ }
57
+
40
58
  nodes = [
41
- { hostname: 'web-vm', box: 'gosddc/precise32' },
59
+ {
60
+ hostname: 'web-vm',
61
+ box: 'gosddc/precise32',
62
+ memory: 512,
63
+ cpus: 1,
64
+ nested_hypervisor: false,
65
+ add_hdds: [ 1024 ],
66
+ power_on: true,
67
+ ssh_enable: true,
68
+ sync_enable: true,
69
+ metadata: [ [ 'key', 'value' ] ],
70
+ nics: [
71
+ type: :vmxnet3,
72
+ connected: true,
73
+ network: "vApp netowrk",
74
+ primary: true,
75
+ ip_mode: "static",
76
+ ip: "10.10.10.1",
77
+ mac: "00:50:56:00:00:01"
78
+ ],
79
+ enable_guest_customization: true,
80
+ guest_customization_script: 'touch /sample.file'
81
+ },
42
82
  { hostname: 'ssh-vm', box: 'gosddc/precise32' },
43
83
  { hostname: 'sql-vm', box: 'gosddc/precise32' },
44
84
  { hostname: 'app-vm', box: 'gosddc/precise32' }
@@ -48,22 +88,30 @@ Vagrant.configure('2') do |config|
48
88
 
49
89
  # vCloud Director provider settings
50
90
  config.vm.provider :vcloud do |vcloud|
51
- vcloud.vapp_prefix = 'multibox-sample'
52
91
 
53
92
  vcloud.hostname = 'https://my.cloudprovider.com'
54
93
  vcloud.username = 'MyUserName'
55
94
  vcloud.password = 'MySup3rS3cr3tPassw0rd!'
56
95
 
57
- vcloud.org_name = 'OrganizationName'
58
- vcloud.vdc_name = 'vDC_Name'
59
-
60
- vcloud.catalog_name = 'Vagrant'
61
- vcloud.ip_subnet = '172.16.32.125/255.255.255.240'
62
-
63
- vcloud.vdc_network_name = 'MyNetwork'
96
+ vcloud.vapp_prefix = 'multibox-sample'
64
97
 
65
- vcloud.vdc_edge_gateway = 'MyOrgEdgeGateway'
66
- vcloud.vdc_edge_gateway_ip = '10.10.10.10'
98
+ vcloud.org_name = vapp[:org_name]
99
+ vcloud.vdc_name = vapp[:orgvdc_name]
100
+ vcloud.catalog_name = vapp[:orgvdccatalog_name]
101
+
102
+ vcloud.vapp_name = vapp[:name]
103
+ vcloud.metadata_vapp = vapp[:metadata]
104
+ vcloud.auto_yes_for_upload = vapp[:auto_yes_for_upload]
105
+
106
+ vcloud.advanced_network = vapp[:advanced_networking]
107
+ if vapp[:advanced_networking]
108
+ vcloud.networks = vapp[:networks]
109
+ else
110
+ vcloud.ip_subnet = '172.16.32.125/255.255.255.240'
111
+ vcloud.vdc_network_name = 'MyNetwork'
112
+ vcloud.vdc_edge_gateway = 'MyOrgEdgeGateway'
113
+ vcloud.vdc_edge_gateway_ip = '10.10.10.10'
114
+ end
67
115
  end
68
116
 
69
117
  nodes.each do |node|
@@ -71,10 +119,27 @@ Vagrant.configure('2') do |config|
71
119
  node_config.vm.box = node[:box]
72
120
  node_config.vm.hostname = node[:hostname]
73
121
  node_config.vm.box_url = node[:box_url]
74
- node_config.vm.network :forwarded_port,
75
- guest: 80,
76
- host: 8080,
77
- auto_correct: true
122
+ if vapp[:advanced_networking]
123
+ node_config.vm.provider :vcloud do |pro|
124
+ pro.memory = node[:memory]
125
+ pro.cpus = node[:cpus]
126
+ pro.add_hdds = node[:add_hdds]
127
+ pro.nics = node[:nics]
128
+ pro.ssh_enabled = node[:ssh_enabled]
129
+ pro.sync_enabled = node[:sync_enabled]
130
+ pro.power_on = node[:power_on]
131
+ pro.metadata_vm = node[:metadata]
132
+ pro.nested_hypervisor = node[:nested_hypervisor]
133
+ pro.enable_guest_customization = node[:enable_guest_customization]
134
+ pro.guest_customization_script = node[:guest_customization_script]
135
+ end
136
+ node_config.vm.network :public_network
137
+ else
138
+ node_config.vm.network :forwarded_port,
139
+ guest: 80,
140
+ host: 8080,
141
+ auto_correct: true
142
+ end
78
143
  # node_config.vm.provision :puppet do |puppet|
79
144
  # puppet.manifests_path = 'puppet/manifests'
80
145
  # puppet.manifest_file = 'site.pp'
@@ -85,22 +150,19 @@ Vagrant.configure('2') do |config|
85
150
  end
86
151
  ```
87
152
 
88
- For additional documentation on different network setups with vCloud Director, check the [Network Deployment Options](../../wiki/Network-Deployment-Options) Wiki page
153
+ For additional documentation on network setups with vCloud Director, check the [Network Deployment Options](../../wiki/Network-Deployment-Options) Wiki page
89
154
 
90
155
  Contribute
91
- -------------
156
+ ----------
92
157
 
93
158
  What is still missing:
94
159
 
95
- - TEST SUITES! (working on that).
96
- - Speed, the code is definitely not optimized.
97
- - Permission checks, make sure you have at least Catalog Admin privileges if you want to upload boxes to vCloud.
98
- - Thorough testing.
99
- - Error checking is absymal.
100
- - Some spaghetti code here and there.
101
- - Bugs, bugs and BUGS!.
102
-
103
- If you're a developer and want to lend us a hand, head over to our ```develop``` branch and send us PRs!
104
-
160
+ - TEST SUITES! (working on that).
161
+ - Speed, the code is definitely not optimized.
162
+ - Permission checks, make sure you have at least Catalog Admin privileges if you want to upload boxes to vCloud.
163
+ - Thorough testing.
164
+ - Error checking is absymal.
165
+ - Some spaghetti code here and there.
166
+ - Bugs, bugs and BUGS!.
105
167
 
106
- [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/frapposelli/vagrant-vcloud/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
168
+ If you're a developer and want to lend us a hand, head over to our `develop` branch and send us PRs!
data/Rakefile CHANGED
@@ -11,7 +11,3 @@ $stderr.sync = true
11
11
  Dir.chdir(File.expand_path('../', __FILE__))
12
12
 
13
13
  Bundler::GemHelper.install_tasks
14
-
15
- RSpec::Core::RakeTask.new
16
-
17
- task :default => 'spec'
@@ -20,10 +20,21 @@ module VagrantPlugins
20
20
  b2.use HandleNATPortCollisions
21
21
  b2.use ForwardPorts
22
22
  end
23
+ cfg = env[:machine].provider_config
24
+ if cfg.power_on.nil? || cfg.power_on == true
25
+ if cfg.ssh_enabled.nil? || cfg.ssh_enabled == true
26
+ b2.use WaitForCommunicator, [:starting, :running]
27
+ end
28
+ end
29
+ b2.use Provision
30
+ if cfg.power_on.nil? || cfg.power_on == true # can't ssh if not on
31
+ if cfg.ssh_enabled.nil? || cfg.ssh_enabled == true # can't sync if ssh is disabled
32
+ if cfg.sync_enabled.nil? || cfg.sync_enabled == true
33
+ b2.use SyncFolders
34
+ end
35
+ end
36
+ end
23
37
  end
24
- b.use WaitForCommunicator, [:starting, :running]
25
- b.use Provision
26
- b.use SyncFolders
27
38
  end
28
39
  end
29
40
 
@@ -59,7 +70,7 @@ module VagrantPlugins
59
70
  end
60
71
  end
61
72
 
62
- def self.action_halt
73
+ def self.action_poweroff
63
74
  Vagrant::Action::Builder.new.tap do |b|
64
75
  b.use ConfigValidate
65
76
  b.use ConnectVCloud
@@ -70,6 +81,17 @@ module VagrantPlugins
70
81
  end
71
82
  end
72
83
 
84
+ def self.action_halt
85
+ Vagrant::Action::Builder.new.tap do |b|
86
+ b.use ConfigValidate
87
+ b.use ConnectVCloud
88
+ b.use Call, IsPaused do |env, b2|
89
+ b2.use Resume if env[:result]
90
+ end
91
+ b.use ShutDown
92
+ end
93
+ end
94
+
73
95
  def self.action_suspend
74
96
  Vagrant::Action::Builder.new.tap do |b|
75
97
  b.use ConnectVCloud
@@ -105,15 +127,15 @@ module VagrantPlugins
105
127
 
106
128
  b3.use Call, IsRunning do |env3, b4|
107
129
  # If the VM is running, must power off
108
- b4.use action_halt if env3[:result]
130
+ b4.use action_poweroff if env3[:result]
109
131
  end
110
132
  b3.use Call, IsLastVM do |env3, b4|
111
133
  if env3[:result]
112
134
  # Check if the network is bridged
113
- b4.use Call, IsBridged do |env4, b5|
114
- # if it's not, delete port forwardings.
115
- b5.use UnmapPortForwardings unless env4[:bridged_network]
116
- end
135
+ # b4.use Call, IsBridged do |env4, b5|
136
+ # # if it's not, delete port forwardings.
137
+ # b5.use UnmapPortForwardings unless env4[:bridged_network] || env4[:advanced_network]
138
+ # end
117
139
  b4.use PowerOffVApp
118
140
  b4.use DestroyVApp
119
141
  else
@@ -286,6 +308,8 @@ module VagrantPlugins
286
308
  action_root.join('read_state')
287
309
  autoload :Resume,
288
310
  action_root.join('resume')
311
+ autoload :ShutDown,
312
+ action_root.join('shut_down')
289
313
  autoload :Suspend,
290
314
  action_root.join('suspend')
291
315
  autoload :SyncFolders,
@@ -19,15 +19,14 @@ module VagrantPlugins
19
19
  cnx = cfg.vcloud_cnx.driver
20
20
  vm_name = cfg.name ? cfg.name.to_sym : env[:machine].name
21
21
 
22
- if cfg.ip_dns.nil?
23
- dns_address1 = '8.8.8.8'
24
- dns_address2 = '8.8.4.4'
25
- else
26
- dns_address1 = cfg.ip_dns.shift
27
- dns_address2 = cfg.ip_dns.shift
28
- end
29
-
30
22
  if !cfg.ip_subnet.nil?
23
+ if cfg.ip_dns.nil?
24
+ dns_address1 = '8.8.8.8'
25
+ dns_address2 = '8.8.4.4'
26
+ else
27
+ dns_address1 = cfg.ip_dns.shift
28
+ dns_address2 = cfg.ip_dns.shift
29
+ end
31
30
  @logger.debug("Input address: #{cfg.ip_subnet}")
32
31
 
33
32
  begin
@@ -56,6 +55,14 @@ module VagrantPlugins
56
55
  # Reverse back the array.
57
56
  range_addresses.reverse!
58
57
 
58
+ dhcp_enabled = 'false'
59
+ if !cfg.dhcp_enabled.nil? and cfg.dhcp_enabled == true
60
+ dhcp_enabled = 'true'
61
+ range_addresses = cfg.pool_range
62
+ dhcp_start = cfg.dhcp_range.shift
63
+ dhcp_end = cfg.dhcp_range.shift
64
+ end
65
+
59
66
  @logger.debug("Gateway IP: #{gateway_ip.to_s}")
60
67
  @logger.debug("Netmask: #{cidr.wildcard_mask}")
61
68
  @logger.debug(
@@ -73,6 +80,9 @@ module VagrantPlugins
73
80
  :ip_allocation_mode => 'POOL',
74
81
  :parent_network => cfg.vdc_network_id,
75
82
  :enable_firewall => 'false',
83
+ :dhcp_enabled => dhcp_enabled,
84
+ :dhcp_start => dhcp_start,
85
+ :dhcp_end => dhcp_end,
76
86
  :dns1 => dns_address1,
77
87
  :dns2 => dns_address2
78
88
  }
@@ -88,7 +98,127 @@ module VagrantPlugins
88
98
 
89
99
  env[:bridged_network] = true
90
100
 
101
+ elsif !cfg.networks.nil?
102
+ # Advanced network definition
103
+ env[:advanced_network] = true
104
+ network_options = []
105
+ if cfg.networks[:org]
106
+ cfg.networks[:org].each do |net|
107
+ net_id = cfg.org[:networks][net]
108
+ if !net_id
109
+ # TEMP FIX: permissions issues at the Org Level for vApp authors
110
+ # to "view" Org vDC Networks but they can see them at the
111
+ # Organization vDC level (tsugliani)
112
+ net_id = cfg.vdc[:networks][net]
113
+ if !net_id
114
+ raise 'vCloud User credentials has insufficient privileges'
115
+ end
116
+ end
117
+ network_options.push({
118
+ :name => net,
119
+ :fence_mode => 'bridged',
120
+ :ip_allocation_mode => 'POOL',
121
+ :parent_network => net_id
122
+ })
123
+ end
124
+ end
125
+ if cfg.networks[:vapp]
126
+ cfg.networks[:vapp].each_with_index do |net, i|
127
+ if net[:ip_dns].nil?
128
+ dns_address1 = '8.8.8.8'
129
+ dns_address2 = '8.8.4.4'
130
+ else
131
+ dns_address1 = net[:ip_dns].shift
132
+ dns_address2 = net[:ip_dns].shift
133
+ end
134
+ @logger.debug("Input address[#{i}]: #{net[:ip_subnet]}")
135
+
136
+ begin
137
+ cidr = NetAddr::CIDR.create(net[:ip_subnet])
138
+ rescue NetAddr::ValidationError
139
+ raise Errors::InvalidSubnet, :message => net[:ip_subnet]
140
+ end
141
+
142
+ if cidr.bits > 30
143
+ @logger.debug('Subnet too small!')
144
+ raise Errors::SubnetTooSmall, :message => net[:ip_subnet]
145
+ end
146
+
147
+ range_addresses = cidr.range(0)
148
+
149
+ @logger.debug("Range[#{i}]: #{range_addresses}")
150
+
151
+ # Delete the "network" address from the range.
152
+ range_addresses.shift
153
+ # Retrieve the first usable IP, to be used as a gateway.
154
+ if net[:gateway]
155
+ gateway_ip = net[:gateway]
156
+ else
157
+ gateway_ip = range_addresses.shift
158
+ end
159
+ # Reverse the array in place.
160
+ range_addresses.reverse!
161
+ # Delete the "broadcast" address from the range.
162
+ range_addresses.shift
163
+ # Reverse back the array.
164
+ range_addresses.reverse!
165
+
166
+ dhcp_enabled = 'false'
167
+ dhcp_start = nil
168
+ dhcp_end = nil
169
+ if !net[:dhcp_enabled].nil? and net[:dhcp_enabled] == true
170
+ dhcp_enabled = 'true'
171
+ range_addresses = net[:pool_range]
172
+ dhcp_start = net[:dhcp_range].shift
173
+ dhcp_end = net[:dhcp_range].shift
174
+ end
175
+
176
+ @logger.debug("Gateway IP[#{i}]: #{gateway_ip.to_s}")
177
+ @logger.debug("Netmask[#{i}]: #{cidr.wildcard_mask}")
178
+ @logger.debug("IP Pool[#{i}]: #{range_addresses.first}-#{range_addresses.last}")
179
+ @logger.debug("DNS1[#{i}]: #{dns_address1} DNS2[#{i}]: #{dns_address2}")
180
+ n = {
181
+ :name => net[:name],
182
+ :gateway => gateway_ip.to_s,
183
+ :netmask => cidr.wildcard_mask,
184
+ :start_address => range_addresses.first,
185
+ :end_address => range_addresses.last,
186
+ :fence_mode => 'natRouted',
187
+ :ip_allocation_mode => 'POOL',
188
+ :enable_firewall => 'false',
189
+ :dhcp_enabled => dhcp_enabled,
190
+ :dhcp_start => dhcp_start,
191
+ :dhcp_end => dhcp_end,
192
+ :dns1 => dns_address1,
193
+ :dns2 => dns_address2
194
+ }
195
+ if net[:vdc_network_name]
196
+ net_id = cfg.org[:networks][net[:vdc_network_name]]
197
+ if !net_id
198
+ # TEMP FIX: permissions issues at the Org Level for vApp authors
199
+ # to "view" Org vDC Networks but they can see them at the
200
+ # Organization vDC level (tsugliani)
201
+ net_id = cfg.vdc[:networks][net[:vdc_network_name]]
202
+ if !net_id
203
+ raise 'vCloud User credentials has insufficient privileges'
204
+ end
205
+ end
206
+ n[:parent_network] = net_id
207
+ net[:parent_network] = net_id
208
+ end
209
+
210
+ network_options.push(n)
211
+ end
212
+ end
213
+
91
214
  else
215
+ if cfg.ip_dns.nil?
216
+ dns_address1 = '8.8.8.8'
217
+ dns_address2 = '8.8.4.4'
218
+ else
219
+ dns_address1 = cfg.ip_dns.shift
220
+ dns_address2 = cfg.ip_dns.shift
221
+ end
92
222
 
93
223
  @logger.debug("DNS1: #{dns_address1} DNS2: #{dns_address2}")
94
224
  # No IP subnet specified, reverting to defaults
@@ -108,23 +238,31 @@ module VagrantPlugins
108
238
 
109
239
  end
110
240
 
241
+ network_options = [network_options] if !network_options.kind_of?(Array)
242
+
111
243
  if env[:machine].get_vapp_id.nil?
112
244
  env[:ui].info('Building vApp...')
113
245
 
114
- vapp_prefix = cfg.vapp_prefix
115
- vapp_prefix = 'Vagrant' if vapp_prefix.nil?
246
+ if cfg.vapp_name
247
+ vapp_name = cfg.vapp_name
248
+ else
249
+ vapp_prefix = cfg.vapp_prefix
250
+ vapp_prefix = 'Vagrant' if vapp_prefix.nil?
251
+ vapp_name = "#{vapp_prefix}-#{Etc.getlogin}-#{Socket.gethostname.downcase}-" +
252
+ "#{SecureRandom.hex(4)}"
253
+ end
116
254
 
117
255
  compose = cnx.compose_vapp_from_vm(
118
256
  cfg.vdc_id,
119
- "#{vapp_prefix}-#{Etc.getlogin}-#{Socket.gethostname.downcase}-" +
120
- "#{SecureRandom.hex(4)}",
257
+ vapp_name,
121
258
  "vApp created by #{Etc.getlogin} running on " +
122
259
  "#{Socket.gethostname.downcase} using vagrant-vcloud on " +
123
260
  "#{Time.now.strftime("%B %d, %Y")}",
124
261
  {
125
262
  vm_name => cfg.catalog_item[:vms_hash].first.last[:id]
126
263
  },
127
- network_options
264
+ network_options,
265
+ cfg
128
266
  )
129
267
  @logger.debug('Launch Compose vApp...')
130
268
  # Wait for the task to finish.
@@ -146,27 +284,12 @@ module VagrantPlugins
146
284
  # FIXME: Add a lot of error handling for each step here !
147
285
  if new_vapp
148
286
  env[:ui].success("vApp #{new_vapp[:name]} successfully created.")
149
-
150
- # Add the vm id as machine.id
151
- new_vm_properties = new_vapp[:vms_hash].fetch(vm_name)
152
- env[:machine].id = new_vm_properties[:id]
153
-
154
- ### SET GUEST CONFIG
155
- @logger.info(
156
- "Setting Guest Customization on ID: [#{vm_name}] " +
157
- "of vApp [#{new_vapp[:name]}]"
158
- )
159
-
160
- set_custom = cnx.set_vm_guest_customization(
161
- new_vm_properties[:id],
162
- vm_name,
163
- {
164
- :enabled => true,
165
- :admin_passwd_enabled => false
166
- }
167
- )
168
- cnx.wait_task_completion(set_custom)
169
-
287
+ # add vapp metadata
288
+ if !cfg.metadata_vapp.nil?
289
+ env[:ui].info('Setting vApp metadata...')
290
+ set_metadata_vapp = cnx.set_vapp_metadata vapp_id, cfg.metadata_vapp
291
+ cnx.wait_task_completion(set_metadata_vapp)
292
+ end
170
293
  else
171
294
  env[:ui].error("vApp #{new_vapp[:name]} creation failed!")
172
295
  raise # FIXME: error handling missing.
@@ -180,7 +303,8 @@ module VagrantPlugins
180
303
  {
181
304
  vm_name => cfg.catalog_item[:vms_hash].first.last[:id]
182
305
  },
183
- network_options
306
+ network_options,
307
+ cfg
184
308
  )
185
309
 
186
310
  @logger.info('Waiting for the recompose task to complete ...')
@@ -190,31 +314,14 @@ module VagrantPlugins
190
314
 
191
315
  new_vapp = cnx.get_vapp(env[:machine].get_vapp_id)
192
316
  # FIXME: Add a lot of error handling for each step here !
193
- if new_vapp
194
- new_vm_properties = new_vapp[:vms_hash].fetch(vm_name)
195
- env[:machine].id = new_vm_properties[:id]
196
-
197
- ### SET GUEST CONFIG
198
- @logger.info(
199
- 'Setting Guest Customization on ID: ' +
200
- "[#{new_vm_properties[:id]}] of vApp [#{new_vapp[:name]}]"
201
- )
202
-
203
- set_custom = cnx.set_vm_guest_customization(
204
- new_vm_properties[:id],
205
- vm_name,
206
- {
207
- :enabled => true,
208
- :admin_passwd_enabled => false
209
- }
210
- )
211
- cnx.wait_task_completion(set_custom)
212
-
213
- else
317
+ if !new_vapp
214
318
  env[:ui].error("VM #{vm_name} add to #{new_vapp[:name]} failed!")
215
319
  raise
216
320
  end
217
321
  end
322
+ # Add the vm id as machine.id
323
+ new_vm_properties = new_vapp[:vms_hash].fetch(vm_name)
324
+ env[:machine].id = new_vm_properties[:id]
218
325
 
219
326
  @app.call env
220
327
  end