esx 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +0 -1
- data/bin/esx +0 -0
- data/esx.gemspec +95 -0
- data/lib/esx.rb +31 -6
- data/spec/unit/helper_spec.rb +129 -0
- data/templates/vmx_template.erb +1 -1
- metadata +5 -3
data/README.md
CHANGED
data/bin/esx
CHANGED
File without changes
|
data/esx.gemspec
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "esx"
|
8
|
+
s.version = "0.4.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Sergio Rubio", "Massimo Maino"]
|
12
|
+
s.date = "2013-03-29"
|
13
|
+
s.description = "Manage VMWare ESX hosts with ease"
|
14
|
+
s.email = "rubiojr@frameos.org"
|
15
|
+
s.executables = ["esx"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.md"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
"CHANGELOG.md",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"Rakefile",
|
28
|
+
"bin/esx",
|
29
|
+
"esx.gemspec",
|
30
|
+
"examples/basics.rb",
|
31
|
+
"lib/esx.rb",
|
32
|
+
"spec/spec_helper.rb",
|
33
|
+
"spec/unit/helper_spec.rb",
|
34
|
+
"spec/unit/host_spec.rb",
|
35
|
+
"spec/unit/vm_spec.rb",
|
36
|
+
"templates/vmx_template.erb"
|
37
|
+
]
|
38
|
+
s.homepage = "http://github.com/rubiojr/esx"
|
39
|
+
s.licenses = ["MIT"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = "1.8.25"
|
42
|
+
s.summary = "Simple RbVmomi wrapper library to manage VMWare ESX hosts"
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_development_dependency(%q<net-ssh>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<net-scp>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<rbvmomi>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<alchemist>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<bundler>, ["> 1.0.0"])
|
54
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
56
|
+
s.add_runtime_dependency(%q<alchemist>, [">= 0"])
|
57
|
+
s.add_runtime_dependency(%q<rbvmomi>, [">= 0"])
|
58
|
+
s.add_runtime_dependency(%q<terminal-table>, [">= 0"])
|
59
|
+
s.add_runtime_dependency(%q<net-ssh>, [">= 0"])
|
60
|
+
s.add_runtime_dependency(%q<net-scp>, [">= 0"])
|
61
|
+
s.add_runtime_dependency(%q<clamp>, [">= 0"])
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<net-ssh>, [">= 0"])
|
64
|
+
s.add_dependency(%q<net-scp>, [">= 0"])
|
65
|
+
s.add_dependency(%q<rbvmomi>, [">= 0"])
|
66
|
+
s.add_dependency(%q<alchemist>, [">= 0"])
|
67
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
68
|
+
s.add_dependency(%q<bundler>, ["> 1.0.0"])
|
69
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
70
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
71
|
+
s.add_dependency(%q<alchemist>, [">= 0"])
|
72
|
+
s.add_dependency(%q<rbvmomi>, [">= 0"])
|
73
|
+
s.add_dependency(%q<terminal-table>, [">= 0"])
|
74
|
+
s.add_dependency(%q<net-ssh>, [">= 0"])
|
75
|
+
s.add_dependency(%q<net-scp>, [">= 0"])
|
76
|
+
s.add_dependency(%q<clamp>, [">= 0"])
|
77
|
+
end
|
78
|
+
else
|
79
|
+
s.add_dependency(%q<net-ssh>, [">= 0"])
|
80
|
+
s.add_dependency(%q<net-scp>, [">= 0"])
|
81
|
+
s.add_dependency(%q<rbvmomi>, [">= 0"])
|
82
|
+
s.add_dependency(%q<alchemist>, [">= 0"])
|
83
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
84
|
+
s.add_dependency(%q<bundler>, ["> 1.0.0"])
|
85
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
86
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
87
|
+
s.add_dependency(%q<alchemist>, [">= 0"])
|
88
|
+
s.add_dependency(%q<rbvmomi>, [">= 0"])
|
89
|
+
s.add_dependency(%q<terminal-table>, [">= 0"])
|
90
|
+
s.add_dependency(%q<net-ssh>, [">= 0"])
|
91
|
+
s.add_dependency(%q<net-scp>, [">= 0"])
|
92
|
+
s.add_dependency(%q<clamp>, [">= 0"])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
data/lib/esx.rb
CHANGED
@@ -4,10 +4,11 @@ require 'alchemist'
|
|
4
4
|
require 'net/scp'
|
5
5
|
require 'net/ssh'
|
6
6
|
require 'erb'
|
7
|
+
require 'tempfile'
|
7
8
|
|
8
9
|
module ESX
|
9
10
|
|
10
|
-
VERSION = '0.4.
|
11
|
+
VERSION = '0.4.3'
|
11
12
|
|
12
13
|
if !defined? Log or Log.nil?
|
13
14
|
Log = Logger.new($stdout)
|
@@ -41,7 +42,7 @@ module ESX
|
|
41
42
|
#
|
42
43
|
# Host connection is insecure by default
|
43
44
|
def self.connect(host, user, password, insecure = true, opts = {})
|
44
|
-
vim = RbVmomi::VIM.connect :host => host, :user => user, :password => password, :insecure => insecure
|
45
|
+
vim = RbVmomi::VIM.connect :host => host, :user => user, :password => password, :insecure => insecure, :rev => opts[:rev]||'4.0'
|
45
46
|
host = Host.new(host, user,password, opts)
|
46
47
|
host.vim = vim
|
47
48
|
host
|
@@ -184,6 +185,7 @@ module ESX
|
|
184
185
|
else
|
185
186
|
gem_root = Gem::Specification.find_by_name("esx").gem_dir
|
186
187
|
template_path = File.join(gem_root, 'templates', 'vmx_template.erb')
|
188
|
+
spec[:guest_id] = convert_guest_id_for_vmdk(spec[:guest_id])
|
187
189
|
erb = ERB.new File.read(template_path)
|
188
190
|
vmx = erb.result binding
|
189
191
|
tmp_vmx = Tempfile.new 'vmx'
|
@@ -192,6 +194,7 @@ module ESX
|
|
192
194
|
ds = spec[:datastore]||'datastore1'
|
193
195
|
ds = ds.gsub('[','').gsub(']','')
|
194
196
|
vmx_path = "/vmfs/volumes/#{ds}/#{spec[:vm_name]}/#{spec[:vm_name]}.vmx"
|
197
|
+
remote_command "mkdir -p #{File.dirname(vmx_path)}"
|
195
198
|
upload_file tmp_vmx.path, vmx_path
|
196
199
|
remote_command "vim-cmd solo/registervm #{vmx_path}"
|
197
200
|
VM.wrap(@_datacenter.find_vm(spec[:vm_name]),self)
|
@@ -235,16 +238,29 @@ module ESX
|
|
235
238
|
]
|
236
239
|
end
|
237
240
|
|
238
|
-
# Return a list of VM available in the inventory
|
241
|
+
# Return a list of VM available in the inventory * recursive search of folders as well
|
239
242
|
#
|
240
243
|
def virtual_machines
|
241
244
|
vms = []
|
242
|
-
vm = @_datacenter.vmFolder
|
243
|
-
|
244
|
-
|
245
|
+
vm = @_datacenter.vmFolder
|
246
|
+
vms = recursive_virtual_machine(vm,vms)
|
247
|
+
|
245
248
|
vms
|
246
249
|
end
|
247
250
|
|
251
|
+
def recursive_virtual_machine(parentObject,array)
|
252
|
+
vm = parentObject.childEntity.each do |x|
|
253
|
+
if x.to_s.match("Folder")
|
254
|
+
array = recursive_virtual_machine(x,array)
|
255
|
+
else
|
256
|
+
array << VM.wrap(x,self)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
array
|
261
|
+
end
|
262
|
+
private :recursive_virtual_machine
|
263
|
+
|
248
264
|
#
|
249
265
|
# Run a command in the ESX host via SSH
|
250
266
|
#
|
@@ -438,6 +454,15 @@ module ESX
|
|
438
454
|
spec[:fileOperation] = :create if disk_file.nil?
|
439
455
|
spec
|
440
456
|
end
|
457
|
+
|
458
|
+
def convert_guest_id_for_vmdk(guest_id)
|
459
|
+
exceptions = {
|
460
|
+
"winLonghornGuest" => "longhorn",
|
461
|
+
"winLonghorn64Guest" => "longhorn-64",
|
462
|
+
}
|
463
|
+
return exceptions[guest_id] if exceptions[guest_id]
|
464
|
+
guest_id.downcase.gsub(/guest/, '').gsub(/_?64/, '-64')
|
465
|
+
end
|
441
466
|
end
|
442
467
|
|
443
468
|
class VM
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "ESX host helpers" do
|
4
|
+
subject { ESX::Host.new("address", "user", "password") }
|
5
|
+
|
6
|
+
describe "convert_guest_id_for_vmdk" do
|
7
|
+
|
8
|
+
# key: http://pubs.vmware.com/vsphere-50/index.jsp?topic=/com.vmware.wssdk.apiref.doc_50/vim.vm.GuestOsDescriptor.GuestOsIdentifier.html
|
9
|
+
# value: in vmx file
|
10
|
+
guest_id_map = {
|
11
|
+
"dosGuest" => "dos",
|
12
|
+
"win31Guest" => "win31",
|
13
|
+
"win95Guest" => "win95",
|
14
|
+
"win98Guest" => "win98",
|
15
|
+
"winMeGuest" => "winme",
|
16
|
+
"winNTGuest" => "winnt",
|
17
|
+
"win2000ProGuest" => "win2000pro",
|
18
|
+
"win2000ServGuest" => "win2000serv",
|
19
|
+
"win2000AdvServGuest" => "win2000advserv",
|
20
|
+
"winXPHomeGuest" => "winxphome",
|
21
|
+
"winXPProGuest" => "winxppro",
|
22
|
+
"winXPPro64Guest" => "winxppro-64",
|
23
|
+
"winNetWebGuest" => "winnetweb",
|
24
|
+
"winNetStandardGuest" => "winnetstandard",
|
25
|
+
"winNetEnterpriseGuest" => "winnetenterprise",
|
26
|
+
"winNetDatacenterGuest" => "",
|
27
|
+
"winNetBusinessGuest" => "",
|
28
|
+
"winNetStandard64Guest" => "winnetstandard-64",
|
29
|
+
"winNetEnterprise64Guest" => "winnetenterprise-64",
|
30
|
+
"winLonghornGuest" => "longhorn",
|
31
|
+
"winLonghorn64Guest" => "longhorn-64",
|
32
|
+
"winNetDatacenter64Guest" => "",
|
33
|
+
"winVistaGuest" => "winvista",
|
34
|
+
"winVista64Guest" => "winvista-64",
|
35
|
+
"windows7Guest" => "windows7",
|
36
|
+
"windows7_64Guest" => "windows7-64",
|
37
|
+
"windows7Server64Guest" => "",
|
38
|
+
"windows8Guest" => "windows8",
|
39
|
+
"windows8_64Guest" => "windows8-64",
|
40
|
+
"windows8Server64Guest" => "",
|
41
|
+
"freebsdGuest" => "freebsd",
|
42
|
+
"freebsd64Guest" => "freebsd-64",
|
43
|
+
"redhatGuest" => "redhat",
|
44
|
+
"rhel2Guest" => "rhel2",
|
45
|
+
"rhel3Guest" => "rhel3",
|
46
|
+
"rhel3_64Guest" => "rhel3-64",
|
47
|
+
"rhel4Guest" => "rhel4",
|
48
|
+
"rhel4_64Guest" => "rhel4-64",
|
49
|
+
"rhel5Guest" => "rhel5",
|
50
|
+
"rhel5_64Guest" => "rhel5-64",
|
51
|
+
"rhel6Guest" => "rhel6",
|
52
|
+
"rhel6_64Guest" => "rhel6-64",
|
53
|
+
"centosGuest" => "centos",
|
54
|
+
"centos64Guest" => "centos-64",
|
55
|
+
"oracleLinuxGuest" => "oraclelinux",
|
56
|
+
"oracleLinux64Guest" => "oraclelinux-64",
|
57
|
+
"suseGuest" => "suse",
|
58
|
+
"suse64Guest" => "suse-64",
|
59
|
+
"slesGuest" => "sles",
|
60
|
+
"sles64Guest" => "sles-64",
|
61
|
+
"sles10Guest" => "sles10",
|
62
|
+
"sles10_64Guest" => "sles10-64",
|
63
|
+
"sles11Guest" => "sles11",
|
64
|
+
"sles11_64Guest" => "sles11-64",
|
65
|
+
"nld9Guest" => "nld9",
|
66
|
+
"oesGuest" => "oes",
|
67
|
+
"sjdsGuest" => "sjds",
|
68
|
+
"mandrivaGuest" => "mandriva",
|
69
|
+
"mandriva64Guest" => "mandriva-64",
|
70
|
+
"turboLinuxGuest" => "turbolinux",
|
71
|
+
"turboLinux64Guest" => "turbolinux-64",
|
72
|
+
"ubuntuGuest" => "ubuntu",
|
73
|
+
"ubuntu64Guest" => "ubuntu-64",
|
74
|
+
"debian4Guest" => "debian4",
|
75
|
+
"debian4_64Guest" => "debian4-64",
|
76
|
+
"debian5Guest" => "debian5",
|
77
|
+
"debian5_64Guest" => "debian5-64",
|
78
|
+
"debian6Guest" => "debian6",
|
79
|
+
"debian6_64Guest" => "debian6-64",
|
80
|
+
"asianux3Guest" => "asianux3",
|
81
|
+
"asianux3_64Guest" => "asianux3-64",
|
82
|
+
"asianux4Guest" => "asianux4",
|
83
|
+
"asianux4_64Guest" => "asianux4-64",
|
84
|
+
"other24xLinuxGuest" => "other24xlinux",
|
85
|
+
"other26xLinuxGuest" => "other26xlinux",
|
86
|
+
"otherLinuxGuest" => "otherlinux",
|
87
|
+
"other24xLinux64Guest" => "other24xlinux-64",
|
88
|
+
"other26xLinux64Guest" => "other26xlinux-64",
|
89
|
+
"otherLinux64Guest" => "otherlinux-64",
|
90
|
+
"solaris6Guest" => "",
|
91
|
+
"solaris7Guest" => "",
|
92
|
+
"solaris8Guest" => "solaris8",
|
93
|
+
"solaris9Guest" => "solaris9",
|
94
|
+
"solaris10Guest" => "solaris10",
|
95
|
+
"solaris10_64Guest" => "solaris10-64",
|
96
|
+
"solaris11_64Guest" => "solaris11-64",
|
97
|
+
"os2Guest" => "os2",
|
98
|
+
"eComStationGuest" => "ecomstation",
|
99
|
+
"eComStation2Guest" => "ecomstation2",
|
100
|
+
"netware4Guest" => "",
|
101
|
+
"netware5Guest" => "netware5",
|
102
|
+
"netware6Guest" => "netware6",
|
103
|
+
"openServer5Guest" => "",
|
104
|
+
"openServer6Guest" => "",
|
105
|
+
"unixWare7Guest" => "",
|
106
|
+
"darwinGuest" => "darwin",
|
107
|
+
"darwin64Guest" => "darwin-64",
|
108
|
+
"darwin10Guest" => "darwin10",
|
109
|
+
"darwin10_64Guest" => "darwin10-64",
|
110
|
+
"darwin11Guest" => "darwin11",
|
111
|
+
"darwin11_64Guest" => "darwin11-64",
|
112
|
+
"vmkernelGuest" => "vmkernel",
|
113
|
+
"vmkernel5Guest" => "vmkernel5",
|
114
|
+
"otherGuest" => "other",
|
115
|
+
"otherGuest64" => "other-64",
|
116
|
+
}
|
117
|
+
|
118
|
+
guest_id_map.each do |api_value, vmx_value|
|
119
|
+
if vmx_value.empty?
|
120
|
+
it "should convert #{api_value} to vmx guestOS value"
|
121
|
+
else
|
122
|
+
it "should convert #{api_value} to #{vmx_value}" do
|
123
|
+
subject.send(:convert_guest_id_for_vmdk, api_value).should == vmx_value
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
data/templates/vmx_template.erb
CHANGED
@@ -11,7 +11,7 @@ scsi0.virtualDev = "lsilogic"
|
|
11
11
|
scsi0:0.present = "true"
|
12
12
|
scsi0:0.fileName = "<%= spec[:disk_file].split("/").last %>"
|
13
13
|
scsi0:0.deviceType = "scsi-hardDisk"
|
14
|
-
guestOS = <%= spec[:guest_id] %>
|
14
|
+
guestOS = "<%= spec[:guest_id] %>"
|
15
15
|
floppy0.present = "FALSE"
|
16
16
|
<% spec[:nics].each_with_index do |nic,index| %>
|
17
17
|
ethernet<%= index %>.present = "true"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-03-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: net-ssh
|
@@ -253,9 +253,11 @@ files:
|
|
253
253
|
- README.md
|
254
254
|
- Rakefile
|
255
255
|
- bin/esx
|
256
|
+
- esx.gemspec
|
256
257
|
- examples/basics.rb
|
257
258
|
- lib/esx.rb
|
258
259
|
- spec/spec_helper.rb
|
260
|
+
- spec/unit/helper_spec.rb
|
259
261
|
- spec/unit/host_spec.rb
|
260
262
|
- spec/unit/vm_spec.rb
|
261
263
|
- templates/vmx_template.erb
|
@@ -280,7 +282,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
280
282
|
version: '0'
|
281
283
|
requirements: []
|
282
284
|
rubyforge_project:
|
283
|
-
rubygems_version: 1.8.
|
285
|
+
rubygems_version: 1.8.25
|
284
286
|
signing_key:
|
285
287
|
specification_version: 3
|
286
288
|
summary: Simple RbVmomi wrapper library to manage VMWare ESX hosts
|