knife-vsphere 1.0.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,46 +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::VsphereVmConfig < Chef::Knife::BaseVsphereCommand
|
10
|
-
banner "knife vsphere vm config VMNAME PROPERTY VALUE.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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::VsphereVmConfig < Chef::Knife::BaseVsphereCommand
|
10
|
+
banner "knife vsphere vm config VMNAME PROPERTY VALUE.
|
11
|
+
See \"http://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.ConfigSpec.html\"
|
12
|
+
for allowed ATTRIBUTE values (any property of type xs:string is supported)."
|
13
|
+
|
14
|
+
common_options
|
15
|
+
|
16
|
+
def run
|
17
|
+
$stdout.sync = true
|
18
|
+
vmname = @name_args[0]
|
19
|
+
if vmname.nil?
|
20
|
+
show_usage
|
21
|
+
fatal_exit('You must specify a virtual machine name')
|
22
|
+
end
|
23
|
+
|
24
|
+
property_name = @name_args[1]
|
25
|
+
if property_name.nil?
|
26
|
+
show_usage
|
27
|
+
fatal_exit('You must specify a PROPERTY name (e.g. annotation)')
|
28
|
+
end
|
29
|
+
property_name = property_name.to_sym
|
30
|
+
|
31
|
+
property_value = @name_args[2]
|
32
|
+
if property_value.nil?
|
33
|
+
show_usage
|
34
|
+
fatal_exit('You must specify a PROPERTY value')
|
35
|
+
end
|
36
|
+
|
37
|
+
vim_connection
|
38
|
+
|
39
|
+
dc = datacenter
|
40
|
+
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
41
|
+
|
42
|
+
vm = traverse_folders_for_vm(folder, vmname) || abort("VM #{vmname} not found")
|
43
|
+
|
44
|
+
properties = {}
|
45
|
+
properties[property_name] = property_value
|
46
|
+
vm.ReconfigVM_Task(spec: RbVmomi::VIM.VirtualMachineConfigSpec(properties)).wait_for_completion
|
47
|
+
end
|
48
|
+
end
|
@@ -1,66 +1,70 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Ezra Pagel (<ezra@cpan.org>)
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
|
6
|
-
require 'chef/knife'
|
7
|
-
require 'chef/knife/base_vsphere_command'
|
8
|
-
require 'rbvmomi'
|
9
|
-
|
10
|
-
# These two are needed for the '--purge' deletion case
|
11
|
-
require 'chef/node'
|
12
|
-
require 'chef/api_client'
|
13
|
-
|
14
|
-
# Delete a virtual machine from vCenter
|
15
|
-
class Chef::Knife::VsphereVmDelete < Chef::Knife::BaseVsphereCommand
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
#
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
vm
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
1
|
+
#
|
2
|
+
# Author:: Ezra Pagel (<ezra@cpan.org>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
|
6
|
+
require 'chef/knife'
|
7
|
+
require 'chef/knife/base_vsphere_command'
|
8
|
+
require 'rbvmomi'
|
9
|
+
|
10
|
+
# These two are needed for the '--purge' deletion case
|
11
|
+
require 'chef/node'
|
12
|
+
require 'chef/api_client'
|
13
|
+
|
14
|
+
# Delete a virtual machine from vCenter
|
15
|
+
class Chef::Knife::VsphereVmDelete < Chef::Knife::BaseVsphereCommand
|
16
|
+
banner 'knife vsphere vm delete VMNAME (options)'
|
17
|
+
|
18
|
+
option :purge,
|
19
|
+
short: '-P',
|
20
|
+
long: '--purge',
|
21
|
+
boolean: true,
|
22
|
+
description: 'Destroy corresponding node and client on the Chef Server, in addition to destroying the VM itself.'
|
23
|
+
|
24
|
+
option :chef_node_name,
|
25
|
+
short: '-N NAME',
|
26
|
+
long: '--node-name NAME',
|
27
|
+
description: 'Use this option if the Chef node name is different from the VM name'
|
28
|
+
|
29
|
+
common_options
|
30
|
+
|
31
|
+
# Extracted from Chef::Knife.delete_object, because it has a
|
32
|
+
# confirmation step built in... By specifying the '--purge'
|
33
|
+
# flag (and also explicitly confirming the server destruction!)
|
34
|
+
# the user is already making their intent known. It is not
|
35
|
+
# necessary to make them confirm two more times.
|
36
|
+
def destroy_item(itemClass, name, type_name)
|
37
|
+
object = itemClass.load(name)
|
38
|
+
object.destroy
|
39
|
+
puts "Deleted #{type_name} #{name}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def run
|
43
|
+
$stdout.sync = true
|
44
|
+
|
45
|
+
vmname = @name_args[0]
|
46
|
+
|
47
|
+
if vmname.nil?
|
48
|
+
show_usage
|
49
|
+
fatal_exit('You must specify a virtual machine name')
|
50
|
+
end
|
51
|
+
|
52
|
+
vim_connection
|
53
|
+
|
54
|
+
base_folder = find_folder(get_config(:folder))
|
55
|
+
|
56
|
+
vm = traverse_folders_for_vm(base_folder, vmname) || fatal_exit("VM #{vmname} not found")
|
57
|
+
|
58
|
+
vm.PowerOffVM_Task.wait_for_completion unless vm.runtime.powerState == 'poweredOff'
|
59
|
+
vm.Destroy_Task.wait_for_completion
|
60
|
+
puts "Deleted virtual machine #{vmname}"
|
61
|
+
|
62
|
+
if config[:purge]
|
63
|
+
vmname = config[:chef_node_name] if config[:chef_node_name]
|
64
|
+
destroy_item(Chef::Node, vmname, 'node')
|
65
|
+
destroy_item(Chef::ApiClient, vmname, 'client')
|
66
|
+
else
|
67
|
+
puts "Corresponding node and client for the #{vmname} server were not deleted and remain registered with the Chef Server"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -1,66 +1,62 @@
|
|
1
|
-
# Author:: Ian Delahorne (<ian@delahorne.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::VsphereVmExecute < Chef::Knife::BaseVsphereCommand
|
10
|
-
banner
|
11
|
-
|
12
|
-
option :exec_user,
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
|
17
|
-
option :exec_passwd,
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
|
22
|
-
option :exec_dir,
|
23
|
-
:
|
24
|
-
:
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
def run
|
29
|
-
$stdout.sync = true
|
30
|
-
vmname = @name_args[0]
|
31
|
-
if vmname.nil?
|
32
|
-
show_usage
|
33
|
-
fatal_exit(
|
34
|
-
end
|
35
|
-
command = @name_args[1]
|
36
|
-
if command.nil?
|
37
|
-
show_usage
|
38
|
-
fatal_exit(
|
39
|
-
end
|
40
|
-
|
41
|
-
args = @name_args[2]
|
42
|
-
if args.nil?
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
gom.processManager.StartProgramInGuest(:vm => vm, :auth => guest_auth, :spec => prog_spec)
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
1
|
+
# Author:: Ian Delahorne (<ian@delahorne.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::VsphereVmExecute < Chef::Knife::BaseVsphereCommand
|
10
|
+
banner 'knife vsphere vm execute VMNAME COMMAND ARGS'
|
11
|
+
|
12
|
+
option :exec_user,
|
13
|
+
long: '--exec-user USER',
|
14
|
+
description: 'User to execute as',
|
15
|
+
required: true
|
16
|
+
|
17
|
+
option :exec_passwd,
|
18
|
+
long: '--exec-passwd PASSWORD',
|
19
|
+
description: 'Password for execute user',
|
20
|
+
required: true
|
21
|
+
|
22
|
+
option :exec_dir,
|
23
|
+
long: '--exec-dir DIRECTORY',
|
24
|
+
description: 'Working directory to execute in'
|
25
|
+
|
26
|
+
common_options
|
27
|
+
|
28
|
+
def run
|
29
|
+
$stdout.sync = true
|
30
|
+
vmname = @name_args[0]
|
31
|
+
if vmname.nil?
|
32
|
+
show_usage
|
33
|
+
fatal_exit('You must specify a virtual machine name')
|
34
|
+
end
|
35
|
+
command = @name_args[1]
|
36
|
+
if command.nil?
|
37
|
+
show_usage
|
38
|
+
fatal_exit('You must specify a command to execute')
|
39
|
+
end
|
40
|
+
|
41
|
+
args = @name_args[2]
|
42
|
+
args = '' if args.nil?
|
43
|
+
|
44
|
+
vim = vim_connection
|
45
|
+
|
46
|
+
dc = datacenter
|
47
|
+
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
48
|
+
|
49
|
+
vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) || abort("VM #{vmname} not found")
|
50
|
+
|
51
|
+
gom = vim.serviceContent.guestOperationsManager
|
52
|
+
|
53
|
+
guest_auth = RbVmomi::VIM::NamePasswordAuthentication(interactiveSession: false,
|
54
|
+
username: config[:exec_user],
|
55
|
+
password: config[:exec_passwd])
|
56
|
+
prog_spec = RbVmomi::VIM::GuestProgramSpec(programPath: command,
|
57
|
+
arguments: args,
|
58
|
+
workingDirectory: get_config(:exec_dir))
|
59
|
+
|
60
|
+
gom.processManager.StartProgramInGuest(vm: vm, auth: guest_auth, spec: prog_spec)
|
61
|
+
end
|
62
|
+
end
|
@@ -1,61 +1,57 @@
|
|
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 known virtual machines in the configured datacenter
|
9
|
-
class Chef::Knife::VsphereVmList < Chef::Knife::BaseVsphereCommand
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
:
|
17
|
-
:
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
when
|
42
|
-
ui.color(
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
is_top = true
|
59
|
-
traverse_folders(baseFolder, is_top, recurse)
|
60
|
-
end
|
61
|
-
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 known virtual machines in the configured datacenter
|
9
|
+
class Chef::Knife::VsphereVmList < Chef::Knife::BaseVsphereCommand
|
10
|
+
banner 'knife vsphere vm list'
|
11
|
+
|
12
|
+
common_options
|
13
|
+
|
14
|
+
option :recursive,
|
15
|
+
long: '--recursive',
|
16
|
+
short: '-r',
|
17
|
+
description: 'Recurse into sub-folders'
|
18
|
+
|
19
|
+
def traverse_folders(folder, is_top = false, recurse = false)
|
20
|
+
vms = find_all_in_folder(folder, RbVmomi::VIM::VirtualMachine).select { |v| v.config && !v.config.template }
|
21
|
+
if vms.any?
|
22
|
+
puts "#{ui.color('Folder', :cyan)}: " + (folder.path[3..-1].map { |x| x[1] }.* '/')
|
23
|
+
vms.each { |v| print_vm(v) }
|
24
|
+
elsif is_top
|
25
|
+
puts "#{ui.color('No VMs', :cyan)}"
|
26
|
+
end
|
27
|
+
|
28
|
+
return unless recurse
|
29
|
+
folders = find_all_in_folder(folder, RbVmomi::VIM::Folder)
|
30
|
+
folders.each do |child|
|
31
|
+
traverse_folders(child, false, recurse)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def print_vm(vm)
|
36
|
+
state = case vm.runtime.powerState
|
37
|
+
when PS_ON
|
38
|
+
ui.color('on', :green)
|
39
|
+
when PS_OFF
|
40
|
+
ui.color('off', :red)
|
41
|
+
when PS_SUSPENDED
|
42
|
+
ui.color('suspended', :yellow)
|
43
|
+
end
|
44
|
+
puts "\t#{ui.color('VM Name:', :cyan)} #{vm.name}"
|
45
|
+
puts "\t\t#{ui.color('IP:', :magenta)} #{vm.guest.ipAddress}"
|
46
|
+
puts "\t\t#{ui.color('RAM:', :magenta)} #{vm.summary.config.memorySizeMB}"
|
47
|
+
puts "\t\t#{ui.color('State:', :magenta)} #{state}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def run
|
51
|
+
vim_connection
|
52
|
+
base_folder = find_folder(get_config(:folder))
|
53
|
+
recurse = get_config(:recursive)
|
54
|
+
is_top = true
|
55
|
+
traverse_folders(base_folder, is_top, recurse)
|
56
|
+
end
|
57
|
+
end
|