kitchen-vcenter 1.3.4 → 1.4.2

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
  SHA256:
3
- metadata.gz: 9e72f7421bcae71612b39ca42859c0ba3ad8ad8809f29e0e9720e5c8f4ebd668
4
- data.tar.gz: '062093f1b32dfff9571cfd4aad8e3072de37fc3485f93ff0908f5d34e60ffa23'
3
+ metadata.gz: 7f49e8fc98358fba0a3d791d90cd7114dca3ebea36114c78243bd8290198660c
4
+ data.tar.gz: d495c5cac6372f7afa189c27d6e7079c2bfc69b73bf5ff4ec82d6f4d02fdf4b8
5
5
  SHA512:
6
- metadata.gz: 7dd6a013bb356d39b9c59d2eaea3c93f3bc6a9629958fbde48807ab40ea249ef518f05c98580f27d080c73f24da503b5952439fc03368bcae7536eb1772278ee
7
- data.tar.gz: 15f635777a44a3e1d6e70af030589300ebb5a8d86e7b74d27d6141c2fdef433d6d32b8b5cf8c467e9ace37e5abde8620034d461ab725ca59378bf0e8e453c6fc
6
+ metadata.gz: 79182163a7adc1acf518959674e4c07833ba83e5e7de7ce46805887c68b998d9987a087c0e0897b14c0d6042df66620445091d742569e56de122fde30c770a23
7
+ data.tar.gz: bdd5b03a192e3e71ff84017ffcd7ffa2314e4eef3bd82042c8822f18688061aba854951f0ab524ab5468756e2e87a63f9eed0996f5ac8aee5e3c4d3ae7e343b0
@@ -20,5 +20,5 @@
20
20
  # The main kitchen-vcenter module
21
21
  module KitchenVcenter
22
22
  # The version of this version of test-kitchen we assume enterprises want.
23
- VERSION = "1.3.4"
23
+ VERSION = "1.4.2"
24
24
  end
@@ -51,6 +51,7 @@ module Kitchen
51
51
  default_config :vm_name, nil
52
52
  default_config :resource_pool, nil
53
53
  default_config :clone_type, :full
54
+ default_config :cluster, nil
54
55
  default_config :lookup_service_host, nil
55
56
 
56
57
  # The main create method
@@ -63,6 +64,7 @@ module Kitchen
63
64
  password: config[:vcenter_password],
64
65
  insecure: config[:vcenter_disable_ssl_verify] ? true : false,
65
66
  host: config[:vcenter_host],
67
+ rev: config[:clone_type] == "instant" ? "6.7" : nil,
66
68
  }
67
69
 
68
70
  # If the vm_name has not been set then set it now based on the suite, platform and a random number
@@ -70,14 +72,24 @@ module Kitchen
70
72
  config[:vm_name] = format("%s-%s-%s", instance.suite.name, instance.platform.name, SecureRandom.hex(4))
71
73
  end
72
74
 
75
+ raise format("Cannot specify both cluster and resource_pool") if !config[:cluster].nil? && !config[:resource_pool].nil?
76
+
73
77
  connect
74
78
 
75
79
  # Using the clone class, create a machine for TK
76
80
  # Find the identifier for the targethost to pass to rbvmomi
77
81
  config[:targethost] = get_host(config[:targethost])
78
82
 
79
- # Find the resource pool
80
- config[:resource_pool] = get_resource_pool(config[:resource_pool])
83
+ # Use the root resource pool of a specified cluster, if any
84
+ # @todo This does not allow to specify cluster AND pool yet
85
+ unless config[:cluster].nil?
86
+ cluster = get_cluster(config[:cluster])
87
+ # @todo Check for active hosts, to avoid "A specified parameter was not correct: spec.pool"
88
+ config[:resource_pool] = cluster.resource_pool
89
+ else
90
+ # Find the first resource pool on any cluster
91
+ config[:resource_pool] = get_resource_pool(config[:resource_pool])
92
+ end
81
93
 
82
94
  # Check that the datacenter exists
83
95
  datacenter_exists?(config[:datacenter])
@@ -92,6 +104,7 @@ module Kitchen
92
104
 
93
105
  # Allow different clone types
94
106
  config[:clone_type] = :linked if config[:clone_type] == "linked"
107
+ config[:clone_type] = :instant if config[:clone_type] == "instant"
95
108
 
96
109
  # Create a hash of options that the clone requires
97
110
  options = {
@@ -170,7 +183,7 @@ module Kitchen
170
183
 
171
184
  raise format("Unable to find target host: %s", name) if host.empty?
172
185
 
173
- host[0].host
186
+ host[0]
174
187
  end
175
188
 
176
189
  # Gets the folder you want to create the VM
@@ -196,6 +209,21 @@ module Kitchen
196
209
  vm_obj.list(filter)[0]
197
210
  end
198
211
 
212
+ # Gets the info of the cluster
213
+ #
214
+ # @param [name] name is the name of the Cluster
215
+ def get_cluster(name)
216
+ cl_obj = Com::Vmware::Vcenter::Cluster.new(vapi_config)
217
+
218
+ # @todo: Use Cluster::FilterSpec to only get the cluster which was asked
219
+ # filter = Com::Vmware::Vcenter::Cluster::FilterSpec.new(clusters: Set.new(['...']))
220
+ clusters = cl_obj.list.select { |cluster| cluster.name == name }
221
+ raise format("Unable to find Cluster: %s", name) if clusters.empty?
222
+
223
+ cluster_id = clusters[0].cluster
224
+ cl_obj.get(cluster_id)
225
+ end
226
+
199
227
  # Gets the name of the resource pool
200
228
  #
201
229
  # @todo Will not yet work with nested pools ("Pool1/Subpool1")
@@ -213,7 +241,7 @@ module Kitchen
213
241
 
214
242
  # Revert to default pool, if no user-defined pool found (> 1.2.1 behaviour)
215
243
  # (This one might not be found under some circumstances by the statement above)
216
- resource_pool = get_resource_pool("Resources") if resource_pool.empty?
244
+ return get_resource_pool("Resources") if resource_pool.empty?
217
245
  else
218
246
  # create a filter to find the named resource pool
219
247
  filter = Com::Vmware::Vcenter::ResourcePool::FilterSpec.new(names: Set.new([name]))
@@ -20,7 +20,9 @@ class Support
20
20
 
21
21
  # Specify where the machine is going to be created
22
22
  relocate_spec = RbVmomi::VIM.VirtualMachineRelocateSpec
23
- relocate_spec.host = options[:targethost]
23
+
24
+ # Setting the host is not allowed for instant clone due to VM memory sharing
25
+ relocate_spec.host = options[:targethost].host unless options[:clone_type] == :instant
24
26
 
25
27
  # Change to delta disks for linked clones
26
28
  relocate_spec.diskMoveType = :moveChildMostDiskBacking if options[:clone_type] == :linked
@@ -28,15 +30,46 @@ class Support
28
30
  # Set the resource pool
29
31
  relocate_spec.pool = options[:resource_pool]
30
32
 
31
- clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(location: relocate_spec,
32
- powerOn: options[:poweron],
33
- template: false)
34
-
35
33
  # Set the folder to use
36
34
  dest_folder = options[:folder].nil? ? src_vm.parent : options[:folder][:id]
37
35
 
38
- puts "Cloning the template '#{options[:template]}' to create the VM..."
39
- task = src_vm.CloneVM_Task(folder: dest_folder, name: options[:name], spec: clone_spec)
36
+ puts "Cloning '#{options[:template]}' to create the VM..."
37
+ if options[:clone_type] == :instant
38
+ vcenter_data = vim.serviceInstance.content.about
39
+ raise "Instant clones only supported with vCenter 6.7 or higher" unless vcenter_data.version.to_f >= 6.7
40
+ puts "- Detected #{vcenter_data.fullName}"
41
+
42
+ resources = dc.hostFolder.children
43
+ hosts = resources.select { |resource| resource.class.to_s == "ComputeResource" }.map { |c| c.host }.flatten
44
+ targethost = hosts.select { |host| host.summary.config.name == options[:targethost].name }.first
45
+ esx_data = targethost.summary.config.product
46
+ raise "Instant clones only supported with ESX 6.7 or higher" unless esx_data.version.to_f >= 6.7
47
+ puts "- Detected #{esx_data.fullName}"
48
+
49
+ # Other tools check for VMWare Tools status, but that will be toolsNotRunning on frozen VMs
50
+ raise "Need a running VM for instant clones" unless src_vm.runtime.powerState == "poweredOn"
51
+
52
+ # In first iterations, only support the Frozen Source VM workflow. This is more efficient
53
+ # but needs preparations (freezing the source VM). Running Source VM support is to be
54
+ # added later
55
+ raise "Need a frozen VM for instant clones, running source VM not supported yet" unless src_vm.runtime.instantCloneFrozen
56
+
57
+ # Swapping NICs not needed anymore (blog posts mention this), instant clones get a new
58
+ # MAC at least with 6.7.0 build 9433931
59
+
60
+ # @todo not working yet
61
+ # relocate_spec.folder = dest_folder
62
+ clone_spec = RbVmomi::VIM.VirtualMachineInstantCloneSpec(location: relocate_spec,
63
+ name: options[:name])
64
+
65
+ task = src_vm.InstantClone_Task(spec: clone_spec)
66
+ else
67
+ clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(location: relocate_spec,
68
+ powerOn: options[:poweron],
69
+ template: false)
70
+
71
+ task = src_vm.CloneVM_Task(spec: clone_spec, folder: dest_folder, name: options[:name])
72
+ end
40
73
  task.wait_for_completion
41
74
 
42
75
  # get the IP address of the machine for bootstrapping
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-vcenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Russell Seymour
@@ -101,9 +101,7 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
- - CHANGELOG.md
105
104
  - LICENSE
106
- - README.md
107
105
  - lib/base.rb
108
106
  - lib/kitchen-vcenter/version.rb
109
107
  - lib/kitchen/driver/vcenter.rb
@@ -122,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
120
  requirements:
123
121
  - - ">="
124
122
  - !ruby/object:Gem::Version
125
- version: '0'
123
+ version: '2.3'
126
124
  required_rubygems_version: !ruby/object:Gem::Requirement
127
125
  requirements:
128
126
  - - ">="
data/CHANGELOG.md DELETED
@@ -1,66 +0,0 @@
1
- # Change Log
2
-
3
- <!-- latest_release 1.3.4 -->
4
- ## [v1.3.4](https://github.com/chef/kitchen-vcenter/tree/v1.3.4) (2019-01-04)
5
-
6
- #### Merged Pull Requests
7
- - Fix for Issues #26 and #30 [#44](https://github.com/chef/kitchen-vcenter/pull/44) ([tecracer-theinen](https://github.com/tecracer-theinen))
8
- <!-- latest_release -->
9
- <!-- release_rollup since=1.3.1 -->
10
- ### Changes not yet released to rubygems.org
11
-
12
- #### Merged Pull Requests
13
- - Fix for Issues #26 and #30 [#44](https://github.com/chef/kitchen-vcenter/pull/44) ([tecracer-theinen](https://github.com/tecracer-theinen)) <!-- 1.3.4 -->
14
- - Feature/check parameters [#40](https://github.com/chef/kitchen-vcenter/pull/40) ([tecracer-theinen](https://github.com/tecracer-theinen)) <!-- 1.3.3 -->
15
- - README edits [#38](https://github.com/chef/kitchen-vcenter/pull/38) ([mjingle](https://github.com/mjingle)) <!-- 1.3.2 -->
16
- <!-- release_rollup -->
17
- <!-- latest_stable_release -->
18
- ## [v1.3.1](https://github.com/chef/kitchen-vcenter/tree/v1.3.1) (2018-11-19)
19
-
20
- #### Merged Pull Requests
21
- - Fixed behaviour when not having any resource pools (Issue #28) [#31](https://github.com/chef/kitchen-vcenter/pull/31) ([tecracer-theinen](https://github.com/tecracer-theinen))
22
- - Implement support for linked clones (feature #18) [#32](https://github.com/chef/kitchen-vcenter/pull/32) ([tecracer-theinen](https://github.com/tecracer-theinen))
23
- - Chefstyle fixes [#37](https://github.com/chef/kitchen-vcenter/pull/37) ([tas50](https://github.com/tas50))
24
- <!-- latest_stable_release -->
25
-
26
- ## [1.2.1](https://github.com/chef/kitchen-vcenter/tree/1.2.1) (2017-09-14)
27
- [Full Changelog](https://github.com/chef/kitchen-vcenter/compare/v1.2.0...1.2.1)
28
-
29
- **Closed issues:**
30
-
31
- - Install attempt errors with message about requiring vsphere-automation-sdk [\#11](https://github.com/chef/kitchen-vcenter/issues/11)
32
-
33
- **Merged pull requests:**
34
-
35
- - Update dependency reqs. Update README for dep install. [\#12](https://github.com/chef/kitchen-vcenter/pull/12) ([akulbe](https://github.com/akulbe))
36
-
37
- ## [v1.2.0](https://github.com/chef/kitchen-vcenter/tree/v1.2.0) (2017-09-12)
38
- [Full Changelog](https://github.com/chef/kitchen-vcenter/compare/v1.1.0...v1.2.0)
39
-
40
- **Merged pull requests:**
41
-
42
- - Resource pool and target host no longer have to be specified. [\#10](https://github.com/chef/kitchen-vcenter/pull/10) ([russellseymour](https://github.com/russellseymour))
43
-
44
- ## [v1.1.0](https://github.com/chef/kitchen-vcenter/tree/v1.1.0) (2017-09-07)
45
- [Full Changelog](https://github.com/chef/kitchen-vcenter/compare/v1.0.0...v1.1.0)
46
-
47
- **Closed issues:**
48
-
49
- - Resource pool is not specified when creating a new machine [\#7](https://github.com/chef/kitchen-vcenter/issues/7)
50
- - Unhelpful messages from driver if specified item does not exist [\#6](https://github.com/chef/kitchen-vcenter/issues/6)
51
-
52
- **Merged pull requests:**
53
-
54
- - Updated to handle resource\_pools [\#8](https://github.com/chef/kitchen-vcenter/pull/8) ([russellseymour](https://github.com/russellseymour))
55
-
56
- ## [v1.0.0](https://github.com/chef/kitchen-vcenter/tree/v1.0.0) (2017-08-28)
57
- **Merged pull requests:**
58
-
59
- - 1.0.0 release [\#4](https://github.com/chef/kitchen-vcenter/pull/4) ([jjasghar](https://github.com/jjasghar))
60
- - Second walk through [\#3](https://github.com/chef/kitchen-vcenter/pull/3) ([jjasghar](https://github.com/jjasghar))
61
- - Updated so that the vm\_name is set according to suite and platform. [\#2](https://github.com/chef/kitchen-vcenter/pull/2) ([russellseymour](https://github.com/russellseymour))
62
- - Prep-for-public release [\#1](https://github.com/chef/kitchen-vcenter/pull/1) ([jjasghar](https://github.com/jjasghar))
63
-
64
-
65
-
66
- \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/README.md DELETED
@@ -1,175 +0,0 @@
1
- # kitchen-vcenter
2
-
3
- [![Gem Version](https://badge.fury.io/rb/kitchen-vcenter.svg)](https://rubygems.org/gems/kitchen-vcenter)
4
- [![Build Status](https://travis-ci.org/chef/kitchen-vcenter.svg?branch=master)](https://travis-ci.org/chef/kitchen-vcenter)
5
- [![Inline docs](http://inch-ci.org/github/chef/kitchen-vcenter.svg?branch=master)](http://inch-ci.org/github/chef/kitchen-vcenter)
6
-
7
- This is the official Chef test-kitchen plugin for VMware REST API. This plugin gives kitchen the ability to create, bootstrap, and test VMware vms.
8
-
9
- - Documentation: [https://github.com/chef/kitchen-vcenter/blob/master/README.md](https://github.com/chef/kitchen-vcenter/blob/master/README.md)
10
- - Source: [https://github.com/chef/kitchen-vcenter/tree/master](https://github.com/chef/kitchen-vcenter/tree/master)
11
- - Issues: [https://github.com/chef/kitchen-vcenter/issues](https://github.com/chef/knife-vcenter/issues)
12
- - Slack: sign up: https://code.vmware.com/slack/ slack channel: #chef
13
- - Mailing list: [https://discourse.chef.io/](https://discourse.chef.io/)
14
-
15
- This is a `test-kitchen` plugin that allows interaction with vSphere using the vSphere Automation SDK.
16
-
17
- Please refer to the [CHANGELOG](CHANGELOG.md) for version history and known issues.
18
-
19
- ## Requirements
20
-
21
- - Chef 13.0 higher
22
- - Ruby 2.3.3 or higher
23
-
24
- ## Installation
25
-
26
- This driver has a dependency. It requires the [vSphere Automation SDK](https://github.com/vmware/vsphere-automation-sdk-ruby) be installed. The steps to do that are as follows, for the time being it's not published to Rubygems. If you are interested, please comment [here](https://github.com/vmware/vsphere-automation-sdk-ruby/issues/10).
27
-
28
- - `$ git clone` [https://github.com/vmware/vsphere-automation-sdk-ruby.git](https://github.com/vmware/vsphere-automation-sdk-ruby.git)
29
- - `cd vsphere-automation-sdk-ruby`
30
- - `gem build vsphere-automation-sdk-ruby.gemspec`
31
- - `chef gem install vsphere-automation-sdk-<version>.gem`
32
-
33
- Using [ChefDK](https://downloads.chef.io/chef-dk/), simply install the Gem:
34
-
35
- ```bash
36
- chef gem install kitchen-vcenter
37
- ```
38
-
39
- If you're using bundler, simply add Chef and kitchen-vcenter to your Gemfile:
40
-
41
- ```ruby
42
- gem 'chef'
43
- gem 'kitchen-vcenter'
44
- ```
45
-
46
- ## Usage
47
-
48
- A sample `.kitchen.yml` file, details are below.
49
-
50
- ```yml
51
- ---
52
- driver:
53
- name: vcenter
54
- vcenter_username: 'administrator@vsphere.local'
55
- vcenter_password: <%= ENV['VCENTER_PASSWORD'] %>
56
- vcenter_host: <%= ENV['VCENTER_HOST'] %>
57
- vcenter_disable_ssl_verify: true
58
-
59
- provisioner:
60
- name: chef_zero
61
- sudo_command: sudo
62
- deprecations_as_errors: true
63
- retry_on_exit_code:
64
- - 35 # 35 is the exit code signaling that the node is rebooting
65
- max_retries: 2
66
- wait_for_retry: 90
67
-
68
- verifier:
69
- name: inspec
70
-
71
- platforms:
72
- - name: ubuntu-1604
73
- driver_config:
74
- targethost: 10.0.0.42
75
- template: ubuntu16-template
76
- datacenter: "Datacenter"
77
- transport:
78
- username: "admini"
79
- password: admini
80
-
81
- - name: centos-7
82
- driver_config:
83
- targethost: 10.0.0.42
84
- template: centos7-template
85
- datacenter: "Datacenter"
86
- transport:
87
- username: "root"
88
- password: admini
89
-
90
- - name: windows2012R2
91
- driver_config:
92
- targethost: 10.0.0.42
93
- template: windows2012R2-template
94
- datacenter: "Datacenter"
95
- transport:
96
- username: "Administrator"
97
- password: "p@ssW0rd!"
98
-
99
- suites:
100
- - name: default
101
- run_list:
102
- - recipe[cookbook::default]
103
- ```
104
-
105
- ### Required parameters:
106
-
107
- The following parameters should be set in the main `driver_config` section as they are common to all platforms:
108
-
109
- - `vcenter_username` - Name to use when connecting to the vSphere environment
110
- - `vcenter_password` - Password associated with the specified user
111
- - `vcenter_host` - Host against which logins should be attempted
112
-
113
- The following parameters should be set in the `driver_config` for the individual platform:
114
-
115
- - `datacenter` - Name of the datacenter to use to deploy into
116
- - `template` - Template or virtual machine to use when cloning the new machine (needs to be a VM for linked clones)
117
-
118
- ### Optional Parameters
119
-
120
- The following parameters should be set in the main `driver_config` section as they are common to all platforms:
121
- - `vcenter_disable_ssl_verify` - Whether or not to disable SSL verification checks. Good when using self signed certificates. Default: false
122
-
123
- The following optional parameters should be used in the `driver_config` for the platform.
124
-
125
- - `targethost` - Host on which the new virtual machine should be created. If not specified then the first host in the cluster is used.
126
- - `folder` - Folder into which the new machine should be stored. If specified the folder _must_ already exist.
127
- - `poweron` - Power on the new virtual machine. Default: true
128
- - `vm_name` - Specify name of virtual machine. Default: `<suite>-<platform>-<random-hexid>`
129
- - `resource_pool` - Name of the resource pool to use when creating the machine. Will search first pool by default, can use value 'Resources' for none.
130
- - `clone_type` - Type of clone, will default to "full" to create complete copies of template. Needs a VM as template parameter, if "linked" clone desired.
131
- - `lookup_service_host` - Specify hostname of Lookup Service for setups with external PSC. Default: autodetect
132
-
133
- ## Contributing
134
-
135
- For information on contributing to this project see <https://github.com/chef/chef/blob/master/CONTRIBUTING.md>
136
-
137
- ## Development
138
-
139
- * Report issues/questions/feature requests on [GitHub Issues][issues]
140
-
141
- Pull requests are very welcome! Make sure your patches are well tested. Ideally create a topic branch for every separate change you make. For example:
142
-
143
- 1. Fork the repo
144
- 2. Create your feature branch (`git checkout -b my-new-feature`)
145
- 3. Run the tests and rubocop, `bundle exec rake spec` and `bundle exec rake rubocop`
146
- 4. Commit your changes (`git commit -am 'Added some feature'`)
147
- 5. Push to the branch (`git push origin my-new-feature`)
148
- 6. Create new Pull Request
149
-
150
-
151
- ## License
152
-
153
- Author:: Russell Seymour ([rseymour@chef.io](mailto:rseymour@chef.io))
154
-
155
- Author:: JJ Asghar ([jj@chef.io](mailto:jj@chef.io))
156
-
157
- Copyright:: Copyright (c) 2017-2018 Chef Software, Inc.
158
-
159
- License:: Apache License, Version 2.0
160
-
161
- ```text
162
- Licensed under the Apache License, Version 2.0 (the "License");
163
- you may not use this file except in compliance with the License.
164
- You may obtain a copy of the License at
165
-
166
- http://www.apache.org/licenses/LICENSE-2.0
167
-
168
- Unless required by applicable law or agreed to in writing, software
169
- distributed under the License is distributed on an "AS IS" BASIS,
170
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
171
- See the License for the specific language governing permissions and
172
- limitations under the License.
173
- ```
174
-
175
- [issues]: https://github.com/chef/kitchen-vcenter/issues