knife-vsphere 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chef/knife/BaseVsphereCommand.rb +169 -167
- data/lib/chef/knife/vsphere_customization_list.rb +29 -29
- data/lib/chef/knife/vsphere_datastore_list.rb +58 -0
- data/lib/chef/knife/vsphere_template_list.rb +32 -32
- data/lib/chef/knife/vsphere_vm_clone.rb +397 -373
- data/lib/chef/knife/vsphere_vm_delete.rb +39 -39
- data/lib/chef/knife/vsphere_vm_list.rb +32 -28
- data/lib/chef/knife/vsphere_vm_state.rb +85 -85
- data/lib/knife-vsphere/version.rb +4 -4
- metadata +38 -46
@@ -1,39 +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
|
-
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
|
+
#
|
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,28 +1,32 @@
|
|
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
|
-
|
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
|
+
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
|
+
folders = find_all_in_folder(baseFolder, RbVmomi::VIM::Folder)
|
28
|
+
folders.each do |folder|
|
29
|
+
puts "#{ui.color("Folder Name", :cyan)}: #{folder.name}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,85 +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
|
-
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
|
+
#
|
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.8"
|
3
|
+
end
|
4
|
+
|
metadata
CHANGED
@@ -1,63 +1,59 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-vsphere
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.8
|
4
5
|
prerelease:
|
5
|
-
version: 0.1.7
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Ezra Pagel
|
9
|
-
- Jesse Campbell
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
|
14
|
-
date: 2012-01-24 00:00:00 -06:00
|
12
|
+
date: 2012-03-06 00:00:00.000000000 +01:00
|
15
13
|
default_executable:
|
16
|
-
dependencies:
|
17
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
18
16
|
name: netaddr
|
19
|
-
|
20
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirement: &70237366117520 !ruby/object:Gem::Requirement
|
21
18
|
none: false
|
22
|
-
requirements:
|
19
|
+
requirements:
|
23
20
|
- - ~>
|
24
|
-
- !ruby/object:Gem::Version
|
21
|
+
- !ruby/object:Gem::Version
|
25
22
|
version: 1.5.0
|
26
23
|
type: :runtime
|
27
|
-
version_requirements: *id001
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: chef
|
30
24
|
prerelease: false
|
31
|
-
|
25
|
+
version_requirements: *70237366117520
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: chef
|
28
|
+
requirement: &70237366113920 !ruby/object:Gem::Requirement
|
32
29
|
none: false
|
33
|
-
requirements:
|
30
|
+
requirements:
|
34
31
|
- - ~>
|
35
|
-
- !ruby/object:Gem::Version
|
32
|
+
- !ruby/object:Gem::Version
|
36
33
|
version: 0.10.0
|
37
34
|
type: :runtime
|
38
|
-
version_requirements: *id002
|
39
|
-
- !ruby/object:Gem::Dependency
|
40
|
-
name: rbvmomi
|
41
35
|
prerelease: false
|
42
|
-
|
36
|
+
version_requirements: *70237366113920
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rbvmomi
|
39
|
+
requirement: &70237366111900 !ruby/object:Gem::Requirement
|
43
40
|
none: false
|
44
|
-
requirements:
|
41
|
+
requirements:
|
45
42
|
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
43
|
+
- !ruby/object:Gem::Version
|
47
44
|
version: 1.2.3
|
48
45
|
type: :runtime
|
49
|
-
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70237366111900
|
50
48
|
description: VMware vSphere Support for Chef's Knife Command
|
51
49
|
email: ezra@cpan.org
|
52
50
|
executables: []
|
53
|
-
|
54
51
|
extensions: []
|
55
|
-
|
56
52
|
extra_rdoc_files: []
|
57
|
-
|
58
|
-
files:
|
53
|
+
files:
|
59
54
|
- lib/chef/knife/BaseVsphereCommand.rb
|
60
55
|
- lib/chef/knife/vsphere_customization_list.rb
|
56
|
+
- lib/chef/knife/vsphere_datastore_list.rb
|
61
57
|
- lib/chef/knife/vsphere_template_list.rb
|
62
58
|
- lib/chef/knife/vsphere_vm_clone.rb
|
63
59
|
- lib/chef/knife/vsphere_vm_delete.rb
|
@@ -65,32 +61,28 @@ files:
|
|
65
61
|
- lib/chef/knife/vsphere_vm_state.rb
|
66
62
|
- lib/knife-vsphere/version.rb
|
67
63
|
has_rdoc: true
|
68
|
-
homepage:
|
64
|
+
homepage:
|
69
65
|
licenses: []
|
70
|
-
|
71
66
|
post_install_message:
|
72
67
|
rdoc_options: []
|
73
|
-
|
74
|
-
require_paths:
|
68
|
+
require_paths:
|
75
69
|
- lib
|
76
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
71
|
none: false
|
78
|
-
requirements:
|
79
|
-
- -
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version:
|
82
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
77
|
none: false
|
84
|
-
requirements:
|
85
|
-
- -
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version:
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
88
82
|
requirements: []
|
89
|
-
|
90
83
|
rubyforge_project:
|
91
84
|
rubygems_version: 1.6.2
|
92
85
|
signing_key:
|
93
86
|
specification_version: 3
|
94
87
|
summary: vSphere Support for Knife
|
95
88
|
test_files: []
|
96
|
-
|