vmonkey 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0b377b2e2e04e33a7e11a78bfdba2a9359e2f7a6
4
+ data.tar.gz: 69f2335719ab9d9fde2e4a7a2b1d91a86567c06d
5
+ SHA512:
6
+ metadata.gz: e24027bf933a229dedc82fe9958b0e1b57ca9eb79fff135d358805f5ab372d0946d0215af39c06f554b9c4cbe3366a49b9f4b6ecff85d8003f9fc9a2cc73ef20
7
+ data.tar.gz: d5812887c249c9cca6cbc72ae0985b7eb9b46776615b64a9c5edd9819a2862957109cd917f68de5287b2eccd0807e84436c563eda58fea1eb0ebcfebea13ef24
data/lib/vmonkey.rb CHANGED
@@ -15,14 +15,16 @@ module VMonkey
15
15
  end
16
16
  end
17
17
 
18
- class String
19
- def parent
20
- p = self.split('/')[0...-1].join('/')
21
- p == '' ? '/' : p
22
- end
18
+ module VMonkey
19
+ refine String do
20
+ def parent
21
+ p = self.split('/')[0...-1].join('/')
22
+ p == '' ? '/' : p
23
+ end
23
24
 
24
- def basename
25
- p = self.split('/').last
25
+ def basename
26
+ p = self.split('/').last
27
+ end
26
28
  end
27
29
  end
28
30
 
@@ -1,3 +1,3 @@
1
1
  module Vmonkey
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -1,4 +1,12 @@
1
+ using VMonkey
2
+
1
3
  class RbVmomi::VIM::VirtualApp
4
+
5
+ def destroy
6
+ self.PowerOffVApp_Task( force: true ).wait_for_completion unless summary.vAppState.downcase == 'stopped'
7
+ self.Destroy_Task( force: true ).wait_for_completion
8
+ end
9
+
2
10
  def vm_pool
3
11
  self
4
12
  end
@@ -10,6 +18,97 @@ class RbVmomi::VIM::VirtualApp
10
18
  def find_vm(vm_name)
11
19
  vm.find { |vm| vm.name == vm_name }
12
20
  end
21
+
22
+ def annotation
23
+ vAppConfig.annotation
24
+ end
25
+
26
+ def annotation=(value)
27
+ UpdateVAppConfig(spec: {annotation: value})
28
+ end
29
+
30
+ def properties
31
+ vAppConfig.property
32
+ end
33
+
34
+ def property(*args)
35
+ case args.size
36
+ when 1
37
+ read_property(*args)
38
+ when 2
39
+ set_property(*args)
40
+ else
41
+ raise ArgumentError.new("wrong number of arguments (#{args.size} for 1 or 2)")
42
+ end
43
+ end
44
+
45
+ def property!(name)
46
+ read_property(name) || raise("vApp Property not found. [#{name}]")
47
+ end
48
+
49
+ def clone_to(path, opts = {})
50
+ dest = monkey.get(path.parent)
51
+ unless dest.is_a? RbVmomi::VIM::Folder or dest.is_a? RbVmomi::VIM::VirtualApp
52
+ raise "Cannot clone_to [#{path.parent}] - destination must specify a Folder or VirtualApp"
53
+ end
54
+
55
+ if opts[:datastore].nil?
56
+ opts[:datastore] = datastore.first #take the first datastore on the vApp to be cloned
57
+ end
58
+
59
+ params = _clone_params(path.basename, dest, opts)
60
+
61
+ self.CloneVApp_Task(params).wait_for_completion
62
+ end
63
+
64
+ def find_property(name)
65
+ vAppConfig.property.find { |p| p.props[:id] == name.to_s }
66
+ end
67
+
68
+ def read_property(name)
69
+ p = find_property(name)
70
+ p.nil? ? nil : p[:value]
71
+ end
72
+
73
+ def set_property(name, value)
74
+ if vAppConfig.property
75
+ existing_property = find_property(name)
76
+ end
77
+
78
+ if existing_property
79
+ operation = 'edit'
80
+ property_key = existing_property.props[:key]
81
+ else
82
+ operation = 'add'
83
+ property_key = name.object_id
84
+ end
85
+
86
+ vm_config_spec = RbVmomi::VIM.VAppConfigSpec(
87
+ property: [
88
+ RbVmomi::VIM.VAppPropertySpec(
89
+ operation: operation,
90
+ info: {
91
+ key: property_key,
92
+ id: name.to_s,
93
+ type: 'string',
94
+ userConfigurable: true,
95
+ value: value
96
+ })])
97
+
98
+ UpdateVAppConfig( spec: vm_config_spec )
99
+ end
100
+
101
+ def _clone_params(vapp_name, dest, opts)
102
+ {
103
+ name: vapp_name,
104
+ target: monkey.cluster.resourcePool,
105
+ spec: RbVmomi::VIM.VAppCloneSpec(
106
+ location: opts[:datastore],
107
+ vmFolder: dest
108
+ )
109
+ }
110
+ end
111
+
13
112
  end
14
113
 
15
114
 
@@ -1,3 +1,5 @@
1
+ using VMonkey
2
+
1
3
  class RbVmomi::VIM::VirtualMachine
2
4
 
3
5
  def destroy
@@ -65,6 +65,14 @@ module RbVmomi
65
65
  dc.vmFolder.traverse path
66
66
  end
67
67
 
68
+ def datastore(datastore_name)
69
+ dc.datastore.find { |ds| ds.info.name.to_s == datastore_name.to_s }
70
+ end
71
+
72
+ def datastore!(datastore_name)
73
+ datastore(datastore_name) || raise("Datastore not found. [#{datastore_name}]")
74
+ end
75
+
68
76
  def customization_spec(spec_name)
69
77
  return nil if spec_name.nil?
70
78
  serviceContent.customizationSpecManager.GetCustomizationSpec(name: spec_name).spec
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require_relative '../lib/vmonkey'
2
+ require 'rspec/its'
2
3
 
3
4
  instructions = "
4
5
  For the integration tests to run, you need:
@@ -28,6 +29,7 @@ instructions = "
28
29
  :vapp_pool_path: /cluster_name/monkey_vapp
29
30
  :vapp_path: /path/to/a/vapp
30
31
  :customization_spec: name-of-a-cust-spec
32
+ :datastore: name-of-a-datastore
31
33
  "
32
34
 
33
35
  raise instructions unless File.exists? ENV['VMONKEY_YML']
@@ -40,9 +42,10 @@ raise instructions unless monkey.vm VM_SPEC_OPTS[:template_path]
40
42
  raise instructions unless monkey.vapp VM_SPEC_OPTS[:vapp_path]
41
43
  raise instructions unless monkey.dc.find_pool VM_SPEC_OPTS[:vapp_pool_path]
42
44
  raise instructions unless monkey.customization_spec VM_SPEC_OPTS[:customization_spec]
45
+ raise instructions unless monkey.datastore VM_SPEC_OPTS[:datastore]
43
46
 
44
47
  RSpec.configure do |config|
45
- config.color_enabled = true
46
- config.tty = true
47
- config.formatter = :documentation
48
+ config.color = true
49
+ config.tty = true
50
+ config.formatter = :documentation
48
51
  end
data/spec/vapp_spec.rb CHANGED
@@ -1,14 +1,59 @@
1
1
  require_relative 'spec_helper'
2
+ using VMonkey
2
3
 
3
- describe RbVmomi::VIM::Folder do
4
+ describe RbVmomi::VIM::VirtualApp do
4
5
 
5
6
  before :all do
6
- @monkey ||= VMonkey.connect
7
- @vapp ||= @monkey.vapp VM_SPEC_OPTS[:vapp_path]
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"
8
10
  end
9
11
 
10
12
  describe '#vm_pool' do
11
13
  subject { @vapp.vm_pool }
12
14
  it { should_not be_nil }
13
15
  end
16
+
17
+ describe '#_clone_params' do
18
+ context 'with Folder destination' do
19
+ subject { @params ||= @vapp._clone_params(@spec_vapp_path.basename, @monkey.get(@spec_vapp_path.parent), {}) }
20
+
21
+ it { expect(subject[:name]).to eq @spec_vapp_path.basename }
22
+ it { expect(subject[:spec].location).to be_nil }
23
+ it { expect(subject[:spec].vmFolder.name).to eql @spec_vapp_path.parent.basename }
24
+ end
25
+ end
26
+
27
+ context 'with a cloned vapp' do
28
+ before(:all) { @spec_vapp = @vapp.clone_to @spec_vapp_path }
29
+ after(:all) { @spec_vapp.destroy }
30
+
31
+ describe '#clone' do
32
+ context 'to a Folder' do
33
+ subject { @monkey.vapp @spec_vapp_path }
34
+ it { should_not be_nil }
35
+ end
36
+ end
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
+ end
58
+
14
59
  end
data/spec/vim_spec.rb CHANGED
@@ -108,7 +108,21 @@ describe RbVmomi::VIM do
108
108
 
109
109
  it { should be_nil }
110
110
  end
111
+ end
111
112
 
113
+ describe '#datastore' do
114
+ context 'given an existing datastore' do
115
+ subject { @ds ||= @monkey.datastore VM_SPEC_OPTS[:datastore] }
116
+ it { should_not be_nil }
117
+ its(:name) { should == VM_SPEC_OPTS[:datastore] }
118
+ end
112
119
  end
113
120
 
121
+ describe '#datastore!' do
122
+ it 'should raise a RuntimeError given a non-existent datastore' do
123
+ expect { @monkey.datastore! '/xyzzy' }.to raise_error RuntimeError
124
+ end
125
+ end
126
+
127
+
114
128
  end
@@ -1,4 +1,5 @@
1
1
  require_relative 'spec_helper'
2
+ using VMonkey
2
3
 
3
4
  describe RbVmomi::VIM::VirtualMachine do
4
5
  before :all do
@@ -167,7 +168,7 @@ describe RbVmomi::VIM::VirtualMachine do
167
168
 
168
169
  describe '#port_ready?' do
169
170
  it 'should be false when the VM is powered off' do
170
- expect( @spec_vm.port_ready? 22 ).to be_false
171
+ expect( @spec_vm.port_ready? 22 ).to be_falsey
171
172
  end
172
173
  end
173
174
 
@@ -177,13 +178,13 @@ describe RbVmomi::VIM::VirtualMachine do
177
178
  context 'immediately following start' do
178
179
  describe '#ready?' do
179
180
  it 'should be false' do
180
- expect(@spec_vm.ready?).to be_false
181
+ expect(@spec_vm.ready?).to be_falsey
181
182
  end
182
183
  end
183
184
 
184
185
  describe '#port_ready?' do
185
186
  it 'should be false' do
186
- expect(@spec_vm.port_ready? 22).to be_false
187
+ expect(@spec_vm.port_ready? 22).to be_falsey
187
188
  end
188
189
  end
189
190
  end
@@ -193,13 +194,13 @@ describe RbVmomi::VIM::VirtualMachine do
193
194
 
194
195
  describe '#ready?' do
195
196
  it 'should be true' do
196
- expect(@spec_vm.ready?).to be_true
197
+ expect(@spec_vm.ready?).to be_truthy
197
198
  end
198
199
  end
199
200
 
200
201
  describe '#port_ready?' do
201
202
  it 'should be true' do
202
- expect(@spec_vm.port_ready? 22).to be_true
203
+ expect(@spec_vm.port_ready? 22).to be_truthy
203
204
  end
204
205
  end
205
206
  end
data/vmonkey.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['brian@duprasville.com', 'dsmith@rallydev.com']
11
11
  spec.summary = %q{ simple to use vsphere methods }
12
12
  spec.description = %q{ simple to use vsphere methods }
13
- spec.homepage = 'https://github.com/something/vmonkey'
13
+ spec.homepage = 'https://github.com/vmtricks/vmonkey'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'bundler', '~> 1.6'
25
25
  spec.add_development_dependency 'rake'
26
26
  spec.add_development_dependency 'rspec', '~> 2.14'
27
+ spec.add_development_dependency 'rspec-its'
27
28
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmonkey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
5
- prerelease:
4
+ version: 0.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Brian Dupras
@@ -10,12 +9,11 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2014-07-02 00:00:00.000000000 Z
12
+ date: 2014-08-07 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: nokogiri
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
18
  - - '='
21
19
  - !ruby/object:Gem::Version
@@ -23,7 +21,6 @@ dependencies:
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
25
  - - '='
29
26
  - !ruby/object:Gem::Version
@@ -31,7 +28,6 @@ dependencies:
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: rbvmomi
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
32
  - - ~>
37
33
  - !ruby/object:Gem::Version
@@ -39,7 +35,6 @@ dependencies:
39
35
  type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
39
  - - ~>
45
40
  - !ruby/object:Gem::Version
@@ -47,7 +42,6 @@ dependencies:
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: bundler
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
46
  - - ~>
53
47
  - !ruby/object:Gem::Version
@@ -55,7 +49,6 @@ dependencies:
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
53
  - - ~>
61
54
  - !ruby/object:Gem::Version
@@ -63,23 +56,20 @@ dependencies:
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: rake
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ! '>='
60
+ - - '>='
69
61
  - !ruby/object:Gem::Version
70
62
  version: '0'
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
- - - ! '>='
67
+ - - '>='
77
68
  - !ruby/object:Gem::Version
78
69
  version: '0'
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: rspec
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
74
  - - ~>
85
75
  - !ruby/object:Gem::Version
@@ -87,12 +77,25 @@ dependencies:
87
77
  type: :development
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
81
  - - ~>
93
82
  - !ruby/object:Gem::Version
94
83
  version: '2.14'
95
- description: ! ' simple to use vsphere methods '
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec-its
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: ' simple to use vsphere methods '
96
99
  email:
97
100
  - brian@duprasville.com
98
101
  - dsmith@rallydev.com
@@ -121,36 +124,29 @@ files:
121
124
  - spec/virtualmachine_spec.rb
122
125
  - spec/vmonkey_spec.rb
123
126
  - vmonkey.gemspec
124
- homepage: https://github.com/something/vmonkey
127
+ homepage: https://github.com/vmtricks/vmonkey
125
128
  licenses:
126
129
  - MIT
130
+ metadata: {}
127
131
  post_install_message:
128
132
  rdoc_options: []
129
133
  require_paths:
130
134
  - lib
131
135
  required_ruby_version: !ruby/object:Gem::Requirement
132
- none: false
133
136
  requirements:
134
- - - ! '>='
137
+ - - '>='
135
138
  - !ruby/object:Gem::Version
136
139
  version: '0'
137
- segments:
138
- - 0
139
- hash: 683573069034948857
140
140
  required_rubygems_version: !ruby/object:Gem::Requirement
141
- none: false
142
141
  requirements:
143
- - - ! '>='
142
+ - - '>='
144
143
  - !ruby/object:Gem::Version
145
144
  version: '0'
146
- segments:
147
- - 0
148
- hash: 683573069034948857
149
145
  requirements: []
150
146
  rubyforge_project:
151
- rubygems_version: 1.8.25
147
+ rubygems_version: 2.0.14
152
148
  signing_key:
153
- specification_version: 3
149
+ specification_version: 4
154
150
  summary: simple to use vsphere methods
155
151
  test_files:
156
152
  - spec/datacenter_spec.rb