esx 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +20 -0
- data/README.md +83 -0
- data/Rakefile +41 -0
- data/bin/esx +62 -0
- data/examples/basics.rb +36 -0
- data/lib/esx.rb +256 -0
- data/test/helper.rb +18 -0
- data/test/test_esx.rb +7 -0
- metadata +177 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.2"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Sergio Rubio
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# ESX
|
2
|
+
|
3
|
+
Simple rbvmomi wrapper to manage VMWare ESX hosts
|
4
|
+
|
5
|
+
# Usage
|
6
|
+
|
7
|
+
ESX ruby library includes a script to print ESX host information.
|
8
|
+
|
9
|
+
Usage: esx my-esx-host-here
|
10
|
+
|
11
|
+
This will ask you for the username and password of the host.
|
12
|
+
|
13
|
+
Sample output:
|
14
|
+
|
15
|
+
*********
|
16
|
+
ESXHOST1
|
17
|
+
*********
|
18
|
+
Memory Size: 32756
|
19
|
+
Memory Usage: 7429
|
20
|
+
Cpu Cores: 8
|
21
|
+
Power State: poweredOn
|
22
|
+
|
23
|
+
Virtual Machines:
|
24
|
+
+-------------------------+--------+------+------+-------+
|
25
|
+
| NAME | MEMORY | CPUS | NICS | DISKS |
|
26
|
+
+-------------------------+--------+------+------+-------+
|
27
|
+
| foobar | 128 | 1 | 1 | 1 |
|
28
|
+
| foobar2 | 256 | 2 | 1 | 1 |
|
29
|
+
+-------------------------+--------+------+------+-------+
|
30
|
+
|
31
|
+
Datastores:
|
32
|
+
+------------+--------------+--------------+-----------+------+---------------------------------------------------+
|
33
|
+
| NAME | CAPACITY | FREESPACE | ACCESIBLE | TYPE | URL |
|
34
|
+
+------------+--------------+--------------+-----------+------+---------------------------------------------------+
|
35
|
+
| datastore2 | 146565758976 | 145547591680 | VMFS | true | /vmfs/volumes/4e611c69-16474ca5-d290-5ef3fc9a99c3 |
|
36
|
+
| datastore1 | 141465485312 | 20716716032 | VMFS | true | /vmfs/volumes/4e6117e7-35c82a3e-ba79-5cf3fc9699c2 |
|
37
|
+
+------------+--------------+--------------+-----------+------+---------------------------------------------------+
|
38
|
+
|
39
|
+
|
40
|
+
# Using the library
|
41
|
+
|
42
|
+
require 'rubygems'
|
43
|
+
require 'lib/esx.rb'
|
44
|
+
|
45
|
+
|
46
|
+
# Connect to the ESX Host
|
47
|
+
host = ESX::Host.connect 'my-esx-host', 'root', 'secret'
|
48
|
+
|
49
|
+
# Print hypervisor info
|
50
|
+
puts
|
51
|
+
name = host.name.upcase
|
52
|
+
puts "*" * name.size
|
53
|
+
puts name
|
54
|
+
puts "*" * name.size
|
55
|
+
puts "Memory Size: %s" % host.memory_size.bytes.to.megabytes.to_i
|
56
|
+
puts "Memory Usage: %s" % host.memory_usage.bytes.to.megabytes.to_i
|
57
|
+
puts "Cpu Cores: %s" % host.cpu_cores
|
58
|
+
puts "Power State: %s" % host.power_state
|
59
|
+
|
60
|
+
# Create a VM with 4GB disk, 128 MB mem, e1000 nic, 1CPU in datastore1
|
61
|
+
vm = host.create_vm :vm_name => 'foobar'
|
62
|
+
|
63
|
+
# Create a VM with 5GB disk, 256 MB mem, e1000 nic, 1CPU in datastore2
|
64
|
+
vm = host.create_vm :vm_name => 'foobar2', :disk_size => 5000, :cpus => 2, :memory => 256, :datastore => 'datastore2'
|
65
|
+
|
66
|
+
|
67
|
+
host.virtual_machines.each do |vm|
|
68
|
+
|
69
|
+
# PowerOff the VM if powered On
|
70
|
+
vm.power_off if (vm.name =~ /foobar/ and vm.power_state == 'poweredOn')
|
71
|
+
|
72
|
+
# Destroy the VM if name matches foobar
|
73
|
+
if vm.name =~ /foobar.*/
|
74
|
+
vm.destroy
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
# Copyright
|
80
|
+
|
81
|
+
Copyright (c) 2011 Sergio Rubio. See LICENSE.txt for
|
82
|
+
further details.
|
83
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'lib/esx.rb'
|
4
|
+
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
8
|
+
gem.version = ESX::VERSION
|
9
|
+
gem.name = "esx"
|
10
|
+
gem.homepage = "http://github.com/rubiojr/esx"
|
11
|
+
gem.license = "MIT"
|
12
|
+
gem.summary = %Q{Simple RbVmomi wrapper library to manage VMWare ESX hosts}
|
13
|
+
gem.description = %Q{Manage VMWare ESX hosts with ease}
|
14
|
+
gem.email = "rubiojr@frameos.org"
|
15
|
+
gem.authors = ["Sergio Rubio"]
|
16
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
17
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
18
|
+
gem.add_runtime_dependency 'alchemist'
|
19
|
+
gem.add_runtime_dependency 'rbvmomi'
|
20
|
+
gem.add_runtime_dependency 'terminal-table'
|
21
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
22
|
+
end
|
23
|
+
Jeweler::RubygemsDotOrgTasks.new
|
24
|
+
|
25
|
+
require 'rake/testtask'
|
26
|
+
Rake::TestTask.new(:test) do |test|
|
27
|
+
test.libs << 'lib' << 'test'
|
28
|
+
test.pattern = 'test/**/test_*.rb'
|
29
|
+
test.verbose = true
|
30
|
+
end
|
31
|
+
|
32
|
+
task :default => :build
|
33
|
+
|
34
|
+
require 'rdoc/task'
|
35
|
+
Rake::RDocTask.new do |rdoc|
|
36
|
+
version = ESX::VERSION
|
37
|
+
rdoc.rdoc_dir = 'rdoc'
|
38
|
+
rdoc.title = "esx #{version}"
|
39
|
+
rdoc.rdoc_files.include('README*')
|
40
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
41
|
+
end
|
data/bin/esx
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'esx'
|
4
|
+
require 'terminal-table/import'
|
5
|
+
|
6
|
+
host_addr = ARGV[0]
|
7
|
+
|
8
|
+
if host_addr.nil?
|
9
|
+
$stderr.puts 'Usage: esx HOST'
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
|
13
|
+
print "Username: "
|
14
|
+
user = $stdin.gets.strip.chomp
|
15
|
+
|
16
|
+
|
17
|
+
system "stty -echo"
|
18
|
+
print "Password: "
|
19
|
+
pass = $stdin.gets.strip.chomp
|
20
|
+
system "stty echo"
|
21
|
+
puts
|
22
|
+
|
23
|
+
begin
|
24
|
+
|
25
|
+
host = ESX::Host.connect(host_addr, user, pass)
|
26
|
+
|
27
|
+
puts
|
28
|
+
name = host.name.upcase
|
29
|
+
puts "*" * name.size
|
30
|
+
puts name
|
31
|
+
puts "*" * name.size
|
32
|
+
puts "Memory Size: %s" % host.memory_size.bytes.to.megabytes.to_i
|
33
|
+
puts "Memory Usage: %s" % host.memory_usage.bytes.to.megabytes.to_i
|
34
|
+
puts "Cpu Cores: %s" % host.cpu_cores
|
35
|
+
puts "Power State: %s" % host.power_state
|
36
|
+
puts "\nVirtual Machines:"
|
37
|
+
user_table = table do |t|
|
38
|
+
t.headings = "NAME","MEMORY","CPUS","NICS","DISKS"
|
39
|
+
host.virtual_machines.each do |vm|
|
40
|
+
t << [vm.name,vm.memory_size.bytes.to.megabytes.to_i, vm.cpus, vm.ethernet_cards_number, vm.virtual_disks_number]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
puts user_table
|
44
|
+
puts "\nDatastores:"
|
45
|
+
user_table = table do |t|
|
46
|
+
t.headings = "NAME","CAPACITY","FREESPACE","ACCESIBLE","TYPE","URL"
|
47
|
+
host.datastores.each do |ds|
|
48
|
+
dsname = ds.name
|
49
|
+
if dsname.size > 20
|
50
|
+
dsname = dsname[0..19] + '...'
|
51
|
+
end
|
52
|
+
t << [dsname,ds.capacity, ds.free_space, ds.datastore_type, ds.accessible, ds.url]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
puts user_table
|
56
|
+
puts
|
57
|
+
|
58
|
+
rescue Exception => e
|
59
|
+
puts "Error connecting to the ESX host"
|
60
|
+
puts "\n#{e.message}"
|
61
|
+
puts e.backtrace
|
62
|
+
end
|
data/examples/basics.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'lib/esx.rb'
|
3
|
+
|
4
|
+
|
5
|
+
# Connect to the ESX Host
|
6
|
+
host = ESX::Host.connect 'my-esx-host', 'root', 'secret'
|
7
|
+
|
8
|
+
# Print hypervisor info
|
9
|
+
puts
|
10
|
+
name = host.name.upcase
|
11
|
+
puts "*" * name.size
|
12
|
+
puts name
|
13
|
+
puts "*" * name.size
|
14
|
+
puts "Memory Size: %s" % host.memory_size.bytes.to.megabytes.to_i
|
15
|
+
puts "Memory Usage: %s" % host.memory_usage.bytes.to.megabytes.to_i
|
16
|
+
puts "Cpu Cores: %s" % host.cpu_cores
|
17
|
+
puts "Power State: %s" % host.power_state
|
18
|
+
|
19
|
+
# Create a VM with 4GB disk, 128 MB mem, e1000 nic, 1CPU in datastore1
|
20
|
+
vm = host.create_vm :vm_name => 'foobar'
|
21
|
+
|
22
|
+
# Create a VM with 5GB disk, 256 MB mem, e1000 nic, 1CPU in datastore2
|
23
|
+
vm = host.create_vm :vm_name => 'foobar2', :disk_size => 5000, :cpus => 2, :memory => 256, :datastore => 'datastore2'
|
24
|
+
|
25
|
+
|
26
|
+
host.virtual_machines.each do |vm|
|
27
|
+
|
28
|
+
# PowerOff the VM if powered On
|
29
|
+
vm.power_off if (vm.name =~ /foobar/ and vm.power_state == 'poweredOn')
|
30
|
+
|
31
|
+
# Destroy the VM if name matches foobar
|
32
|
+
if vm.name =~ /foobar.*/
|
33
|
+
vm.destroy
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/lib/esx.rb
ADDED
@@ -0,0 +1,256 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rbvmomi'
|
3
|
+
require 'alchemist'
|
4
|
+
|
5
|
+
module ESX
|
6
|
+
VERSION = '0.1'
|
7
|
+
|
8
|
+
class Host
|
9
|
+
|
10
|
+
# Connect to a ESX host
|
11
|
+
#
|
12
|
+
# Requires hostname/ip, username and password
|
13
|
+
#
|
14
|
+
# Host connection is insecure by default
|
15
|
+
def self.connect(host, user, password, insecure=true)
|
16
|
+
vim = RbVmomi::VIM.connect :host => host, :user => 'root', :password => 'temporal', :insecure => insecure
|
17
|
+
host = Host.new
|
18
|
+
host.vim = vim
|
19
|
+
host
|
20
|
+
end
|
21
|
+
|
22
|
+
def vim=(vim)
|
23
|
+
@_vim = vim
|
24
|
+
@_datacenter = @_vim.serviceInstance.find_datacenter
|
25
|
+
@_host = @_datacenter.hostFolder.children.first.host.first
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns the name of this host
|
29
|
+
#
|
30
|
+
def name
|
31
|
+
@_host.summary.config.name
|
32
|
+
end
|
33
|
+
|
34
|
+
# Host memory size in bytes
|
35
|
+
#
|
36
|
+
def memory_size
|
37
|
+
@_host.hardware.memorySize
|
38
|
+
end
|
39
|
+
|
40
|
+
# Number of CPU cores available in this host
|
41
|
+
#
|
42
|
+
def cpu_cores
|
43
|
+
@_host.hardware.cpuInfo.numCpuCores
|
44
|
+
end
|
45
|
+
|
46
|
+
# Power state of this host
|
47
|
+
#
|
48
|
+
def power_state
|
49
|
+
@_host.summary.runtime.powerState
|
50
|
+
end
|
51
|
+
|
52
|
+
# Host memory usage in bytes
|
53
|
+
#
|
54
|
+
def memory_usage
|
55
|
+
@_host.summary.quickStats.overallMemoryUsage.megabytes.to.bytes.to_i
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
# Return a list of ESX::Datastore objects available in this host
|
60
|
+
#
|
61
|
+
def datastores
|
62
|
+
datastores = []
|
63
|
+
@_host.datastore.each do |ds|
|
64
|
+
datastores << Datastore.wrap(ds)
|
65
|
+
end
|
66
|
+
datastores
|
67
|
+
end
|
68
|
+
|
69
|
+
# Create a Virtual Machine
|
70
|
+
#
|
71
|
+
# Requires a Hash with the following keys:
|
72
|
+
#
|
73
|
+
# {
|
74
|
+
# :vm_name => name, (string, required)
|
75
|
+
# :cpus => 1, #(int, optional)
|
76
|
+
# :guest_id => 'otherGuest', #(string, optional)
|
77
|
+
# :disk_size => 4096, #(in MB, optional)
|
78
|
+
# :memory => 128, #(in MB, optional)
|
79
|
+
# :datastore => datastore1 #(string, optional)
|
80
|
+
# }
|
81
|
+
#
|
82
|
+
# Default values above.
|
83
|
+
def create_vm(specification)
|
84
|
+
spec = specification
|
85
|
+
spec[:cpus] = (specification[:cpus] || 1).to_i
|
86
|
+
spec[:guest_id] = specification[:guest_id] || 'otherGuest'
|
87
|
+
if specification[:disk_size]
|
88
|
+
spec[:disk_size] = (specification[:disk_size].to_i * 1024)
|
89
|
+
else
|
90
|
+
spec[:disk_size] = 4194304
|
91
|
+
end
|
92
|
+
spec[:memory] = (specification[:memory] || 128).to_i
|
93
|
+
if specification[:datastore]
|
94
|
+
spec[:datastore] = "[#{specification[:datastore]}]"
|
95
|
+
else
|
96
|
+
spec[:datastore] = '[datastore1]'
|
97
|
+
end
|
98
|
+
vm_cfg = {
|
99
|
+
:name => spec[:vm_name],
|
100
|
+
:guestId => spec[:guest_id],
|
101
|
+
:files => { :vmPathName => '[datastore1]' },
|
102
|
+
:numCPUs => spec[:cpus],
|
103
|
+
:memoryMB => spec[:memory],
|
104
|
+
:deviceChange => [
|
105
|
+
{
|
106
|
+
:operation => :add,
|
107
|
+
:device => RbVmomi::VIM.VirtualLsiLogicController(
|
108
|
+
:key => 1000,
|
109
|
+
:busNumber => 0,
|
110
|
+
:sharedBus => :noSharing)
|
111
|
+
},
|
112
|
+
{
|
113
|
+
:operation => :add,
|
114
|
+
:fileOperation => :create,
|
115
|
+
:device => RbVmomi::VIM.VirtualDisk(
|
116
|
+
:key => 0,
|
117
|
+
:backing => RbVmomi::VIM.VirtualDiskFlatVer2BackingInfo(
|
118
|
+
:fileName => spec[:datastore],
|
119
|
+
:diskMode => :persistent,
|
120
|
+
:thinProvisioned => true),
|
121
|
+
:controllerKey => 1000,
|
122
|
+
:unitNumber => 0,
|
123
|
+
:capacityInKB => spec[:disk_size])
|
124
|
+
},
|
125
|
+
{
|
126
|
+
:operation => :add,
|
127
|
+
:device => RbVmomi::VIM.VirtualE1000(
|
128
|
+
:key => 0,
|
129
|
+
:deviceInfo => {
|
130
|
+
:label => 'Network Adapter 1',
|
131
|
+
:summary => 'VM Network'
|
132
|
+
},
|
133
|
+
:backing => RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(
|
134
|
+
:deviceName => 'VM Network'
|
135
|
+
),
|
136
|
+
:addressType => 'generated')
|
137
|
+
}
|
138
|
+
],
|
139
|
+
:extraConfig => [
|
140
|
+
{
|
141
|
+
:key => 'bios.bootOrder',
|
142
|
+
:value => 'ethernet0'
|
143
|
+
}
|
144
|
+
]
|
145
|
+
}
|
146
|
+
VM.wrap(@_datacenter.vmFolder.CreateVM_Task(:config => vm_cfg, :pool => @_datacenter.hostFolder.children.first.resourcePool).wait_for_completion)
|
147
|
+
end
|
148
|
+
|
149
|
+
# Return product info as an array of strings containing
|
150
|
+
#
|
151
|
+
# fullName, apiType, apiVersion, osType, productLineId, vendor, version
|
152
|
+
#
|
153
|
+
def host_info
|
154
|
+
[
|
155
|
+
@_host.summary.config.product.fullName,
|
156
|
+
@_host.summary.config.product.apiType,
|
157
|
+
@_host.summary.config.product.apiVersion,
|
158
|
+
@_host.summary.config.product.osType,
|
159
|
+
@_host.summary.config.product.productLineId,
|
160
|
+
@_host.summary.config.product.vendor,
|
161
|
+
@_host.summary.config.product.version
|
162
|
+
]
|
163
|
+
end
|
164
|
+
|
165
|
+
# Return a list of VM available in the inventory
|
166
|
+
#
|
167
|
+
def virtual_machines
|
168
|
+
vms = []
|
169
|
+
vm = @_datacenter.vmFolder.childEntity.each do |x|
|
170
|
+
vms << VM.wrap(x)
|
171
|
+
end
|
172
|
+
vms
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
class VM
|
178
|
+
|
179
|
+
attr_accessor :memory_size, :cpus, :ethernet_cards_number
|
180
|
+
attr_accessor :name, :virtual_disks_number, :vm_object
|
181
|
+
|
182
|
+
# Wraps a RbVmomi::VirtualMachine object
|
183
|
+
#
|
184
|
+
# **This method should never be called manually.**
|
185
|
+
#
|
186
|
+
def self.wrap(vm)
|
187
|
+
_vm = VM.new
|
188
|
+
_vm.name = vm.name
|
189
|
+
_vm.memory_size = vm.summary.config.memorySizeMB.megabytes.to.bytes
|
190
|
+
_vm.cpus = vm.summary.config.numCpu
|
191
|
+
_vm.ethernet_cards_number = vm.summary.config.numEthernetCards
|
192
|
+
_vm.virtual_disks_number = vm.summary.config.numVirtualDisks
|
193
|
+
_vm.vm_object = vm
|
194
|
+
_vm
|
195
|
+
end
|
196
|
+
|
197
|
+
# Returns the state of the VM as a string
|
198
|
+
# 'poweredOff', 'poweredOn'
|
199
|
+
#
|
200
|
+
def power_state
|
201
|
+
vm_object.summary.runtime.powerState
|
202
|
+
end
|
203
|
+
|
204
|
+
# Power On a VM
|
205
|
+
def power_on
|
206
|
+
vm_object.PowerOnVM_Task.wait_for_completion
|
207
|
+
end
|
208
|
+
|
209
|
+
# Power Off a VM
|
210
|
+
def power_off
|
211
|
+
vm_object.PowerOffVM_Task.wait_for_completion
|
212
|
+
end
|
213
|
+
|
214
|
+
# Destroy the VirtualMaching removing it from the inventory
|
215
|
+
#
|
216
|
+
# This operation does not destroy VM disks
|
217
|
+
#
|
218
|
+
def destroy
|
219
|
+
disks = vm_object.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk)
|
220
|
+
#disks.select { |x| x.backing.parent == nil }.each do |disk|
|
221
|
+
# spec = {
|
222
|
+
# :deviceChange => [
|
223
|
+
# {
|
224
|
+
# :operation => :remove,
|
225
|
+
# :device => disk
|
226
|
+
# }
|
227
|
+
# ]
|
228
|
+
# }
|
229
|
+
# vm_object.ReconfigVM_Task(:spec => spec).wait_for_completion
|
230
|
+
#end
|
231
|
+
vm_object.Destroy_Task.wait_for_completion
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
class Datastore
|
237
|
+
|
238
|
+
attr_accessor :name, :capacity, :datastore_type, :free_space, :accessible
|
239
|
+
attr_accessor :url
|
240
|
+
|
241
|
+
#
|
242
|
+
# Internal method. Do not use
|
243
|
+
#
|
244
|
+
def self.wrap(ds)
|
245
|
+
@_datastore = ds
|
246
|
+
_ds = Datastore.new
|
247
|
+
_ds.name = ds.summary.name
|
248
|
+
_ds.capacity = ds.summary.capacity
|
249
|
+
_ds.free_space = ds.summary.freeSpace
|
250
|
+
_ds.datastore_type = ds.summary.type
|
251
|
+
_ds.accessible = ds.summary.accessible
|
252
|
+
_ds.url = ds.summary.url
|
253
|
+
_ds
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'esx'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
data/test/test_esx.rb
ADDED
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: esx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Sergio Rubio
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-09-06 00:00:00 Z
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
21
|
+
none: false
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
hash: 3
|
26
|
+
segments:
|
27
|
+
- 0
|
28
|
+
version: "0"
|
29
|
+
version_requirements: *id001
|
30
|
+
name: shoulda
|
31
|
+
prerelease: false
|
32
|
+
type: :development
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ~>
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
hash: 23
|
40
|
+
segments:
|
41
|
+
- 1
|
42
|
+
- 0
|
43
|
+
- 0
|
44
|
+
version: 1.0.0
|
45
|
+
version_requirements: *id002
|
46
|
+
name: bundler
|
47
|
+
prerelease: false
|
48
|
+
type: :development
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 7
|
56
|
+
segments:
|
57
|
+
- 1
|
58
|
+
- 5
|
59
|
+
- 2
|
60
|
+
version: 1.5.2
|
61
|
+
version_requirements: *id003
|
62
|
+
name: jeweler
|
63
|
+
prerelease: false
|
64
|
+
type: :development
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
version_requirements: *id004
|
76
|
+
name: rcov
|
77
|
+
prerelease: false
|
78
|
+
type: :development
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
version_requirements: *id005
|
90
|
+
name: alchemist
|
91
|
+
prerelease: false
|
92
|
+
type: :runtime
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
version_requirements: *id006
|
104
|
+
name: rbvmomi
|
105
|
+
prerelease: false
|
106
|
+
type: :runtime
|
107
|
+
- !ruby/object:Gem::Dependency
|
108
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
version_requirements: *id007
|
118
|
+
name: terminal-table
|
119
|
+
prerelease: false
|
120
|
+
type: :runtime
|
121
|
+
description: Manage VMWare ESX hosts with ease
|
122
|
+
email: rubiojr@frameos.org
|
123
|
+
executables:
|
124
|
+
- esx
|
125
|
+
extensions: []
|
126
|
+
|
127
|
+
extra_rdoc_files:
|
128
|
+
- LICENSE.txt
|
129
|
+
- README.md
|
130
|
+
files:
|
131
|
+
- .document
|
132
|
+
- Gemfile
|
133
|
+
- LICENSE.txt
|
134
|
+
- README.md
|
135
|
+
- Rakefile
|
136
|
+
- bin/esx
|
137
|
+
- examples/basics.rb
|
138
|
+
- lib/esx.rb
|
139
|
+
- test/helper.rb
|
140
|
+
- test/test_esx.rb
|
141
|
+
homepage: http://github.com/rubiojr/esx
|
142
|
+
licenses:
|
143
|
+
- MIT
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
hash: 3
|
155
|
+
segments:
|
156
|
+
- 0
|
157
|
+
version: "0"
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
none: false
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
hash: 3
|
164
|
+
segments:
|
165
|
+
- 0
|
166
|
+
version: "0"
|
167
|
+
requirements: []
|
168
|
+
|
169
|
+
rubyforge_project:
|
170
|
+
rubygems_version: 1.7.2
|
171
|
+
signing_key:
|
172
|
+
specification_version: 3
|
173
|
+
summary: Simple RbVmomi wrapper library to manage VMWare ESX hosts
|
174
|
+
test_files:
|
175
|
+
- examples/basics.rb
|
176
|
+
- test/helper.rb
|
177
|
+
- test/test_esx.rb
|