knife-vsphere 2.1.1 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/chef/knife/base_vsphere_command.rb +69 -70
- data/lib/chef/knife/customization_helper.rb +4 -4
- data/lib/chef/knife/search_helper.rb +16 -7
- data/lib/chef/knife/vsphere_cluster_list.rb +8 -8
- data/lib/chef/knife/vsphere_cpu_ratio.rb +4 -4
- data/lib/chef/knife/vsphere_customization_list.rb +3 -3
- data/lib/chef/knife/vsphere_datastore_file.rb +17 -17
- data/lib/chef/knife/vsphere_datastore_list.rb +11 -11
- data/lib/chef/knife/vsphere_datastore_maxfree.rb +14 -14
- data/lib/chef/knife/vsphere_datastorecluster_list.rb +7 -7
- data/lib/chef/knife/vsphere_datastorecluster_maxfree.rb +10 -10
- data/lib/chef/knife/vsphere_folder_list.rb +4 -4
- data/lib/chef/knife/vsphere_hosts_list.rb +10 -10
- data/lib/chef/knife/vsphere_pool_list.rb +5 -5
- data/lib/chef/knife/vsphere_pool_query.rb +7 -7
- data/lib/chef/knife/vsphere_pool_show.rb +8 -8
- data/lib/chef/knife/vsphere_template_list.rb +7 -7
- data/lib/chef/knife/vsphere_vlan_create.rb +8 -8
- data/lib/chef/knife/vsphere_vlan_list.rb +3 -3
- data/lib/chef/knife/vsphere_vm_cdrom.rb +27 -27
- data/lib/chef/knife/vsphere_vm_clone.rb +224 -214
- data/lib/chef/knife/vsphere_vm_config.rb +6 -6
- data/lib/chef/knife/vsphere_vm_delete.rb +17 -17
- data/lib/chef/knife/vsphere_vm_disk_extend.rb +11 -11
- data/lib/chef/knife/vsphere_vm_disk_list.rb +6 -6
- data/lib/chef/knife/vsphere_vm_execute.rb +14 -14
- data/lib/chef/knife/vsphere_vm_find.rb +87 -87
- data/lib/chef/knife/vsphere_vm_list.rb +12 -12
- data/lib/chef/knife/vsphere_vm_markastemplate.rb +5 -5
- data/lib/chef/knife/vsphere_vm_migrate.rb +20 -25
- data/lib/chef/knife/vsphere_vm_move.rb +17 -17
- data/lib/chef/knife/vsphere_vm_net.rb +8 -8
- data/lib/chef/knife/vsphere_vm_network_add.rb +22 -24
- data/lib/chef/knife/vsphere_vm_network_delete.rb +8 -8
- data/lib/chef/knife/vsphere_vm_network_list.rb +5 -5
- data/lib/chef/knife/vsphere_vm_network_set.rb +10 -10
- data/lib/chef/knife/vsphere_vm_property_get.rb +7 -7
- data/lib/chef/knife/vsphere_vm_property_set.rb +16 -16
- data/lib/chef/knife/vsphere_vm_show.rb +8 -8
- data/lib/chef/knife/vsphere_vm_snapshot.rb +35 -35
- data/lib/chef/knife/vsphere_vm_state.rb +31 -31
- data/lib/chef/knife/vsphere_vm_toolsconfig.rb +11 -11
- data/lib/chef/knife/vsphere_vm_vmdk_add.rb +32 -32
- data/lib/chef/knife/vsphere_vm_vnc_set.rb +15 -15
- data/lib/chef/knife/vsphere_vm_wait_sysprep.rb +10 -11
- data/lib/knife-vsphere/version.rb +1 -1
- metadata +5 -89
@@ -1,9 +1,9 @@
|
|
1
1
|
# Author:: Brian Dupras (<bdupras@rallydev.com>)
|
2
2
|
# License:: Apache License, Version 2.0
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
4
|
+
require "chef/knife"
|
5
|
+
require "chef/knife/base_vsphere_command"
|
6
|
+
require "chef/knife/search_helper"
|
7
7
|
|
8
8
|
# VsphereVMconfig extends the BaseVspherecommand
|
9
9
|
class Chef::Knife::VsphereVmConfig < Chef::Knife::BaseVsphereCommand
|
@@ -21,11 +21,11 @@ class Chef::Knife::VsphereVmConfig < Chef::Knife::BaseVsphereCommand
|
|
21
21
|
vmname = @name_args.shift
|
22
22
|
if vmname.nil?
|
23
23
|
show_usage
|
24
|
-
fatal_exit(
|
24
|
+
fatal_exit("You must specify a virtual machine name")
|
25
25
|
end
|
26
26
|
|
27
|
-
unless @name_args.length > 0 && @name_args.length
|
28
|
-
fatal_exit(
|
27
|
+
unless @name_args.length > 0 && @name_args.length.even?
|
28
|
+
fatal_exit("You must specify a series of PROPERTY name (e.g. annotation) followed by a value")
|
29
29
|
end
|
30
30
|
|
31
31
|
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
@@ -3,31 +3,31 @@
|
|
3
3
|
# License:: Apache License, Version 2.0
|
4
4
|
#
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
6
|
+
require "chef/knife"
|
7
|
+
require "chef/knife/base_vsphere_command"
|
8
|
+
require "chef/knife/search_helper"
|
9
|
+
require "rbvmomi"
|
10
10
|
|
11
11
|
# These two are needed for the '--purge' deletion case
|
12
|
-
require
|
13
|
-
require
|
12
|
+
require "chef/node"
|
13
|
+
require "chef/api_client"
|
14
14
|
|
15
15
|
# Delete a virtual machine from vCenter
|
16
16
|
# VsphereVmDelete extends the BaseVspherecommand
|
17
17
|
class Chef::Knife::VsphereVmDelete < Chef::Knife::BaseVsphereCommand
|
18
18
|
include SearchHelper
|
19
|
-
banner
|
19
|
+
banner "knife vsphere vm delete VMNAME (options)"
|
20
20
|
|
21
21
|
option :purge,
|
22
|
-
short:
|
23
|
-
long:
|
22
|
+
short: "-P",
|
23
|
+
long: "--purge",
|
24
24
|
boolean: true,
|
25
|
-
description:
|
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
|
-
short:
|
29
|
-
long:
|
30
|
-
description:
|
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
|
|
@@ -55,19 +55,19 @@ class Chef::Knife::VsphereVmDelete < Chef::Knife::BaseVsphereCommand
|
|
55
55
|
|
56
56
|
if vmname.nil?
|
57
57
|
show_usage
|
58
|
-
fatal_exit(
|
58
|
+
fatal_exit("You must specify a virtual machine name")
|
59
59
|
end
|
60
60
|
|
61
61
|
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
62
62
|
|
63
|
-
vm.PowerOffVM_Task.wait_for_completion unless vm.runtime.powerState ==
|
63
|
+
vm.PowerOffVM_Task.wait_for_completion unless vm.runtime.powerState == "poweredOff"
|
64
64
|
vm.Destroy_Task.wait_for_completion
|
65
65
|
puts "Deleted virtual machine #{vmname}"
|
66
66
|
|
67
67
|
if config[:purge]
|
68
68
|
vmname = config[:chef_node_name] if config[:chef_node_name]
|
69
|
-
destroy_item(Chef::Node, vmname,
|
70
|
-
destroy_item(Chef::ApiClient, vmname,
|
69
|
+
destroy_item(Chef::Node, vmname, "node")
|
70
|
+
destroy_item(Chef::ApiClient, vmname, "client")
|
71
71
|
puts "Corresponding node and client for the #{vmname} server were deleted and unregistered with the Chef Server"
|
72
72
|
end
|
73
73
|
end
|
@@ -3,32 +3,32 @@
|
|
3
3
|
# License:: Apache License, Version 2.0
|
4
4
|
#
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
6
|
+
require "chef/knife"
|
7
|
+
require "chef/knife/base_vsphere_command"
|
8
|
+
require "chef/knife/search_helper"
|
9
9
|
|
10
10
|
class Chef::Knife::VsphereVmDiskExtend < Chef::Knife::BaseVsphereCommand
|
11
11
|
include SearchHelper
|
12
|
-
banner
|
12
|
+
banner "knife vsphere vm disk extend VMNAME SIZE. Extends the disk of vm VMNAME to SIZE kilobytes."
|
13
13
|
|
14
14
|
common_options
|
15
15
|
|
16
16
|
option :diskname,
|
17
|
-
long:
|
18
|
-
description:
|
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
|
22
22
|
vmname = @name_args[0]
|
23
23
|
if vmname.nil?
|
24
24
|
show_usage
|
25
|
-
fatal_exit(
|
25
|
+
fatal_exit("You must specify a virtual machine name")
|
26
26
|
end
|
27
27
|
|
28
28
|
size = @name_args[1]
|
29
29
|
if size.nil? || !size.match(/^\d+$/)
|
30
30
|
show_usage
|
31
|
-
fatal_exit(
|
31
|
+
fatal_exit("You must specify the new disk size")
|
32
32
|
end
|
33
33
|
|
34
34
|
disk_name = get_config(:diskname) unless get_config(:diskname).nil?
|
@@ -47,7 +47,7 @@ class Chef::Knife::VsphereVmDiskExtend < Chef::Knife::BaseVsphereCommand
|
|
47
47
|
names = disks.map { |disk| disk.deviceInfo.label }
|
48
48
|
abort("More than 1 disk found: #{names}, please use --diskname DISKNAME")
|
49
49
|
elsif disks.length == 0
|
50
|
-
abort(
|
50
|
+
abort("No disk found")
|
51
51
|
end
|
52
52
|
|
53
53
|
disk = disks[0]
|
@@ -57,9 +57,9 @@ 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(
|
60
|
+
operation: RbVmomi::VIM::VirtualDeviceConfigSpecOperation("edit"))]
|
61
61
|
)).wait_for_completion
|
62
62
|
|
63
|
-
puts
|
63
|
+
puts "Disk resized successfully"
|
64
64
|
end
|
65
65
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "chef/knife"
|
2
|
+
require "chef/knife/base_vsphere_command"
|
3
|
+
require "chef/knife/search_helper"
|
4
4
|
|
5
5
|
# List the disks attached to a VM
|
6
6
|
# VsphereVmdisklist extends the BaseVspherecommand
|
7
7
|
class Chef::Knife::VsphereVmDiskList < Chef::Knife::BaseVsphereCommand
|
8
8
|
include SearchHelper
|
9
9
|
|
10
|
-
banner
|
10
|
+
banner "knife vsphere vm disk list VMNAME"
|
11
11
|
|
12
12
|
common_options
|
13
13
|
|
@@ -18,7 +18,7 @@ class Chef::Knife::VsphereVmDiskList < Chef::Knife::BaseVsphereCommand
|
|
18
18
|
|
19
19
|
unless vmname = @name_args[0]
|
20
20
|
show_usage
|
21
|
-
fatal_exit
|
21
|
+
fatal_exit "You must specify a virtual machine name"
|
22
22
|
end
|
23
23
|
|
24
24
|
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
@@ -28,7 +28,7 @@ class Chef::Knife::VsphereVmDiskList < Chef::Knife::BaseVsphereCommand
|
|
28
28
|
end
|
29
29
|
|
30
30
|
disks.each do |disk|
|
31
|
-
puts
|
31
|
+
puts "%3d %20s %20s %s" % [disk.unitNumber,
|
32
32
|
disk.deviceInfo.label,
|
33
33
|
disk.backing.datastore.name,
|
34
34
|
Filesize.from("#{disk.capacityInKB} KiB").pretty]
|
@@ -1,29 +1,29 @@
|
|
1
1
|
# Author:: Ian Delahorne (<ian@delahorne.com>)
|
2
2
|
# License:: Apache License, Version 2.0
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
4
|
+
require "chef/knife"
|
5
|
+
require "chef/knife/base_vsphere_command"
|
6
|
+
require "chef/knife/search_helper"
|
7
7
|
|
8
8
|
# VsphereVMexecute extends the Basevspherecommand
|
9
9
|
class Chef::Knife::VsphereVmExecute < Chef::Knife::BaseVsphereCommand
|
10
10
|
include SearchHelper
|
11
11
|
|
12
|
-
banner
|
12
|
+
banner "knife vsphere vm execute VMNAME COMMAND ARGS"
|
13
13
|
|
14
14
|
option :exec_user,
|
15
|
-
long:
|
16
|
-
description:
|
15
|
+
long: "--exec-user USER",
|
16
|
+
description: "User to execute as",
|
17
17
|
required: true
|
18
18
|
|
19
19
|
option :exec_passwd,
|
20
|
-
long:
|
21
|
-
description:
|
20
|
+
long: "--exec-passwd PASSWORD",
|
21
|
+
description: "Password for execute user",
|
22
22
|
required: true
|
23
23
|
|
24
24
|
option :exec_dir,
|
25
|
-
long:
|
26
|
-
description:
|
25
|
+
long: "--exec-dir DIRECTORY",
|
26
|
+
description: "Working directory to execute in"
|
27
27
|
|
28
28
|
common_options
|
29
29
|
|
@@ -34,16 +34,16 @@ class Chef::Knife::VsphereVmExecute < Chef::Knife::BaseVsphereCommand
|
|
34
34
|
vmname = @name_args.shift
|
35
35
|
if vmname.nil?
|
36
36
|
show_usage
|
37
|
-
fatal_exit(
|
37
|
+
fatal_exit("You must specify a virtual machine name")
|
38
38
|
end
|
39
39
|
command = @name_args.shift
|
40
40
|
if command.nil?
|
41
41
|
show_usage
|
42
|
-
fatal_exit(
|
42
|
+
fatal_exit("You must specify a command to execute")
|
43
43
|
end
|
44
44
|
|
45
45
|
args = @name_args
|
46
|
-
args =
|
46
|
+
args = "" if args.nil? || args.empty?
|
47
47
|
|
48
48
|
vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
|
49
49
|
|
@@ -53,7 +53,7 @@ class Chef::Knife::VsphereVmExecute < Chef::Knife::BaseVsphereCommand
|
|
53
53
|
username: config[:exec_user],
|
54
54
|
password: config[:exec_passwd])
|
55
55
|
prog_spec = RbVmomi::VIM::GuestProgramSpec(programPath: command,
|
56
|
-
arguments: args.join(
|
56
|
+
arguments: args.join(" "),
|
57
57
|
workingDirectory: get_config(:exec_dir))
|
58
58
|
|
59
59
|
gom.processManager.StartProgramInGuest(vm: vm, auth: guest_auth, spec: prog_spec)
|
@@ -2,155 +2,155 @@
|
|
2
2
|
# License:: Apache License, Version 2.0
|
3
3
|
#
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
5
|
+
require "chef/knife"
|
6
|
+
require "chef/knife/base_vsphere_command"
|
7
|
+
require "chef/knife/search_helper"
|
8
8
|
|
9
9
|
# find vms belonging to pool that match criteria, display specified fields
|
10
10
|
class Chef::Knife::VsphereVmFind < Chef::Knife::BaseVsphereCommand
|
11
11
|
include SearchHelper
|
12
|
-
banner
|
12
|
+
banner "knife vsphere vm find"
|
13
13
|
|
14
|
-
VMFOLDER =
|
14
|
+
VMFOLDER = "vm".freeze
|
15
15
|
|
16
16
|
common_options
|
17
17
|
|
18
18
|
# Deprecating
|
19
19
|
option :pool,
|
20
|
-
long:
|
21
|
-
short:
|
22
|
-
description:
|
20
|
+
long: "--pool pool",
|
21
|
+
short: "-h",
|
22
|
+
description: "Target pool"
|
23
23
|
# Deprecating
|
24
24
|
option :poolpath,
|
25
|
-
long:
|
26
|
-
description:
|
25
|
+
long: "--pool-path",
|
26
|
+
description: "Pool is full-path"
|
27
27
|
|
28
28
|
option :esx_disk,
|
29
|
-
long:
|
30
|
-
description:
|
29
|
+
long: "--esx-disk",
|
30
|
+
description: "Show esx disks"
|
31
31
|
|
32
32
|
option :snapshots,
|
33
|
-
long:
|
34
|
-
description:
|
33
|
+
long: "--snapshots",
|
34
|
+
description: "Show snapshots"
|
35
35
|
|
36
36
|
option :os_disk,
|
37
|
-
long:
|
38
|
-
description:
|
37
|
+
long: "--os-disks",
|
38
|
+
description: "Show os disks"
|
39
39
|
|
40
40
|
option :cpu,
|
41
|
-
long:
|
42
|
-
description:
|
41
|
+
long: "--cpu",
|
42
|
+
description: "Show cpu"
|
43
43
|
|
44
44
|
option :cpu_hot_add_enabled,
|
45
|
-
long:
|
46
|
-
description:
|
45
|
+
long: "--cpu_hot_add_enabled",
|
46
|
+
description: "Show cpu hot add enabled"
|
47
47
|
|
48
48
|
option :memory_hot_add_enabled,
|
49
|
-
long:
|
50
|
-
description:
|
49
|
+
long: "--memory_hot_add_enabled",
|
50
|
+
description: "Show memory hot add enabled"
|
51
51
|
|
52
52
|
option :ram,
|
53
|
-
long:
|
54
|
-
description:
|
53
|
+
long: "--ram",
|
54
|
+
description: "Show ram"
|
55
55
|
|
56
56
|
option :ip,
|
57
|
-
long:
|
58
|
-
description:
|
57
|
+
long: "--ip",
|
58
|
+
description: "Show primary ip"
|
59
59
|
|
60
60
|
option :networks,
|
61
|
-
long:
|
62
|
-
description:
|
61
|
+
long: "--networks",
|
62
|
+
description: "Show all networks with their IPs"
|
63
63
|
|
64
64
|
option :soff,
|
65
|
-
long:
|
66
|
-
description:
|
65
|
+
long: "--powered-off",
|
66
|
+
description: "Show only stopped machines"
|
67
67
|
|
68
68
|
option :son,
|
69
|
-
long:
|
70
|
-
description:
|
69
|
+
long: "--powered-on",
|
70
|
+
description: "Show only started machines"
|
71
71
|
|
72
72
|
option :matchip,
|
73
|
-
long:
|
74
|
-
description:
|
73
|
+
long: "--match-ip IP",
|
74
|
+
description: "match ip"
|
75
75
|
|
76
76
|
option :matchos,
|
77
|
-
long:
|
78
|
-
description:
|
77
|
+
long: "--match-os OS",
|
78
|
+
description: "match os"
|
79
79
|
|
80
80
|
option :matchname,
|
81
|
-
long:
|
82
|
-
description:
|
81
|
+
long: "--match-name VMNAME",
|
82
|
+
description: "match name"
|
83
83
|
|
84
84
|
option :matchtools,
|
85
|
-
long:
|
86
|
-
description:
|
85
|
+
long: "--match-tools TOOLSSTATE",
|
86
|
+
description: "match tools state"
|
87
87
|
|
88
88
|
option :hostname,
|
89
|
-
long:
|
90
|
-
description:
|
89
|
+
long: "--hostname",
|
90
|
+
description: "show hostname of the guest"
|
91
91
|
|
92
92
|
option :host_name,
|
93
|
-
long:
|
94
|
-
description:
|
93
|
+
long: "--host_name",
|
94
|
+
description: "show name of the VMs host"
|
95
95
|
|
96
96
|
option :os,
|
97
|
-
long:
|
98
|
-
description:
|
97
|
+
long: "--os",
|
98
|
+
description: "show os details"
|
99
99
|
|
100
100
|
option :alarms,
|
101
|
-
long:
|
102
|
-
description:
|
101
|
+
long: "--alarms",
|
102
|
+
description: "show alarm status"
|
103
103
|
|
104
104
|
option :tools,
|
105
|
-
long:
|
106
|
-
description:
|
105
|
+
long: "--tools",
|
106
|
+
description: "show tools status"
|
107
107
|
|
108
108
|
option :full_path,
|
109
|
-
long:
|
110
|
-
description:
|
109
|
+
long: "--full-path",
|
110
|
+
description: "Show full folder path to the VM"
|
111
111
|
|
112
112
|
option :short_path,
|
113
|
-
long:
|
114
|
-
description:
|
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
|
|
118
118
|
# Main entry point to the command
|
119
119
|
def run
|
120
|
-
property_map(
|
121
|
-
property_map(
|
122
|
-
|
123
|
-
property_map(
|
124
|
-
property_map(
|
125
|
-
property_map(
|
126
|
-
property_map(
|
127
|
-
property_map(
|
128
|
-
property_map(
|
129
|
-
property_map(
|
130
|
-
property_map(
|
131
|
-
property_map(
|
132
|
-
property_map(
|
120
|
+
property_map("name" => "name")
|
121
|
+
property_map("runtime.powerState" => "state") { |value| state_to_english(value) }
|
122
|
+
|
123
|
+
property_map("config.cpuHotAddEnabled" => "cpu_hot_add_enabled") if get_config(:cpu_hot_add_enabled)
|
124
|
+
property_map("config.memoryHotAddEnabled" => "memory_hot_add_enabled") if get_config(:memory_hot_add_enabled)
|
125
|
+
property_map("guest.guestFullName" => "os") if get_config(:matchos) || get_config(:os)
|
126
|
+
property_map("guest.hostName" => "hostname") if get_config(:hostname)
|
127
|
+
property_map("guest.ipAddress" => "ip") if get_config(:matchip) || get_config(:ip)
|
128
|
+
property_map("guest.toolsStatus" => "tools") if get_config(:matchtools) || get_config(:tools)
|
129
|
+
property_map("summary.config.memorySizeMB" => "ram") if get_config(:ram)
|
130
|
+
property_map("summary.config.numCpu" => "cpu") if get_config(:cpu)
|
131
|
+
property_map("summary.overallStatus" => "alarms") if get_config(:alarms)
|
132
|
+
property_map("summary.runtime.host" => "host_name", &:name) if get_config(:host_name)
|
133
133
|
|
134
134
|
# TODO: https://www.vmware.com/support/developer/converter-sdk/conv55_apireference/vim.VirtualMachine.html#field_detail says this is deprecated
|
135
|
-
property_map(
|
136
|
-
property_map(
|
135
|
+
property_map("layout.disk" => "esx_disk") { |disks| disks.map(&:diskFile) } if get_config(:esx_disk)
|
136
|
+
property_map("snapshot.rootSnapshotList" => "snapshots") { |snapshots| Array(snapshots).map(&:name) } if get_config(:snapshots)
|
137
137
|
|
138
138
|
if get_config(:networks)
|
139
|
-
property_map(
|
139
|
+
property_map("guest.net" => "networks") do |nets|
|
140
140
|
ipregex = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/
|
141
141
|
nets.map do |net|
|
142
142
|
firstip = net.ipConfig.ipAddress.first { |i| i.ipAddress[ipregex] }
|
143
|
-
{
|
143
|
+
{ "name" => net.network, "ip" => firstip.ipAddress, "prefix" => firstip.prefixLength }
|
144
144
|
end
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
148
|
if get_config(:os_disk)
|
149
|
-
property_map(
|
149
|
+
property_map("guest.disk" => "disks") do |disks|
|
150
150
|
disks.map do |disk|
|
151
|
-
{
|
152
|
-
|
153
|
-
|
151
|
+
{ "name" => disk.diskPath,
|
152
|
+
"capacity" => disk.capacity / 1024 / 1024,
|
153
|
+
"free" => disk.freeSpace / 1024 / 1024 }
|
154
154
|
end
|
155
155
|
end
|
156
156
|
end
|
@@ -165,8 +165,8 @@ class Chef::Knife::VsphereVmFind < Chef::Knife::BaseVsphereCommand
|
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
168
|
-
thisvm[
|
169
|
-
thisvm[
|
168
|
+
thisvm["folder"] = full_path_to(vm) if get_config(:full_path)
|
169
|
+
thisvm["folder"] = vm.obj.parent.name if get_config(:short_path)
|
170
170
|
|
171
171
|
thisvm
|
172
172
|
end
|
@@ -195,11 +195,11 @@ class Chef::Knife::VsphereVmFind < Chef::Knife::BaseVsphereCommand
|
|
195
195
|
end
|
196
196
|
|
197
197
|
def match_vm?(vm)
|
198
|
-
match_name?(vm[
|
199
|
-
match_tools?(vm[
|
200
|
-
match_power_state?(vm[
|
201
|
-
match_ip?(vm[
|
202
|
-
match_os?(vm[
|
198
|
+
match_name?(vm["name"]) &&
|
199
|
+
match_tools?(vm["guest.toolsStatus"]) &&
|
200
|
+
match_power_state?(vm["runtime.powerState"]) &&
|
201
|
+
match_ip?(vm["guest.ipAddress"]) &&
|
202
|
+
match_os?(vm["guest.guestFullName"])
|
203
203
|
end
|
204
204
|
|
205
205
|
def match_name?(name)
|
@@ -217,7 +217,7 @@ class Chef::Knife::VsphereVmFind < Chef::Knife::BaseVsphereCommand
|
|
217
217
|
end
|
218
218
|
|
219
219
|
def match_ip?(ip)
|
220
|
-
ip ||=
|
220
|
+
ip ||= "NOTANIP"
|
221
221
|
!get_config(:matchip) || ip.include?(get_config(:matchip))
|
222
222
|
end
|
223
223
|
|
@@ -228,11 +228,11 @@ class Chef::Knife::VsphereVmFind < Chef::Knife::BaseVsphereCommand
|
|
228
228
|
def state_to_english(power_state)
|
229
229
|
case power_state
|
230
230
|
when PS_ON
|
231
|
-
|
231
|
+
"on"
|
232
232
|
when PS_OFF
|
233
|
-
|
233
|
+
"off"
|
234
234
|
when PS_SUSPENDED
|
235
|
-
|
235
|
+
"suspended"
|
236
236
|
end
|
237
237
|
end
|
238
238
|
|
@@ -244,6 +244,6 @@ class Chef::Knife::VsphereVmFind < Chef::Knife::BaseVsphereCommand
|
|
244
244
|
path.unshift iterator.name
|
245
245
|
end
|
246
246
|
|
247
|
-
path.join
|
247
|
+
path.join "/"
|
248
248
|
end
|
249
249
|
end
|