knife-vsphere 3.0.1 → 4.0.1
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 +35 -32
- data/lib/chef/knife/search_helper.rb +3 -3
- data/lib/chef/knife/vsphere_customization_list.rb +1 -1
- data/lib/chef/knife/vsphere_datastore_file.rb +12 -12
- data/lib/chef/knife/vsphere_datastore_list.rb +6 -6
- data/lib/chef/knife/vsphere_datastore_maxfree.rb +8 -8
- data/lib/chef/knife/vsphere_datastorecluster_list.rb +2 -1
- data/lib/chef/knife/vsphere_datastorecluster_maxfree.rb +4 -4
- data/lib/chef/knife/vsphere_folder_list.rb +1 -1
- data/lib/chef/knife/vsphere_hosts_list.rb +3 -3
- data/lib/chef/knife/vsphere_pool_list.rb +1 -1
- data/lib/chef/knife/vsphere_vlan_create.rb +2 -2
- data/lib/chef/knife/vsphere_vlan_list.rb +1 -1
- data/lib/chef/knife/vsphere_vm_cdrom.rb +18 -18
- data/lib/chef/knife/vsphere_vm_clone.rb +168 -333
- data/lib/chef/knife/vsphere_vm_delete.rb +7 -7
- data/lib/chef/knife/vsphere_vm_disk_extend.rb +4 -3
- data/lib/chef/knife/vsphere_vm_execute.rb +8 -8
- data/lib/chef/knife/vsphere_vm_find.rb +50 -49
- data/lib/chef/knife/vsphere_vm_list.rb +13 -12
- data/lib/chef/knife/vsphere_vm_migrate.rb +8 -8
- data/lib/chef/knife/vsphere_vm_move.rb +13 -13
- data/lib/chef/knife/vsphere_vm_net.rb +1 -1
- data/lib/chef/knife/vsphere_vm_network_add.rb +7 -8
- data/lib/chef/knife/vsphere_vm_network_delete.rb +1 -1
- data/lib/chef/knife/vsphere_vm_property_set.rb +3 -3
- data/lib/chef/knife/vsphere_vm_snapshot.rb +32 -30
- data/lib/chef/knife/vsphere_vm_state.rb +12 -12
- data/lib/chef/knife/vsphere_vm_toolsconfig.rb +3 -3
- data/lib/chef/knife/vsphere_vm_vmdk_add.rb +15 -13
- data/lib/chef/knife/vsphere_vm_vnc_set.rb +7 -7
- data/lib/chef/knife/vsphere_vm_wait_sysprep.rb +6 -6
- data/lib/knife-vsphere/version.rb +1 -1
- metadata +31 -17
@@ -19,15 +19,15 @@ class Chef::Knife::VsphereVmDelete < Chef::Knife::BaseVsphereCommand
|
|
19
19
|
banner "knife vsphere vm delete VMNAME (options)"
|
20
20
|
|
21
21
|
option :purge,
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
short: "-P",
|
23
|
+
long: "--purge",
|
24
|
+
boolean: true,
|
25
|
+
description: "Destroy corresponding node and client on the Chef Server, in addition to destroying the VM itself."
|
26
26
|
|
27
27
|
option :chef_node_name,
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
short: "-N NAME",
|
29
|
+
long: "--node-name NAME",
|
30
|
+
description: "Use this option if the Chef node name is different from the VM name"
|
31
31
|
|
32
32
|
common_options
|
33
33
|
|
@@ -14,8 +14,8 @@ class Chef::Knife::VsphereVmDiskExtend < Chef::Knife::BaseVsphereCommand
|
|
14
14
|
common_options
|
15
15
|
|
16
16
|
option :diskname,
|
17
|
-
|
18
|
-
|
17
|
+
long: "--diskname DISKNAME",
|
18
|
+
description: "The name of the disk that will be extended"
|
19
19
|
|
20
20
|
def run
|
21
21
|
$stdout.sync = true
|
@@ -57,7 +57,8 @@ class Chef::Knife::VsphereVmDiskExtend < Chef::Knife::BaseVsphereCommand
|
|
57
57
|
RbVmomi::VIM::VirtualMachineConfigSpec(
|
58
58
|
deviceChange: [RbVmomi::VIM::VirtualDeviceConfigSpec(
|
59
59
|
device: disk,
|
60
|
-
operation: RbVmomi::VIM::VirtualDeviceConfigSpecOperation("edit")
|
60
|
+
operation: RbVmomi::VIM::VirtualDeviceConfigSpecOperation("edit")
|
61
|
+
)]
|
61
62
|
)).wait_for_completion
|
62
63
|
|
63
64
|
puts "Disk resized successfully"
|
@@ -12,18 +12,18 @@ class Chef::Knife::VsphereVmExecute < Chef::Knife::BaseVsphereCommand
|
|
12
12
|
banner "knife vsphere vm execute VMNAME COMMAND ARGS"
|
13
13
|
|
14
14
|
option :exec_user,
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
long: "--exec-user USER",
|
16
|
+
description: "User to execute as",
|
17
|
+
required: true
|
18
18
|
|
19
19
|
option :exec_passwd,
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
long: "--exec-passwd PASSWORD",
|
21
|
+
description: "Password for execute user",
|
22
|
+
required: true
|
23
23
|
|
24
24
|
option :exec_dir,
|
25
|
-
|
26
|
-
|
25
|
+
long: "--exec-dir DIRECTORY",
|
26
|
+
description: "Working directory to execute in"
|
27
27
|
|
28
28
|
common_options
|
29
29
|
|
@@ -17,101 +17,101 @@ class Chef::Knife::VsphereVmFind < Chef::Knife::BaseVsphereCommand
|
|
17
17
|
|
18
18
|
# Deprecating
|
19
19
|
option :pool,
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
long: "--pool pool",
|
21
|
+
short: "-h",
|
22
|
+
description: "Target pool"
|
23
23
|
# Deprecating
|
24
24
|
option :poolpath,
|
25
|
-
|
26
|
-
|
25
|
+
long: "--pool-path",
|
26
|
+
description: "Pool is full-path"
|
27
27
|
|
28
28
|
option :esx_disk,
|
29
|
-
|
30
|
-
|
29
|
+
long: "--esx-disk",
|
30
|
+
description: "Show esx disks"
|
31
31
|
|
32
32
|
option :snapshots,
|
33
|
-
|
34
|
-
|
33
|
+
long: "--snapshots",
|
34
|
+
description: "Show snapshots"
|
35
35
|
|
36
36
|
option :os_disk,
|
37
|
-
|
38
|
-
|
37
|
+
long: "--os-disks",
|
38
|
+
description: "Show os disks"
|
39
39
|
|
40
40
|
option :cpu,
|
41
|
-
|
42
|
-
|
41
|
+
long: "--cpu",
|
42
|
+
description: "Show cpu"
|
43
43
|
|
44
44
|
option :cpu_hot_add_enabled,
|
45
|
-
|
46
|
-
|
45
|
+
long: "--cpu_hot_add_enabled",
|
46
|
+
description: "Show cpu hot add enabled"
|
47
47
|
|
48
48
|
option :memory_hot_add_enabled,
|
49
|
-
|
50
|
-
|
49
|
+
long: "--memory_hot_add_enabled",
|
50
|
+
description: "Show memory hot add enabled"
|
51
51
|
|
52
52
|
option :ram,
|
53
|
-
|
54
|
-
|
53
|
+
long: "--ram",
|
54
|
+
description: "Show ram"
|
55
55
|
|
56
56
|
option :ip,
|
57
|
-
|
58
|
-
|
57
|
+
long: "--ip",
|
58
|
+
description: "Show primary ip"
|
59
59
|
|
60
60
|
option :networks,
|
61
|
-
|
62
|
-
|
61
|
+
long: "--networks",
|
62
|
+
description: "Show all networks with their IPs"
|
63
63
|
|
64
64
|
option :soff,
|
65
|
-
|
66
|
-
|
65
|
+
long: "--powered-off",
|
66
|
+
description: "Show only stopped machines"
|
67
67
|
|
68
68
|
option :son,
|
69
|
-
|
70
|
-
|
69
|
+
long: "--powered-on",
|
70
|
+
description: "Show only started machines"
|
71
71
|
|
72
72
|
option :matchip,
|
73
|
-
|
74
|
-
|
73
|
+
long: "--match-ip IP",
|
74
|
+
description: "match ip"
|
75
75
|
|
76
76
|
option :matchos,
|
77
|
-
|
78
|
-
|
77
|
+
long: "--match-os OS",
|
78
|
+
description: "match os"
|
79
79
|
|
80
80
|
option :matchname,
|
81
|
-
|
82
|
-
|
81
|
+
long: "--match-name VMNAME",
|
82
|
+
description: "match name"
|
83
83
|
|
84
84
|
option :matchtools,
|
85
|
-
|
86
|
-
|
85
|
+
long: "--match-tools TOOLSSTATE",
|
86
|
+
description: "match tools state"
|
87
87
|
|
88
88
|
option :hostname,
|
89
|
-
|
90
|
-
|
89
|
+
long: "--hostname",
|
90
|
+
description: "show hostname of the guest"
|
91
91
|
|
92
92
|
option :host_name,
|
93
|
-
|
94
|
-
|
93
|
+
long: "--host_name",
|
94
|
+
description: "show name of the VMs host"
|
95
95
|
|
96
96
|
option :os,
|
97
|
-
|
98
|
-
|
97
|
+
long: "--os",
|
98
|
+
description: "show os details"
|
99
99
|
|
100
100
|
option :alarms,
|
101
|
-
|
102
|
-
|
101
|
+
long: "--alarms",
|
102
|
+
description: "show alarm status"
|
103
103
|
|
104
104
|
option :tools,
|
105
|
-
|
106
|
-
|
105
|
+
long: "--tools",
|
106
|
+
description: "show tools status"
|
107
107
|
|
108
108
|
option :full_path,
|
109
|
-
|
110
|
-
|
109
|
+
long: "--full-path",
|
110
|
+
description: "Show full folder path to the VM"
|
111
111
|
|
112
112
|
option :short_path,
|
113
|
-
|
114
|
-
|
113
|
+
long: "--short-path",
|
114
|
+
description: "Show the VM's enclosing folder name"
|
115
115
|
|
116
116
|
$stdout.sync = true # smoother output from print
|
117
117
|
|
@@ -241,6 +241,7 @@ class Chef::Knife::VsphereVmFind < Chef::Knife::BaseVsphereCommand
|
|
241
241
|
iterator = vm.obj
|
242
242
|
while (iterator = iterator.parent)
|
243
243
|
break if iterator.name == VMFOLDER
|
244
|
+
|
244
245
|
path.unshift iterator.name
|
245
246
|
end
|
246
247
|
|
@@ -12,14 +12,14 @@ class Chef::Knife::VsphereVmList < Chef::Knife::BaseVsphereCommand
|
|
12
12
|
common_options
|
13
13
|
|
14
14
|
option :recursive,
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
long: "--recursive",
|
16
|
+
short: "-r",
|
17
|
+
description: "Recurse into sub-folders"
|
18
18
|
|
19
19
|
option :onlyfolders,
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
long: "--only-folders",
|
21
|
+
description: "List only the folders found",
|
22
|
+
boolean: false
|
23
23
|
|
24
24
|
def traverse_folders(folder, is_top = false, recurse = false, only_folders = false)
|
25
25
|
if only_folders
|
@@ -30,11 +30,12 @@ class Chef::Knife::VsphereVmList < Chef::Knife::BaseVsphereCommand
|
|
30
30
|
print_folder(folder)
|
31
31
|
vms.each { |v| print_vm(v) }
|
32
32
|
elsif is_top
|
33
|
-
puts "#{ui.color(
|
33
|
+
puts "#{ui.color("No VMs", :cyan)}"
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
return unless recurse
|
38
|
+
|
38
39
|
folders = find_all_in_folder(folder, RbVmomi::VIM::Folder)
|
39
40
|
folders.each do |child|
|
40
41
|
traverse_folders(child, false, recurse, only_folders)
|
@@ -50,14 +51,14 @@ class Chef::Knife::VsphereVmList < Chef::Knife::BaseVsphereCommand
|
|
50
51
|
when PS_SUSPENDED
|
51
52
|
ui.color("suspended", :yellow)
|
52
53
|
end
|
53
|
-
puts "\t#{ui.color(
|
54
|
-
puts "\t\t#{ui.color(
|
55
|
-
puts "\t\t#{ui.color(
|
56
|
-
puts "\t\t#{ui.color(
|
54
|
+
puts "\t#{ui.color("VM Name:", :cyan)} #{vm.name}"
|
55
|
+
puts "\t\t#{ui.color("IP:", :magenta)} #{vm.guest.ipAddress}"
|
56
|
+
puts "\t\t#{ui.color("RAM:", :magenta)} #{vm.summary.config.memorySizeMB}"
|
57
|
+
puts "\t\t#{ui.color("State:", :magenta)} #{state}"
|
57
58
|
end
|
58
59
|
|
59
60
|
def print_folder(folder)
|
60
|
-
puts "#{ui.color(
|
61
|
+
puts "#{ui.color("Folder", :cyan)}: " + (folder.path[3..-1].map { |x| x[1] }.* "/")
|
61
62
|
end
|
62
63
|
|
63
64
|
def run
|
@@ -15,20 +15,20 @@ class Chef::Knife::VsphereVmMigrate < Chef::Knife::BaseVsphereCommand
|
|
15
15
|
common_options
|
16
16
|
|
17
17
|
option :dest_host,
|
18
|
-
|
19
|
-
|
18
|
+
long: "--dest-host HOST",
|
19
|
+
description: "Destination host for the VM or template"
|
20
20
|
|
21
21
|
option :dest_datastore,
|
22
|
-
|
23
|
-
|
22
|
+
long: "--dest-datastore DATASTORE",
|
23
|
+
description: "The destination datastore"
|
24
24
|
|
25
25
|
option :priority,
|
26
|
-
|
27
|
-
|
26
|
+
long: "--priority PRIORITY",
|
27
|
+
description: "migration priority"
|
28
28
|
|
29
29
|
option :resource_pool,
|
30
|
-
|
31
|
-
|
30
|
+
long: "--resource-pool POOL",
|
31
|
+
description: "The resource pool into which to put the VM"
|
32
32
|
|
33
33
|
def run
|
34
34
|
$stdout.sync = true
|
@@ -15,27 +15,27 @@ class Chef::Knife::VsphereVmMove < Chef::Knife::BaseVsphereCommand
|
|
15
15
|
common_options
|
16
16
|
|
17
17
|
option :dest_name,
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
long: "--dest-name NAME",
|
19
|
+
short: "-r",
|
20
|
+
description: "Destination name of the VM or template"
|
21
21
|
|
22
22
|
option :dest_folder,
|
23
|
-
|
24
|
-
|
23
|
+
long: "--dest-folder FOLDER",
|
24
|
+
description: "The destination folder into which the VM or template should be moved"
|
25
25
|
|
26
26
|
option :datastore,
|
27
|
-
|
28
|
-
|
27
|
+
long: "--datastore STORE",
|
28
|
+
description: "The datastore into which to put the cloned VM"
|
29
29
|
|
30
30
|
option :thin_provision,
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
long: "--thin-provision",
|
32
|
+
description: "Indicates whether disk should be thin provisioned.",
|
33
|
+
boolean: true
|
34
34
|
|
35
35
|
option :thick_provision,
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
long: "--thick-provision",
|
37
|
+
description: "Indicates whether disk should be thick provisioned.",
|
38
|
+
boolean: true
|
39
39
|
|
40
40
|
# Convert VM
|
41
41
|
#
|
@@ -41,7 +41,7 @@ class Chef::Knife::VsphereVmNet < Chef::Knife::BaseVsphereCommand
|
|
41
41
|
backing = a.backing
|
42
42
|
key = a.key
|
43
43
|
|
44
|
-
puts "#{ui.color(
|
44
|
+
puts "#{ui.color("Setting network adapter", :cyan)} :#{a.deviceInfo.label} on vlan :#{a.deviceInfo.summary} :#{state}"
|
45
45
|
|
46
46
|
conninfo = RbVmomi::VIM.VirtualDeviceConnectInfo(startConnected: true,
|
47
47
|
allowGuestControl: true,
|
@@ -12,14 +12,14 @@ class Chef::Knife::VsphereVmNetworkAdd < Chef::Knife::BaseVsphereCommand
|
|
12
12
|
banner "knife vsphere vm network add VMNAME NETWORKNAME"
|
13
13
|
|
14
14
|
option :adapter_type,
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
long: "--adapter-type STRING",
|
16
|
+
description: "Adapter type eg e1000,vmxnet3",
|
17
|
+
required: true
|
18
18
|
|
19
19
|
option :mac_address,
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
long: "--mac-address STRING",
|
21
|
+
description: "Adapter MAC address eg. AA:BB:CC:DD:EE:FF",
|
22
|
+
required: false
|
23
23
|
|
24
24
|
common_options
|
25
25
|
|
@@ -83,8 +83,7 @@ class Chef::Knife::VsphereVmNetworkAdd < Chef::Knife::BaseVsphereCommand
|
|
83
83
|
deviceInfo: { summary: summary, label: "" },
|
84
84
|
backing: backing,
|
85
85
|
addressType: address_type,
|
86
|
-
macAddress: mac_address
|
87
|
-
),
|
86
|
+
macAddress: mac_address),
|
88
87
|
}],
|
89
88
|
}
|
90
89
|
).wait_for_completion
|
@@ -43,7 +43,7 @@ class Chef::Knife::VsphereVmNetworkDelete < Chef::Knife::BaseVsphereCommand
|
|
43
43
|
)
|
44
44
|
|
45
45
|
vm.ReconfigVM_Task(spec: spec).wait_for_completion
|
46
|
-
puts "#{ui.color(
|
46
|
+
puts "#{ui.color("NIC", :red)}: #{card.deviceInfo.label} was deleted"
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -13,8 +13,8 @@ class Chef::Knife::VsphereVmPropertySet < Chef::Knife::BaseVsphereCommand
|
|
13
13
|
common_options
|
14
14
|
|
15
15
|
option :ovf_environment_transport,
|
16
|
-
|
17
|
-
|
16
|
+
long: "--ovf-environment-transport STRING",
|
17
|
+
description: "Comma delimited string. Configures the transports to use for properties. Supported values are: iso and com.vmware.guestInfo."
|
18
18
|
|
19
19
|
# The main run method for vm_property_set
|
20
20
|
#
|
@@ -69,7 +69,7 @@ class Chef::Knife::VsphereVmPropertySet < Chef::Knife::BaseVsphereCommand
|
|
69
69
|
userConfigurable: true,
|
70
70
|
value: property_value,
|
71
71
|
}
|
72
|
-
)
|
72
|
+
),
|
73
73
|
]
|
74
74
|
)
|
75
75
|
)
|
@@ -14,56 +14,56 @@ class Chef::Knife::VsphereVmSnapshot < Chef::Knife::BaseVsphereCommand
|
|
14
14
|
common_options
|
15
15
|
|
16
16
|
option :list,
|
17
|
-
|
18
|
-
|
17
|
+
long: "--list",
|
18
|
+
description: "The current tree of snapshots"
|
19
19
|
|
20
20
|
option :create_new_snapshot,
|
21
|
-
|
22
|
-
|
21
|
+
long: "--create SNAPSHOT",
|
22
|
+
description: "Create a new snapshot off of the current snapshot."
|
23
23
|
|
24
24
|
option :remove_named_snapshot,
|
25
|
-
|
26
|
-
|
25
|
+
long: "--remove SNAPSHOT",
|
26
|
+
description: "Remove a named snapshot."
|
27
27
|
|
28
28
|
option :revert_snapshot,
|
29
|
-
|
30
|
-
|
29
|
+
long: "--revert SNAPSHOT",
|
30
|
+
description: "Revert to a named snapshot."
|
31
31
|
|
32
32
|
option :revert_current_snapshot,
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
long: "--revert-current",
|
34
|
+
description: "Revert to current snapshot.",
|
35
|
+
boolean: false
|
36
36
|
|
37
37
|
option :power,
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
long: "--start",
|
39
|
+
description: "Indicates whether to start the VM after a successful revert",
|
40
|
+
boolean: false
|
41
41
|
|
42
42
|
option :wait,
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
long: "--wait",
|
44
|
+
description: "Indicates whether to wait for creation/removal to complete",
|
45
|
+
boolean: false
|
46
46
|
|
47
47
|
option :find, # imma deprecate this
|
48
|
-
|
49
|
-
|
48
|
+
long: "--find",
|
49
|
+
description: "Finds the virtual machine by searching all folders"
|
50
50
|
|
51
51
|
option :dump_memory,
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
long: "--dump-memory",
|
53
|
+
boolean: true,
|
54
|
+
description: "Dump the memory in the snapshot",
|
55
|
+
default: false
|
56
56
|
|
57
57
|
option :quiesce,
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
long: "--quiesce",
|
59
|
+
boolean: true,
|
60
|
+
description: "Quiesce the VM prior to snapshotting",
|
61
|
+
default: false
|
62
62
|
|
63
63
|
option :snapshot_description,
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
long: "--snapshot-descr DESCR",
|
65
|
+
description: "Snapshot description",
|
66
|
+
default: ""
|
67
67
|
|
68
68
|
def run
|
69
69
|
$stdout.sync = true
|
@@ -114,10 +114,12 @@ class Chef::Knife::VsphereVmSnapshot < Chef::Knife::BaseVsphereCommand
|
|
114
114
|
end
|
115
115
|
|
116
116
|
return unless get_config(:revert_snapshot)
|
117
|
+
|
117
118
|
ss_name = get_config(:revert_snapshot)
|
118
119
|
snapshot = find_node(snapshot_list, ss_name)
|
119
120
|
snapshot.RevertToSnapshot_Task(suppressPowerOn: false).wait_for_completion
|
120
121
|
return unless get_config(:power)
|
122
|
+
|
121
123
|
vm.PowerOnVM_Task.wait_for_completion
|
122
124
|
puts "Powered on virtual machine #{vmname}"
|
123
125
|
end
|