vmonkey 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c508835c077aca3004f773a73dfb541babb3819
4
- data.tar.gz: 326b56af7fd2c5dd1ba364fe834fd0546863e859
3
+ metadata.gz: 5b5abf9886b87a12c8c10b8325e21b066efbde2e
4
+ data.tar.gz: e5dbdfb1e613e7bb2bddfc548daac3a2fb2f006b
5
5
  SHA512:
6
- metadata.gz: 47e5a378a2fadf4304ff8d4bf19f66b30ce9745dabc44ac5a30262b428f57500285a1bd730bb90df0709d7c2daeb858c220ceb4114f5be33c5f81d73d2ed864d
7
- data.tar.gz: 04c89a6f1bf9e2f978bbdf4b78086616a174e6f5326b3a3095868c4ef555e83fc3d7759111b5d991038f6d6cdd70d43b42033dc5a9020e6608a144b0a19dad77
6
+ metadata.gz: 179e134d60a7800751beee309ef87abed62b5d06032eb0ef3f37af53e3da762631c02662a2382205c6388ca7456192c2bd94fc11b6d8ed29203843df03a4bc89
7
+ data.tar.gz: cc36d62392f7c923dbc1fd3cd4588652f7c86fb60fd9f247f8c22047a5d1bcc7c6ef0a71a72b9ea8b21539478ed148f0864c629fbcca70455f54235d30dd18de
@@ -1,3 +1,3 @@
1
1
  module Vmonkey
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.0'
3
3
  end
@@ -12,12 +12,12 @@ class RbVmomi::VIM::VirtualApp
12
12
  end
13
13
 
14
14
  def start
15
- PowerOnVApp_Task().wait_for_completion unless vapp_state? 'started'
15
+ self.PowerOnVApp_Task().wait_for_completion unless vapp_state? 'started'
16
16
  end
17
17
 
18
18
  def stop
19
19
  return if vapp_state? 'stopped'
20
- PowerOffVApp_Task()
20
+ self.PowerOffVApp_Task( force: true )
21
21
  sleep 2 until vapp_state? 'stopped'
22
22
  end
23
23
 
@@ -37,12 +37,16 @@ class RbVmomi::VIM::VirtualApp
37
37
  vm.find { |vm| vm.name == vm_name }
38
38
  end
39
39
 
40
+ def find_vm!(vm_name)
41
+ find_vm(vm_name) || raise("VM not found. [#{vm_name}]")
42
+ end
43
+
40
44
  def annotation
41
45
  vAppConfig.annotation
42
46
  end
43
47
 
44
48
  def annotation=(value)
45
- UpdateVAppConfig(spec: {annotation: value})
49
+ self.UpdateVAppConfig(spec: {annotation: value})
46
50
  end
47
51
 
48
52
  def properties
@@ -53,10 +57,10 @@ class RbVmomi::VIM::VirtualApp
53
57
  case args.size
54
58
  when 1
55
59
  read_property(*args)
56
- when 2
60
+ when 2, 3
57
61
  set_property(*args)
58
62
  else
59
- raise ArgumentError.new("wrong number of arguments (#{args.size} for 1 or 2)")
63
+ raise ArgumentError.new("wrong number of arguments (#{args.size} for 1, 2 or 3)")
60
64
  end
61
65
  end
62
66
 
@@ -85,10 +89,20 @@ class RbVmomi::VIM::VirtualApp
85
89
 
86
90
  def read_property(name)
87
91
  p = find_property(name)
88
- p.nil? ? nil : p[:value]
92
+ value = nil
93
+ unless p.nil?
94
+ value = p[:value]
95
+ value = p[:defaultValue] if value.empty?
96
+ end
97
+ value
89
98
  end
90
99
 
91
- def set_property(name, value)
100
+ def set_property(name, value, opts={})
101
+ opts = {
102
+ type: 'string',
103
+ userConfigurable: true
104
+ }.merge opts
105
+
92
106
  if vAppConfig.property
93
107
  existing_property = find_property(name)
94
108
  end
@@ -101,19 +115,17 @@ class RbVmomi::VIM::VirtualApp
101
115
  property_key = name.object_id
102
116
  end
103
117
 
104
- vm_config_spec = RbVmomi::VIM.VAppConfigSpec(
118
+ vapp_config_spec = RbVmomi::VIM.VAppConfigSpec(
105
119
  property: [
106
120
  RbVmomi::VIM.VAppPropertySpec(
107
121
  operation: operation,
108
- info: {
122
+ info: opts.merge({
109
123
  key: property_key,
110
124
  id: name.to_s,
111
- type: 'string',
112
- userConfigurable: true,
113
125
  value: value.to_s
114
- })])
126
+ }))])
115
127
 
116
- UpdateVAppConfig( spec: vm_config_spec )
128
+ self.UpdateVAppConfig( spec: vapp_config_spec )
117
129
  end
118
130
 
119
131
  def port_ready?(port, timeout=5)
@@ -150,11 +162,11 @@ class RbVmomi::VIM::VirtualApp
150
162
  reparent = parent != to_folder
151
163
 
152
164
  if reparent
153
- Rename_Task(newName: "#{path.basename}-tmp").wait_for_completion if rename
165
+ self.Rename_Task(newName: "#{path.basename}-tmp").wait_for_completion if rename
154
166
  to_folder.MoveIntoFolder_Task(list: [self]).wait_for_completion
155
- Rename_Task(newName: path.basename).wait_for_completion if rename
167
+ self.Rename_Task(newName: path.basename).wait_for_completion if rename
156
168
  else
157
- Rename_Task(newName: path.basename).wait_for_completion
169
+ self.Rename_Task(newName: path.basename).wait_for_completion
158
170
  end
159
171
  end
160
172
 
@@ -37,10 +37,10 @@ class RbVmomi::VIM::VirtualMachine
37
37
  case args.size
38
38
  when 1
39
39
  read_property(*args)
40
- when 2
40
+ when 2, 3
41
41
  set_property(*args)
42
42
  else
43
- raise ArgumentError.new("wrong number of arguments (#{args.size} for 1 or 2)")
43
+ raise ArgumentError.new("wrong number of arguments (#{args.size} for 1, 2 or 3)")
44
44
  end
45
45
  end
46
46
 
@@ -175,10 +175,20 @@ class RbVmomi::VIM::VirtualMachine
175
175
 
176
176
  def read_property(name)
177
177
  p = find_property(name)
178
- p.nil? ? nil : p[:value]
178
+ value = nil
179
+ unless p.nil?
180
+ value = p[:value]
181
+ value = p[:defaultValue] if value.empty?
182
+ end
183
+ value
179
184
  end
180
185
 
181
- def set_property(name, value)
186
+ def set_property(name, value, opts={})
187
+ opts = {
188
+ type: 'string',
189
+ userConfigurable: true
190
+ }.merge opts
191
+
182
192
  if config.vAppConfig && config.vAppConfig.property
183
193
  existing_property = find_property(name)
184
194
  end
@@ -198,13 +208,11 @@ class RbVmomi::VIM::VirtualMachine
198
208
  property: [
199
209
  RbVmomi::VIM.VAppPropertySpec(
200
210
  operation: operation,
201
- info: {
211
+ info: opts.merge({
202
212
  key: property_key,
203
213
  id: name.to_s,
204
- type: 'string',
205
- userConfigurable: true,
206
- value: value
207
- })]))
214
+ value: value.to_s
215
+ }))]))
208
216
 
209
217
  if config.vAppConfig.nil? || config.vAppConfig.ovfEnvironmentTransport.empty?
210
218
  vm_config_spec[:vAppConfig][:ovfEnvironmentTransport] = ['com.vmware.guestInfo']
@@ -0,0 +1,51 @@
1
+ require_relative 'spec_helper'
2
+ using VMonkey unless RUBY_VERSION.split('.')[0] == '1'
3
+
4
+ describe RbVmomi::VIM::VirtualApp do
5
+
6
+ before :all do
7
+ @monkey ||= VMonkey.connect
8
+ @vapp ||= @monkey.vapp VM_SPEC_OPTS[:vapp_path]
9
+ @spec_vapp_path = "#{VM_SPEC_OPTS[:working_folder]}/vmonkey_spec_vapp"
10
+ end
11
+
12
+ context 'with a cloned vapp' do
13
+ before(:all) { @spec_vapp = @vapp.clone_to @spec_vapp_path }
14
+ after(:all) { @spec_vapp.destroy }
15
+
16
+ describe '#clone' do
17
+ context 'to a Folder' do
18
+ subject { @monkey.vapp @spec_vapp_path }
19
+ it { should_not be_nil }
20
+ end
21
+ end
22
+
23
+ describe '#annotation=' do
24
+ it 'sets the annotation' do
25
+ @spec_vapp.annotation = 'xyzzy'
26
+ expect(@spec_vapp.annotation).to eq 'xyzzy'
27
+ end
28
+ end
29
+
30
+ describe '#property' do
31
+ before(:all) do
32
+ @spec_vapp.property :prop, 'xyzzy'
33
+ @spec_vapp.property :prop2, 'abc123'
34
+ @spec_vapp.property :prop2, 'abc456'
35
+ @spec_vapp.property :ip_prop, nil, type: 'ip'
36
+ @spec_vapp.property :ip_prop_with_default, nil, type: 'ip', defaultValue: '0.0.0.0'
37
+ end
38
+
39
+ it { expect(@spec_vapp.property :prop).to eq 'xyzzy' }
40
+ it { expect(@spec_vapp.property :prop2).to eq 'abc456' }
41
+ it { expect(@spec_vapp.property :xyzzy).to be_nil }
42
+
43
+ it { expect(@spec_vapp.property :ip_prop).to be_empty }
44
+ it { expect(@spec_vapp.find_property(:ip_prop)[:type]).to eq 'ip' }
45
+
46
+ it { expect(@spec_vapp.property :ip_prop_with_default).to eq '0.0.0.0' }
47
+ it { expect(@spec_vapp.find_property(:ip_prop_with_default)[:type]).to eq 'ip' }
48
+ end
49
+
50
+ end
51
+ end
data/spec/vapp_spec.rb CHANGED
@@ -35,25 +35,6 @@ describe RbVmomi::VIM::VirtualApp do
35
35
  end
36
36
  end
37
37
 
38
- describe '#annotation=' do
39
- it 'sets the annotation' do
40
- @spec_vapp.annotation = 'xyzzy'
41
- expect(@spec_vapp.annotation).to eq 'xyzzy'
42
- end
43
- end
44
-
45
- describe '#property' do
46
- before(:all) do
47
- @spec_vapp.property :prop, 'xyzzy'
48
- @spec_vapp.property :prop2, 'abc123'
49
- @spec_vapp.property :prop2, 'abc456'
50
- end
51
-
52
- it { expect(@spec_vapp.property :prop).to eq 'xyzzy' }
53
- it { expect(@spec_vapp.property :prop2).to eq 'abc456' }
54
- it { expect(@spec_vapp.property :xyzzy).to be_nil }
55
- end
56
-
57
38
  describe '#move_to' do
58
39
  it 'should raise a RuntimeError when given a path of an existing vApp' do
59
40
  expect { @spec_vapp.move_to @spec_vapp_path }.to raise_error RuntimeError
@@ -137,6 +118,7 @@ describe RbVmomi::VIM::VirtualApp do
137
118
 
138
119
  context 'that has had #start called' do
139
120
  before(:all) { @spec_vapp.start }
121
+ after(:all) { @spec_vapp.stop }
140
122
 
141
123
  context 'immediately following start' do
142
124
  describe '#port_ready?' do
@@ -156,7 +138,6 @@ describe RbVmomi::VIM::VirtualApp do
156
138
  end
157
139
  end
158
140
 
159
- after(:all) { @spec_vapp.stop }
160
141
  end
161
142
 
162
143
  end
@@ -0,0 +1,48 @@
1
+ require_relative 'spec_helper'
2
+ using VMonkey unless RUBY_VERSION.split('.')[0] == '1'
3
+
4
+ describe RbVmomi::VIM::VirtualMachine do
5
+ before :all do
6
+ @monkey ||= VMonkey.connect
7
+ @template = @monkey.vm VM_SPEC_OPTS[:template_path]
8
+ @vm_path = "#{VM_SPEC_OPTS[:working_folder]}/vmonkey_spec"
9
+ end
10
+
11
+ context 'with a cloned VM' do
12
+ before(:all) { @spec_vm = @template.clone_to @vm_path }
13
+ after(:all) { @spec_vm.destroy }
14
+
15
+ describe '#annotation=' do
16
+ it 'sets the annotation' do
17
+ @spec_vm.annotation = 'xyzzy'
18
+ expect(@spec_vm.annotation).to eq 'xyzzy'
19
+ end
20
+ end
21
+
22
+ describe '#property' do
23
+ before(:all) do
24
+ @spec_vm.property :prop, 'xyzzy'
25
+ @spec_vm.property :prop2, 'abc123'
26
+ @spec_vm.property :prop2, 'abc456'
27
+ @spec_vm.property :ip_prop, nil, type: 'ip'
28
+ @spec_vm.property :ip_prop_with_default, nil, type: 'ip', defaultValue: '0.0.0.0'
29
+ end
30
+
31
+ it { expect(@spec_vm.property :prop).to eq 'xyzzy' }
32
+ it { expect(@spec_vm.property :prop2).to eq 'abc456' }
33
+ it { expect(@spec_vm.property :xyzzy).to be_nil }
34
+
35
+ it { expect(@spec_vm.property :ip_prop).to be_empty }
36
+ it { expect(@spec_vm.find_property(:ip_prop)[:type]).to eq 'ip' }
37
+
38
+ it { expect(@spec_vm.property :ip_prop_with_default).to eq '0.0.0.0' }
39
+ it { expect(@spec_vm.find_property(:ip_prop_with_default)[:type]).to eq 'ip' }
40
+ end
41
+
42
+ describe '#property!' do
43
+ it 'should raise a RuntimeError given a path to a non-existent property' do
44
+ expect { @spec_vm.property! :xyzzy }.to raise_error RuntimeError
45
+ end
46
+ end
47
+ end
48
+ end
@@ -84,31 +84,6 @@ describe RbVmomi::VIM::VirtualMachine do
84
84
  end
85
85
  end
86
86
 
87
- describe '#annotation=' do
88
- it 'sets the annotation' do
89
- @spec_vm.annotation = 'xyzzy'
90
- expect(@spec_vm.annotation).to eq 'xyzzy'
91
- end
92
- end
93
-
94
- describe '#property' do
95
- before(:all) do
96
- @spec_vm.property :prop, 'xyzzy'
97
- @spec_vm.property :prop2, 'abc123'
98
- @spec_vm.property :prop2, 'abc456'
99
- end
100
-
101
- it { expect(@spec_vm.property :prop).to eq 'xyzzy' }
102
- it { expect(@spec_vm.property :prop2).to eq 'abc456' }
103
- it { expect(@spec_vm.property :xyzzy).to be_nil }
104
- end
105
-
106
- describe '#property!' do
107
- it 'should raise a RuntimeError given a path to a non-existent property' do
108
- expect { @spec_vm.property! :xyzzy }.to raise_error RuntimeError
109
- end
110
- end
111
-
112
87
  describe '#move_to' do
113
88
  it 'should raise a RuntimeError when given a path of an existing VM' do
114
89
  expect { @spec_vm.move_to @vm_path }.to raise_error RuntimeError
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmonkey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Dupras
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-17 00:00:00.000000000 Z
12
+ date: 2014-09-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -119,8 +119,10 @@ files:
119
119
  - spec/datacenter_spec.rb
120
120
  - spec/folder_spec.rb
121
121
  - spec/spec_helper.rb
122
+ - spec/vapp_property_spec.rb
122
123
  - spec/vapp_spec.rb
123
124
  - spec/vim_spec.rb
125
+ - spec/virtualmachine_property_spec.rb
124
126
  - spec/virtualmachine_spec.rb
125
127
  - spec/vmonkey_spec.rb
126
128
  - vmonkey.gemspec
@@ -152,7 +154,9 @@ test_files:
152
154
  - spec/datacenter_spec.rb
153
155
  - spec/folder_spec.rb
154
156
  - spec/spec_helper.rb
157
+ - spec/vapp_property_spec.rb
155
158
  - spec/vapp_spec.rb
156
159
  - spec/vim_spec.rb
160
+ - spec/virtualmachine_property_spec.rb
157
161
  - spec/virtualmachine_spec.rb
158
162
  - spec/vmonkey_spec.rb