knife-vsphere 2.1.1 → 2.1.3
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/lib/chef/knife/base_vsphere_command.rb +69 -70
- data/lib/chef/knife/customization_helper.rb +4 -4
- data/lib/chef/knife/search_helper.rb +16 -7
- data/lib/chef/knife/vsphere_cluster_list.rb +8 -8
- data/lib/chef/knife/vsphere_cpu_ratio.rb +4 -4
- data/lib/chef/knife/vsphere_customization_list.rb +3 -3
- data/lib/chef/knife/vsphere_datastore_file.rb +17 -17
- data/lib/chef/knife/vsphere_datastore_list.rb +11 -11
- data/lib/chef/knife/vsphere_datastore_maxfree.rb +14 -14
- data/lib/chef/knife/vsphere_datastorecluster_list.rb +7 -7
- data/lib/chef/knife/vsphere_datastorecluster_maxfree.rb +10 -10
- data/lib/chef/knife/vsphere_folder_list.rb +4 -4
- data/lib/chef/knife/vsphere_hosts_list.rb +10 -10
- data/lib/chef/knife/vsphere_pool_list.rb +5 -5
- data/lib/chef/knife/vsphere_pool_query.rb +7 -7
- data/lib/chef/knife/vsphere_pool_show.rb +8 -8
- data/lib/chef/knife/vsphere_template_list.rb +7 -7
- data/lib/chef/knife/vsphere_vlan_create.rb +8 -8
- data/lib/chef/knife/vsphere_vlan_list.rb +3 -3
- data/lib/chef/knife/vsphere_vm_cdrom.rb +27 -27
- data/lib/chef/knife/vsphere_vm_clone.rb +224 -214
- data/lib/chef/knife/vsphere_vm_config.rb +6 -6
- data/lib/chef/knife/vsphere_vm_delete.rb +17 -17
- data/lib/chef/knife/vsphere_vm_disk_extend.rb +11 -11
- data/lib/chef/knife/vsphere_vm_disk_list.rb +6 -6
- data/lib/chef/knife/vsphere_vm_execute.rb +14 -14
- data/lib/chef/knife/vsphere_vm_find.rb +87 -87
- data/lib/chef/knife/vsphere_vm_list.rb +12 -12
- data/lib/chef/knife/vsphere_vm_markastemplate.rb +5 -5
- data/lib/chef/knife/vsphere_vm_migrate.rb +20 -25
- data/lib/chef/knife/vsphere_vm_move.rb +17 -17
- data/lib/chef/knife/vsphere_vm_net.rb +8 -8
- data/lib/chef/knife/vsphere_vm_network_add.rb +22 -24
- data/lib/chef/knife/vsphere_vm_network_delete.rb +8 -8
- data/lib/chef/knife/vsphere_vm_network_list.rb +5 -5
- data/lib/chef/knife/vsphere_vm_network_set.rb +10 -10
- data/lib/chef/knife/vsphere_vm_property_get.rb +7 -7
- data/lib/chef/knife/vsphere_vm_property_set.rb +16 -16
- data/lib/chef/knife/vsphere_vm_show.rb +8 -8
- data/lib/chef/knife/vsphere_vm_snapshot.rb +35 -35
- data/lib/chef/knife/vsphere_vm_state.rb +31 -31
- data/lib/chef/knife/vsphere_vm_toolsconfig.rb +11 -11
- data/lib/chef/knife/vsphere_vm_vmdk_add.rb +32 -32
- data/lib/chef/knife/vsphere_vm_vnc_set.rb +15 -15
- data/lib/chef/knife/vsphere_vm_wait_sysprep.rb +10 -11
- data/lib/knife-vsphere/version.rb +1 -1
- metadata +5 -89
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e528b518f61a2b89add76550ea53e352456f4beba7353b7347daba3bf0e19cad
|
4
|
+
data.tar.gz: d3ce8d781c6978dda58408f8221c61f6e609d2679186d1dc15092b9f8738cbac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84c58eb0029c57b8cb583924b41ad7e4f5c51b9f7ff23f4e19380d1cc24d23f29a059319744a44cc54b451e6b84bf1fb14bf00a779b9ccc4fd948b7f77cf5724
|
7
|
+
data.tar.gz: 532c60b0f873d716f29ee2c256589c5a54f5e3f0fbf9486a793f40756decdfb9684c6329b9d8af762639d37e4f8c6473b3c923838d3f1e535b502ee722e88290
|
@@ -4,17 +4,17 @@
|
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
7
|
+
require "chef/knife"
|
8
|
+
require "rbvmomi"
|
9
|
+
require "base64"
|
10
|
+
require "filesize"
|
11
11
|
|
12
12
|
# Power state on
|
13
|
-
PS_ON ||=
|
13
|
+
PS_ON ||= "poweredOn".freeze
|
14
14
|
# Power state off
|
15
|
-
PS_OFF ||=
|
15
|
+
PS_OFF ||= "poweredOff".freeze
|
16
16
|
# Power state suspended
|
17
|
-
PS_SUSPENDED ||=
|
17
|
+
PS_SUSPENDED ||= "suspended".freeze
|
18
18
|
|
19
19
|
# Base class for vsphere knife commands
|
20
20
|
class Chef
|
@@ -23,66 +23,65 @@ class Chef
|
|
23
23
|
# Main knife vsphere that more or less everything in this gem is built off of
|
24
24
|
class BaseVsphereCommand < Knife
|
25
25
|
deps do
|
26
|
-
require
|
26
|
+
require "chef/knife/bootstrap"
|
27
27
|
Chef::Knife::Bootstrap.load_deps
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require 'chef/json_compat'
|
28
|
+
require "socket"
|
29
|
+
require "net/ssh/multi"
|
30
|
+
require "readline"
|
31
|
+
require "chef/json_compat"
|
33
32
|
end
|
34
33
|
|
35
34
|
def self.common_options
|
36
35
|
option :vsphere_user,
|
37
|
-
short:
|
38
|
-
long:
|
39
|
-
description:
|
36
|
+
short: "-u USERNAME",
|
37
|
+
long: "--vsuser USERNAME",
|
38
|
+
description: "The username for vsphere"
|
40
39
|
|
41
40
|
option :vsphere_pass,
|
42
|
-
short:
|
43
|
-
long:
|
44
|
-
description:
|
41
|
+
short: "-p PASSWORD",
|
42
|
+
long: "--vspass PASSWORD",
|
43
|
+
description: "The password for vsphere"
|
45
44
|
|
46
45
|
option :vsphere_host,
|
47
|
-
long:
|
48
|
-
description:
|
46
|
+
long: "--vshost HOST",
|
47
|
+
description: "The vsphere host"
|
49
48
|
|
50
49
|
option :vsphere_dc,
|
51
|
-
short:
|
52
|
-
long:
|
53
|
-
description:
|
50
|
+
short: "-D DATACENTER",
|
51
|
+
long: "--vsdc DATACENTER",
|
52
|
+
description: "The Datacenter for vsphere"
|
54
53
|
|
55
54
|
option :vsphere_path,
|
56
|
-
long:
|
57
|
-
description:
|
58
|
-
default:
|
55
|
+
long: "--vspath SOAP_PATH",
|
56
|
+
description: "The vsphere SOAP endpoint path",
|
57
|
+
default: "/sdk"
|
59
58
|
|
60
59
|
option :vsphere_port,
|
61
|
-
long:
|
62
|
-
description:
|
63
|
-
default:
|
60
|
+
long: "--vsport PORT",
|
61
|
+
description: "The VI SDK port number to use",
|
62
|
+
default: "443"
|
64
63
|
|
65
64
|
option :vsphere_nossl,
|
66
|
-
long:
|
67
|
-
description:
|
65
|
+
long: "--vsnossl",
|
66
|
+
description: "Disable SSL connectivity"
|
68
67
|
|
69
68
|
option :vsphere_insecure,
|
70
|
-
long:
|
71
|
-
description:
|
69
|
+
long: "--vsinsecure",
|
70
|
+
description: "Disable SSL certificate verification"
|
72
71
|
|
73
72
|
option :folder,
|
74
|
-
short:
|
75
|
-
long:
|
76
|
-
description:
|
77
|
-
default:
|
73
|
+
short: "-f FOLDER",
|
74
|
+
long: "--folder FOLDER",
|
75
|
+
description: "The folder to get VMs from",
|
76
|
+
default: ""
|
78
77
|
|
79
78
|
option :proxy_host,
|
80
|
-
long:
|
81
|
-
description:
|
79
|
+
long: "--proxyhost PROXY_HOSTNAME",
|
80
|
+
description: "Proxy hostname"
|
82
81
|
|
83
82
|
option :proxy_port,
|
84
|
-
long:
|
85
|
-
description:
|
83
|
+
long: "--proxyport PROXY_PORT",
|
84
|
+
description: "Proxy port"
|
86
85
|
end
|
87
86
|
|
88
87
|
def get_config(key)
|
@@ -97,7 +96,7 @@ class Chef
|
|
97
96
|
# Password is not in the config file - grab it
|
98
97
|
# from the command line
|
99
98
|
get_password_from_stdin
|
100
|
-
elsif get_config(:vsphere_pass).start_with?(
|
99
|
+
elsif get_config(:vsphere_pass).start_with?("base64:")
|
101
100
|
Base64.decode64(get_config(:vsphere_pass)[7..-1]).chomp
|
102
101
|
else
|
103
102
|
get_config(:vsphere_pass)
|
@@ -114,7 +113,7 @@ class Chef
|
|
114
113
|
password: password,
|
115
114
|
insecure: get_config(:vsphere_insecure),
|
116
115
|
proxyHost: get_config(:proxy_host),
|
117
|
-
proxyPort: get_config(:proxy_port)
|
116
|
+
proxyPort: get_config(:proxy_port),
|
118
117
|
}
|
119
118
|
end
|
120
119
|
|
@@ -123,7 +122,7 @@ class Chef
|
|
123
122
|
end
|
124
123
|
|
125
124
|
def get_password_from_stdin
|
126
|
-
@password ||= ui.ask(
|
125
|
+
@password ||= ui.ask("Enter your password: ") { |q| q.echo = false }
|
127
126
|
end
|
128
127
|
|
129
128
|
def traverse_folders_for_pools(folder)
|
@@ -174,17 +173,17 @@ class Chef
|
|
174
173
|
|
175
174
|
def datacenter
|
176
175
|
dcname = get_config(:vsphere_dc)
|
177
|
-
traverse_folders_for_dc(vim_connection.rootFolder, dcname) || abort(
|
176
|
+
traverse_folders_for_dc(vim_connection.rootFolder, dcname) || abort("datacenter not found")
|
178
177
|
end
|
179
178
|
|
180
179
|
def find_folder(folderName)
|
181
180
|
dc = datacenter
|
182
181
|
base_entity = dc.vmFolder
|
183
|
-
entity_array = folderName.split(
|
182
|
+
entity_array = folderName.split("/")
|
184
183
|
entity_array.each do |entityArrItem|
|
185
|
-
if entityArrItem !=
|
184
|
+
if entityArrItem != ""
|
186
185
|
base_entity = base_entity.childEntity.grep(RbVmomi::VIM::Folder).find { |f| f.name == entityArrItem } ||
|
187
|
-
|
186
|
+
abort("no such folder #{folderName} while looking for #{entityArrItem}")
|
188
187
|
end
|
189
188
|
end
|
190
189
|
base_entity
|
@@ -197,7 +196,7 @@ class Chef
|
|
197
196
|
networks = base_entity.select { |f| f.name == networkName }
|
198
197
|
abort("no such network #{networkName}") if networks.empty?
|
199
198
|
|
200
|
-
if dvswitch && dvswitch !=
|
199
|
+
if dvswitch && dvswitch != "auto"
|
201
200
|
return networks.find do |f|
|
202
201
|
next unless f.respond_to?(:config)
|
203
202
|
sw = f.config.distributedVirtualSwitch
|
@@ -211,11 +210,11 @@ class Chef
|
|
211
210
|
def find_pool_folder(folderName)
|
212
211
|
dc = datacenter
|
213
212
|
base_entity = dc.hostFolder
|
214
|
-
entity_array = folderName.split(
|
213
|
+
entity_array = folderName.split("/")
|
215
214
|
entity_array.each do |entityArrItem|
|
216
|
-
if entityArrItem !=
|
215
|
+
if entityArrItem != ""
|
217
216
|
base_entity = base_entity.childEntity.grep(RbVmomi::VIM::ManagedObject).find { |f| f.name == entityArrItem } ||
|
218
|
-
|
217
|
+
abort("no such folder #{folderName} while looking for #{entityArrItem}")
|
219
218
|
end
|
220
219
|
end
|
221
220
|
base_entity
|
@@ -224,18 +223,18 @@ class Chef
|
|
224
223
|
def find_pool(poolName)
|
225
224
|
dc = datacenter
|
226
225
|
base_entity = dc.hostFolder
|
227
|
-
entity_array = poolName.split(
|
226
|
+
entity_array = poolName.split("/")
|
228
227
|
entity_array.each do |entityArrItem|
|
229
|
-
next if entityArrItem ==
|
228
|
+
next if entityArrItem == ""
|
230
229
|
if base_entity.is_a? RbVmomi::VIM::Folder
|
231
230
|
base_entity = base_entity.childEntity.find { |f| f.name == entityArrItem } ||
|
232
|
-
|
231
|
+
abort("no such pool #{poolName} while looking for #{entityArrItem}")
|
233
232
|
elsif base_entity.is_a?(RbVmomi::VIM::ClusterComputeResource) || base_entity.is_a?(RbVmomi::VIM::ComputeResource)
|
234
233
|
base_entity = base_entity.resourcePool.resourcePool.find { |f| f.name == entityArrItem } ||
|
235
|
-
|
234
|
+
abort("no such pool #{poolName} while looking for #{entityArrItem}")
|
236
235
|
elsif base_entity.is_a? RbVmomi::VIM::ResourcePool
|
237
236
|
base_entity = base_entity.resourcePool.find { |f| f.name == entityArrItem } ||
|
238
|
-
|
237
|
+
abort("no such pool #{poolName} while looking for #{entityArrItem}")
|
239
238
|
else
|
240
239
|
abort "Unexpected Object type encountered #{base_entity.type} while finding resourcePool"
|
241
240
|
end
|
@@ -266,7 +265,7 @@ class Chef
|
|
266
265
|
if candidates.length > 0
|
267
266
|
vmdk_datastore = candidates[0]
|
268
267
|
else
|
269
|
-
puts
|
268
|
+
puts "Insufficient space on all LUNs designated or assigned to the virtual machine. Please specify a new target."
|
270
269
|
vmdk_datastore = nil
|
271
270
|
end
|
272
271
|
vmdk_datastore
|
@@ -278,7 +277,7 @@ class Chef
|
|
278
277
|
dc = datacenter
|
279
278
|
base_entity = dc.datastore
|
280
279
|
base_entity.each do |ds|
|
281
|
-
stores.push ds if ds.name
|
280
|
+
stores.push ds if ds.name =~ /#{regex}/
|
282
281
|
end
|
283
282
|
stores
|
284
283
|
end
|
@@ -295,10 +294,10 @@ class Chef
|
|
295
294
|
folder = dc.datastoreFolder
|
296
295
|
end
|
297
296
|
folder.childEntity.each do |child|
|
298
|
-
if child.class.to_s ==
|
297
|
+
if child.class.to_s == "Folder"
|
299
298
|
ds = find_datastorecluster(dsName, child)
|
300
299
|
return ds if ds
|
301
|
-
elsif child.class.to_s ==
|
300
|
+
elsif child.class.to_s == "StoragePod" && child.name == dsName
|
302
301
|
return child
|
303
302
|
end
|
304
303
|
end
|
@@ -307,7 +306,7 @@ class Chef
|
|
307
306
|
|
308
307
|
def number_to_human_size(number)
|
309
308
|
number = number.to_f
|
310
|
-
storage_units_fmt = %w
|
309
|
+
storage_units_fmt = %w{byte kB MB GB TB}
|
311
310
|
base = 1024
|
312
311
|
if number.to_i < base
|
313
312
|
unit = storage_units_fmt[0]
|
@@ -319,7 +318,7 @@ class Chef
|
|
319
318
|
unit = storage_units_fmt[exponent]
|
320
319
|
end
|
321
320
|
|
322
|
-
format(
|
321
|
+
format("%0.2f %s", number, unit)
|
323
322
|
end
|
324
323
|
|
325
324
|
def find_device(vm, deviceName)
|
@@ -346,9 +345,9 @@ class Chef
|
|
346
345
|
def get_path_to_object(object)
|
347
346
|
if object.is_a?(RbVmomi::VIM:: ManagedEntity)
|
348
347
|
if object.parent.is_a?(RbVmomi::VIM:: ManagedEntity)
|
349
|
-
|
348
|
+
get_path_to_object(object.parent) + "/" + object.parent.name
|
350
349
|
else
|
351
|
-
|
350
|
+
""
|
352
351
|
end
|
353
352
|
else
|
354
353
|
puts "Unknown type #{object.class}, not enumerating"
|
@@ -398,8 +397,8 @@ class Chef
|
|
398
397
|
end
|
399
398
|
|
400
399
|
def windows?(config)
|
401
|
-
is_win_bool = config.guestId.downcase.include?(
|
402
|
-
Chef::Log.debug(
|
400
|
+
is_win_bool = config.guestId.downcase.include?("windows")
|
401
|
+
Chef::Log.debug("Identified os as windows.") if is_win_bool
|
403
402
|
is_win_bool
|
404
403
|
end
|
405
404
|
|
@@ -407,8 +406,8 @@ class Chef
|
|
407
406
|
gid = config.guestId.downcase
|
408
407
|
# This makes the assumption that if it isn't mac or windows it's linux
|
409
408
|
# See https://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.vm.GuestOsDescriptor.GuestOsIdentifier.html for values
|
410
|
-
is_linux_bool = !gid.include?(
|
411
|
-
Chef::Log.debug(
|
409
|
+
is_linux_bool = !gid.include?("windows") && !gid.include?("darwin")
|
410
|
+
Chef::Log.debug("Identified os as linux.") if is_linux_bool
|
412
411
|
is_linux_bool
|
413
412
|
end
|
414
413
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# License:: Apache License, Version 2.0
|
4
4
|
#
|
5
5
|
|
6
|
-
require
|
6
|
+
require "rbvmomi"
|
7
7
|
|
8
8
|
# The Customization helper for sysprep
|
9
9
|
module CustomizationHelper
|
@@ -19,7 +19,7 @@ module CustomizationHelper
|
|
19
19
|
wait = true
|
20
20
|
waited_seconds = 0
|
21
21
|
|
22
|
-
print
|
22
|
+
print "Waiting for sysprep..."
|
23
23
|
while wait
|
24
24
|
events = query_customization_succeeded(vm, vem)
|
25
25
|
|
@@ -31,7 +31,7 @@ module CustomizationHelper
|
|
31
31
|
elsif waited_seconds >= timeout
|
32
32
|
abort "\nCustomization of VM #{vm.name} not succeeded within #{timeout} seconds."
|
33
33
|
else
|
34
|
-
print
|
34
|
+
print "."
|
35
35
|
sleep(sleep_time)
|
36
36
|
waited_seconds += sleep_time
|
37
37
|
end
|
@@ -46,6 +46,6 @@ module CustomizationHelper
|
|
46
46
|
vem.QueryEvents(filter:
|
47
47
|
RbVmomi::VIM::EventFilterSpec(entity:
|
48
48
|
RbVmomi::VIM::EventFilterSpecByEntity(entity: vm, recursion:
|
49
|
-
RbVmomi::VIM::EventFilterSpecRecursionOption(:self)), eventTypeId: [
|
49
|
+
RbVmomi::VIM::EventFilterSpecRecursionOption(:self)), eventTypeId: ["CustomizationSucceeded"]))
|
50
50
|
end
|
51
51
|
end
|
@@ -7,6 +7,10 @@ module SearchHelper
|
|
7
7
|
# param [Array<String>] properties to retrieve
|
8
8
|
# @return [Array<RbVmomi::VIM::ObjectContent>]
|
9
9
|
def get_all_vm_objects(opts = {})
|
10
|
+
get_all_objects(opts.merge(type: "VirtualMachine"))
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_all_objects(opts = {})
|
10
14
|
pc = vim_connection.serviceInstance.content.propertyCollector
|
11
15
|
viewmgr = vim_connection.serviceInstance.content.viewManager
|
12
16
|
folder = if opts[:folder]
|
@@ -15,10 +19,10 @@ module SearchHelper
|
|
15
19
|
vim_connection.serviceInstance.content.rootFolder
|
16
20
|
end
|
17
21
|
vmview = viewmgr.CreateContainerView(container: folder,
|
18
|
-
type: [
|
22
|
+
type: [opts[:type]],
|
19
23
|
recursive: true)
|
20
24
|
|
21
|
-
opts[:properties] ||= [
|
25
|
+
opts[:properties] ||= ["name"]
|
22
26
|
|
23
27
|
filter_spec = RbVmomi::VIM.PropertyFilterSpec(
|
24
28
|
objectSet: [
|
@@ -26,22 +30,27 @@ module SearchHelper
|
|
26
30
|
skip: true,
|
27
31
|
selectSet: [
|
28
32
|
RbVmomi::VIM.TraversalSpec(
|
29
|
-
name:
|
30
|
-
type:
|
31
|
-
path:
|
33
|
+
name: "traverseEntities",
|
34
|
+
type: "ContainerView",
|
35
|
+
path: "view",
|
32
36
|
skip: false
|
33
37
|
)
|
34
38
|
]
|
35
39
|
],
|
36
40
|
propSet: [
|
37
|
-
{ type:
|
41
|
+
{ type: opts[:type], pathSet: opts[:properties] }
|
38
42
|
]
|
39
43
|
)
|
40
44
|
pc.RetrieveProperties(specSet: [filter_spec])
|
41
45
|
end
|
42
46
|
|
43
47
|
def get_vm_by_name(vmname, folder = nil)
|
44
|
-
vm = get_all_vm_objects(folder: folder).detect { |r| r[
|
48
|
+
vm = get_all_vm_objects(folder: folder).detect { |r| r["name"] == vmname }
|
45
49
|
vm ? vm.obj : nil
|
46
50
|
end
|
51
|
+
|
52
|
+
def get_vm_host_by_name(name, folder = nil)
|
53
|
+
host = get_all_objects(type: "HostSystem", folder: folder).detect { |r| r["name"] == name }
|
54
|
+
host ? host.obj : nil
|
55
|
+
end
|
47
56
|
end
|
@@ -3,12 +3,12 @@
|
|
3
3
|
# Contributor:: Dennis Pattmann (https://github.com/DennisBP)
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
|
-
require
|
7
|
-
require
|
6
|
+
require "chef/knife"
|
7
|
+
require "chef/knife/base_vsphere_command"
|
8
8
|
|
9
9
|
# Lists all known clusters in the configured datacenter
|
10
10
|
class Chef::Knife::VsphereClusterList < Chef::Knife::BaseVsphereCommand
|
11
|
-
banner
|
11
|
+
banner "knife vsphere cluster list"
|
12
12
|
|
13
13
|
common_options
|
14
14
|
|
@@ -16,8 +16,8 @@ class Chef::Knife::VsphereClusterList < Chef::Knife::BaseVsphereCommand
|
|
16
16
|
return if folder.is_a? RbVmomi::VIM::VirtualApp
|
17
17
|
|
18
18
|
if folder.is_a? RbVmomi::VIM::ClusterComputeResource
|
19
|
-
clusters = folder.path[3..-1].reject { |p| p.last ==
|
20
|
-
return {
|
19
|
+
clusters = folder.path[3..-1].reject { |p| p.last == "ClusterComputeResource" }
|
20
|
+
return { "Cluster" => clusters.map(&:last).join("/") }
|
21
21
|
end
|
22
22
|
|
23
23
|
folders = find_all_in_folder(folder, RbVmomi::VIM::ManagedObject) || []
|
@@ -29,11 +29,11 @@ class Chef::Knife::VsphereClusterList < Chef::Knife::BaseVsphereCommand
|
|
29
29
|
def find_cluster_folder(folderName)
|
30
30
|
dc = datacenter
|
31
31
|
base_entity = dc.hostFolder
|
32
|
-
entity_array = folderName.split(
|
32
|
+
entity_array = folderName.split("/")
|
33
33
|
entity_array.each do |entityArrItem|
|
34
|
-
if entityArrItem !=
|
34
|
+
if entityArrItem != ""
|
35
35
|
base_entity = base_entity.childEntity.grep(RbVmomi::VIM::ManagedObject).find { |f| f.name == entityArrItem } ||
|
36
|
-
|
36
|
+
abort("no such folder #{folderName} while looking for #{entityArrItem}")
|
37
37
|
end
|
38
38
|
end
|
39
39
|
base_entity
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "chef/knife"
|
2
|
+
require "chef/knife/base_vsphere_command"
|
3
3
|
|
4
4
|
# VsphereCpuratio extends the BaseVspherecommand
|
5
5
|
class Chef::Knife::VsphereCpuRatio < Chef::Knife::BaseVsphereCommand
|
6
|
-
banner
|
6
|
+
banner "knife vsphere cpu ratio [CLUSTER] [HOST]"
|
7
7
|
|
8
8
|
common_options
|
9
9
|
|
@@ -38,7 +38,7 @@ class Chef::Knife::VsphereCpuRatio < Chef::Knife::BaseVsphereCommand
|
|
38
38
|
|
39
39
|
puts "#{h.name}: #{ratio}"
|
40
40
|
end
|
41
|
-
puts
|
41
|
+
puts ""
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|