knife-vsphere 2.0.4 → 2.0.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 +4 -4
- data/lib/chef/knife/base_vsphere_command.rb +0 -38
- data/lib/chef/knife/search_helper.rb +12 -6
- data/lib/chef/knife/vsphere_template_list.rb +7 -5
- data/lib/chef/knife/vsphere_vm_cdrom.rb +3 -16
- data/lib/chef/knife/vsphere_vm_config.rb +1 -1
- data/lib/chef/knife/vsphere_vm_delete.rb +3 -5
- data/lib/chef/knife/vsphere_vm_disk_extend.rb +3 -4
- data/lib/chef/knife/vsphere_vm_disk_list.rb +1 -1
- data/lib/chef/knife/vsphere_vm_markastemplate.rb +3 -15
- data/lib/chef/knife/vsphere_vm_migrate.rb +4 -6
- data/lib/chef/knife/vsphere_vm_move.rb +3 -6
- data/lib/chef/knife/vsphere_vm_net.rb +5 -5
- data/lib/chef/knife/vsphere_vm_network_add.rb +3 -5
- data/lib/chef/knife/vsphere_vm_network_delete.rb +3 -4
- data/lib/chef/knife/vsphere_vm_network_list.rb +5 -6
- data/lib/chef/knife/vsphere_vm_network_set.rb +3 -1
- data/lib/chef/knife/vsphere_vm_property_get.rb +3 -8
- data/lib/chef/knife/vsphere_vm_property_set.rb +1 -1
- data/lib/chef/knife/vsphere_vm_query.rb +0 -2
- data/lib/chef/knife/vsphere_vm_show.rb +3 -6
- data/lib/chef/knife/vsphere_vm_snapshot.rb +1 -3
- data/lib/chef/knife/vsphere_vm_toolsconfig.rb +3 -8
- data/lib/chef/knife/vsphere_vm_vmdk_add.rb +4 -1
- data/lib/chef/knife/vsphere_vm_vnc_set.rb +3 -8
- data/lib/chef/knife/vsphere_vm_wait_sysprep.rb +3 -4
- data/lib/knife-vsphere/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb16b64d53791bd6e96ba472a5567de9c8f16cf2
|
4
|
+
data.tar.gz: 6da5cf9fe415bba0e43e48ecf6b70e084152dde1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29a121097a149a4f65a477e25e81a8a5050f30211a34819453bd9ee40f919b5173c6fd42f96ffc23804c5530e1ec79a18f8453eac427e3146d4b6db654fd586c
|
7
|
+
data.tar.gz: 54c0d812429c81c78961c7e3cdda47c713fa175e53304289831c1fb8105f5132a7bcdb7a57e4648519d53daae996812c556c2b944c3c7ea6d7e7b72726d2b069
|
@@ -126,31 +126,6 @@ class Chef
|
|
126
126
|
@password ||= ui.ask('Enter your password: ') { |q| q.echo = false }
|
127
127
|
end
|
128
128
|
|
129
|
-
def get_vm(vmname)
|
130
|
-
vim_connection
|
131
|
-
base_folder = find_folder(get_config(:folder))
|
132
|
-
traverse_folders_for_vm(base_folder, vmname)
|
133
|
-
end
|
134
|
-
|
135
|
-
def get_vms(vmname)
|
136
|
-
vim_connection
|
137
|
-
base_folder = find_folder(get_config(:folder))
|
138
|
-
traverse_folders_for_vms(base_folder, vmname)
|
139
|
-
end
|
140
|
-
|
141
|
-
def traverse_folders_for_vm(folder, vmname)
|
142
|
-
children = folder.children.find_all
|
143
|
-
children.each do |child|
|
144
|
-
if child.class == RbVmomi::VIM::VirtualMachine && child.name == vmname
|
145
|
-
return child
|
146
|
-
elsif child.class == RbVmomi::VIM::Folder
|
147
|
-
vm = traverse_folders_for_vm(child, vmname)
|
148
|
-
return vm if vm
|
149
|
-
end
|
150
|
-
end
|
151
|
-
false
|
152
|
-
end
|
153
|
-
|
154
129
|
def traverse_folders_for_pools(folder)
|
155
130
|
retval = []
|
156
131
|
children = folder.children.find_all
|
@@ -177,19 +152,6 @@ class Chef
|
|
177
152
|
retval
|
178
153
|
end
|
179
154
|
|
180
|
-
def traverse_folders_for_vms(folder, vmname)
|
181
|
-
retval = []
|
182
|
-
children = folder.children.find_all
|
183
|
-
children.each do |child|
|
184
|
-
if child.class == RbVmomi::VIM::VirtualMachine && child.name == vmname
|
185
|
-
retval << child
|
186
|
-
elsif child.class == RbVmomi::VIM::Folder
|
187
|
-
retval.concat(traverse_folders_for_vms(child, vmname))
|
188
|
-
end
|
189
|
-
end
|
190
|
-
retval
|
191
|
-
end
|
192
|
-
|
193
155
|
def traverse_folders_for_dc(folder, dcname)
|
194
156
|
children = folder.children.find_all
|
195
157
|
children.each do |child|
|
@@ -6,14 +6,20 @@ module SearchHelper
|
|
6
6
|
# and `#obj` will return the actual object (but make a call to the server)
|
7
7
|
# param [Array<String>] properties to retrieve
|
8
8
|
# @return [Array<RbVmomi::VIM::ObjectContent>]
|
9
|
-
def get_all_vm_objects(
|
9
|
+
def get_all_vm_objects(opts = {})
|
10
10
|
pc = vim_connection.serviceInstance.content.propertyCollector
|
11
11
|
viewmgr = vim_connection.serviceInstance.content.viewManager
|
12
|
-
|
13
|
-
|
12
|
+
folder = if opts[:folder]
|
13
|
+
find_folder(opts[:folder])
|
14
|
+
else
|
15
|
+
vim_connection.serviceInstance.content.rootFolder
|
16
|
+
end
|
17
|
+
vmview = viewmgr.CreateContainerView(container: folder,
|
14
18
|
type: ['VirtualMachine'],
|
15
19
|
recursive: true)
|
16
20
|
|
21
|
+
opts[:properties] ||= ['name']
|
22
|
+
|
17
23
|
filter_spec = RbVmomi::VIM.PropertyFilterSpec(
|
18
24
|
objectSet: [
|
19
25
|
obj: vmview,
|
@@ -28,14 +34,14 @@ module SearchHelper
|
|
28
34
|
]
|
29
35
|
],
|
30
36
|
propSet: [
|
31
|
-
{ type: 'VirtualMachine', pathSet: properties }
|
37
|
+
{ type: 'VirtualMachine', pathSet: opts[:properties] }
|
32
38
|
]
|
33
39
|
)
|
34
40
|
pc.RetrieveProperties(specSet: [filter_spec])
|
35
41
|
end
|
36
42
|
|
37
|
-
def get_vm_by_name(vmname)
|
38
|
-
vm = get_all_vm_objects.detect { |r| r['name'] == vmname }
|
43
|
+
def get_vm_by_name(vmname, folder = nil)
|
44
|
+
vm = get_all_vm_objects(folder: folder).detect { |r| r['name'] == vmname }
|
39
45
|
vm ? vm.obj : nil
|
40
46
|
end
|
41
47
|
end
|
@@ -5,10 +5,12 @@
|
|
5
5
|
|
6
6
|
require 'chef/knife'
|
7
7
|
require 'chef/knife/base_vsphere_command'
|
8
|
+
require 'chef/knife/search_helper'
|
8
9
|
|
9
10
|
# Lists all known VM templates in the configured datacenter
|
10
11
|
# VsphereTemplatelist extends the BaseVspherecommand
|
11
12
|
class Chef::Knife::VsphereTemplateList < Chef::Knife::BaseVsphereCommand
|
13
|
+
include SearchHelper
|
12
14
|
banner 'knife vsphere template list'
|
13
15
|
|
14
16
|
common_options
|
@@ -21,13 +23,13 @@ class Chef::Knife::VsphereTemplateList < Chef::Knife::BaseVsphereCommand
|
|
21
23
|
|
22
24
|
vim_connection
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
vms = get_all_vm_objects(
|
27
|
+
folder: get_config(:folder),
|
28
|
+
properties: ['name', 'config.template']
|
29
|
+
).select { |vm| vm['config.template'] == true }
|
28
30
|
|
29
31
|
vm_list = vms.map do |vm|
|
30
|
-
{ 'Template Name' => vm
|
32
|
+
{ 'Template Name' => vm['name'] }
|
31
33
|
end
|
32
34
|
|
33
35
|
ui.output(vm_list)
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'chef/knife'
|
4
4
|
require 'chef/knife/base_vsphere_command'
|
5
|
-
require '
|
6
|
-
require 'netaddr'
|
5
|
+
require 'chef/knife/search_helper'
|
7
6
|
|
8
7
|
# VsphereVmCdrom extends the BaseVspherecommand
|
9
8
|
class Chef::Knife::VsphereVmCdrom < Chef::Knife::BaseVsphereCommand
|
9
|
+
include SearchHelper
|
10
10
|
banner 'knife vsphere vm cdrom VMNAME (options)'
|
11
11
|
|
12
12
|
# The empty device name.
|
@@ -64,20 +64,7 @@ class Chef::Knife::VsphereVmCdrom < Chef::Knife::BaseVsphereCommand
|
|
64
64
|
fatal_exit 'You must specify the name and path of an ISO with --iso' if get_config(:attach) && !get_config(:iso)
|
65
65
|
fatal_exit 'You must specify the datastore containing the ISO with --datastore' if get_config(:attach) && !get_config(:datastore)
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
if get_config(:recursive)
|
70
|
-
vms = get_vms(vmname)
|
71
|
-
if vms.length > 1
|
72
|
-
fatal_exit "More than one VM with name #{vmname} found:\n" + vms.map { |vm| get_path_to_object(vm) }.join("\n")
|
73
|
-
end
|
74
|
-
fatal_exit "VM #{vmname} not found" if vms.empty?
|
75
|
-
vm = vms[0]
|
76
|
-
else
|
77
|
-
base_folder = find_folder(get_config(:folder))
|
78
|
-
|
79
|
-
vm = find_in_folder(base_folder, RbVmomi::VIM::VirtualMachine, vmname) || fatal_exit("VM #{vmname} not found")
|
80
|
-
end
|
67
|
+
vm = get_vm_by_name(vmname, config[:folder]) || fatal_exit("Could not find #{vmname}")
|
81
68
|
|
82
69
|
cdrom_obj = vm.config.hardware.device.find { |hw| hw.class == RbVmomi::VIM::VirtualCdrom }
|
83
70
|
fatal_exit 'Could not find a cd drive' unless cdrom_obj
|
@@ -39,7 +39,7 @@ class Chef::Knife::VsphereVmConfig < Chef::Knife::BaseVsphereCommand
|
|
39
39
|
|
40
40
|
vim_connection
|
41
41
|
|
42
|
-
vm = get_vm_by_name(vmname) || fatal_exit("Could not find #{vmname}")
|
42
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
43
43
|
|
44
44
|
properties = {}
|
45
45
|
properties[property_name] = property_value
|
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
require 'chef/knife'
|
7
7
|
require 'chef/knife/base_vsphere_command'
|
8
|
+
require 'chef/knife/search_helper'
|
8
9
|
require 'rbvmomi'
|
9
10
|
|
10
11
|
# These two are needed for the '--purge' deletion case
|
@@ -14,6 +15,7 @@ require 'chef/api_client'
|
|
14
15
|
# Delete a virtual machine from vCenter
|
15
16
|
# VsphereVmDelete extends the BaseVspherecommand
|
16
17
|
class Chef::Knife::VsphereVmDelete < Chef::Knife::BaseVsphereCommand
|
18
|
+
include SearchHelper
|
17
19
|
banner 'knife vsphere vm delete VMNAME (options)'
|
18
20
|
|
19
21
|
option :purge,
|
@@ -56,11 +58,7 @@ class Chef::Knife::VsphereVmDelete < Chef::Knife::BaseVsphereCommand
|
|
56
58
|
fatal_exit('You must specify a virtual machine name')
|
57
59
|
end
|
58
60
|
|
59
|
-
|
60
|
-
|
61
|
-
base_folder = find_folder(get_config(:folder))
|
62
|
-
|
63
|
-
vm = traverse_folders_for_vm(base_folder, vmname) || fatal_exit("VM #{vmname} not found")
|
61
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
64
62
|
|
65
63
|
vm.PowerOffVM_Task.wait_for_completion unless vm.runtime.powerState == 'poweredOff'
|
66
64
|
vm.Destroy_Task.wait_for_completion
|
@@ -5,9 +5,10 @@
|
|
5
5
|
|
6
6
|
require 'chef/knife'
|
7
7
|
require 'chef/knife/base_vsphere_command'
|
8
|
-
require '
|
8
|
+
require 'chef/knife/search_helper'
|
9
9
|
|
10
10
|
class Chef::Knife::VsphereVmDiskExtend < Chef::Knife::BaseVsphereCommand
|
11
|
+
include SearchHelper
|
11
12
|
banner 'knife vsphere vm disk extend VMNAME SIZE. Extends the disk of vm VMNAME to SIZE kilobytes.'
|
12
13
|
|
13
14
|
common_options
|
@@ -36,9 +37,7 @@ class Chef::Knife::VsphereVmDiskExtend < Chef::Knife::BaseVsphereCommand
|
|
36
37
|
|
37
38
|
dc = datacenter
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) || abort("VM #{vmname} not found")
|
40
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
42
41
|
|
43
42
|
disks = vm.config.hardware.device.select do |device|
|
44
43
|
device.is_a?(RbVmomi::VIM::VirtualDisk) && (disk_name.nil? || device.deviceInfo.label == disk_name)
|
@@ -21,7 +21,7 @@ class Chef::Knife::VsphereVmDiskList < Chef::Knife::BaseVsphereCommand
|
|
21
21
|
fatal_exit 'You must specify a virtual machine name'
|
22
22
|
end
|
23
23
|
|
24
|
-
vm = get_vm_by_name(vmname) || fatal_exit("Could not find #{vmname}")
|
24
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
25
25
|
|
26
26
|
disks = vm.config.hardware.device.select do |device|
|
27
27
|
device.is_a? RbVmomi::VIM::VirtualDisk
|
@@ -8,22 +8,18 @@
|
|
8
8
|
|
9
9
|
require 'chef/knife'
|
10
10
|
require 'chef/knife/base_vsphere_command'
|
11
|
-
require '
|
11
|
+
require 'chef/knife/search_helper'
|
12
12
|
|
13
13
|
# Clone an existing template into a new VM, optionally applying a customization specification.
|
14
14
|
# usage:
|
15
15
|
# knife vsphere vm markastemplate MyVM --folder /templates
|
16
16
|
# Vspherevmmarkastemplate extends the Basevspherecommand
|
17
17
|
class Chef::Knife::VsphereVmMarkastemplate < Chef::Knife::BaseVsphereCommand
|
18
|
+
include SearchHelper
|
18
19
|
banner 'knife vsphere vm markastemplate VMNAME'
|
19
20
|
|
20
21
|
common_options
|
21
22
|
|
22
|
-
option :folder,
|
23
|
-
long: '--folder FOLDER',
|
24
|
-
description: 'The folder which contains the VM',
|
25
|
-
default: ''
|
26
|
-
|
27
23
|
# The main run method for vm_markastemplate
|
28
24
|
#
|
29
25
|
def run
|
@@ -34,16 +30,8 @@ class Chef::Knife::VsphereVmMarkastemplate < Chef::Knife::BaseVsphereCommand
|
|
34
30
|
show_usage
|
35
31
|
fatal_exit('You must specify a virtual machine name')
|
36
32
|
end
|
37
|
-
config[:chef_node_name] = vmname unless config[:chef_node_name]
|
38
|
-
config[:vmname] = vmname
|
39
|
-
|
40
|
-
vim_connection
|
41
|
-
|
42
|
-
dc = datacenter
|
43
|
-
|
44
|
-
src_folder = find_folder(get_config(:folder)) || dc.vmFolder
|
45
33
|
|
46
|
-
vm =
|
34
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
47
35
|
|
48
36
|
puts "Marking VM #{vmname} as template"
|
49
37
|
vm.MarkAsTemplate()
|
@@ -4,9 +4,11 @@
|
|
4
4
|
#
|
5
5
|
require 'chef/knife'
|
6
6
|
require 'chef/knife/base_vsphere_command'
|
7
|
+
require 'chef/knife/search_helper'
|
7
8
|
|
8
9
|
# migrate vm to specified resource pool , datastore and host
|
9
10
|
class Chef::Knife::VsphereVmMigrate < Chef::Knife::BaseVsphereCommand
|
11
|
+
include SearchHelper
|
10
12
|
# migrate --resource-pool --dest-host --dest-datastore
|
11
13
|
banner 'knife vsphere vm migrate (options)'
|
12
14
|
|
@@ -45,17 +47,13 @@ class Chef::Knife::VsphereVmMigrate < Chef::Knife::BaseVsphereCommand
|
|
45
47
|
fatal_exit('You must specify a virtual machine name')
|
46
48
|
end
|
47
49
|
|
48
|
-
|
49
|
-
dc = datacenter
|
50
|
-
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
51
|
-
|
52
|
-
vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) || abort("VM #{vmname} not found")
|
50
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
53
51
|
|
54
52
|
priority = config[:priority]
|
55
53
|
dest_host = config[:dest_host]
|
56
54
|
ndc = find_datastore(config[:dest_datastore]) || abort('dest-datastore not found')
|
57
55
|
pool = find_pool(config[:resource_pool]) if config[:resource_pool]
|
58
|
-
dest_host = find_host_folder(
|
56
|
+
dest_host = find_host_folder(datacenter.hostFolder, dest_host)
|
59
57
|
migrate_spec = RbVmomi::VIM.VirtualMachineRelocateSpec(datastore: ndc, pool: pool, host: dest_host)
|
60
58
|
vm.RelocateVM_Task(spec: migrate_spec, priority: priority).wait_for_completion
|
61
59
|
end
|
@@ -4,10 +4,12 @@
|
|
4
4
|
#
|
5
5
|
require 'chef/knife'
|
6
6
|
require 'chef/knife/base_vsphere_command'
|
7
|
+
require 'chef/knife/search_helper'
|
7
8
|
|
8
9
|
# Lists all known virtual machines in the configured datacenter
|
9
10
|
# VsphereVmMove extends the BaseVspherecommand
|
10
11
|
class Chef::Knife::VsphereVmMove < Chef::Knife::BaseVsphereCommand
|
12
|
+
include SearchHelper
|
11
13
|
banner 'knife vsphere vm move'
|
12
14
|
|
13
15
|
common_options
|
@@ -79,12 +81,7 @@ class Chef::Knife::VsphereVmMove < Chef::Knife::BaseVsphereCommand
|
|
79
81
|
fatal_exit('You must specify a virtual machine name')
|
80
82
|
end
|
81
83
|
|
82
|
-
|
83
|
-
dcname = get_config(:vsphere_dc)
|
84
|
-
dc = vim.serviceInstance.find_datacenter(dcname) || abort('datacenter not found')
|
85
|
-
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
86
|
-
|
87
|
-
vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) || abort("VM #{vmname} not found")
|
84
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
88
85
|
|
89
86
|
if get_config(:thin_provision) || get_config(:thick_provision)
|
90
87
|
convert_vm(vm)
|
@@ -4,10 +4,12 @@
|
|
4
4
|
#
|
5
5
|
require 'chef/knife'
|
6
6
|
require 'chef/knife/base_vsphere_command'
|
7
|
+
require 'chef/knife/search_helper'
|
7
8
|
|
8
9
|
# Switch VM networking state up/down (on all network interfaces)
|
9
10
|
# VsphereVmNet extends the BaseVspherecommand
|
10
11
|
class Chef::Knife::VsphereVmNet < Chef::Knife::BaseVsphereCommand
|
12
|
+
include SearchHelper
|
11
13
|
banner 'knife vsphere vm net STATE VMNAME'
|
12
14
|
common_options
|
13
15
|
|
@@ -32,11 +34,9 @@ class Chef::Knife::VsphereVmNet < Chef::Knife::BaseVsphereCommand
|
|
32
34
|
elsif state == 'down'
|
33
35
|
if_state = false
|
34
36
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) ||
|
39
|
-
abort("VM #{vmname} not found")
|
37
|
+
|
38
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
39
|
+
|
40
40
|
vm.config.hardware.device.each.grep(RbVmomi::VIM::VirtualEthernetCard) do |a|
|
41
41
|
backing = a.backing
|
42
42
|
key = a.key
|
@@ -4,10 +4,11 @@
|
|
4
4
|
#
|
5
5
|
require 'chef/knife'
|
6
6
|
require 'chef/knife/base_vsphere_command'
|
7
|
-
require '
|
7
|
+
require 'chef/knife/search_helper'
|
8
8
|
require 'netaddr'
|
9
9
|
|
10
10
|
class Chef::Knife::VsphereVmNetworkAdd < Chef::Knife::BaseVsphereCommand
|
11
|
+
include SearchHelper
|
11
12
|
banner 'knife vsphere vm network add VMNAME NETWORKNAME'
|
12
13
|
|
13
14
|
option :adapter_type,
|
@@ -37,11 +38,8 @@ class Chef::Knife::VsphereVmNetworkAdd < Chef::Knife::BaseVsphereCommand
|
|
37
38
|
fatal_exit('You must specify the network name')
|
38
39
|
end
|
39
40
|
|
40
|
-
vim_connection
|
41
41
|
|
42
|
-
|
43
|
-
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
44
|
-
vm = traverse_folders_for_vm(folder, vmname) || abort("VM #{vmname} not found")
|
42
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
45
43
|
|
46
44
|
network = find_network(networkname)
|
47
45
|
|
@@ -4,10 +4,10 @@
|
|
4
4
|
#
|
5
5
|
require 'chef/knife'
|
6
6
|
require 'chef/knife/base_vsphere_command'
|
7
|
-
require '
|
8
|
-
require 'netaddr'
|
7
|
+
require 'chef/knife/search_helper'
|
9
8
|
|
10
9
|
class Chef::Knife::VsphereVmNetworkDelete < Chef::Knife::BaseVsphereCommand
|
10
|
+
include SearchHelper
|
11
11
|
banner 'knife vsphere vm network delete VMNAME NICNAME'
|
12
12
|
|
13
13
|
common_options
|
@@ -27,8 +27,7 @@ class Chef::Knife::VsphereVmNetworkDelete < Chef::Knife::BaseVsphereCommand
|
|
27
27
|
fatal_exit('You must specify the name of the NIC to delete')
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
vm = get_vm(vmname) || abort('VM not found')
|
30
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
32
31
|
|
33
32
|
cards = vm.config.hardware.device.grep(RbVmomi::VIM::VirtualEthernetCard)
|
34
33
|
card = cards.detect { |c| c.deviceInfo.label == nicname }
|
@@ -4,11 +4,11 @@
|
|
4
4
|
#
|
5
5
|
require 'chef/knife'
|
6
6
|
require 'chef/knife/base_vsphere_command'
|
7
|
-
require '
|
8
|
-
require 'netaddr'
|
7
|
+
require 'chef/knife/search_helper'
|
9
8
|
|
10
9
|
# VsphereVmNetworklist extends the BaseVspherecommand
|
11
10
|
class Chef::Knife::VsphereVmNetworkList < Chef::Knife::BaseVsphereCommand
|
11
|
+
include SearchHelper
|
12
12
|
banner 'knife vsphere vm network list VMNAME'
|
13
13
|
|
14
14
|
common_options
|
@@ -24,15 +24,14 @@ class Chef::Knife::VsphereVmNetworkList < Chef::Knife::BaseVsphereCommand
|
|
24
24
|
fatal_exit('You must specify a virtual machine name')
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
28
28
|
dc = datacenter
|
29
|
-
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
30
|
-
vm = traverse_folders_for_vm(folder, vmname) || abort("VM #{vmname} not found")
|
31
29
|
|
32
30
|
vm.config.hardware.device.each.grep(RbVmomi::VIM::VirtualEthernetCard).map do |nic|
|
33
|
-
dc.network.
|
31
|
+
dc.network.grep(RbVmomi::VIM::DistributedVirtualPortgroup) do |net|
|
34
32
|
if nic.backing.port.portgroupKey.eql?(net.key)
|
35
33
|
puts "NIC: #{nic.deviceInfo.label} VLAN: #{net.name}"
|
34
|
+
break
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
@@ -4,10 +4,12 @@
|
|
4
4
|
#
|
5
5
|
require 'chef/knife'
|
6
6
|
require 'chef/knife/base_vsphere_command'
|
7
|
+
require 'chef/knife/search_helper'
|
7
8
|
|
8
9
|
# Changes network on a certain VM
|
9
10
|
# VsphereVmNetworkSet extends the BaseVspherecommand
|
10
11
|
class Chef::Knife::VsphereVmNetworkSet < Chef::Knife::BaseVsphereCommand
|
12
|
+
include SearchHelper
|
11
13
|
banner 'knife vsphere vm network set VMNAME NETWORKNAME'
|
12
14
|
|
13
15
|
common_options
|
@@ -33,7 +35,7 @@ class Chef::Knife::VsphereVmNetworkSet < Chef::Knife::BaseVsphereCommand
|
|
33
35
|
end
|
34
36
|
|
35
37
|
network = find_network(networkname)
|
36
|
-
vm =
|
38
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
37
39
|
nic = vm.config.hardware.device.each.grep(RbVmomi::VIM::VirtualEthernetCard)[Integer(get_config(:nic))]
|
38
40
|
if network.is_a? RbVmomi::VIM::DistributedVirtualPortgroup
|
39
41
|
port = RbVmomi::VIM.DistributedVirtualSwitchPortConnection(switchUuid: network.config.distributedVirtualSwitch.uuid, portgroupKey: network.key)
|
@@ -3,11 +3,11 @@
|
|
3
3
|
|
4
4
|
require 'chef/knife'
|
5
5
|
require 'chef/knife/base_vsphere_command'
|
6
|
-
require '
|
7
|
-
require 'netaddr'
|
6
|
+
require 'chef/knife/search_helper'
|
8
7
|
|
9
8
|
# VsphereVMPropertyget extends the BaseVspherecommand
|
10
9
|
class Chef::Knife::VsphereVmPropertyGet < Chef::Knife::BaseVsphereCommand
|
10
|
+
include SearchHelper
|
11
11
|
banner 'knife vsphere vm property get VMNAME PROPERTY. Gets a vApp Property on VMNAME.'
|
12
12
|
|
13
13
|
common_options
|
@@ -29,12 +29,7 @@ class Chef::Knife::VsphereVmPropertyGet < Chef::Knife::BaseVsphereCommand
|
|
29
29
|
end
|
30
30
|
property_name = property_name.to_sym
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
dc = datacenter
|
35
|
-
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
36
|
-
|
37
|
-
vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) || abort("VM #{vmname} not found")
|
32
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
38
33
|
|
39
34
|
existing_property = vm.config.vAppConfig.property.find { |p| p.props[:id] == property_name.to_s }
|
40
35
|
|
@@ -43,7 +43,7 @@ class Chef::Knife::VsphereVmPropertySet < Chef::Knife::BaseVsphereCommand
|
|
43
43
|
|
44
44
|
dc = datacenter
|
45
45
|
|
46
|
-
vm = get_vm_by_name(vmname) || fatal_exit("Could not find #{vmname}")
|
46
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
47
47
|
|
48
48
|
if vm.config.vAppConfig && vm.config.vAppConfig.property
|
49
49
|
existing_property = vm.config.vAppConfig.property.find { |p| p.props[:id] == property_name.to_s }
|
@@ -3,11 +3,11 @@
|
|
3
3
|
|
4
4
|
require 'chef/knife'
|
5
5
|
require 'chef/knife/base_vsphere_command'
|
6
|
-
require '
|
7
|
-
require 'netaddr'
|
6
|
+
require 'chef/knife/search_helper'
|
8
7
|
|
9
8
|
# VsphereVmShow extends the BaseVspherecommand
|
10
9
|
class Chef::Knife::VsphereVmShow < Chef::Knife::BaseVsphereCommand
|
10
|
+
include SearchHelper
|
11
11
|
banner "knife vsphere vm show VMNAME QUERY. See \"http://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.VirtualMachine.html\" for allowed QUERY values."
|
12
12
|
|
13
13
|
common_options
|
@@ -30,10 +30,7 @@ class Chef::Knife::VsphereVmShow < Chef::Knife::BaseVsphereCommand
|
|
30
30
|
|
31
31
|
vim_connection
|
32
32
|
|
33
|
-
|
34
|
-
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
35
|
-
|
36
|
-
vm = traverse_folders_for_vm(folder, vmname) || abort("VM #{vmname} not found")
|
33
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
37
34
|
|
38
35
|
# split QUERY by dots, and walk the object model
|
39
36
|
query = query_string.split '.'
|
@@ -75,9 +75,7 @@ class Chef::Knife::VsphereVmSnapshot < Chef::Knife::BaseVsphereCommand
|
|
75
75
|
exit 1
|
76
76
|
end
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
vm = get_vm_by_name(vmname) || fatal_exit("Could not find #{vmname}")
|
78
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
81
79
|
|
82
80
|
if vm.snapshot
|
83
81
|
snapshot_list = vm.snapshot.rootSnapshotList
|
@@ -3,11 +3,11 @@
|
|
3
3
|
|
4
4
|
require 'chef/knife'
|
5
5
|
require 'chef/knife/base_vsphere_command'
|
6
|
-
require '
|
7
|
-
require 'netaddr'
|
6
|
+
require 'chef/knife/search_helper'
|
8
7
|
|
9
8
|
# Vspherevmtoolsconfig extends the BaseVspherecommand
|
10
9
|
class Chef::Knife::VsphereVmToolsconfig < Chef::Knife::BaseVsphereCommand
|
10
|
+
include SearchHelper
|
11
11
|
banner "knife vsphere vm toolsconfig PROPERTY VALUE.
|
12
12
|
See \"https://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.vm.ToolsConfigInfo.html\"
|
13
13
|
for available properties and types."
|
@@ -42,12 +42,7 @@ class Chef::Knife::VsphereVmToolsconfig < Chef::Knife::BaseVsphereCommand
|
|
42
42
|
|
43
43
|
value = '' if get_config(:empty)
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
dc = datacenter
|
48
|
-
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
49
|
-
|
50
|
-
vm = traverse_folders_for_vm(folder, vmname) || abort("VM #{vmname} not found")
|
45
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
51
46
|
|
52
47
|
vm_config_spec = RbVmomi::VIM.VirtualMachineConfigSpec(tools: RbVmomi::VIM.ToolsConfigInfo(property => value))
|
53
48
|
vm.ReconfigVM_Task(spec: vm_config_spec)
|
@@ -4,10 +4,12 @@
|
|
4
4
|
#
|
5
5
|
require 'chef/knife'
|
6
6
|
require 'chef/knife/base_vsphere_command'
|
7
|
+
require 'chef/knife/search_helper'
|
7
8
|
|
8
9
|
# Add a new disk to a virtual machine
|
9
10
|
# VsphereVmvmdkadd extends the BaseVspherecommand
|
10
11
|
class Chef::Knife::VsphereVmVmdkAdd < Chef::Knife::BaseVsphereCommand
|
12
|
+
include SearchHelper
|
11
13
|
banner 'knife vsphere vm vmdk add VMNAME DISK_GB'
|
12
14
|
|
13
15
|
common_options
|
@@ -43,7 +45,8 @@ class Chef::Knife::VsphereVmVmdkAdd < Chef::Knife::BaseVsphereCommand
|
|
43
45
|
|
44
46
|
vim = vim_connection
|
45
47
|
vdm = vim.serviceContent.virtualDiskManager
|
46
|
-
vm =
|
48
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
49
|
+
|
47
50
|
fatal_exit "Could not find #{vmname}" unless vm
|
48
51
|
|
49
52
|
target_lun = get_config(:target_lun) unless get_config(:target_lun).nil?
|
@@ -4,11 +4,11 @@
|
|
4
4
|
#
|
5
5
|
require 'chef/knife'
|
6
6
|
require 'chef/knife/base_vsphere_command'
|
7
|
-
require '
|
8
|
-
require 'netaddr'
|
7
|
+
require 'chef/knife/search_helper'
|
9
8
|
|
10
9
|
# Main class VsphereVMvncset extends the BaseVspherecommand
|
11
10
|
class Chef::Knife::VsphereVmVncset < Chef::Knife::BaseVsphereCommand
|
11
|
+
include SearchHelper
|
12
12
|
banner 'knife vsphere vm vncset VMNAME COMMAND ARGS'
|
13
13
|
|
14
14
|
option :vnc_port,
|
@@ -33,12 +33,7 @@ class Chef::Knife::VsphereVmVncset < Chef::Knife::BaseVsphereCommand
|
|
33
33
|
fatal_exit('You must specify a virtual machine name')
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
dc = datacenter
|
39
|
-
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
40
|
-
|
41
|
-
vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) || abort("VM #{vmname} not found")
|
36
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
42
37
|
|
43
38
|
extra_config, = vm.collect('config.extraConfig')
|
44
39
|
|
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
require 'chef/knife'
|
8
8
|
require 'chef/knife/base_vsphere_command'
|
9
|
-
require '
|
9
|
+
require 'chef/knife/search_helper'
|
10
10
|
require 'chef/knife/customization_helper'
|
11
11
|
|
12
12
|
# Wait for vm finishing Sysprep.
|
@@ -14,6 +14,7 @@ require 'chef/knife/customization_helper'
|
|
14
14
|
# knife vsphere vm wait sysprep somemachine --sleep 30 \
|
15
15
|
# --timeout 600
|
16
16
|
class Chef::Knife::VsphereVmWaitSysprep < Chef::Knife::BaseVsphereCommand
|
17
|
+
include SearchHelper
|
17
18
|
include CustomizationHelper
|
18
19
|
|
19
20
|
banner 'knife vsphere vm wait sysprep VMNAME (options)'
|
@@ -47,10 +48,8 @@ class Chef::Knife::VsphereVmWaitSysprep < Chef::Knife::BaseVsphereCommand
|
|
47
48
|
sleep_timeout = get_config(:timeout).to_i
|
48
49
|
|
49
50
|
vim = vim_connection
|
50
|
-
|
51
|
+
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
51
52
|
|
52
|
-
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
53
|
-
vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) || abort("VM could not be found in #{folder}")
|
54
53
|
|
55
54
|
CustomizationHelper.wait_for_sysprep(vm, vim, sleep_timeout, sleep_time)
|
56
55
|
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: 2.0.
|
4
|
+
version: 2.0.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: 2018-03-
|
11
|
+
date: 2018-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: knife-windows
|
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
237
|
version: '0'
|
238
238
|
requirements: []
|
239
239
|
rubyforge_project:
|
240
|
-
rubygems_version: 2.6.
|
240
|
+
rubygems_version: 2.6.14
|
241
241
|
signing_key:
|
242
242
|
specification_version: 4
|
243
243
|
summary: vSphere Support for Knife
|