rbvmomi 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,67 @@
1
+ require 'test/unit'
2
+ require 'rbvmomi'
3
+ include RbVmomi
4
+
5
+ class ParseResponseTest < Test::Unit::TestCase
6
+ def check desc, str, expected
7
+ soap = RbVmomi::Soap.new(ns: 'urn:vim25', rev: '4.0')
8
+ got = soap.parse_response Nokogiri(str).root, desc
9
+
10
+ puts "expected:"
11
+ pp expected
12
+ puts
13
+ puts "got:"
14
+ pp got
15
+ puts
16
+
17
+ assert_equal expected, got
18
+ end
19
+
20
+ def test_string_array
21
+ desc = { 'wsdl_type' => 'xsd:string', 'is-array' => true, 'is-task' => false }
22
+
23
+ check desc, <<-EOS, ['a', 'b', 'c']
24
+ <root xmlns="urn:vim25">
25
+ <blah>a</blah>
26
+ <blah>b</blah>
27
+ <blah>c</blah>
28
+ </root>
29
+ EOS
30
+ end
31
+
32
+ def test_missing_parameter_fault
33
+ desc = { 'wsdl_type' => nil, 'is-array' => false, 'is-task' => false }
34
+
35
+ assert_raise RuntimeError do
36
+ check desc, <<-EOS, ['a', 'b', 'c']
37
+ <soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
38
+ <faultcode>ClientFaultCode</faultcode>
39
+ <faultstring>Required parameter selectionSet is missing</faultstring>
40
+ </soapenv:Fault>
41
+ EOS
42
+ end
43
+ end
44
+
45
+ def test_invalid_argument_fault
46
+ desc = { 'wsdl_type' => nil, 'is-array' => false, 'is-task' => false }
47
+
48
+ assert_raise RbVmomi::Fault do
49
+ begin
50
+ check desc, <<-EOS, nil
51
+ <soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
52
+ <faultcode>ServerFaultCode</faultcode>
53
+ <faultstring>A specified parameter was not correct. ticketType</faultstring>
54
+ <detail>
55
+ <InvalidArgumentFault xmlns="urn:vim25" xsi:type="InvalidArgument">
56
+ <invalidProperty>ticketType</invalidProperty>
57
+ </InvalidArgumentFault>
58
+ </detail>
59
+ </soapenv:Fault>
60
+ EOS
61
+ rescue RbVmomi::Fault
62
+ raise
63
+ end
64
+ end
65
+ end
66
+ end
67
+
@@ -0,0 +1,208 @@
1
+ require 'test/unit'
2
+ require 'rbvmomi'
3
+ include RbVmomi
4
+
5
+ class SerializationTest < Test::Unit::TestCase
6
+ def check str, obj, type, array=false
7
+ @soap = RbVmomi::Soap.new(ns: 'urn:vim25', rev: '4.0')
8
+ xml = Builder::XmlMarkup.new :indent => 2
9
+ soap.obj2xml(xml, 'root', type, array, obj)
10
+
11
+ puts "expected:"
12
+ puts str
13
+ puts
14
+ puts "got:"
15
+ puts xml.target!
16
+ puts
17
+
18
+ assert_equal str, xml.target!
19
+ end
20
+
21
+ def test_moref
22
+ check <<-EOS, VIM.Folder(nil, "ha-folder-host"), "Folder"
23
+ <root type="Folder">ha-folder-host</root>
24
+ EOS
25
+ end
26
+
27
+ def test_config
28
+ cfg = VIM.VirtualMachineConfigSpec(
29
+ name: 'vm',
30
+ files: { vmPathName: '[datastore1]' },
31
+ guestId: 'otherGuest64',
32
+ numCPUs: 2,
33
+ memoryMB: 3072,
34
+ deviceChange: [
35
+ {
36
+ operation: :add,
37
+ device: VIM.VirtualLsiLogicController(
38
+ key: 1000,
39
+ busNumber: 0,
40
+ sharedBus: :noSharing,
41
+ )
42
+ }, VIM.VirtualDeviceConfigSpec(
43
+ operation: VIM.VirtualDeviceConfigSpecOperation(:add),
44
+ fileOperation: VIM.VirtualDeviceConfigSpecFileOperation(:create),
45
+ device: VIM.VirtualDisk(
46
+ key: 0,
47
+ backing: VIM.VirtualDiskFlatVer2BackingInfo(
48
+ fileName: '[datastore1]',
49
+ diskMode: :persistent,
50
+ thinProvisioned: true,
51
+ ),
52
+ controllerKey: 1000,
53
+ unitNumber: 0,
54
+ capacityInKB: 4000000,
55
+ )
56
+ ), {
57
+ operation: :add,
58
+ device: VIM.VirtualE1000(
59
+ key: 0,
60
+ deviceInfo: {
61
+ label: 'Network Adapter 1',
62
+ summary: 'VM Network',
63
+ },
64
+ backing: VIM.VirtualEthernetCardNetworkBackingInfo(
65
+ deviceName: 'VM Network',
66
+ ),
67
+ addressType: 'generated'
68
+ )
69
+ }
70
+ ],
71
+ extraConfig: [
72
+ {
73
+ key: 'bios.bootOrder',
74
+ value: 'ethernet0'
75
+ }
76
+ ]
77
+ )
78
+ check <<-EOS, cfg, "VirtualMachineConfigSpec"
79
+ <root xsi:type="VirtualMachineConfigSpec">
80
+ <name>vm</name>
81
+ <guestId>otherGuest64</guestId>
82
+ <files xsi:type="VirtualMachineFileInfo">
83
+ <vmPathName>[datastore1]</vmPathName>
84
+ </files>
85
+ <numCPUs>2</numCPUs>
86
+ <memoryMB>3072</memoryMB>
87
+ <deviceChange xsi:type="VirtualDeviceConfigSpec">
88
+ <operation>add</operation>
89
+ <device xsi:type="VirtualLsiLogicController">
90
+ <key>1000</key>
91
+ <busNumber>0</busNumber>
92
+ <sharedBus>noSharing</sharedBus>
93
+ </device>
94
+ </deviceChange>
95
+ <deviceChange xsi:type="VirtualDeviceConfigSpec">
96
+ <operation>add</operation>
97
+ <fileOperation>create</fileOperation>
98
+ <device xsi:type="VirtualDisk">
99
+ <key>0</key>
100
+ <backing xsi:type="VirtualDiskFlatVer2BackingInfo">
101
+ <fileName>[datastore1]</fileName>
102
+ <diskMode>persistent</diskMode>
103
+ <thinProvisioned>1</thinProvisioned>
104
+ </backing>
105
+ <controllerKey>1000</controllerKey>
106
+ <unitNumber>0</unitNumber>
107
+ <capacityInKB>4000000</capacityInKB>
108
+ </device>
109
+ </deviceChange>
110
+ <deviceChange xsi:type="VirtualDeviceConfigSpec">
111
+ <operation>add</operation>
112
+ <device xsi:type="VirtualE1000">
113
+ <key>0</key>
114
+ <deviceInfo xsi:type="Description">
115
+ <label>Network Adapter 1</label>
116
+ <summary>VM Network</summary>
117
+ </deviceInfo>
118
+ <backing xsi:type="VirtualEthernetCardNetworkBackingInfo">
119
+ <deviceName>VM Network</deviceName>
120
+ </backing>
121
+ <addressType>generated</addressType>
122
+ </device>
123
+ </deviceChange>
124
+ <extraConfig xsi:type="OptionValue">
125
+ <key>bios.bootOrder</key>
126
+ <value xsi:type="xsd:string">ethernet0</value>
127
+ </extraConfig>
128
+ </root>
129
+ EOS
130
+ end
131
+
132
+ def test_nil_field
133
+ obj = VIM.OptionValue(key: 'foo', value: nil)
134
+ check <<-EOS, obj, "OptionValue"
135
+ <root xsi:type="OptionValue">
136
+ <key>foo</key>
137
+ </root>
138
+ EOS
139
+ end
140
+
141
+ def test_string_array
142
+ obj = ["foo", "bar", "baz"]
143
+ check <<-EOS, obj, "xsd:string", true
144
+ <root>foo</root>
145
+ <root>bar</root>
146
+ <root>baz</root>
147
+ EOS
148
+ end
149
+
150
+ def test_int_array
151
+ obj = [1,2,3]
152
+ check <<-EOS, obj, "xsd:int", true
153
+ <root>1</root>
154
+ <root>2</root>
155
+ <root>3</root>
156
+ EOS
157
+ end
158
+
159
+ def test_boolean_array
160
+ obj = [true,false,true]
161
+ check <<-EOS, obj, "xsd:boolean", true
162
+ <root>1</root>
163
+ <root>0</root>
164
+ <root>1</root>
165
+ EOS
166
+ end
167
+
168
+ def test_float_array
169
+ obj = [0.0,1.5,3.14]
170
+ check <<-EOS, obj, "xsd:float", true
171
+ <root>0.0</root>
172
+ <root>1.5</root>
173
+ <root>3.14</root>
174
+ EOS
175
+ end
176
+
177
+ def test_binary
178
+ obj = "\x00foo\x01bar\x02baz"
179
+ check <<-EOS, obj, 'xsd:base64Binary'
180
+ <root>AGZvbwFiYXICYmF6</root>
181
+ EOS
182
+ end
183
+
184
+ def test_property_spec
185
+ interested = %w(info.progress info.state info.entityName info.error)
186
+ tasks = [VIM::Task.new(nil, 'task-11')]
187
+ obj = {
188
+ :propSet => [{ :type => 'Task', :all => false, :pathSet => interested }],
189
+ :objectSet => tasks.map { |x| { :obj => x } },
190
+ }
191
+ check <<-EOS, obj, 'PropertyFilterSpec'
192
+ <root xsi:type="PropertyFilterSpec">
193
+ <propSet xsi:type="PropertySpec">
194
+ <type>Task</type>
195
+ <all>0</all>
196
+ <pathSet>info.progress</pathSet>
197
+ <pathSet>info.state</pathSet>
198
+ <pathSet>info.entityName</pathSet>
199
+ <pathSet>info.error</pathSet>
200
+ </propSet>
201
+ <objectSet xsi:type="ObjectSpec">
202
+ <obj type="Task">task-11</obj>
203
+ </objectSet>
204
+ </root>
205
+ EOS
206
+
207
+ end
208
+ end
data/vmodl.tc ADDED
Binary file
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbvmomi
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 1
10
+ version: 1.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Rich Lane
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-09 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: nokogiri
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 1
32
+ - 4
33
+ - 1
34
+ version: 1.4.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: builder
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: trollop
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :runtime
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: tokyocabinet
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :runtime
78
+ version_requirements: *id004
79
+ description:
80
+ email: rlane@vmware.com
81
+ executables: []
82
+
83
+ extensions: []
84
+
85
+ extra_rdoc_files:
86
+ - LICENSE
87
+ - README.md
88
+ files:
89
+ - .gitignore
90
+ - LICENSE
91
+ - README.md
92
+ - Rakefile
93
+ - VERSION
94
+ - devel/analyze-vim-declarations.rb
95
+ - devel/analyze-xml.rb
96
+ - lib/rbvmomi.rb
97
+ - lib/rbvmomi/extensions.rb
98
+ - lib/rbvmomi/profile.rb
99
+ - lib/rbvmomi/trollop.rb
100
+ - lib/rbvmomi/types.rb
101
+ - lib/trivial_soap.rb
102
+ - test/runner.rb
103
+ - test/test.rb
104
+ - test/test_deserialization.rb
105
+ - test/test_emit_request.rb
106
+ - test/test_parse_response.rb
107
+ - test/test_serialization.rb
108
+ - vmodl.tc
109
+ has_rdoc: true
110
+ homepage: https://github.com/rlane/rbvmomi
111
+ licenses: []
112
+
113
+ post_install_message:
114
+ rdoc_options:
115
+ - --charset=UTF-8
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 49
124
+ segments:
125
+ - 1
126
+ - 9
127
+ - 1
128
+ version: 1.9.1
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ requirements: []
139
+
140
+ rubyforge_project:
141
+ rubygems_version: 1.3.7
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Ruby interface to the VI API
145
+ test_files:
146
+ - test/runner.rb
147
+ - test/test_serialization.rb
148
+ - test/test.rb
149
+ - test/test_deserialization.rb
150
+ - test/test_parse_response.rb
151
+ - test/test_emit_request.rb