knife-vsphere 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -39,6 +39,10 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
39
39
|
:description => "The source VM / Template to clone from",
|
40
40
|
:required => true
|
41
41
|
|
42
|
+
option :annotation,
|
43
|
+
:long => "--annotation TEXT",
|
44
|
+
:description => "Add TEXT in Notes field from annotation"
|
45
|
+
|
42
46
|
option :customization_spec,
|
43
47
|
:long => "--cspec CUST_SPEC",
|
44
48
|
:description => "The name of any customization specification to apply"
|
@@ -264,6 +268,10 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
264
268
|
|
265
269
|
clone_spec.config = RbVmomi::VIM.VirtualMachineConfigSpec(:deviceChange => Array.new)
|
266
270
|
|
271
|
+
if get_config(:annotation)
|
272
|
+
clone_spec.config.annotation = get_config(:annotation)
|
273
|
+
end
|
274
|
+
|
267
275
|
if get_config(:customization_cpucount)
|
268
276
|
clone_spec.config.numCPUs = get_config(:customization_cpucount)
|
269
277
|
end
|
@@ -318,7 +326,6 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
318
326
|
|
319
327
|
unless get_config(:disable_customization)
|
320
328
|
use_ident = !config[:customization_hostname].nil? || !get_config(:customization_domain).nil? || cust_spec.identity.nil?
|
321
|
-
end
|
322
329
|
|
323
330
|
|
324
331
|
if use_ident
|
@@ -346,6 +353,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
346
353
|
end
|
347
354
|
|
348
355
|
clone_spec.customization = cust_spec
|
356
|
+
end
|
349
357
|
clone_spec
|
350
358
|
end
|
351
359
|
|
@@ -1,58 +1,66 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Ezra Pagel (<ezra@cpan.org>)
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
require 'chef/knife'
|
6
|
-
require 'chef/knife/BaseVsphereCommand'
|
7
|
-
|
8
|
-
# Lists all known virtual machines in the configured datacenter
|
9
|
-
class Chef::Knife::VsphereVmList < Chef::Knife::BaseVsphereCommand
|
10
|
-
|
11
|
-
banner "knife vsphere vm list"
|
12
|
-
|
13
|
-
get_common_options
|
14
|
-
|
15
|
-
option :recursive,
|
16
|
-
:long => "--recursive",
|
17
|
-
:short => "-r",
|
18
|
-
:description => "Recurse down through sub-folders"
|
19
|
-
|
20
|
-
option :only_folders,
|
21
|
-
:long => "--only-folders",
|
22
|
-
:description => "Print only sub-folders"
|
23
|
-
|
24
|
-
def traverse_folders(folder)
|
25
|
-
puts "#{ui.color("Folder", :cyan)}: "+(folder.path[3..-1].map{|x| x[1]}.*'/')
|
26
|
-
print_vms_in_folder(folder) unless get_config(:only_folders)
|
27
|
-
folders = find_all_in_folder(folder, RbVmomi::VIM::Folder)
|
28
|
-
folders.each do |child|
|
29
|
-
traverse_folders(child)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def print_vms_in_folder(folder)
|
34
|
-
vms = find_all_in_folder(folder, RbVmomi::VIM::VirtualMachine)
|
35
|
-
vms.each do |vm|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
1
|
+
#
|
2
|
+
# Author:: Ezra Pagel (<ezra@cpan.org>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
require 'chef/knife'
|
6
|
+
require 'chef/knife/BaseVsphereCommand'
|
7
|
+
|
8
|
+
# Lists all known virtual machines in the configured datacenter
|
9
|
+
class Chef::Knife::VsphereVmList < Chef::Knife::BaseVsphereCommand
|
10
|
+
|
11
|
+
banner "knife vsphere vm list"
|
12
|
+
|
13
|
+
get_common_options
|
14
|
+
|
15
|
+
option :recursive,
|
16
|
+
:long => "--recursive",
|
17
|
+
:short => "-r",
|
18
|
+
:description => "Recurse down through sub-folders"
|
19
|
+
|
20
|
+
option :only_folders,
|
21
|
+
:long => "--only-folders",
|
22
|
+
:description => "Print only sub-folders"
|
23
|
+
|
24
|
+
def traverse_folders(folder)
|
25
|
+
puts "#{ui.color("Folder", :cyan)}: "+(folder.path[3..-1].map{|x| x[1]}.*'/')
|
26
|
+
print_vms_in_folder(folder) unless get_config(:only_folders)
|
27
|
+
folders = find_all_in_folder(folder, RbVmomi::VIM::Folder)
|
28
|
+
folders.each do |child|
|
29
|
+
traverse_folders(child)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def print_vms_in_folder(folder)
|
34
|
+
vms = find_all_in_folder(folder, RbVmomi::VIM::VirtualMachine)
|
35
|
+
vms.each do |vm|
|
36
|
+
state = case vm.runtime.powerState
|
37
|
+
when PsOn
|
38
|
+
ui.color("on", :green)
|
39
|
+
when PsOff
|
40
|
+
ui.color("off", :red)
|
41
|
+
when PsSuspended
|
42
|
+
ui.color("suspended", :yellow)
|
43
|
+
end
|
44
|
+
puts "#{ui.color("VM Name:", :cyan)} #{vm.name}\t#{ui.color("IP:", :magenta)} #{vm.guest.ipAddress}\t#{ui.color("RAM:", :magenta)} #{vm.summary.config.memorySizeMB}\t#{ui.color("State:", :cyan)} #{state}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def print_subfolders(folder)
|
49
|
+
folders = find_all_in_folder(folder, RbVmomi::VIM::Folder)
|
50
|
+
folders.each do |subfolder|
|
51
|
+
puts "#{ui.color("Folder Name", :cyan)}: #{subfolder.name}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def run
|
56
|
+
$stdout.sync = true
|
57
|
+
vim = get_vim_connection
|
58
|
+
baseFolder = find_folder(get_config(:folder));
|
59
|
+
if get_config(:recursive)
|
60
|
+
traverse_folders(baseFolder)
|
61
|
+
else
|
62
|
+
print_subfolders(baseFolder)
|
63
|
+
print_vms_in_folder(baseFolder)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: knife-vsphere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.8.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ezra Pagel
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-08-02 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|