kitchen-vcenter 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -1
- data/README.md +2 -0
- data/lib/kitchen-vcenter/version.rb +1 -1
- data/lib/kitchen/driver/vcenter.rb +41 -8
- data/lib/support/clone_vm.rb +6 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ad83365e404c24b62793647a264cc753dcd8c39
|
4
|
+
data.tar.gz: 39add38626871f3a8720cd2bff7c28cdb904d56a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9acb72a51bae96c57eff8b8b7074b132b22b3c07c28c1ad781d20e60a1ee2db173c3df65b420b290db929f54cc4b0e07e04dc5ef75a8a78f3d4ef0ff3c39c13b
|
7
|
+
data.tar.gz: 0c1b2ab4a0426c987047ab6843aa4f852604ecb2c068c4533b4d1c302dbaa509a4fad1875baa6376bfc69d7f9f4f4cf18832c53e225f066178e97b20916ba27d
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [1.
|
3
|
+
## [1.1.0](https://github.com/chef/kitchen-vcenter/tree/1.1.0) (2017-09-07)
|
4
|
+
[Full Changelog](https://github.com/chef/kitchen-vcenter/compare/v1.0.0...1.1.0)
|
5
|
+
|
6
|
+
**Closed issues:**
|
7
|
+
|
8
|
+
- Resource pool is not specified when creating a new machine [\#7](https://github.com/chef/kitchen-vcenter/issues/7)
|
9
|
+
- Unhelpful messages from driver if specified item does not exist [\#6](https://github.com/chef/kitchen-vcenter/issues/6)
|
10
|
+
|
11
|
+
**Merged pull requests:**
|
12
|
+
|
13
|
+
- Updated to handle resource\_pools [\#8](https://github.com/chef/kitchen-vcenter/pull/8) ([russellseymour](https://github.com/russellseymour))
|
14
|
+
|
15
|
+
## [v1.0.0](https://github.com/chef/kitchen-vcenter/tree/v1.0.0) (2017-08-28)
|
4
16
|
**Merged pull requests:**
|
5
17
|
|
6
18
|
- 1.0.0 release [\#4](https://github.com/chef/kitchen-vcenter/pull/4) ([jjasghar](https://github.com/jjasghar))
|
data/README.md
CHANGED
@@ -50,6 +50,7 @@ driver:
|
|
50
50
|
driver_config:
|
51
51
|
targethost: 172.16.20.41
|
52
52
|
datacenter: "Datacenter"
|
53
|
+
resource_pool: "testkitchen"
|
53
54
|
|
54
55
|
platforms:
|
55
56
|
- name: ubuntu-1604
|
@@ -75,6 +76,7 @@ The following parameters should be set in the `driver_config` for the individual
|
|
75
76
|
- `targethost` - Host on which the new virtual machine should be created
|
76
77
|
- `template` - Template or virtual machine to use when cloning the new machine
|
77
78
|
- `datacenter` - Name of the datacenter to use to deploy into
|
79
|
+
- `resource_pool` - Name of the resource pool to use when creating the machine. The resource pool _must_ already exist
|
78
80
|
|
79
81
|
### Optional Parameters
|
80
82
|
|
@@ -47,6 +47,7 @@ module Kitchen
|
|
47
47
|
default_config :vcenter_disable_ssl_verify, false
|
48
48
|
default_config :poweron, true
|
49
49
|
default_config :vm_name, nil
|
50
|
+
default_config :resource_pool, nil
|
50
51
|
|
51
52
|
def create(state)
|
52
53
|
# If the vm_name has not been set then set it now based on the suite, platform and a random number
|
@@ -54,16 +55,24 @@ module Kitchen
|
|
54
55
|
config[:vm_name] = format('%s-%s-%s', instance.suite.name, instance.platform.name, SecureRandom.hex(4))
|
55
56
|
end
|
56
57
|
|
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
|
+
|
57
60
|
connect
|
58
61
|
|
59
62
|
# Using the clone class, create a machine for TK
|
60
63
|
# Find the identifier for the targethost to pass to rbvmomi
|
61
64
|
config[:targethost] = get_host(config[:targethost])
|
62
65
|
|
66
|
+
# Find the resource pool
|
67
|
+
config[:resource_pool] = get_resource_pool(config[:resource_pool])
|
68
|
+
|
69
|
+
# Check that the datacenter exists
|
70
|
+
datacenter_exists?(config[:datacenter])
|
71
|
+
|
63
72
|
# Same thing needs to happen with the folder name if it has been set
|
64
73
|
config[:folder] = {
|
65
74
|
name: config[:folder],
|
66
|
-
id: get_folder(config[:folder])
|
75
|
+
id: get_folder(config[:folder]),
|
67
76
|
} unless config[:folder].nil?
|
68
77
|
|
69
78
|
# Create a hash of options that the clone requires
|
@@ -73,7 +82,8 @@ module Kitchen
|
|
73
82
|
poweron: config[:poweron],
|
74
83
|
template: config[:template],
|
75
84
|
datacenter: config[:datacenter],
|
76
|
-
folder: config[:folder]
|
85
|
+
folder: config[:folder],
|
86
|
+
resource_pool: config[:resource_pool],
|
77
87
|
}
|
78
88
|
|
79
89
|
# Create an object from which the clone operation can be called
|
@@ -90,7 +100,7 @@ module Kitchen
|
|
90
100
|
vm_obj = Com::Vmware::Vcenter::VM.new(vapi_config)
|
91
101
|
|
92
102
|
# shut the machine down if it is running
|
93
|
-
if vm.power_state.value ==
|
103
|
+
if vm.power_state.value == 'POWERED_ON'
|
94
104
|
power = Com::Vmware::Vcenter::Vm::Power.new(vapi_config)
|
95
105
|
power.stop(vm.vm)
|
96
106
|
end
|
@@ -102,36 +112,59 @@ module Kitchen
|
|
102
112
|
private
|
103
113
|
|
104
114
|
def validate_state(state = {})
|
105
|
-
|
106
115
|
end
|
107
116
|
|
108
117
|
def existing_state_value?(state, property)
|
109
118
|
state.key?(property) && !state[property].nil?
|
110
119
|
end
|
111
120
|
|
121
|
+
def datacenter_exists?(name)
|
122
|
+
filter = Com::Vmware::Vcenter::Datacenter::FilterSpec.new(names: Set.new([name]))
|
123
|
+
dc_obj = Com::Vmware::Vcenter::Datacenter.new(vapi_config)
|
124
|
+
dc = dc_obj.list(filter)
|
125
|
+
|
126
|
+
raise format('Unable to find data center: %s', name) if dc.empty?
|
127
|
+
end
|
128
|
+
|
112
129
|
def get_host(name)
|
113
|
-
filter = Com::Vmware::Vcenter::Host::FilterSpec.new(
|
130
|
+
filter = Com::Vmware::Vcenter::Host::FilterSpec.new(names: Set.new([name]))
|
114
131
|
host_obj = Com::Vmware::Vcenter::Host.new(vapi_config)
|
115
|
-
host = host_obj.list
|
132
|
+
host = host_obj.list(filter)
|
133
|
+
|
134
|
+
raise format('Unable to find target host: %s', name) if host.empty?
|
135
|
+
|
116
136
|
host[0].host
|
117
137
|
end
|
118
138
|
|
119
139
|
def get_folder(name)
|
120
140
|
# Create a filter to ensure that only the named folder is returned
|
121
|
-
filter = Com::Vmware::Vcenter::Folder::FilterSpec.new(
|
141
|
+
filter = Com::Vmware::Vcenter::Folder::FilterSpec.new(names: Set.new([name]))
|
122
142
|
# filter.names = name
|
123
143
|
folder_obj = Com::Vmware::Vcenter::Folder.new(vapi_config)
|
124
144
|
folder = folder_obj.list(filter)
|
125
145
|
|
146
|
+
raise format('Unable to find folder: %s', name) if folder.empty?
|
147
|
+
|
126
148
|
folder[0].folder
|
127
149
|
end
|
128
150
|
|
129
151
|
def get_vm(name)
|
130
|
-
filter = Com::Vmware::Vcenter::VM::FilterSpec.new(
|
152
|
+
filter = Com::Vmware::Vcenter::VM::FilterSpec.new(names: Set.new([name]))
|
131
153
|
vm_obj = Com::Vmware::Vcenter::VM.new(vapi_config)
|
132
154
|
vm_obj.list(filter)[0]
|
133
155
|
end
|
134
156
|
|
157
|
+
def get_resource_pool(name)
|
158
|
+
# Create a filter to ensure that only the specified resource pool is returned, if it exists
|
159
|
+
filter = Com::Vmware::Vcenter::ResourcePool::FilterSpec.new(names: Set.new([name]))
|
160
|
+
rp_obj = Com::Vmware::Vcenter::ResourcePool.new(vapi_config)
|
161
|
+
resource_pool = rp_obj.list(filter)
|
162
|
+
|
163
|
+
raise format('Unable to find Resource Pool: %s', name) if resource_pool.empty?
|
164
|
+
|
165
|
+
resource_pool[0].resource_pool
|
166
|
+
end
|
167
|
+
|
135
168
|
def connect
|
136
169
|
# Configure the connection to vCenter
|
137
170
|
lookup_service_helper = LookupServiceHelper.new(config[:vcenter_host])
|
data/lib/support/clone_vm.rb
CHANGED
@@ -12,35 +12,33 @@ class Support
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def clone
|
15
|
-
|
16
15
|
# set the datacenter name
|
17
16
|
dc = vim.serviceInstance.find_datacenter(options[:datacenter])
|
18
17
|
src_vm = dc.find_vm(options[:template])
|
19
|
-
hosts = dc.hostFolder.children
|
20
18
|
|
21
19
|
# Specify where the machine is going to be created
|
22
20
|
relocate_spec = RbVmomi::VIM.VirtualMachineRelocateSpec
|
23
21
|
relocate_spec.host = options[:targethost]
|
24
|
-
relocate_spec.pool =
|
22
|
+
relocate_spec.pool = options[:resource_pool]
|
25
23
|
|
26
24
|
clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(location: relocate_spec,
|
27
|
-
|
28
|
-
|
25
|
+
powerOn: options[:poweron],
|
26
|
+
template: false)
|
29
27
|
|
30
28
|
# Set the folder to use
|
31
29
|
dest_folder = options[:folder].nil? ? src_vm.parent : options[:folder][:id]
|
32
30
|
|
33
|
-
puts "Cloning the template #{options[:template]} to create the VM..."
|
31
|
+
puts "Cloning the template '#{options[:template]}' to create the VM..."
|
34
32
|
task = src_vm.CloneVM_Task(folder: dest_folder, name: options[:name], spec: clone_spec)
|
35
33
|
task.wait_for_completion
|
36
34
|
|
37
35
|
# get the IP address of the machine for bootstrapping
|
38
36
|
# machine name is based on the path, e.g. that includes the folder
|
39
|
-
name = options[:folder].nil? ? options[:name] : format(
|
37
|
+
name = options[:folder].nil? ? options[:name] : format('%s/%s', options[:folder][:name], options[:name])
|
40
38
|
new_vm = dc.find_vm(name)
|
41
39
|
|
42
40
|
if new_vm.nil?
|
43
|
-
puts format(
|
41
|
+
puts format('Unable to find machine: %s', name)
|
44
42
|
else
|
45
43
|
puts 'Waiting for network interfaces to become available...'
|
46
44
|
sleep 2 while new_vm.guest.net.empty? || !new_vm.guest.ipAddress
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitchen-vcenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Russell Seymour
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-kitchen
|