knife-vsphere 1.0.1 → 1.2.0
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 +4 -4
- data/lib/chef/knife/base_vsphere_command.rb +383 -371
- data/lib/chef/knife/customization_helper.rb +40 -0
- data/lib/chef/knife/vsphere_cluster_list.rb +47 -0
- data/lib/chef/knife/vsphere_cpu_ratio.rb +41 -45
- data/lib/chef/knife/vsphere_customization_list.rb +24 -29
- data/lib/chef/knife/vsphere_datastore_list.rb +68 -72
- data/lib/chef/knife/vsphere_datastore_maxfree.rb +48 -49
- data/lib/chef/knife/vsphere_datastorecluster_list.rb +66 -71
- data/lib/chef/knife/vsphere_datastorecluster_maxfree.rb +75 -84
- data/lib/chef/knife/vsphere_folder_list.rb +28 -30
- data/lib/chef/knife/vsphere_hosts_list.rb +42 -42
- data/lib/chef/knife/vsphere_pool_list.rb +46 -48
- data/lib/chef/knife/vsphere_pool_query.rb +58 -58
- data/lib/chef/knife/vsphere_template_list.rb +30 -32
- data/lib/chef/knife/vsphere_vlan_create.rb +51 -0
- data/lib/chef/knife/vsphere_vlan_list.rb +35 -37
- data/lib/chef/knife/vsphere_vm_clone.rb +834 -581
- data/lib/chef/knife/vsphere_vm_config.rb +48 -46
- data/lib/chef/knife/vsphere_vm_delete.rb +70 -66
- data/lib/chef/knife/vsphere_vm_execute.rb +62 -66
- data/lib/chef/knife/vsphere_vm_list.rb +57 -61
- data/lib/chef/knife/vsphere_vm_markastemplate.rb +48 -54
- data/lib/chef/knife/vsphere_vm_migrate.rb +73 -0
- data/lib/chef/knife/vsphere_vm_move.rb +88 -0
- data/lib/chef/knife/vsphere_vm_net.rb +57 -0
- data/lib/chef/knife/vsphere_vm_property_get.rb +44 -46
- data/lib/chef/knife/vsphere_vm_property_set.rb +83 -84
- data/lib/chef/knife/vsphere_vm_query.rb +48 -48
- data/lib/chef/knife/vsphere_vm_snapshot.rb +124 -130
- data/lib/chef/knife/vsphere_vm_state.rb +122 -127
- data/lib/chef/knife/vsphere_vm_toolsconfig.rb +54 -52
- data/lib/chef/knife/vsphere_vm_vmdk_add.rb +234 -241
- data/lib/chef/knife/vsphere_vm_wait_sysprep.rb +54 -0
- data/lib/knife-vsphere/version.rb +3 -4
- metadata +43 -15
- data/lib/chef/knife/vshpere_vm_migrate.rb +0 -80
- data/lib/chef/knife/vshpere_vm_move.rb +0 -92
- data/lib/chef/knife/vshpere_vm_net.rb +0 -57
@@ -1,71 +1,66 @@
|
|
1
|
-
# Copyright (C) 2012, SCM Ventures AB
|
2
|
-
# Author: Ian Delahorne <ian@scmventures.se>
|
3
|
-
#
|
4
|
-
# Permission to use, copy, modify, and/or distribute this software for
|
5
|
-
# any purpose with or without fee is hereby granted, provided that the
|
6
|
-
# above copyright notice and this permission notice appear in all
|
7
|
-
# copies.
|
8
|
-
#
|
9
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
10
|
-
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
11
|
-
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
12
|
-
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
13
|
-
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
|
14
|
-
# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
15
|
-
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
16
|
-
# PERFORMANCE OF THIS SOFTWARE
|
17
|
-
|
18
|
-
require 'chef/knife'
|
19
|
-
require 'chef/knife/base_vsphere_command'
|
20
|
-
|
21
|
-
def number_to_human_size(number)
|
22
|
-
number = number.to_f
|
23
|
-
storage_units_fmt =
|
24
|
-
base = 1024
|
25
|
-
if number.to_i < base
|
26
|
-
unit = storage_units_fmt[0]
|
27
|
-
else
|
28
|
-
max_exp = storage_units_fmt.size - 1
|
29
|
-
exponent = (Math.log(number) / Math.log(base)).to_i # Convert to base
|
30
|
-
exponent = max_exp if exponent > max_exp # we need this to avoid overflow for the highest unit
|
31
|
-
number /= base
|
32
|
-
unit = storage_units_fmt[exponent]
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
def traverse_folders_for_dsclusters(folder)
|
39
|
-
print_dsclusters_in_folder(folder)
|
40
|
-
folder.childEntity.each do |child|
|
41
|
-
if child.class.to_s == 'Folder'
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
dc = get_datacenter
|
68
|
-
traverse_folders_for_dsclusters(dc.datastoreFolder)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
1
|
+
# Copyright (C) 2012, SCM Ventures AB
|
2
|
+
# Author: Ian Delahorne <ian@scmventures.se>
|
3
|
+
#
|
4
|
+
# Permission to use, copy, modify, and/or distribute this software for
|
5
|
+
# any purpose with or without fee is hereby granted, provided that the
|
6
|
+
# above copyright notice and this permission notice appear in all
|
7
|
+
# copies.
|
8
|
+
#
|
9
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
10
|
+
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
11
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
12
|
+
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
13
|
+
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
|
14
|
+
# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
15
|
+
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
16
|
+
# PERFORMANCE OF THIS SOFTWARE
|
17
|
+
|
18
|
+
require 'chef/knife'
|
19
|
+
require 'chef/knife/base_vsphere_command'
|
20
|
+
|
21
|
+
def number_to_human_size(number)
|
22
|
+
number = number.to_f
|
23
|
+
storage_units_fmt = %w(byte kB MB GB TB)
|
24
|
+
base = 1024
|
25
|
+
if number.to_i < base
|
26
|
+
unit = storage_units_fmt[0]
|
27
|
+
else
|
28
|
+
max_exp = storage_units_fmt.size - 1
|
29
|
+
exponent = (Math.log(number) / Math.log(base)).to_i # Convert to base
|
30
|
+
exponent = max_exp if exponent > max_exp # we need this to avoid overflow for the highest unit
|
31
|
+
number /= base**exponent
|
32
|
+
unit = storage_units_fmt[exponent]
|
33
|
+
end
|
34
|
+
|
35
|
+
format('%0.2f %s', number, unit)
|
36
|
+
end
|
37
|
+
|
38
|
+
def traverse_folders_for_dsclusters(folder)
|
39
|
+
print_dsclusters_in_folder(folder)
|
40
|
+
folder.childEntity.each do |child|
|
41
|
+
traverse_folders_for_dsclusters(child) if child.class.to_s == 'Folder'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def print_dsclusters_in_folder(folder)
|
46
|
+
folder.childEntity.each do |child|
|
47
|
+
next unless child.class.to_s == 'StoragePod'
|
48
|
+
avail = number_to_human_size(child.summary[:freeSpace])
|
49
|
+
cap = number_to_human_size(child.summary[:capacity])
|
50
|
+
puts "#{ui.color('DatastoreCluster', :cyan)}: #{child.name} (#{avail} / #{cap})"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Lists all known data store cluster in datacenter with sizes
|
55
|
+
class Chef::Knife::VsphereDatastoreclusterList < Chef::Knife::BaseVsphereCommand
|
56
|
+
banner 'knife vsphere datastorecluster list'
|
57
|
+
|
58
|
+
common_options
|
59
|
+
|
60
|
+
def run
|
61
|
+
$stdout.sync = true
|
62
|
+
vim_connection
|
63
|
+
dc = datacenter
|
64
|
+
traverse_folders_for_dsclusters(dc.datastoreFolder)
|
65
|
+
end
|
66
|
+
end
|
@@ -1,84 +1,75 @@
|
|
1
|
-
# Copyright (C) 2012, SCM Ventures AB
|
2
|
-
# Author: Ian Delahorne <ian@scmventures.se>
|
3
|
-
#
|
4
|
-
# Permission to use, copy, modify, and/or distribute this software for
|
5
|
-
# any purpose with or without fee is hereby granted, provided that the
|
6
|
-
# above copyright notice and this permission notice appear in all
|
7
|
-
# copies.
|
8
|
-
#
|
9
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
10
|
-
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
11
|
-
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
12
|
-
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
13
|
-
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
|
14
|
-
# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
15
|
-
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
16
|
-
# PERFORMANCE OF THIS SOFTWARE
|
17
|
-
|
18
|
-
require 'chef/knife'
|
19
|
-
require 'chef/knife/base_vsphere_command'
|
20
|
-
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
if
|
38
|
-
max_dscluster =
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
if max_dscluster
|
77
|
-
puts max_dscluster.name
|
78
|
-
else
|
79
|
-
puts "No datastore clusters found"
|
80
|
-
exit 1
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
end
|
1
|
+
# Copyright (C) 2012, SCM Ventures AB
|
2
|
+
# Author: Ian Delahorne <ian@scmventures.se>
|
3
|
+
#
|
4
|
+
# Permission to use, copy, modify, and/or distribute this software for
|
5
|
+
# any purpose with or without fee is hereby granted, provided that the
|
6
|
+
# above copyright notice and this permission notice appear in all
|
7
|
+
# copies.
|
8
|
+
#
|
9
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
10
|
+
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
11
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
12
|
+
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
13
|
+
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
|
14
|
+
# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
15
|
+
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
16
|
+
# PERFORMANCE OF THIS SOFTWARE
|
17
|
+
|
18
|
+
require 'chef/knife'
|
19
|
+
require 'chef/knife/base_vsphere_command'
|
20
|
+
|
21
|
+
def max_dscluster(dscluster, max_dscluster)
|
22
|
+
return true unless max_dscluster
|
23
|
+
|
24
|
+
if dscluster.summary[:freeSpace] > max_dscluster.summary[:freeSpace]
|
25
|
+
return true
|
26
|
+
end
|
27
|
+
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
def find_max_dscluster(folder, max_dscluster, regex)
|
32
|
+
folder.childEntity.each do |child|
|
33
|
+
if child.class.to_s == 'Folder'
|
34
|
+
sub_max = find_max_dscluster(child, max_dscluster, regex)
|
35
|
+
max_dscluster = sub_max if max_dscluster(sub_max, max_dscluster)
|
36
|
+
elsif child.class.to_s == 'StoragePod'
|
37
|
+
if max_dscluster(child, max_dscluster) && regex.match(child.name)
|
38
|
+
max_dscluster = child
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
max_dscluster
|
44
|
+
end
|
45
|
+
|
46
|
+
# Gets the data store cluster with the most free space in datacenter
|
47
|
+
class Chef::Knife::VsphereDatastoreclusterMaxfree < Chef::Knife::BaseVsphereCommand
|
48
|
+
banner 'knife vsphere datastorecluster maxfree'
|
49
|
+
|
50
|
+
option :regex,
|
51
|
+
short: '-r REGEX',
|
52
|
+
long: '--regex REGEX',
|
53
|
+
description: 'Regex to match the datastore cluster name',
|
54
|
+
default: ''
|
55
|
+
common_options
|
56
|
+
|
57
|
+
def run
|
58
|
+
$stdout.sync = true
|
59
|
+
|
60
|
+
regex = /#{Regexp.escape(get_config(:regex))}/
|
61
|
+
max_dscluster = nil
|
62
|
+
|
63
|
+
vim_connection
|
64
|
+
dc = datacenter
|
65
|
+
|
66
|
+
max_dscluster = find_max_dscluster(dc.datastoreFolder, max_dscluster, regex)
|
67
|
+
|
68
|
+
if max_dscluster
|
69
|
+
puts max_dscluster.name
|
70
|
+
else
|
71
|
+
puts 'No datastore clusters found'
|
72
|
+
exit 1
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -1,30 +1,28 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Ezra Pagel (<ezra@cpan.org>)
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
require 'chef/knife'
|
6
|
-
require 'chef/knife/base_vsphere_command'
|
7
|
-
|
8
|
-
# Lists all vm folders
|
9
|
-
class Chef::Knife::VsphereFolderList < Chef::Knife::BaseVsphereCommand
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Ezra Pagel (<ezra@cpan.org>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
require 'chef/knife'
|
6
|
+
require 'chef/knife/base_vsphere_command'
|
7
|
+
|
8
|
+
# Lists all vm folders
|
9
|
+
class Chef::Knife::VsphereFolderList < Chef::Knife::BaseVsphereCommand
|
10
|
+
banner 'knife vsphere folder list'
|
11
|
+
|
12
|
+
common_options
|
13
|
+
|
14
|
+
def traverse_folders(folder, indent_level)
|
15
|
+
puts "#{' ' * indent_level} #{ui.color('Folder', :cyan)}: " + folder.name
|
16
|
+
|
17
|
+
folders = find_all_in_folder(folder, RbVmomi::VIM::Folder)
|
18
|
+
folders.each do |child|
|
19
|
+
traverse_folders(child, indent_level + 1)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def run
|
24
|
+
vim_connection
|
25
|
+
base_folder = find_folder(get_config(:folder))
|
26
|
+
traverse_folders(base_folder, 0)
|
27
|
+
end
|
28
|
+
end
|
@@ -1,42 +1,42 @@
|
|
1
|
-
require 'chef/knife'
|
2
|
-
require 'chef/knife/base_vsphere_command'
|
3
|
-
require 'rbvmomi'
|
4
|
-
require 'netaddr'
|
5
|
-
|
6
|
-
#list hosts belonging to pool
|
7
|
-
class Chef::Knife::VsphereHostsList < Chef::Knife::BaseVsphereCommand
|
8
|
-
banner
|
9
|
-
|
10
|
-
|
11
|
-
option :pool,
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
|
16
|
-
def find_pools(folder, poolname = nil)
|
17
|
-
pools = folder.children.find_all.select {|p| p.is_a?(RbVmomi::VIM::ComputeResource) || p.is_a?(RbVmomi::VIM::ResourcePool) }
|
18
|
-
poolname.nil? ? pools : pools.select {|p| p.name == poolname }
|
19
|
-
end
|
20
|
-
|
21
|
-
def run
|
22
|
-
|
23
|
-
dc =
|
24
|
-
folder = dc.hostFolder
|
25
|
-
|
26
|
-
target_pool = config[:pool]
|
27
|
-
|
28
|
-
pools = find_pools(folder, target_pool)
|
29
|
-
if target_pool && pools.empty?
|
30
|
-
puts "Pool #{target_pool} not found"
|
31
|
-
return
|
32
|
-
end
|
33
|
-
|
34
|
-
pools.each do |pool|
|
35
|
-
puts "#{ui.color(
|
36
|
-
hosts = pool.host || []
|
37
|
-
hosts.each do |hostc|
|
38
|
-
puts " #{ui.color(
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
1
|
+
require 'chef/knife'
|
2
|
+
require 'chef/knife/base_vsphere_command'
|
3
|
+
require 'rbvmomi'
|
4
|
+
require 'netaddr'
|
5
|
+
|
6
|
+
# list hosts belonging to pool
|
7
|
+
class Chef::Knife::VsphereHostsList < Chef::Knife::BaseVsphereCommand
|
8
|
+
banner 'knife vsphere hosts list'
|
9
|
+
|
10
|
+
common_options
|
11
|
+
option :pool,
|
12
|
+
long: '--pool pool',
|
13
|
+
short: '-h',
|
14
|
+
description: 'Target pool'
|
15
|
+
|
16
|
+
def find_pools(folder, poolname = nil)
|
17
|
+
pools = folder.children.find_all.select { |p| p.is_a?(RbVmomi::VIM::ComputeResource) || p.is_a?(RbVmomi::VIM::ResourcePool) }
|
18
|
+
poolname.nil? ? pools : pools.select { |p| p.name == poolname }
|
19
|
+
end
|
20
|
+
|
21
|
+
def run
|
22
|
+
vim_connection
|
23
|
+
dc = datacenter
|
24
|
+
folder = dc.hostFolder
|
25
|
+
|
26
|
+
target_pool = config[:pool]
|
27
|
+
|
28
|
+
pools = find_pools(folder, target_pool)
|
29
|
+
if target_pool && pools.empty?
|
30
|
+
puts "Pool #{target_pool} not found"
|
31
|
+
return
|
32
|
+
end
|
33
|
+
|
34
|
+
pools.each do |pool|
|
35
|
+
puts "#{ui.color('Pool', :cyan)}: #{pool.name}"
|
36
|
+
hosts = pool.host || []
|
37
|
+
hosts.each do |hostc|
|
38
|
+
puts " #{ui.color('Host', :cyan)}: #{hostc.name}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,48 +1,46 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Jesse Campbell (<hikeit@gmail.com>)
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
require 'chef/knife'
|
6
|
-
require 'chef/knife/base_vsphere_command'
|
7
|
-
|
8
|
-
# Lists all known pools in the configured datacenter
|
9
|
-
class Chef::Knife::VspherePoolList < Chef::Knife::BaseVsphereCommand
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
folders
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Jesse Campbell (<hikeit@gmail.com>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
require 'chef/knife'
|
6
|
+
require 'chef/knife/base_vsphere_command'
|
7
|
+
|
8
|
+
# Lists all known pools in the configured datacenter
|
9
|
+
class Chef::Knife::VspherePoolList < Chef::Knife::BaseVsphereCommand
|
10
|
+
banner 'knife vsphere pool list'
|
11
|
+
|
12
|
+
common_options
|
13
|
+
|
14
|
+
def traverse_folders(folder)
|
15
|
+
return if folder.is_a? RbVmomi::VIM::VirtualApp
|
16
|
+
|
17
|
+
if folder.is_a? RbVmomi::VIM::ResourcePool
|
18
|
+
pools = folder.path[3..-1].reject { |p| p.last == 'Resources' }
|
19
|
+
puts "#{ui.color('Pool', :cyan)}: " + pools.map(&:last).join('/')
|
20
|
+
end
|
21
|
+
|
22
|
+
folders = find_all_in_folder(folder, RbVmomi::VIM::ManagedObject) || []
|
23
|
+
folders.each do |child|
|
24
|
+
traverse_folders(child)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def find_pool_folder(folderName)
|
29
|
+
dc = datacenter
|
30
|
+
base_entity = dc.hostFolder
|
31
|
+
entity_array = folderName.split('/')
|
32
|
+
entity_array.each do |entityArrItem|
|
33
|
+
if entityArrItem != ''
|
34
|
+
base_entity = base_entity.childEntity.grep(RbVmomi::VIM::ManagedObject).find { |f| f.name == entityArrItem } ||
|
35
|
+
abort("no such folder #{folderName} while looking for #{entityArrItem}")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
base_entity
|
39
|
+
end
|
40
|
+
|
41
|
+
def run
|
42
|
+
vim_connection
|
43
|
+
base_folder = find_pool_folder(get_config(:folder))
|
44
|
+
traverse_folders(base_folder)
|
45
|
+
end
|
46
|
+
end
|