knife-vsphere 1.0.0.pre.2 → 1.0.0.pre.3
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 +358 -358
- data/lib/chef/knife/vshpere_vm_migrate.rb +80 -0
- data/lib/chef/knife/vshpere_vm_move.rb +47 -47
- data/lib/chef/knife/vshpere_vm_net.rb +57 -0
- data/lib/chef/knife/vsphere_customization_list.rb +29 -29
- data/lib/chef/knife/vsphere_datastore_list.rb +58 -58
- data/lib/chef/knife/vsphere_datastore_maxfree.rb +49 -49
- data/lib/chef/knife/vsphere_datastorecluster_list.rb +60 -60
- data/lib/chef/knife/vsphere_datastorecluster_maxfree.rb +48 -49
- data/lib/chef/knife/vsphere_hosts_list.rb +49 -0
- data/lib/chef/knife/vsphere_pool_list.rb +44 -44
- data/lib/chef/knife/vsphere_pool_query.rb +58 -58
- data/lib/chef/knife/vsphere_vlan_list.rb +37 -37
- data/lib/chef/knife/vsphere_vm_clone.rb +567 -539
- data/lib/chef/knife/vsphere_vm_config.rb +46 -46
- data/lib/chef/knife/vsphere_vm_execute.rb +66 -66
- data/lib/chef/knife/vsphere_vm_markastemplate.rb +54 -54
- data/lib/chef/knife/vsphere_vm_property_get.rb +46 -46
- data/lib/chef/knife/vsphere_vm_property_set.rb +84 -84
- data/lib/chef/knife/vsphere_vm_query.rb +48 -48
- data/lib/chef/knife/vsphere_vm_snapshot.rb +129 -129
- data/lib/chef/knife/vsphere_vm_state.rb +127 -127
- data/lib/chef/knife/vsphere_vm_vmdk_add.rb +241 -241
- data/lib/knife-vsphere/version.rb +4 -4
- metadata +18 -16
@@ -1,46 +1,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. See \"http://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.ConfigSpec.html\" for allowed ATTRIBUTE values (any property of type xs:string is supported)."
|
11
|
-
|
12
|
-
get_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
|
-
property_name = @name_args[1]
|
23
|
-
if property_name.nil?
|
24
|
-
show_usage
|
25
|
-
fatal_exit("You must specify a PROPERTY name (e.g. annotation)")
|
26
|
-
end
|
27
|
-
property_name = property_name.to_sym
|
28
|
-
|
29
|
-
property_value = @name_args[2]
|
30
|
-
if property_value.nil?
|
31
|
-
show_usage
|
32
|
-
fatal_exit("You must specify a PROPERTY value")
|
33
|
-
end
|
34
|
-
|
35
|
-
vim = get_vim_connection
|
36
|
-
|
37
|
-
dc = get_datacenter
|
38
|
-
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
39
|
-
|
40
|
-
vm = traverse_folders_for_vm(folder, vmname) or abort "VM #{vmname} not found"
|
41
|
-
|
42
|
-
properties = {}
|
43
|
-
properties[property_name] = property_value
|
44
|
-
vm.ReconfigVM_Task(:spec => RbVmomi::VIM.VirtualMachineConfigSpec(properties)).wait_for_completion
|
45
|
-
end
|
46
|
-
end
|
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. See \"http://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.ConfigSpec.html\" for allowed ATTRIBUTE values (any property of type xs:string is supported)."
|
11
|
+
|
12
|
+
get_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
|
+
property_name = @name_args[1]
|
23
|
+
if property_name.nil?
|
24
|
+
show_usage
|
25
|
+
fatal_exit("You must specify a PROPERTY name (e.g. annotation)")
|
26
|
+
end
|
27
|
+
property_name = property_name.to_sym
|
28
|
+
|
29
|
+
property_value = @name_args[2]
|
30
|
+
if property_value.nil?
|
31
|
+
show_usage
|
32
|
+
fatal_exit("You must specify a PROPERTY value")
|
33
|
+
end
|
34
|
+
|
35
|
+
vim = get_vim_connection
|
36
|
+
|
37
|
+
dc = get_datacenter
|
38
|
+
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
39
|
+
|
40
|
+
vm = traverse_folders_for_vm(folder, vmname) or abort "VM #{vmname} not found"
|
41
|
+
|
42
|
+
properties = {}
|
43
|
+
properties[property_name] = property_value
|
44
|
+
vm.ReconfigVM_Task(:spec => RbVmomi::VIM.VirtualMachineConfigSpec(properties)).wait_for_completion
|
45
|
+
end
|
46
|
+
end
|
@@ -1,66 +1,66 @@
|
|
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
|
-
get_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
|
-
if args.nil?
|
43
|
-
args = ""
|
44
|
-
end
|
45
|
-
|
46
|
-
vim = get_vim_connection
|
47
|
-
|
48
|
-
dc = get_datacenter
|
49
|
-
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
50
|
-
|
51
|
-
vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) or
|
52
|
-
abort "VM #{vmname} not found"
|
53
|
-
|
54
|
-
gom = vim.serviceContent.guestOperationsManager
|
55
|
-
|
56
|
-
guest_auth = RbVmomi::VIM::NamePasswordAuthentication(:interactiveSession => false,
|
57
|
-
:username => config[:exec_user],
|
58
|
-
:password => config[:exec_passwd])
|
59
|
-
prog_spec = RbVmomi::VIM::GuestProgramSpec(:programPath => command,
|
60
|
-
:arguments => args,
|
61
|
-
:workingDirectory => get_config(:exec_dir))
|
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
|
+
get_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
|
+
if args.nil?
|
43
|
+
args = ""
|
44
|
+
end
|
45
|
+
|
46
|
+
vim = get_vim_connection
|
47
|
+
|
48
|
+
dc = get_datacenter
|
49
|
+
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
50
|
+
|
51
|
+
vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) or
|
52
|
+
abort "VM #{vmname} not found"
|
53
|
+
|
54
|
+
gom = vim.serviceContent.guestOperationsManager
|
55
|
+
|
56
|
+
guest_auth = RbVmomi::VIM::NamePasswordAuthentication(:interactiveSession => false,
|
57
|
+
:username => config[:exec_user],
|
58
|
+
:password => config[:exec_passwd])
|
59
|
+
prog_spec = RbVmomi::VIM::GuestProgramSpec(:programPath => command,
|
60
|
+
:arguments => args,
|
61
|
+
:workingDirectory => get_config(:exec_dir))
|
62
|
+
|
63
|
+
gom.processManager.StartProgramInGuest(:vm => vm, :auth => guest_auth, :spec => prog_spec)
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -1,54 +1,54 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Ezra Pagel (<ezra@cpan.org>)
|
3
|
-
# Contributor:: Jesse Campbell (<hikeit@gmail.com>)
|
4
|
-
# Contributor:: Bethany Erskine (<bethany@paperlesspost.com>)
|
5
|
-
# Contributor:: Adrian Stanila (https://github.com/sacx)
|
6
|
-
# License:: Apache License, Version 2.0
|
7
|
-
#
|
8
|
-
|
9
|
-
require 'chef/knife'
|
10
|
-
require 'chef/knife/base_vsphere_command'
|
11
|
-
require 'rbvmomi'
|
12
|
-
|
13
|
-
# Clone an existing template into a new VM, optionally applying a customization specification.
|
14
|
-
# usage:
|
15
|
-
# knife vsphere vm markastemplate MyVM --folder /templates
|
16
|
-
class Chef::Knife::VsphereVmMarkastemplate < Chef::Knife::BaseVsphereCommand
|
17
|
-
|
18
|
-
banner "knife vsphere vm markastemplate VMNAME"
|
19
|
-
|
20
|
-
get_common_options
|
21
|
-
|
22
|
-
option :folder,
|
23
|
-
:long => "--folder FOLDER",
|
24
|
-
:description => "The folder which contains the VM"
|
25
|
-
|
26
|
-
def run
|
27
|
-
$stdout.sync = true
|
28
|
-
|
29
|
-
vmname = @name_args[0]
|
30
|
-
if vmname.nil?
|
31
|
-
show_usage
|
32
|
-
fatal_exit("You must specify a virtual machine name")
|
33
|
-
end
|
34
|
-
config[:chef_node_name] = vmname unless config[:chef_node_name]
|
35
|
-
config[:vmname] = vmname
|
36
|
-
|
37
|
-
if get_config(:bootstrap) && get_config(:distro) && !@@chef_config_dir
|
38
|
-
fatal_exit("Can't find .chef for bootstrap files. chdir to a location with a .chef directory and try again")
|
39
|
-
end
|
40
|
-
|
41
|
-
vim = get_vim_connection
|
42
|
-
|
43
|
-
dc = get_datacenter
|
44
|
-
|
45
|
-
src_folder = find_folder(get_config(:folder)) || dc.vmFolder
|
46
|
-
|
47
|
-
vm = find_in_folder(src_folder, RbVmomi::VIM::VirtualMachine, config[:vmname]) or
|
48
|
-
abort "VM not found"
|
49
|
-
|
50
|
-
puts "Marking VM #{vmname} as template"
|
51
|
-
vm.MarkAsTemplate()
|
52
|
-
puts "Finished marking VM #{vmname} as template"
|
53
|
-
end
|
54
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Ezra Pagel (<ezra@cpan.org>)
|
3
|
+
# Contributor:: Jesse Campbell (<hikeit@gmail.com>)
|
4
|
+
# Contributor:: Bethany Erskine (<bethany@paperlesspost.com>)
|
5
|
+
# Contributor:: Adrian Stanila (https://github.com/sacx)
|
6
|
+
# License:: Apache License, Version 2.0
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'chef/knife'
|
10
|
+
require 'chef/knife/base_vsphere_command'
|
11
|
+
require 'rbvmomi'
|
12
|
+
|
13
|
+
# Clone an existing template into a new VM, optionally applying a customization specification.
|
14
|
+
# usage:
|
15
|
+
# knife vsphere vm markastemplate MyVM --folder /templates
|
16
|
+
class Chef::Knife::VsphereVmMarkastemplate < Chef::Knife::BaseVsphereCommand
|
17
|
+
|
18
|
+
banner "knife vsphere vm markastemplate VMNAME"
|
19
|
+
|
20
|
+
get_common_options
|
21
|
+
|
22
|
+
option :folder,
|
23
|
+
:long => "--folder FOLDER",
|
24
|
+
:description => "The folder which contains the VM"
|
25
|
+
|
26
|
+
def run
|
27
|
+
$stdout.sync = true
|
28
|
+
|
29
|
+
vmname = @name_args[0]
|
30
|
+
if vmname.nil?
|
31
|
+
show_usage
|
32
|
+
fatal_exit("You must specify a virtual machine name")
|
33
|
+
end
|
34
|
+
config[:chef_node_name] = vmname unless config[:chef_node_name]
|
35
|
+
config[:vmname] = vmname
|
36
|
+
|
37
|
+
if get_config(:bootstrap) && get_config(:distro) && !@@chef_config_dir
|
38
|
+
fatal_exit("Can't find .chef for bootstrap files. chdir to a location with a .chef directory and try again")
|
39
|
+
end
|
40
|
+
|
41
|
+
vim = get_vim_connection
|
42
|
+
|
43
|
+
dc = get_datacenter
|
44
|
+
|
45
|
+
src_folder = find_folder(get_config(:folder)) || dc.vmFolder
|
46
|
+
|
47
|
+
vm = find_in_folder(src_folder, RbVmomi::VIM::VirtualMachine, config[:vmname]) or
|
48
|
+
abort "VM not found"
|
49
|
+
|
50
|
+
puts "Marking VM #{vmname} as template"
|
51
|
+
vm.MarkAsTemplate()
|
52
|
+
puts "Finished marking VM #{vmname} as template"
|
53
|
+
end
|
54
|
+
end
|
@@ -1,46 +1,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::VsphereVmPropertyGet < Chef::Knife::BaseVsphereCommand
|
10
|
-
banner "knife vsphere vm property get VMNAME PROPERTY. Gets a vApp Property on VMNAME."
|
11
|
-
|
12
|
-
get_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
|
-
property_name = @name_args[1]
|
23
|
-
if property_name.nil?
|
24
|
-
show_usage
|
25
|
-
fatal_exit("You must specify a PROPERTY name (e.g. annotation)")
|
26
|
-
end
|
27
|
-
property_name = property_name.to_sym
|
28
|
-
|
29
|
-
vim = get_vim_connection
|
30
|
-
|
31
|
-
dc = get_datacenter
|
32
|
-
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
33
|
-
|
34
|
-
vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) or
|
35
|
-
abort "VM #{vmname} not found"
|
36
|
-
|
37
|
-
existing_property = vm.config.vAppConfig.property.find { |p| p.props[:id] == property_name.to_s }
|
38
|
-
|
39
|
-
if existing_property
|
40
|
-
puts existing_property.props[:value]
|
41
|
-
else
|
42
|
-
fatal_exit("PROPERTY [#{property_name.to_s}] not found")
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
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::VsphereVmPropertyGet < Chef::Knife::BaseVsphereCommand
|
10
|
+
banner "knife vsphere vm property get VMNAME PROPERTY. Gets a vApp Property on VMNAME."
|
11
|
+
|
12
|
+
get_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
|
+
property_name = @name_args[1]
|
23
|
+
if property_name.nil?
|
24
|
+
show_usage
|
25
|
+
fatal_exit("You must specify a PROPERTY name (e.g. annotation)")
|
26
|
+
end
|
27
|
+
property_name = property_name.to_sym
|
28
|
+
|
29
|
+
vim = get_vim_connection
|
30
|
+
|
31
|
+
dc = get_datacenter
|
32
|
+
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
33
|
+
|
34
|
+
vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) or
|
35
|
+
abort "VM #{vmname} not found"
|
36
|
+
|
37
|
+
existing_property = vm.config.vAppConfig.property.find { |p| p.props[:id] == property_name.to_s }
|
38
|
+
|
39
|
+
if existing_property
|
40
|
+
puts existing_property.props[:value]
|
41
|
+
else
|
42
|
+
fatal_exit("PROPERTY [#{property_name.to_s}] not found")
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -1,84 +1,84 @@
|
|
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::VsphereVmPropertySet < Chef::Knife::BaseVsphereCommand
|
10
|
-
banner "knife vsphere vm property set VMNAME PROPERTY VALUE. Sets a vApp Property on VMNAME."
|
11
|
-
|
12
|
-
get_common_options
|
13
|
-
|
14
|
-
option :ovf_environment_transport,
|
15
|
-
:long => "--ovf-environment-transport STRING",
|
16
|
-
:description => "Comma delimited string. Configures the transports to use for properties. Supported values are: iso and com.vmware.guestInfo."
|
17
|
-
|
18
|
-
def run
|
19
|
-
$stdout.sync = true
|
20
|
-
vmname = @name_args[0]
|
21
|
-
if vmname.nil?
|
22
|
-
show_usage
|
23
|
-
fatal_exit("You must specify a virtual machine name")
|
24
|
-
end
|
25
|
-
|
26
|
-
property_name = @name_args[1]
|
27
|
-
if property_name.nil?
|
28
|
-
show_usage
|
29
|
-
fatal_exit("You must specify a PROPERTY name (e.g. annotation)")
|
30
|
-
end
|
31
|
-
property_name = property_name.to_sym
|
32
|
-
|
33
|
-
property_value = @name_args[2]
|
34
|
-
if property_value.nil?
|
35
|
-
show_usage
|
36
|
-
fatal_exit("You must specify a PROPERTY value")
|
37
|
-
end
|
38
|
-
|
39
|
-
vim = get_vim_connection
|
40
|
-
|
41
|
-
dc = get_datacenter
|
42
|
-
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
43
|
-
|
44
|
-
vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) or
|
45
|
-
abort "VM #{vmname} not found"
|
46
|
-
|
47
|
-
if vm.config.vAppConfig && vm.config.vAppConfig.property
|
48
|
-
existing_property = vm.config.vAppConfig.property.find { |p| p.props[:id] == property_name.to_s }
|
49
|
-
end
|
50
|
-
|
51
|
-
if existing_property
|
52
|
-
operation = 'edit'
|
53
|
-
property_key = existing_property.props[:key]
|
54
|
-
else
|
55
|
-
operation = 'add'
|
56
|
-
property_key = property_name.object_id
|
57
|
-
end
|
58
|
-
|
59
|
-
vm_config_spec = RbVmomi::VIM.VirtualMachineConfigSpec(
|
60
|
-
:vAppConfig => RbVmomi::VIM.VmConfigSpec(
|
61
|
-
:property => [
|
62
|
-
RbVmomi::VIM.VAppPropertySpec(
|
63
|
-
:operation => operation,
|
64
|
-
:info => {
|
65
|
-
:key => property_key,
|
66
|
-
:id => property_name.to_s,
|
67
|
-
:type => 'string',
|
68
|
-
:userConfigurable => true,
|
69
|
-
:value => property_value
|
70
|
-
}
|
71
|
-
)
|
72
|
-
]
|
73
|
-
)
|
74
|
-
)
|
75
|
-
|
76
|
-
unless config[:ovf_environment_transport].nil?
|
77
|
-
transport = config[:ovf_environment_transport].split(",")
|
78
|
-
transport = [""] if transport == [] ## because "".split returns [] and vmware wants [""]
|
79
|
-
vm_config_spec[:vAppConfig][:ovfEnvironmentTransport] = transport
|
80
|
-
end
|
81
|
-
|
82
|
-
vm.ReconfigVM_Task( :spec => vm_config_spec ).wait_for_completion
|
83
|
-
end
|
84
|
-
end
|
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::VsphereVmPropertySet < Chef::Knife::BaseVsphereCommand
|
10
|
+
banner "knife vsphere vm property set VMNAME PROPERTY VALUE. Sets a vApp Property on VMNAME."
|
11
|
+
|
12
|
+
get_common_options
|
13
|
+
|
14
|
+
option :ovf_environment_transport,
|
15
|
+
:long => "--ovf-environment-transport STRING",
|
16
|
+
:description => "Comma delimited string. Configures the transports to use for properties. Supported values are: iso and com.vmware.guestInfo."
|
17
|
+
|
18
|
+
def run
|
19
|
+
$stdout.sync = true
|
20
|
+
vmname = @name_args[0]
|
21
|
+
if vmname.nil?
|
22
|
+
show_usage
|
23
|
+
fatal_exit("You must specify a virtual machine name")
|
24
|
+
end
|
25
|
+
|
26
|
+
property_name = @name_args[1]
|
27
|
+
if property_name.nil?
|
28
|
+
show_usage
|
29
|
+
fatal_exit("You must specify a PROPERTY name (e.g. annotation)")
|
30
|
+
end
|
31
|
+
property_name = property_name.to_sym
|
32
|
+
|
33
|
+
property_value = @name_args[2]
|
34
|
+
if property_value.nil?
|
35
|
+
show_usage
|
36
|
+
fatal_exit("You must specify a PROPERTY value")
|
37
|
+
end
|
38
|
+
|
39
|
+
vim = get_vim_connection
|
40
|
+
|
41
|
+
dc = get_datacenter
|
42
|
+
folder = find_folder(get_config(:folder)) || dc.vmFolder
|
43
|
+
|
44
|
+
vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) or
|
45
|
+
abort "VM #{vmname} not found"
|
46
|
+
|
47
|
+
if vm.config.vAppConfig && vm.config.vAppConfig.property
|
48
|
+
existing_property = vm.config.vAppConfig.property.find { |p| p.props[:id] == property_name.to_s }
|
49
|
+
end
|
50
|
+
|
51
|
+
if existing_property
|
52
|
+
operation = 'edit'
|
53
|
+
property_key = existing_property.props[:key]
|
54
|
+
else
|
55
|
+
operation = 'add'
|
56
|
+
property_key = property_name.object_id
|
57
|
+
end
|
58
|
+
|
59
|
+
vm_config_spec = RbVmomi::VIM.VirtualMachineConfigSpec(
|
60
|
+
:vAppConfig => RbVmomi::VIM.VmConfigSpec(
|
61
|
+
:property => [
|
62
|
+
RbVmomi::VIM.VAppPropertySpec(
|
63
|
+
:operation => operation,
|
64
|
+
:info => {
|
65
|
+
:key => property_key,
|
66
|
+
:id => property_name.to_s,
|
67
|
+
:type => 'string',
|
68
|
+
:userConfigurable => true,
|
69
|
+
:value => property_value
|
70
|
+
}
|
71
|
+
)
|
72
|
+
]
|
73
|
+
)
|
74
|
+
)
|
75
|
+
|
76
|
+
unless config[:ovf_environment_transport].nil?
|
77
|
+
transport = config[:ovf_environment_transport].split(",")
|
78
|
+
transport = [""] if transport == [] ## because "".split returns [] and vmware wants [""]
|
79
|
+
vm_config_spec[:vAppConfig][:ovfEnvironmentTransport] = transport
|
80
|
+
end
|
81
|
+
|
82
|
+
vm.ReconfigVM_Task( :spec => vm_config_spec ).wait_for_completion
|
83
|
+
end
|
84
|
+
end
|