kitchen-vcenter 1.2.1 → 1.3.1
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 +5 -5
- data/CHANGELOG.md +18 -2
- data/LICENSE +201 -0
- data/README.md +52 -14
- data/lib/base.rb +2 -2
- data/lib/kitchen-vcenter/version.rb +3 -1
- data/lib/kitchen/driver/vcenter.rb +76 -37
- data/lib/lookup_service_helper.rb +345 -344
- data/lib/sso.rb +211 -212
- data/lib/support/clone_vm.rb +8 -5
- metadata +17 -44
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 708b1e6365ef0e46165bcc9e769fed085b00443bcdc7bec5be10408fcf71bf1c
|
|
4
|
+
data.tar.gz: c946b45441efa5b7fa06b6f98275923e1222fcdf506091bbce72c917d5003fd1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8740db6063447e8c72d0fba7df35ce022143136938bb26de5de1f7ed1e6c7521cd94615ea44970358e7345b502a76a029c499521426c0917b228f119fc06c49b
|
|
7
|
+
data.tar.gz: 3919686c7c95821aa077fbf519a0ab31c36920a2e4392c9f2689b115e553c008bbb03295ca0593a173fe5438da481a043fc2d0fbd8184858c77ff12294680549
|
data/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[
|
|
3
|
+
<!-- latest_release 1.3.1 -->
|
|
4
|
+
## [v1.3.1](https://github.com/chef/kitchen-vcenter/tree/v1.3.1) (2018-11-19)
|
|
5
|
+
|
|
6
|
+
#### Merged Pull Requests
|
|
7
|
+
- Chefstyle fixes [#37](https://github.com/chef/kitchen-vcenter/pull/37) ([tas50](https://github.com/tas50))
|
|
8
|
+
<!-- latest_release -->
|
|
9
|
+
<!-- release_rollup since=1.2.1 -->
|
|
10
|
+
### Changes since 1.2.1 release
|
|
11
|
+
|
|
12
|
+
#### Merged Pull Requests
|
|
13
|
+
- Chefstyle fixes [#37](https://github.com/chef/kitchen-vcenter/pull/37) ([tas50](https://github.com/tas50)) <!-- 1.3.1 -->
|
|
14
|
+
- Implement support for linked clones (feature #18) [#32](https://github.com/chef/kitchen-vcenter/pull/32) ([tecracer-theinen](https://github.com/tecracer-theinen)) <!-- 1.3.0 -->
|
|
15
|
+
- 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)) <!-- 1.2.2 -->
|
|
16
|
+
<!-- release_rollup -->
|
|
17
|
+
<!-- latest_stable_release -->
|
|
18
|
+
## [1.2.0](https://github.com/chef/kitchen-vcenter/tree/1.2.1) (2017-09-14)
|
|
19
|
+
[Full Changelog](https://github.com/chef/kitchen-vcenter/compare/v1.2.0...1.2.1)
|
|
5
20
|
|
|
6
21
|
**Closed issues:**
|
|
7
22
|
|
|
@@ -10,6 +25,7 @@
|
|
|
10
25
|
**Merged pull requests:**
|
|
11
26
|
|
|
12
27
|
- Update dependency reqs. Update README for dep install. [\#12](https://github.com/chef/kitchen-vcenter/pull/12) ([akulbe](https://github.com/akulbe))
|
|
28
|
+
<!-- latest_stable_release -->
|
|
13
29
|
|
|
14
30
|
## [v1.2.0](https://github.com/chef/kitchen-vcenter/tree/v1.2.0) (2017-09-12)
|
|
15
31
|
[Full Changelog](https://github.com/chef/kitchen-vcenter/compare/v1.1.0...v1.2.0)
|
data/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
data/README.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://rubygems.org/gems/kitchen-vcenter)
|
|
4
4
|
[](https://travis-ci.org/chef/kitchen-vcenter)
|
|
5
|
-
[](https://gemnasium.com/chef/kitchen-vcenter)
|
|
6
5
|
[](http://inch-ci.org/github/chef/kitchen-vcenter)
|
|
7
6
|
|
|
8
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
9
|
- Documentation: [https://github.com/chef/kitchen-vcenter/blob/master/README.md](https://github.com/chef/kitchen-vcenter/blob/master/README.md)
|
|
10
10
|
- Source: [https://github.com/chef/kitchen-vcenter/tree/master](https://github.com/chef/kitchen-vcenter/tree/master)
|
|
11
11
|
- Issues: [https://github.com/chef/kitchen-vcenter/issues](https://github.com/chef/knife-vcenter/issues)
|
|
@@ -23,12 +23,12 @@ Please refer to the [CHANGELOG](CHANGELOG.md) for version history and known issu
|
|
|
23
23
|
|
|
24
24
|
## Installation
|
|
25
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
|
|
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
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
|
|
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
32
|
|
|
33
33
|
Using [ChefDK](https://downloads.chef.io/chef-dk/), simply install the Gem:
|
|
34
34
|
|
|
@@ -48,23 +48,58 @@ gem 'kitchen-vcenter'
|
|
|
48
48
|
A sample `.kitchen.yml` file, details are below.
|
|
49
49
|
|
|
50
50
|
```yml
|
|
51
|
+
---
|
|
51
52
|
driver:
|
|
52
53
|
name: vcenter
|
|
53
|
-
vcenter_username:
|
|
54
|
-
vcenter_password: <%= ENV['VCENTER_PASSWORD']
|
|
55
|
-
vcenter_host:
|
|
54
|
+
vcenter_username: 'administrator@vsphere.local'
|
|
55
|
+
vcenter_password: <%= ENV['VCENTER_PASSWORD'] %>
|
|
56
|
+
vcenter_host: <%= ENV['VCENTER_HOST'] %>
|
|
56
57
|
vcenter_disable_ssl_verify: true
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
59
70
|
|
|
60
71
|
platforms:
|
|
61
72
|
- name: ubuntu-1604
|
|
62
73
|
driver_config:
|
|
74
|
+
targethost: 10.0.0.42
|
|
63
75
|
template: ubuntu16-template
|
|
76
|
+
datacenter: "Datacenter"
|
|
77
|
+
transport:
|
|
78
|
+
username: "admini"
|
|
79
|
+
password: admini
|
|
80
|
+
|
|
64
81
|
- name: centos-7
|
|
65
82
|
driver_config:
|
|
83
|
+
targethost: 10.0.0.42
|
|
66
84
|
template: centos7-template
|
|
85
|
+
datacenter: "Datacenter"
|
|
86
|
+
transport:
|
|
87
|
+
username: "root"
|
|
88
|
+
password: admini
|
|
67
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]
|
|
68
103
|
```
|
|
69
104
|
|
|
70
105
|
### Required parameters:
|
|
@@ -78,7 +113,7 @@ The following parameters should be set in the main `driver_config` section as th
|
|
|
78
113
|
|
|
79
114
|
The following parameters should be set in the `driver_config` for the individual platform.
|
|
80
115
|
|
|
81
|
-
- `template` - Template or virtual machine to use when cloning the new machine
|
|
116
|
+
- `template` - Template or virtual machine to use when cloning the new machine (needs to be a VM for linked clones)
|
|
82
117
|
- `datacenter` - Name of the datacenter to use to deploy into
|
|
83
118
|
|
|
84
119
|
### Optional Parameters
|
|
@@ -87,7 +122,8 @@ The following optional parameters should be used in the `driver_config` for the
|
|
|
87
122
|
|
|
88
123
|
- `targethost` - Host on which the new virtual machine should be created. If not specified then the first host in the cluster is used.
|
|
89
124
|
- `folder` - Folder into which the new machine should be stored. If specified the folder _must_ already exist.
|
|
90
|
-
- `resource_pool` - Name of the resource pool to use when creating the machine.
|
|
125
|
+
- `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
|
|
126
|
+
- `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
|
|
91
127
|
|
|
92
128
|
## Contributing
|
|
93
129
|
|
|
@@ -115,7 +151,7 @@ Author:: Russell Seymour ([rseymour@chef.io](mailto:rseymour@chef.io))
|
|
|
115
151
|
|
|
116
152
|
Author:: JJ Asghar ([jj@chef.io](mailto:jj@chef.io))
|
|
117
153
|
|
|
118
|
-
Copyright:: Copyright (c) 2017 Chef Software, Inc.
|
|
154
|
+
Copyright:: Copyright (c) 2017-2018 Chef Software, Inc.
|
|
119
155
|
|
|
120
156
|
License:: Apache License, Version 2.0
|
|
121
157
|
|
|
@@ -132,3 +168,5 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
132
168
|
See the License for the specific language governing permissions and
|
|
133
169
|
limitations under the License.
|
|
134
170
|
```
|
|
171
|
+
|
|
172
|
+
[issues]: https://github.com/chef/kitchen-vcenter/issues
|
data/lib/base.rb
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
# limitations under the License.
|
|
18
18
|
#
|
|
19
19
|
|
|
20
|
-
require
|
|
20
|
+
require "logger"
|
|
21
21
|
|
|
22
22
|
module Base
|
|
23
23
|
attr_accessor :log
|
|
@@ -28,7 +28,7 @@ module Base
|
|
|
28
28
|
|
|
29
29
|
def self.init_logger
|
|
30
30
|
log = Logger.new(STDOUT)
|
|
31
|
-
log.progname =
|
|
31
|
+
log.progname = "Knife VCenter"
|
|
32
32
|
log.level = Logger::INFO
|
|
33
33
|
log
|
|
34
34
|
end
|
|
@@ -17,23 +17,23 @@
|
|
|
17
17
|
# limitations under the License.
|
|
18
18
|
#
|
|
19
19
|
|
|
20
|
-
require
|
|
21
|
-
require
|
|
22
|
-
require
|
|
23
|
-
require
|
|
24
|
-
require
|
|
25
|
-
require
|
|
26
|
-
require
|
|
27
|
-
require
|
|
28
|
-
require
|
|
29
|
-
require
|
|
30
|
-
require
|
|
31
|
-
|
|
20
|
+
require "kitchen"
|
|
21
|
+
require "rbvmomi"
|
|
22
|
+
require "sso"
|
|
23
|
+
require "base"
|
|
24
|
+
require "lookup_service_helper"
|
|
25
|
+
require "vapi"
|
|
26
|
+
require "com/vmware/cis"
|
|
27
|
+
require "com/vmware/vcenter"
|
|
28
|
+
require "com/vmware/vcenter/vm"
|
|
29
|
+
require "support/clone_vm"
|
|
30
|
+
require "securerandom"
|
|
31
|
+
|
|
32
|
+
# The main kitchen module
|
|
32
33
|
module Kitchen
|
|
34
|
+
# The main driver module for kitchen-vcenter
|
|
33
35
|
module Driver
|
|
34
|
-
#
|
|
35
|
-
# Vcenter
|
|
36
|
-
#
|
|
36
|
+
# Extends the Base class for vCenter
|
|
37
37
|
class Vcenter < Kitchen::Driver::Base
|
|
38
38
|
attr_accessor :connection_options, :ipaddress, :vapi_config, :session_svc, :session_id
|
|
39
39
|
|
|
@@ -48,15 +48,17 @@ module Kitchen
|
|
|
48
48
|
default_config :poweron, true
|
|
49
49
|
default_config :vm_name, nil
|
|
50
50
|
default_config :resource_pool, nil
|
|
51
|
+
default_config :clone_type, :full
|
|
51
52
|
|
|
53
|
+
# The main create method
|
|
54
|
+
#
|
|
55
|
+
# @param [Object] state is the state of the vm
|
|
52
56
|
def create(state)
|
|
53
57
|
# If the vm_name has not been set then set it now based on the suite, platform and a random number
|
|
54
58
|
if config[:vm_name].nil?
|
|
55
|
-
config[:vm_name] = format(
|
|
59
|
+
config[:vm_name] = format("%s-%s-%s", instance.suite.name, instance.platform.name, SecureRandom.hex(4))
|
|
56
60
|
end
|
|
57
61
|
|
|
58
|
-
# raise "Please set the resource pool name using `resource_pool` parameter in the 'drive_config' section of your .kitchen.yml file" if config[:resource_pool].nil?
|
|
59
|
-
|
|
60
62
|
connect
|
|
61
63
|
|
|
62
64
|
# Using the clone class, create a machine for TK
|
|
@@ -70,10 +72,15 @@ module Kitchen
|
|
|
70
72
|
datacenter_exists?(config[:datacenter])
|
|
71
73
|
|
|
72
74
|
# Same thing needs to happen with the folder name if it has been set
|
|
73
|
-
config[:folder]
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
unless config[:folder].nil?
|
|
76
|
+
config[:folder] = {
|
|
77
|
+
name: config[:folder],
|
|
78
|
+
id: get_folder(config[:folder]),
|
|
79
|
+
}
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Allow different clone types
|
|
83
|
+
config[:clone_type] = :linked if config[:clone_type] == "linked"
|
|
77
84
|
|
|
78
85
|
# Create a hash of options that the clone requires
|
|
79
86
|
options = {
|
|
@@ -84,23 +91,28 @@ module Kitchen
|
|
|
84
91
|
datacenter: config[:datacenter],
|
|
85
92
|
folder: config[:folder],
|
|
86
93
|
resource_pool: config[:resource_pool],
|
|
94
|
+
clone_type: config[:clone_type],
|
|
87
95
|
}
|
|
88
96
|
|
|
89
97
|
# Create an object from which the clone operation can be called
|
|
90
98
|
clone_obj = Support::CloneVm.new(connection_options, options)
|
|
91
|
-
state[:hostname] = clone_obj.clone
|
|
99
|
+
state[:hostname] = clone_obj.clone
|
|
92
100
|
state[:vm_name] = config[:vm_name]
|
|
93
101
|
end
|
|
94
102
|
|
|
103
|
+
# The main destroy method
|
|
104
|
+
#
|
|
105
|
+
# @param [Object] state is the state of the vm
|
|
95
106
|
def destroy(state)
|
|
96
107
|
return if state[:vm_name].nil?
|
|
108
|
+
|
|
97
109
|
connect
|
|
98
110
|
vm = get_vm(state[:vm_name])
|
|
99
111
|
|
|
100
112
|
vm_obj = Com::Vmware::Vcenter::VM.new(vapi_config)
|
|
101
113
|
|
|
102
114
|
# shut the machine down if it is running
|
|
103
|
-
if vm.power_state.value ==
|
|
115
|
+
if vm.power_state.value == "POWERED_ON"
|
|
104
116
|
power = Com::Vmware::Vcenter::Vm::Power.new(vapi_config)
|
|
105
117
|
power.stop(vm.vm)
|
|
106
118
|
end
|
|
@@ -111,21 +123,29 @@ module Kitchen
|
|
|
111
123
|
|
|
112
124
|
private
|
|
113
125
|
|
|
114
|
-
|
|
115
|
-
|
|
126
|
+
# A helper method to validate the state
|
|
127
|
+
#
|
|
128
|
+
# @param [Object] state is the state of the vm
|
|
129
|
+
def validate_state(state = {}); end
|
|
116
130
|
|
|
117
131
|
def existing_state_value?(state, property)
|
|
118
132
|
state.key?(property) && !state[property].nil?
|
|
119
133
|
end
|
|
120
134
|
|
|
135
|
+
# Sees in the datacenter exists or not
|
|
136
|
+
#
|
|
137
|
+
# @param [name] name is the name of the datacenter
|
|
121
138
|
def datacenter_exists?(name)
|
|
122
139
|
filter = Com::Vmware::Vcenter::Datacenter::FilterSpec.new(names: Set.new([name]))
|
|
123
140
|
dc_obj = Com::Vmware::Vcenter::Datacenter.new(vapi_config)
|
|
124
141
|
dc = dc_obj.list(filter)
|
|
125
142
|
|
|
126
|
-
raise format(
|
|
143
|
+
raise format("Unable to find data center: %s", name) if dc.empty?
|
|
127
144
|
end
|
|
128
145
|
|
|
146
|
+
# Validates the host name of the server you can connect to
|
|
147
|
+
#
|
|
148
|
+
# @param [name] name is the name of the host
|
|
129
149
|
def get_host(name)
|
|
130
150
|
# create a host object to work with
|
|
131
151
|
host_obj = Com::Vmware::Vcenter::Host.new(vapi_config)
|
|
@@ -137,51 +157,70 @@ module Kitchen
|
|
|
137
157
|
host = host_obj.list(filter)
|
|
138
158
|
end
|
|
139
159
|
|
|
140
|
-
raise format(
|
|
160
|
+
raise format("Unable to find target host: %s", name) if host.empty?
|
|
141
161
|
|
|
142
162
|
host[0].host
|
|
143
163
|
end
|
|
144
164
|
|
|
165
|
+
# Gets the folder you want to create the VM
|
|
166
|
+
#
|
|
167
|
+
# @param [name] name is the name of the folder
|
|
145
168
|
def get_folder(name)
|
|
146
169
|
# Create a filter to ensure that only the named folder is returned
|
|
147
170
|
filter = Com::Vmware::Vcenter::Folder::FilterSpec.new(names: Set.new([name]))
|
|
148
171
|
folder_obj = Com::Vmware::Vcenter::Folder.new(vapi_config)
|
|
149
172
|
folder = folder_obj.list(filter)
|
|
150
173
|
|
|
151
|
-
raise format(
|
|
174
|
+
raise format("Unable to find folder: %s", name) if folder.empty?
|
|
152
175
|
|
|
153
176
|
folder[0].folder
|
|
154
177
|
end
|
|
155
178
|
|
|
179
|
+
# Gets the name of the VM you are creating
|
|
180
|
+
#
|
|
181
|
+
# @param [name] name is the name of the VM
|
|
156
182
|
def get_vm(name)
|
|
157
183
|
filter = Com::Vmware::Vcenter::VM::FilterSpec.new(names: Set.new([name]))
|
|
158
184
|
vm_obj = Com::Vmware::Vcenter::VM.new(vapi_config)
|
|
159
185
|
vm_obj.list(filter)[0]
|
|
160
186
|
end
|
|
161
187
|
|
|
188
|
+
# Gets the name of the resource pool
|
|
189
|
+
#
|
|
190
|
+
# @todo Will not yet work with nested pools ("Pool1/Subpool1")
|
|
191
|
+
# @param [name] name is the name of the ResourcePool
|
|
162
192
|
def get_resource_pool(name)
|
|
163
193
|
# Create a resource pool object
|
|
164
194
|
rp_obj = Com::Vmware::Vcenter::ResourcePool.new(vapi_config)
|
|
165
195
|
|
|
166
|
-
# If
|
|
167
|
-
#
|
|
196
|
+
# If no name has been set, use the first resource pool that can be found,
|
|
197
|
+
# otherwise try to find by given name
|
|
168
198
|
if name.nil?
|
|
169
|
-
|
|
199
|
+
# Remove default pool for first pass (<= 1.2.1 behaviour to pick first user-defined pool found)
|
|
200
|
+
resource_pool = rp_obj.list.delete_if { |pool| pool.name == "Resources" }
|
|
201
|
+
debug("Search of all resource pools found: " + resource_pool.map { |pool| pool.name }.to_s)
|
|
202
|
+
|
|
203
|
+
# Revert to default pool, if no user-defined pool found (> 1.2.1 behaviour)
|
|
204
|
+
# (This one might not be found under some circumstances by the statement above)
|
|
205
|
+
resource_pool = get_resource_pool("Resources") if resource_pool.empty?
|
|
170
206
|
else
|
|
171
207
|
# create a filter to find the named resource pool
|
|
172
208
|
filter = Com::Vmware::Vcenter::ResourcePool::FilterSpec.new(names: Set.new([name]))
|
|
173
209
|
resource_pool = rp_obj.list(filter)
|
|
210
|
+
debug("Search for resource pools found: " + resource_pool.map { |pool| pool.name }.to_s)
|
|
174
211
|
end
|
|
175
212
|
|
|
176
|
-
raise format(
|
|
213
|
+
raise format("Unable to find Resource Pool: %s", name) if resource_pool.empty?
|
|
177
214
|
|
|
178
215
|
resource_pool[0].resource_pool
|
|
179
216
|
end
|
|
180
217
|
|
|
218
|
+
# The main connect method
|
|
219
|
+
#
|
|
181
220
|
def connect
|
|
182
221
|
# Configure the connection to vCenter
|
|
183
222
|
lookup_service_helper = LookupServiceHelper.new(config[:vcenter_host])
|
|
184
|
-
vapi_urls = lookup_service_helper.find_vapi_urls
|
|
223
|
+
vapi_urls = lookup_service_helper.find_vapi_urls
|
|
185
224
|
vapi_url = vapi_urls.values[0]
|
|
186
225
|
|
|
187
226
|
# Create the VAPI config object
|
|
@@ -190,16 +229,16 @@ module Kitchen
|
|
|
190
229
|
@vapi_config = VAPI::Bindings::VapiConfig.new(vapi_url, ssl_options)
|
|
191
230
|
|
|
192
231
|
# get the SSO url
|
|
193
|
-
sso_url = lookup_service_helper.find_sso_url
|
|
232
|
+
sso_url = lookup_service_helper.find_sso_url
|
|
194
233
|
sso = SSO::Connection.new(sso_url).login(config[:vcenter_username], config[:vcenter_password])
|
|
195
|
-
token = sso.request_bearer_token
|
|
234
|
+
token = sso.request_bearer_token
|
|
196
235
|
vapi_config.set_security_context(
|
|
197
236
|
VAPI::Security.create_saml_bearer_security_context(token.to_s)
|
|
198
237
|
)
|
|
199
238
|
|
|
200
239
|
# Login and get the session information
|
|
201
240
|
@session_svc = Com::Vmware::Cis::Session.new(vapi_config)
|
|
202
|
-
@session_id = session_svc.create
|
|
241
|
+
@session_id = session_svc.create
|
|
203
242
|
vapi_config.set_security_context(
|
|
204
243
|
VAPI::Security.create_session_security_context(session_id)
|
|
205
244
|
)
|