knife-vsphere 1.2.4 → 1.2.5

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
  SHA1:
3
- metadata.gz: 1b99f48fa873d629a1882d1f8f269fa314014fea
4
- data.tar.gz: 980c7c2071e841eb6008515308d4241f9196dc94
3
+ metadata.gz: 06e3ee523488e2e14df1e267f2c980880a427e19
4
+ data.tar.gz: 7050570b79976dc09f12b4370176645a857e3894
5
5
  SHA512:
6
- metadata.gz: 77f5f85d54f7e1df223cba68410c076ff732bb3a7e5379bed7e331c45e307f7911f7ea68e26662dc6857e7bead771a43436442636bed9a9c98a6b38bf54b1a37
7
- data.tar.gz: cfc52c14fff451c70b0f0878fef47ce45bac4a41c74089dba8315ada86ad62329456be23fb723282447e7fff706d2ee6a804724308bc30a435700d73d22a953e
6
+ metadata.gz: 6df9b92b2fe8a8ece228ca68104968c49943e6440ddbf239a590fd4de221836533cc665d5c5447e8188c1298c542966072570f44b05066a0afe7df28b0d96bc6
7
+ data.tar.gz: 733ec8e53a9930bb05632f5d8864d19bfa51c5eb44ef8ac068a532127bfe6141ee7147c05751954c5cb9db4b865100f0f45a700fb36d98d2aacad1b587c78614
@@ -8,51 +8,11 @@ class Chef::Knife::VspherePoolQuery < Chef::Knife::BaseVsphereCommand
8
8
 
9
9
  common_options
10
10
 
11
- def traverse_folders_for_pool(folder, poolname)
12
- children = folder.children.find_all
13
- children.each do |child|
14
- if child.class == RbVmomi::VIM::ClusterComputeResource || child.class == RbVmomi::VIM::ComputeResource || child.class == RbVmomi::VIM::ResourcePool
15
- return child if child.name == poolname
16
- elsif child.class == RbVmomi::VIM::Folder
17
- pool = traverse_folders_for_pool(child, poolname)
18
- return pool if pool
19
- end
20
- end
21
- false
22
- end
23
-
24
11
  def run
25
- $stdout.sync = true
26
- poolname = @name_args[0]
27
- if poolname.nil?
28
- show_usage
29
- fatal_exit('You must specify a resource poor or cluster name (see knife vsphere pool list)')
30
- end
31
-
32
- query_string = @name_args[1]
33
- if query_string.nil?
34
- show_usage
35
- fatal_exit('You must specify a QUERY value (e.g. summary.overallStatus )')
36
- end
37
-
38
- vim_connection
39
-
40
- dc = datacenter
41
- folder = dc.hostFolder
42
-
43
- pool = traverse_folders_for_pool(folder, poolname) || abort("Pool #{poolname} not found")
44
-
45
- # split QUERY by dots, and walk the object model
46
- query = query_string.split '.'
47
- result = pool
48
- query.each do |part|
49
- message, index = part.split(/[\[\]]/)
50
- unless result.respond_to? message.to_sym
51
- fatal_exit("\"#{query_string}\" not recognized.")
52
- end
53
-
54
- result = index ? result.send(message)[index.to_i] : result.send(message)
55
- end
56
- puts result
12
+ args = ARGV
13
+ args[2] = 'show'
14
+ ui.warn 'vsphere pool query is moving to vsphere pool show. Next time, please run'
15
+ ui.warn args.join " "
16
+ Chef::Knife.run(args)
57
17
  end
58
18
  end
@@ -0,0 +1,58 @@
1
+ require 'chef/knife'
2
+ require 'chef/knife/base_vsphere_command'
3
+ require 'rbvmomi'
4
+ require 'netaddr'
5
+
6
+ class Chef::Knife::VspherePoolShow < Chef::Knife::BaseVsphereCommand
7
+ banner "knife vsphere pool show POOLNAME QUERY. See \"http://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.ComputeResource.html\" for allowed QUERY values."
8
+
9
+ common_options
10
+
11
+ def traverse_folders_for_pool(folder, poolname)
12
+ children = folder.children.find_all
13
+ children.each do |child|
14
+ if child.class == RbVmomi::VIM::ClusterComputeResource || child.class == RbVmomi::VIM::ComputeResource || child.class == RbVmomi::VIM::ResourcePool
15
+ return child if child.name == poolname
16
+ elsif child.class == RbVmomi::VIM::Folder
17
+ pool = traverse_folders_for_pool(child, poolname)
18
+ return pool if pool
19
+ end
20
+ end
21
+ false
22
+ end
23
+
24
+ def run
25
+ $stdout.sync = true
26
+ poolname = @name_args[0]
27
+ if poolname.nil?
28
+ show_usage
29
+ fatal_exit('You must specify a resource poor or cluster name (see knife vsphere pool list)')
30
+ end
31
+
32
+ query_string = @name_args[1]
33
+ if query_string.nil?
34
+ show_usage
35
+ fatal_exit('You must specify a QUERY value (e.g. summary.overallStatus )')
36
+ end
37
+
38
+ vim_connection
39
+
40
+ dc = datacenter
41
+ folder = dc.hostFolder
42
+
43
+ pool = traverse_folders_for_pool(folder, poolname) || abort("Pool #{poolname} not found")
44
+
45
+ # split QUERY by dots, and walk the object model
46
+ query = query_string.split '.'
47
+ result = pool
48
+ query.each do |part|
49
+ message, index = part.split(/[\[\]]/)
50
+ unless result.respond_to? message.to_sym
51
+ fatal_exit("\"#{query_string}\" not recognized.")
52
+ end
53
+
54
+ result = index ? result.send(message)[index.to_i] : result.send(message)
55
+ end
56
+ puts result
57
+ end
58
+ end
@@ -437,7 +437,10 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
437
437
  fatal_exit "No hosts have the requested DatastoreCluster available! #{get_config(:datastorecluster)}" if hosts.empty?
438
438
 
439
439
  if get_config(:customization_vlan)
440
- hosts.reject! { |host| !host.network.include?(find_network(get_config(:customization_vlan))) }
440
+ vlan_list = get_config(:customization_vlan).split(',')
441
+ vlan_list.each do |network|
442
+ hosts.reject! { |host| !host.network.include?(find_network(network)) }
443
+ end
441
444
  end
442
445
 
443
446
  fatal_exit "No hosts have the requested Network available! #{get_config(:customization_vlan)}" if hosts.empty?
@@ -0,0 +1,235 @@
1
+ #
2
+ # Author:: Raducu Deaconu (<rhadoo_io@yahoo.com>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+
6
+ require 'chef/knife'
7
+ require 'chef/knife/base_vsphere_command'
8
+ require 'rbvmomi'
9
+ require 'netaddr'
10
+
11
+ PsOn = 'poweredOn'
12
+ PsOff = 'poweredOff'
13
+ PsSuspended = 'suspended'
14
+
15
+ # find vms belonging to pool that match criteria, display specified fields
16
+ class Chef::Knife::VsphereVmFind < Chef::Knife::BaseVsphereCommand
17
+ banner 'knife vsphere vm find'
18
+
19
+ common_options
20
+
21
+ option :pool,
22
+ long: '--pool pool',
23
+ short: '-h',
24
+ description: 'Target pool'
25
+
26
+ option :esx_disk,
27
+ long: '--esx-disk',
28
+ description: 'Show esx disks'
29
+
30
+ option :snapshots,
31
+ long: '--snapshots',
32
+ description: 'Show snapshots'
33
+
34
+ option :os_disk,
35
+ long: '--os-disks',
36
+ description: 'Show os disks'
37
+
38
+ option :cpu,
39
+ long: '--cpu',
40
+ description: 'Show cpu'
41
+
42
+ option :ram,
43
+ long: '--ram',
44
+ description: 'Show ram'
45
+
46
+ option :ip,
47
+ long: '--ip',
48
+ description: 'Show ip'
49
+
50
+ option :soff,
51
+ long: '--powered-off',
52
+ description: 'Show only stopped machines'
53
+
54
+ option :son,
55
+ long: '--powered-on',
56
+ description: 'Show only started machines'
57
+
58
+ option :matchip,
59
+ long: '--match-ip IP',
60
+ description: 'match ip'
61
+
62
+ option :matchos,
63
+ long: '--match-os OS',
64
+ description: 'match os'
65
+
66
+ option :matchname,
67
+ long: '--match-name VMNAME',
68
+ description: 'match name'
69
+
70
+ option :hostname,
71
+ long: '--hostname',
72
+ description: 'show hostname'
73
+
74
+ option :os,
75
+ long: '--os',
76
+ description: 'show os details'
77
+
78
+ option :alarms,
79
+ long: '--alarms',
80
+ description: 'show alarm status'
81
+
82
+ option :tools,
83
+ long: '--tools',
84
+ description: 'show tools status'
85
+
86
+ option :matchtools,
87
+ long: '--match-tools TOOLSSTATE',
88
+ description: 'match tools state'
89
+
90
+ option :full_path,
91
+ long: '--full-path',
92
+ description: 'Show full path'
93
+
94
+ $stdout.sync = true # smoother output from print
95
+
96
+ def traverse_folders_for_pool_clustercompute(folder, poolname)
97
+ # children = folder.children.find_all
98
+ children = find_all_in_folder(folder, RbVmomi::VIM::ManagedObject)
99
+ children.each do |child|
100
+ if child.class == RbVmomi::VIM::ClusterComputeResource || child.class == RbVmomi::VIM::ComputeResource || child.class == RbVmomi::VIM::ResourcePool
101
+ if child.name == poolname then return child
102
+ else if child.class == RbVmomi::VIM::Folder || child.class == RbVmomi::VIM::ComputeResource || child.class == RbVmomi::VIM::ClusterComputeResource || child.class == RbVmomi::VIM::ResourcePool
103
+ pool = traverse_folders_for_pool_clustercompute(child, poolname)
104
+ end
105
+ end
106
+ if pool then return pool end
107
+ end
108
+ end
109
+ return false
110
+ end
111
+
112
+ def run
113
+ poolname = config[:pool]
114
+ if poolname.nil?
115
+ show_usage
116
+ fatal_exit('You must specify a resource pool or cluster name (see knife vsphere pool list)')
117
+ end
118
+
119
+ vim = vim_connection
120
+ dc = datacenter
121
+ folder = dc.hostFolder
122
+
123
+ pool = traverse_folders_for_pool_clustercompute(folder, poolname) or abort "Pool #{poolname} not found"
124
+
125
+ if pool.class == RbVmomi::VIM::ResourcePool
126
+ vm = pool.vm
127
+ else
128
+ vm = pool.resourcePool.vm
129
+ end
130
+
131
+ unless vm.nil?
132
+ vm.each do |vmc|
133
+ state = case vmc.runtime.powerState
134
+ when PsOn
135
+ ui.color('on', :green)
136
+ when PsOff
137
+ ui.color('off', :red)
138
+ when PsSuspended
139
+ ui.color('suspended', :yellow)
140
+ end
141
+
142
+ if get_config(:matchname)
143
+ next unless vmc.name.include? config[:matchname]
144
+ end
145
+
146
+ if get_config(:matchtools)
147
+ next unless vmc.guest.toolsStatus == config[:matchtools]
148
+ end
149
+
150
+ next if get_config(:soff) && (vmc.runtime.powerState == PsOn)
151
+
152
+ next if get_config(:son) && (vmc.runtime.powerState == PsOff)
153
+
154
+ if get_config(:matchip)
155
+ if (!vmc.guest.ipAddress.nil? && vmc.guest.ipAddress != '')
156
+ next unless vmc.guest.ipAddress.include? config[:matchip]
157
+ else
158
+ next
159
+ end
160
+ end
161
+
162
+ unless vmc.guest.guestFullName.nil?
163
+ if get_config(:matchos)
164
+ next unless vmc.guest.guestFullName.include? config[:matchos]
165
+ end
166
+ end
167
+
168
+ print "#{ui.color("VM Name:", :cyan)} #{vmc.name}\t"
169
+ if get_config(:hostname)
170
+ print "#{ui.color("Hostname:", :cyan)} #{vmc.guest.hostName}\t"
171
+ end
172
+
173
+ if get_config(:full_path)
174
+ actualname = ''
175
+ vmcp = vmc
176
+ while vmcp.parent != nil && vmcp.parent.name != 'vm'
177
+ actualname.concat("#{vmcp.parent.name}/")
178
+ vmcp = vmcp.parent
179
+ end
180
+ print "#{ui.color("Folder:", :cyan)}"
181
+ print "\""
182
+ print actualname.split('/').reverse().join('/')
183
+ print "\"\t"
184
+
185
+ else
186
+ print "#{ui.color("Folder", :cyan)}: #{vmc.parent.name}\t"
187
+ end
188
+
189
+ if get_config(:ip)
190
+ print "#{ui.color("IP:", :cyan)} #{vmc.guest.ipAddress}\t"
191
+ end
192
+ if get_config(:os)
193
+ print "#{ui.color("OS:", :cyan)} #{vmc.guest.guestFullName}\t"
194
+ end
195
+ if get_config(:ram)
196
+ print "#{ui.color("RAM:", :cyan)} #{vmc.summary.config.memorySizeMB}\t"
197
+ end
198
+ if get_config(:cpu)
199
+ print "#{ui.color("CPU:", :cyan)} #{vmc.summary.config.numCpu}\t"
200
+ end
201
+ if get_config(:alarms)
202
+ print "#{ui.color("Alarms:", :cyan)} #{vmc.summary.overallStatus}\t"
203
+ end
204
+ print "#{ui.color("State:", :cyan)} #{state}\t"
205
+ if get_config(:tools)
206
+ print "#{ui.color("Tools:", :cyan)} #{vmc.guest.toolsStatus}\t"
207
+ end
208
+
209
+ if get_config(:os_disk)
210
+ print "#{ui.color("OS Disks:", :cyan)}"
211
+ vmc.guest.disk.each do |disc|
212
+ print "#{disc.diskPath} #{disc.capacity / 1024 / 1024}MB Free:#{disc.freeSpace / 1024 / 1024}MB |"
213
+ end
214
+ end
215
+
216
+ if get_config(:esx_disk)
217
+ print "#{ui.color("ESX Disks:", :cyan)}"
218
+ vmc.layout.disk.each do |dsc|
219
+ print "#{dsc.diskFile} | "
220
+ end
221
+ end
222
+
223
+ if get_config(:snapshots)
224
+ unless vmc.snapshot.nil?
225
+ print "#{ui.color("Snapshots:", :cyan)}"
226
+ vmc.snapshot.rootSnapshotList.each do |snap|
227
+ print " #{snap.name}"
228
+ end
229
+ end
230
+ end
231
+ puts
232
+ end
233
+ end
234
+ end
235
+ end
@@ -1,6 +1,3 @@
1
- # Author:: Brian Dupras (<bdupras@rallydev.com>)
2
- # License:: Apache License, Version 2.0
3
-
4
1
  require 'chef/knife'
5
2
  require 'chef/knife/base_vsphere_command'
6
3
  require 'rbvmomi'
@@ -12,37 +9,10 @@ class Chef::Knife::VsphereVmQuery < Chef::Knife::BaseVsphereCommand
12
9
  common_options
13
10
 
14
11
  def run
15
- $stdout.sync = true
16
- vmname = @name_args[0]
17
- if vmname.nil?
18
- show_usage
19
- fatal_exit('You must specify a virtual machine name')
20
- end
21
-
22
- query_string = @name_args[1]
23
- if query_string.nil?
24
- show_usage
25
- fatal_exit('You must specify a QUERY value (e.g. guest.ipAddress or network[0].name)')
26
- end
27
-
28
- vim_connection
29
-
30
- dc = datacenter
31
- folder = find_folder(get_config(:folder)) || dc.vmFolder
32
-
33
- vm = traverse_folders_for_vm(folder, vmname) || abort("VM #{vmname} not found")
34
-
35
- # split QUERY by dots, and walk the object model
36
- query = query_string.split '.'
37
- result = vm
38
- query.each do |part|
39
- message, index = part.split(/[\[\]]/)
40
- unless result.respond_to? message.to_sym
41
- fatal_exit("\"#{query_string}\" not recognized.")
42
- end
43
-
44
- result = index ? result.send(message)[index.to_i] : result.send(message)
45
- end
46
- puts result
12
+ args = ARGV
13
+ args[2] = 'show'
14
+ ui.warn 'vsphere vm query is moving to vsphere vm show. Next time, please run'
15
+ ui.warn args.join " "
16
+ Chef::Knife.run(args)
47
17
  end
48
18
  end
@@ -0,0 +1,48 @@
1
+ # Author:: Brian Dupras (<bdupras@rallydev.com>)
2
+ # License:: Apache License, Version 2.0
3
+
4
+ require 'chef/knife'
5
+ require 'chef/knife/base_vsphere_command'
6
+ require 'rbvmomi'
7
+ require 'netaddr'
8
+
9
+ class Chef::Knife::VsphereVmShow < Chef::Knife::BaseVsphereCommand
10
+ banner "knife vsphere vm show VMNAME QUERY. See \"http://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.VirtualMachine.html\" for allowed QUERY values."
11
+
12
+ common_options
13
+
14
+ def run
15
+ $stdout.sync = true
16
+ vmname = @name_args[0]
17
+ if vmname.nil?
18
+ show_usage
19
+ fatal_exit('You must specify a virtual machine name')
20
+ end
21
+
22
+ query_string = @name_args[1]
23
+ if query_string.nil?
24
+ show_usage
25
+ fatal_exit('You must specify a QUERY value (e.g. guest.ipAddress or network[0].name)')
26
+ end
27
+
28
+ vim_connection
29
+
30
+ dc = datacenter
31
+ folder = find_folder(get_config(:folder)) || dc.vmFolder
32
+
33
+ vm = traverse_folders_for_vm(folder, vmname) || abort("VM #{vmname} not found")
34
+
35
+ # split QUERY by dots, and walk the object model
36
+ query = query_string.split '.'
37
+ result = vm
38
+ query.each do |part|
39
+ message, index = part.split(/[\[\]]/)
40
+ unless result.respond_to? message.to_sym
41
+ fatal_exit("\"#{query_string}\" not recognized.")
42
+ end
43
+
44
+ result = index ? result.send(message)[index.to_i] : result.send(message)
45
+ end
46
+ puts result
47
+ end
48
+ end
@@ -39,6 +39,12 @@ class Chef::Knife::VsphereVmSnapshot < Chef::Knife::BaseVsphereCommand
39
39
  description: 'Indicates whether to start the VM after a successful revert',
40
40
  boolean: false
41
41
 
42
+ option :wait,
43
+ long: '--wait',
44
+ description: 'Indicates whether to wait for creation/removal to complete',
45
+ boolean: false
46
+
47
+
42
48
  def run
43
49
  $stdout.sync = true
44
50
 
@@ -67,14 +73,18 @@ class Chef::Knife::VsphereVmSnapshot < Chef::Knife::BaseVsphereCommand
67
73
  end
68
74
 
69
75
  if config[:create_new_snapshot]
70
- vm.CreateSnapshot_Task(name: config[:create_new_snapshot], description: '', memory: false, quiesce: false)
76
+ snapshot_task=vm.CreateSnapshot_Task(name: config[:create_new_snapshot], description: '', memory: false, quiesce: false)
77
+ snapshot_task=snapshot_task.wait_for_completion if config[:wait]
78
+ snapshot_task
71
79
  end
72
80
 
73
81
  if config[:remove_named_snapshot]
74
82
  ss_name = config[:remove_named_snapshot]
75
83
  snapshot = find_node(snapshot_list, ss_name)
76
84
  puts "Found snapshot #{ss_name} removing."
77
- snapshot.RemoveSnapshot_Task(removeChildren: false)
85
+ snapshot_task=snapshot.RemoveSnapshot_Task(removeChildren: false)
86
+ snapshot_task=snapshot_task.wait_for_completion if config[:wait]
87
+ snapshot_task
78
88
  end
79
89
 
80
90
  if config[:revert_current_snapshot]
@@ -1,3 +1,3 @@
1
1
  module KnifeVsphere
2
- VERSION = '1.2.4'
2
+ VERSION = '1.2.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-vsphere
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Pagel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-02 00:00:00.000000000 Z
11
+ date: 2015-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: netaddr
@@ -86,6 +86,7 @@ files:
86
86
  - lib/chef/knife/vsphere_hosts_list.rb
87
87
  - lib/chef/knife/vsphere_pool_list.rb
88
88
  - lib/chef/knife/vsphere_pool_query.rb
89
+ - lib/chef/knife/vsphere_pool_show.rb
89
90
  - lib/chef/knife/vsphere_template_list.rb
90
91
  - lib/chef/knife/vsphere_vlan_create.rb
91
92
  - lib/chef/knife/vsphere_vlan_list.rb
@@ -94,6 +95,7 @@ files:
94
95
  - lib/chef/knife/vsphere_vm_config.rb
95
96
  - lib/chef/knife/vsphere_vm_delete.rb
96
97
  - lib/chef/knife/vsphere_vm_execute.rb
98
+ - lib/chef/knife/vsphere_vm_find.rb
97
99
  - lib/chef/knife/vsphere_vm_list.rb
98
100
  - lib/chef/knife/vsphere_vm_markastemplate.rb
99
101
  - lib/chef/knife/vsphere_vm_migrate.rb
@@ -102,6 +104,7 @@ files:
102
104
  - lib/chef/knife/vsphere_vm_property_get.rb
103
105
  - lib/chef/knife/vsphere_vm_property_set.rb
104
106
  - lib/chef/knife/vsphere_vm_query.rb
107
+ - lib/chef/knife/vsphere_vm_show.rb
105
108
  - lib/chef/knife/vsphere_vm_snapshot.rb
106
109
  - lib/chef/knife/vsphere_vm_state.rb
107
110
  - lib/chef/knife/vsphere_vm_toolsconfig.rb