knife-vsphere 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chef/knife/BaseVsphereCommand.rb +167 -111
- data/lib/chef/knife/vsphere_customization_list.rb +29 -29
- data/lib/chef/knife/vsphere_template_list.rb +32 -35
- data/lib/chef/knife/vsphere_vm_clone.rb +360 -176
- data/lib/chef/knife/vsphere_vm_delete.rb +39 -41
- data/lib/chef/knife/vsphere_vm_list.rb +28 -42
- data/lib/chef/knife/vsphere_vm_state.rb +85 -89
- data/lib/knife-vsphere/version.rb +4 -4
- metadata +2 -28
@@ -1,41 +1,39 @@
|
|
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/BaseVsphereCommand'
|
8
|
-
require 'rbvmomi'
|
9
|
-
|
10
|
-
# Delete a virtual machine from vCenter
|
11
|
-
class Chef::Knife::VsphereVmDelete < Chef::Knife::BaseVsphereCommand
|
12
|
-
|
13
|
-
banner "knife vsphere vm delete VMNAME"
|
14
|
-
|
15
|
-
get_common_options
|
16
|
-
|
17
|
-
def run
|
18
|
-
$stdout.sync = true
|
19
|
-
|
20
|
-
vmname = @name_args[0]
|
21
|
-
|
22
|
-
if vmname.nil?
|
23
|
-
show_usage
|
24
|
-
fatal_exit("You must specify a virtual machine name")
|
25
|
-
end
|
26
|
-
|
27
|
-
vim = get_vim_connection
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
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/BaseVsphereCommand'
|
8
|
+
require 'rbvmomi'
|
9
|
+
|
10
|
+
# Delete a virtual machine from vCenter
|
11
|
+
class Chef::Knife::VsphereVmDelete < Chef::Knife::BaseVsphereCommand
|
12
|
+
|
13
|
+
banner "knife vsphere vm delete VMNAME"
|
14
|
+
|
15
|
+
get_common_options
|
16
|
+
|
17
|
+
def run
|
18
|
+
$stdout.sync = true
|
19
|
+
|
20
|
+
vmname = @name_args[0]
|
21
|
+
|
22
|
+
if vmname.nil?
|
23
|
+
show_usage
|
24
|
+
fatal_exit("You must specify a virtual machine name")
|
25
|
+
end
|
26
|
+
|
27
|
+
vim = get_vim_connection
|
28
|
+
|
29
|
+
baseFolder = find_folder(config[:folder]);
|
30
|
+
|
31
|
+
vm = find_in_folder(baseFolder, RbVmomi::VIM::VirtualMachine, vmname) or
|
32
|
+
fatal_exit("VM #{vmname} not found")
|
33
|
+
|
34
|
+
vm.PowerOffVM_Task.wait_for_completion unless vm.runtime.powerState == "poweredOff"
|
35
|
+
vm.Destroy_Task
|
36
|
+
puts "Deleted virtual machine #{vmname}"
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -1,42 +1,28 @@
|
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
baseFolder = dc.vmFolder;
|
31
|
-
|
32
|
-
if config[:folder]
|
33
|
-
baseFolder = get_folders(dc.vmFolder).find { |f| f.name == config[:folder]} or
|
34
|
-
abort "no such folder #{config[:folder]}"
|
35
|
-
end
|
36
|
-
|
37
|
-
vms = find_all_in_folders(baseFolder, RbVmomi::VIM::VirtualMachine)
|
38
|
-
vms.each do |vm|
|
39
|
-
puts "#{ui.color("VM Name", :cyan)}: #{vm.name}"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
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/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
|
+
def run
|
16
|
+
|
17
|
+
$stdout.sync = true
|
18
|
+
|
19
|
+
vim = get_vim_connection
|
20
|
+
|
21
|
+
baseFolder = find_folder(config[:folder]);
|
22
|
+
|
23
|
+
vms = find_all_in_folder(baseFolder, RbVmomi::VIM::VirtualMachine)
|
24
|
+
vms.each do |vm|
|
25
|
+
puts "#{ui.color("VM Name", :cyan)}: #{vm.name}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,89 +1,85 @@
|
|
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/BaseVsphereCommand'
|
8
|
-
require 'rbvmomi'
|
9
|
-
require 'netaddr'
|
10
|
-
|
11
|
-
PsOn = 'poweredOn'
|
12
|
-
PsOff = 'poweredOff'
|
13
|
-
PsSuspended = 'suspended'
|
14
|
-
|
15
|
-
PowerStates = {
|
16
|
-
PsOn => 'powered on',
|
17
|
-
PsOff => 'powered off',
|
18
|
-
PsSuspended => 'suspended'
|
19
|
-
}
|
20
|
-
|
21
|
-
# Manage power state of a virtual machine
|
22
|
-
class Chef::Knife::VsphereVmState < Chef::Knife::BaseVsphereCommand
|
23
|
-
|
24
|
-
banner "knife vsphere vm state VMNAME (options)"
|
25
|
-
|
26
|
-
get_common_options
|
27
|
-
|
28
|
-
option :state,
|
29
|
-
:short => "-s STATE",
|
30
|
-
:long => "--state STATE",
|
31
|
-
:description => "The power state to transition the VM into; one of on|off|suspended"
|
32
|
-
|
33
|
-
def run
|
34
|
-
|
35
|
-
$stdout.sync = true
|
36
|
-
|
37
|
-
vmname = @name_args[0]
|
38
|
-
if vmname.nil?
|
39
|
-
show_usage
|
40
|
-
ui.fatal("You must specify a virtual machine name")
|
41
|
-
exit 1
|
42
|
-
end
|
43
|
-
|
44
|
-
vim = get_vim_connection
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
puts "
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
puts "
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
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/BaseVsphereCommand'
|
8
|
+
require 'rbvmomi'
|
9
|
+
require 'netaddr'
|
10
|
+
|
11
|
+
PsOn = 'poweredOn'
|
12
|
+
PsOff = 'poweredOff'
|
13
|
+
PsSuspended = 'suspended'
|
14
|
+
|
15
|
+
PowerStates = {
|
16
|
+
PsOn => 'powered on',
|
17
|
+
PsOff => 'powered off',
|
18
|
+
PsSuspended => 'suspended'
|
19
|
+
}
|
20
|
+
|
21
|
+
# Manage power state of a virtual machine
|
22
|
+
class Chef::Knife::VsphereVmState < Chef::Knife::BaseVsphereCommand
|
23
|
+
|
24
|
+
banner "knife vsphere vm state VMNAME (options)"
|
25
|
+
|
26
|
+
get_common_options
|
27
|
+
|
28
|
+
option :state,
|
29
|
+
:short => "-s STATE",
|
30
|
+
:long => "--state STATE",
|
31
|
+
:description => "The power state to transition the VM into; one of on|off|suspended"
|
32
|
+
|
33
|
+
def run
|
34
|
+
|
35
|
+
$stdout.sync = true
|
36
|
+
|
37
|
+
vmname = @name_args[0]
|
38
|
+
if vmname.nil?
|
39
|
+
show_usage
|
40
|
+
ui.fatal("You must specify a virtual machine name")
|
41
|
+
exit 1
|
42
|
+
end
|
43
|
+
|
44
|
+
vim = get_vim_connection
|
45
|
+
|
46
|
+
baseFolder = find_folder(config[:folder]);
|
47
|
+
|
48
|
+
vm = find_in_folder(baseFolder, RbVmomi::VIM::VirtualMachine, vmname) or
|
49
|
+
abort "VM #{vmname} not found"
|
50
|
+
|
51
|
+
state = vm.runtime.powerState
|
52
|
+
|
53
|
+
if config[:state].nil?
|
54
|
+
puts "VM #{vmname} is currently " + PowerStates[vm.runtime.powerState]
|
55
|
+
else
|
56
|
+
|
57
|
+
case config[:state]
|
58
|
+
when 'on'
|
59
|
+
if state == PsOn
|
60
|
+
puts "Virtual machine #{vmname} was already powered on"
|
61
|
+
else
|
62
|
+
vm.PowerOnVM_Task.wait_for_completion
|
63
|
+
puts "Powered on virtual machine #{vmname}"
|
64
|
+
end
|
65
|
+
when 'off'
|
66
|
+
if state == PsOff
|
67
|
+
puts "Virtual machine #{vmname} was already powered off"
|
68
|
+
else
|
69
|
+
vm.PowerOffVM_Task.wait_for_completion
|
70
|
+
puts "Powered off virtual machine #{vmname}"
|
71
|
+
end
|
72
|
+
when 'suspend'
|
73
|
+
if state == PowerStates['suspended']
|
74
|
+
puts "Virtual machine #{vmname} was already suspended"
|
75
|
+
else
|
76
|
+
vm.SuspendVM_Task.wait_for_completion
|
77
|
+
puts "Suspended virtual machine #{vmname}"
|
78
|
+
end
|
79
|
+
when 'reset'
|
80
|
+
vm.ResetVM_Task.wait_for_completion
|
81
|
+
puts "Reset virtual machine #{vmname}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module KnifeVsphere
|
2
|
-
VERSION = "0.1.
|
3
|
-
end
|
4
|
-
|
1
|
+
module KnifeVsphere
|
2
|
+
VERSION = "0.1.6"
|
3
|
+
end
|
4
|
+
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-vsphere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 17
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 5
|
10
|
-
version: 0.1.5
|
5
|
+
version: 0.1.6
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Ezra Pagel
|
@@ -15,7 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date:
|
13
|
+
date: 2012-01-17 00:00:00 -06:00
|
19
14
|
default_executable:
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
@@ -26,11 +21,6 @@ dependencies:
|
|
26
21
|
requirements:
|
27
22
|
- - ~>
|
28
23
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 5
|
33
|
-
- 0
|
34
24
|
version: 1.5.0
|
35
25
|
type: :runtime
|
36
26
|
version_requirements: *id001
|
@@ -42,11 +32,6 @@ dependencies:
|
|
42
32
|
requirements:
|
43
33
|
- - ~>
|
44
34
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 55
|
46
|
-
segments:
|
47
|
-
- 0
|
48
|
-
- 10
|
49
|
-
- 0
|
50
35
|
version: 0.10.0
|
51
36
|
type: :runtime
|
52
37
|
version_requirements: *id002
|
@@ -58,11 +43,6 @@ dependencies:
|
|
58
43
|
requirements:
|
59
44
|
- - ~>
|
60
45
|
- !ruby/object:Gem::Version
|
61
|
-
hash: 25
|
62
|
-
segments:
|
63
|
-
- 1
|
64
|
-
- 2
|
65
|
-
- 3
|
66
46
|
version: 1.2.3
|
67
47
|
type: :runtime
|
68
48
|
version_requirements: *id003
|
@@ -97,18 +77,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
77
|
requirements:
|
98
78
|
- - ">="
|
99
79
|
- !ruby/object:Gem::Version
|
100
|
-
hash: 3
|
101
|
-
segments:
|
102
|
-
- 0
|
103
80
|
version: "0"
|
104
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
82
|
none: false
|
106
83
|
requirements:
|
107
84
|
- - ">="
|
108
85
|
- !ruby/object:Gem::Version
|
109
|
-
hash: 3
|
110
|
-
segments:
|
111
|
-
- 0
|
112
86
|
version: "0"
|
113
87
|
requirements: []
|
114
88
|
|