rbvmomi 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +5 -1
- data/VERSION +1 -1
- data/examples/create_vm-1.9.rb +94 -0
- data/lib/rbvmomi.rb +9 -1
- data/lib/rbvmomi/trollop.rb +38 -2
- data/lib/rbvmomi/vim.rb +3 -1
- metadata +6 -11
data/README.rdoc
CHANGED
@@ -63,6 +63,9 @@ A few important points:
|
|
63
63
|
* Example code is included in the examples/ directory.
|
64
64
|
* A set of helper methods for Trollop is included to speed up development of
|
65
65
|
command line apps. See the included examples for usage.
|
66
|
+
* If you don't have trusted SSL certificates installed on the host you're
|
67
|
+
connecting to, you'll get an +OpenSSL::SSL::SSLError+ "certificate verify failed".
|
68
|
+
You can work around this by using the +:insecure+ option to +RbVmomi::VIM.connect+.
|
66
69
|
* This is a side project of a VMware employee and is entirely unsupported by VMware.
|
67
70
|
|
68
71
|
Built-in extensions are under +lib/rbvmomi/vim/+. You are encouraged to
|
@@ -71,4 +74,5 @@ write something generally useful please send it to me and I'll add it in.
|
|
71
74
|
|
72
75
|
== Development
|
73
76
|
|
74
|
-
|
77
|
+
Fork the project on Github and send me a merge request, or send a patch to
|
78
|
+
rlane@vmware.com.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.2
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'trollop'
|
3
|
+
require 'rbvmomi'
|
4
|
+
require 'rbvmomi/trollop'
|
5
|
+
|
6
|
+
VIM = RbVmomi::VIM
|
7
|
+
N = 2
|
8
|
+
|
9
|
+
opts = Trollop.options do
|
10
|
+
banner <<-EOS
|
11
|
+
Create and destroy a couple of VMs.
|
12
|
+
|
13
|
+
Usage:
|
14
|
+
create_vm.rb [options]
|
15
|
+
|
16
|
+
VIM connection options:
|
17
|
+
EOS
|
18
|
+
|
19
|
+
rbvmomi_connection_opts
|
20
|
+
|
21
|
+
text <<-EOS
|
22
|
+
|
23
|
+
VM location options:
|
24
|
+
EOS
|
25
|
+
|
26
|
+
rbvmomi_datacenter_opt
|
27
|
+
|
28
|
+
text <<-EOS
|
29
|
+
|
30
|
+
Other options:
|
31
|
+
EOS
|
32
|
+
end
|
33
|
+
|
34
|
+
Trollop.die("must specify host") unless opts[:host]
|
35
|
+
vm_name = ARGV[0] or abort "must specify VM name"
|
36
|
+
|
37
|
+
vim = VIM.connect opts
|
38
|
+
dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
|
39
|
+
vmFolder = dc.vmFolder
|
40
|
+
hosts = dc.hostFolder.children
|
41
|
+
rp = hosts.first.resourcePool
|
42
|
+
|
43
|
+
vm_cfg = {
|
44
|
+
name: vm_name,
|
45
|
+
guestId: 'otherGuest',
|
46
|
+
files: { vmPathName: '[datastore1]' },
|
47
|
+
numCPUs: 1,
|
48
|
+
memoryMB: 128,
|
49
|
+
deviceChange: [
|
50
|
+
{
|
51
|
+
operation: :add,
|
52
|
+
device: VIM.VirtualLsiLogicController(
|
53
|
+
key: 1000,
|
54
|
+
busNumber: 0,
|
55
|
+
sharedBus: :noSharing,
|
56
|
+
)
|
57
|
+
}, {
|
58
|
+
operation: :add,
|
59
|
+
fileOperation: :create,
|
60
|
+
device: VIM.VirtualDisk(
|
61
|
+
key: 0,
|
62
|
+
backing: VIM.VirtualDiskFlatVer2BackingInfo(
|
63
|
+
fileName: '[datastore1]',
|
64
|
+
diskMode: :persistent,
|
65
|
+
thinProvisioned: true,
|
66
|
+
),
|
67
|
+
controllerKey: 1000,
|
68
|
+
unitNumber: 0,
|
69
|
+
capacityInKB: 4000000,
|
70
|
+
)
|
71
|
+
}, {
|
72
|
+
operation: :add,
|
73
|
+
device: VIM.VirtualE1000(
|
74
|
+
key: 0,
|
75
|
+
deviceInfo: {
|
76
|
+
label: 'Network Adapter 1',
|
77
|
+
summary: 'VM Network',
|
78
|
+
},
|
79
|
+
backing: VIM.VirtualEthernetCardNetworkBackingInfo(
|
80
|
+
deviceName: 'VM Network',
|
81
|
+
),
|
82
|
+
addressType: 'generated'
|
83
|
+
)
|
84
|
+
}
|
85
|
+
],
|
86
|
+
extraConfig: [
|
87
|
+
{
|
88
|
+
key: 'bios.bootOrder',
|
89
|
+
value: 'ethernet0'
|
90
|
+
}
|
91
|
+
]
|
92
|
+
}
|
93
|
+
|
94
|
+
vmFolder.CreateVM_Task(:config => vm_cfg, :pool => rp).wait_for_completion
|
data/lib/rbvmomi.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
# Copyright (c) 2010 VMware, Inc. All Rights Reserved.
|
2
|
-
module RbVmomi
|
2
|
+
module RbVmomi
|
3
|
+
|
4
|
+
# @private
|
5
|
+
# @deprecated Use +RbVmomi::VIM.connect+.
|
6
|
+
def self.connect opts
|
7
|
+
VIM.connect opts
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
3
11
|
require 'rbvmomi/connection'
|
4
12
|
require 'rbvmomi/vim'
|
data/lib/rbvmomi/trollop.rb
CHANGED
@@ -1,9 +1,29 @@
|
|
1
1
|
# Copyright (c) 2011 VMware, Inc. All Rights Reserved.
|
2
2
|
require 'trollop'
|
3
3
|
|
4
|
-
#
|
4
|
+
# Convenience methods for Trollop, Ruby's premier option parser.
|
5
|
+
# @see http://trollop.rubyforge.org/
|
6
|
+
# @see Trollop::Parser
|
5
7
|
module Trollop
|
8
|
+
|
9
|
+
# Convenience methods for Trollop, Ruby's premier option parser.
|
10
|
+
#
|
11
|
+
# See the examples directory for sample code.
|
12
|
+
# Descriptions are of the form:
|
13
|
+
# <key>: <options> <environment variable> (<default>)
|
14
|
+
# @see http://trollop.rubyforge.org/
|
6
15
|
class Parser
|
16
|
+
# Options used by VIM.connect
|
17
|
+
#
|
18
|
+
# !!!plain
|
19
|
+
# host: -o --host RBVMOMI_HOST
|
20
|
+
# port: --port RBVMOMI_PORT (443)
|
21
|
+
# no-ssl: --no-ssl RBVMOMI_SSL (false)
|
22
|
+
# insecure: -k --insecure RBVMOMI_INSECURE (false)
|
23
|
+
# user: -u --user RBVMOMI_USER (root)
|
24
|
+
# password: -p --password RBVMOMI_PASSWORD ()
|
25
|
+
# path: --path RBVMOMI_PATH (/sdk)
|
26
|
+
# debug: -d --debug RBVMOMI_DEBUG (false)
|
7
27
|
def rbvmomi_connection_opts
|
8
28
|
opt :host, "host", :type => :string, :short => 'o', :default => ENV['RBVMOMI_HOST']
|
9
29
|
opt :port, "port", :type => :int, :short => :none, :default => (ENV.member?('RBVMOMI_PORT') ? ENV['RBVMOMI_PORT'].to_i : 443)
|
@@ -12,21 +32,37 @@ class Parser
|
|
12
32
|
opt :user, "username", :short => 'u', :default => (ENV['RBVMOMI_USER'] || 'root')
|
13
33
|
opt :password, "password", :short => 'p', :default => (ENV['RBVMOMI_PASSWORD'] || '')
|
14
34
|
opt :path, "SOAP endpoint path", :short => :none, :default => (ENV['RBVMOMI_PATH'] || '/sdk')
|
15
|
-
opt :debug, "Log SOAP messages", :short => 'd'
|
35
|
+
opt :debug, "Log SOAP messages", :short => 'd', :default => (ENV['RBVMOMI_DEBUG'] || false)
|
16
36
|
end
|
17
37
|
|
38
|
+
# Select a datacenter
|
39
|
+
#
|
40
|
+
# !!!plain
|
41
|
+
# datacenter: -D --datacenter RBVMOMI_DATACENTER (ha-datacenter)
|
18
42
|
def rbvmomi_datacenter_opt
|
19
43
|
opt :datacenter, "datacenter", :type => :string, :short => "D", :default => (ENV['RBVMOMI_DATACENTER'] || 'ha-datacenter')
|
20
44
|
end
|
21
45
|
|
46
|
+
# Select a folder
|
47
|
+
#
|
48
|
+
# !!!plain
|
49
|
+
# folder: -F --folder RBVMOMI_FOLDER ()
|
22
50
|
def rbvmomi_folder_opt
|
23
51
|
opt :folder, "VM folder", :type => :string, :short => "F", :default => (ENV['RBVMOMI_FOLDER'] || '')
|
24
52
|
end
|
25
53
|
|
54
|
+
# Select a compute resource
|
55
|
+
#
|
56
|
+
# !!!plain
|
57
|
+
# computer: -R --computer RBVMOMI_COMPUTER
|
26
58
|
def rbvmomi_computer_opt
|
27
59
|
opt :computer, "Compute resource", :type => :string, :short => "R", :default => ENV['RBVMOMI_COMPUTER']
|
28
60
|
end
|
29
61
|
|
62
|
+
# Select a datastore
|
63
|
+
#
|
64
|
+
# !!!plain
|
65
|
+
# datastore: -s --datastore RBVMOMI_DATASTORE (datastore1)
|
30
66
|
def rbvmomi_datastore_opt
|
31
67
|
opt :datastore, "Datastore", :short => 's', :default => (ENV['RBVMOMI_DATASTORE'] || 'datastore1')
|
32
68
|
end
|
data/lib/rbvmomi/vim.rb
CHANGED
@@ -27,11 +27,13 @@ class VIM < Connection
|
|
27
27
|
opts[:port] ||= (opts[:ssl] ? 443 : 80)
|
28
28
|
opts[:path] ||= '/sdk'
|
29
29
|
opts[:ns] ||= 'urn:vim25'
|
30
|
-
opts[:rev] = '4.
|
30
|
+
opts[:rev] = '4.0'
|
31
31
|
opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug
|
32
32
|
|
33
33
|
new(opts).tap do |vim|
|
34
34
|
vim.serviceContent.sessionManager.Login :userName => opts[:user], :password => opts[:password]
|
35
|
+
rev = vim.serviceContent.about.apiVersion
|
36
|
+
vim.rev = rev if %w(4.0 4.1).member? rev
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbvmomi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
4
|
+
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 1
|
8
7
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
8
|
+
- 2
|
9
|
+
version: 1.1.2
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Rich Lane
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 5
|
30
28
|
segments:
|
31
29
|
- 1
|
32
30
|
- 4
|
@@ -42,7 +40,6 @@ dependencies:
|
|
42
40
|
requirements:
|
43
41
|
- - ">="
|
44
42
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 3
|
46
43
|
segments:
|
47
44
|
- 0
|
48
45
|
version: "0"
|
@@ -56,7 +53,6 @@ dependencies:
|
|
56
53
|
requirements:
|
57
54
|
- - ">="
|
58
55
|
- !ruby/object:Gem::Version
|
59
|
-
hash: 3
|
60
56
|
segments:
|
61
57
|
- 0
|
62
58
|
version: "0"
|
@@ -70,7 +66,6 @@ dependencies:
|
|
70
66
|
requirements:
|
71
67
|
- - ">="
|
72
68
|
- !ruby/object:Gem::Version
|
73
|
-
hash: 3
|
74
69
|
segments:
|
75
70
|
- 0
|
76
71
|
version: "0"
|
@@ -93,6 +88,7 @@ files:
|
|
93
88
|
- VERSION
|
94
89
|
- devel/analyze-vim-declarations.rb
|
95
90
|
- devel/analyze-xml.rb
|
91
|
+
- examples/create_vm-1.9.rb
|
96
92
|
- examples/create_vm.rb
|
97
93
|
- examples/extraConfig.rb
|
98
94
|
- examples/power.rb
|
@@ -140,7 +136,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
136
|
requirements:
|
141
137
|
- - ">="
|
142
138
|
- !ruby/object:Gem::Version
|
143
|
-
hash: 49
|
144
139
|
segments:
|
145
140
|
- 1
|
146
141
|
- 9
|
@@ -151,18 +146,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
146
|
requirements:
|
152
147
|
- - ">="
|
153
148
|
- !ruby/object:Gem::Version
|
154
|
-
hash: 3
|
155
149
|
segments:
|
156
150
|
- 0
|
157
151
|
version: "0"
|
158
152
|
requirements: []
|
159
153
|
|
160
154
|
rubyforge_project:
|
161
|
-
rubygems_version: 1.
|
155
|
+
rubygems_version: 1.3.7
|
162
156
|
signing_key:
|
163
157
|
specification_version: 3
|
164
158
|
summary: Ruby interface to the VMware vSphere API
|
165
159
|
test_files:
|
160
|
+
- examples/create_vm-1.9.rb
|
166
161
|
- examples/create_vm.rb
|
167
162
|
- examples/extraConfig.rb
|
168
163
|
- examples/power.rb
|