vm_shepherd 3.4.3 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43d31078d70454ba342478843bfe081cd0f1ad09
4
- data.tar.gz: ad2929a6441cd0b6b41641be5c9960fa4b65efbc
3
+ metadata.gz: a056d918fa69521babd0636b90a36bbc4e75a9bc
4
+ data.tar.gz: 23ec4f0d83d118542fc213139604efaaa5b52fd2
5
5
  SHA512:
6
- metadata.gz: 2b0287bcc30353b217f60b924df03b22566c7dfb9b2a214d83f7e6dd74c224d9762c5770c55757d93ad2f467e0b794e074d4a4df156a6147d918725e9b4d705b
7
- data.tar.gz: 1727afdb454f41b600a8916a94f5e3757619936fed96b53857c8b4997506f273dcb010b7e86c30d2b6d526a643876652a6444d30a0b030fe548027b79f587d84
6
+ metadata.gz: ce2cf10d6f705dd3633ec9d3c537c97131568ca6d91f5692a3c887d2f42fb44ffbd28ed854814f0d953a842f4424fcad651410c0b0b436a7b8af26dba7ab3a0d
7
+ data.tar.gz: be9a971752b45af0359c8bd41825ef85f545ba97a1f69b29119a96816e4821de46ee7e43aeca36705127d99551860c932da318aa5b6c89df0a81fb33b9e586f3
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Pivotal CF
1
+ Copyright (c) 2013-Present Pivotal Software, Inc.
2
2
 
3
3
  MIT License
4
4
 
@@ -8,10 +8,11 @@ module VmShepherd
8
8
  class InvalidIaas < StandardError;
9
9
  end
10
10
 
11
- def initialize(settings:)
11
+ def initialize(settings:,system_env:)
12
12
  @iaas_type = settings.dig('iaas_type')
13
13
  @configs = settings.dig('vm_shepherd', 'vm_configs') || []
14
14
  @env_config = settings.dig('vm_shepherd', 'env_config')
15
+ @system_env = system_env
15
16
  end
16
17
 
17
18
  def deploy(paths:)
@@ -190,12 +191,21 @@ module VmShepherd
190
191
  cpus: input_config.dig('vm', 'cpus'),
191
192
  ram_mb: input_config.dig('vm', 'ram_mb'),
192
193
  vm_password: (input_config.dig('vm', 'vm_password') || 'tempest'),
194
+ public_ssh_key: read_assets_home(input_config.dig('vm', 'public_ssh_key')),
193
195
  }.tap do |result|
194
196
  hostname = input_config.dig('vm', 'custom_hostname')
195
197
  result[:custom_hostname] = hostname unless hostname.nil?
196
198
  end
197
199
  end
198
200
 
201
+ def read_assets_home(path_or_value)
202
+ assets_home = @system_env.to_h.dig('ASSETS_HOME')
203
+ return path_or_value if path_or_value.nil? || assets_home.nil?
204
+
205
+ file_path = File.join(assets_home, path_or_value)
206
+ File.read(file_path)
207
+ end
208
+
199
209
  def vcloud_deploy_options(vm_shepherd_config)
200
210
  VmShepherd::Vcloud::VappConfig.new(
201
211
  name: vm_shepherd_config.dig('vapp', 'ops_manager_name'),
@@ -1,3 +1,3 @@
1
1
  module VmShepherd
2
- VERSION = '3.4.3'.freeze
2
+ VERSION = '3.5.0'.freeze
3
3
  end
@@ -296,6 +296,15 @@ module VmShepherd
296
296
  spec.operation = 'edit'
297
297
  spec.info = RbVmomi::VIM::VAppPropertyInfo.new.tap do |p|
298
298
  p.key = 6 # ditto. see above. it makes me sad, too.
299
+ p.label = 'public_ssh_key'
300
+ p.value = vm_config[:public_ssh_key]
301
+ end
302
+ end
303
+
304
+ vapp_property_specs << RbVmomi::VIM::VAppPropertySpec.new.tap do |spec|
305
+ spec.operation = 'edit'
306
+ spec.info = RbVmomi::VIM::VAppPropertyInfo.new.tap do |p|
307
+ p.key = 7 # ditto. see above. it makes me sad, too.
299
308
  p.label = 'custom_hostname'
300
309
  p.value = vm_config[:custom_hostname]
301
310
  end
@@ -18,6 +18,7 @@ vm_shepherd:
18
18
  netmask: OVA_NETMASK
19
19
  dns: OVA_DNS
20
20
  ntp_servers: OVA_NTP
21
+ public_ssh_key: OVA_SSH_KEY
21
22
  cpus: OVA_CPUS
22
23
  ram_mb: OVA_RAM_MB
23
24
  vm_password: not-tempest
@@ -1,3 +1,5 @@
1
+ #require 'tmpdir'
2
+ #require 'fileutils'
1
3
  require 'vm_shepherd/backport_refinements'
2
4
  using VmShepherd::BackportRefinements
3
5
 
@@ -5,7 +7,8 @@ require 'vm_shepherd/shepherd'
5
7
 
6
8
  module VmShepherd
7
9
  RSpec.describe Shepherd do
8
- subject(:manager) { Shepherd.new(settings: settings) }
10
+ subject(:manager) { Shepherd.new(settings: settings, system_env: system_env) }
11
+ let(:system_env) { {} }
9
12
  let(:first_config) { settings.dig('vm_shepherd', 'vm_configs').first }
10
13
  let(:last_config) { settings.dig('vm_shepherd', 'vm_configs').last }
11
14
  let(:settings) { YAML.load_file(File.join(SPEC_ROOT, 'fixtures', 'shepherd', settings_fixture_name)) }
@@ -151,6 +154,7 @@ module VmShepherd
151
154
  cpus: first_config.dig('vm', 'cpus'),
152
155
  ram_mb: first_config.dig('vm', 'ram_mb'),
153
156
  vm_password: first_config.dig('vm', 'vm_password'),
157
+ public_ssh_key: first_config.dig('vm', 'public_ssh_key'),
154
158
  custom_hostname: first_config.dig('vm', 'custom_hostname')
155
159
  },
156
160
  {
@@ -171,6 +175,7 @@ module VmShepherd
171
175
  dns: last_config.dig('vm', 'dns'),
172
176
  ntp_servers: last_config.dig('vm', 'ntp_servers'),
173
177
  vm_password: 'tempest',
178
+ public_ssh_key: nil,
174
179
  cpus: last_config.dig('vm', 'cpus'),
175
180
  ram_mb: last_config.dig('vm', 'ram_mb'),
176
181
  },
@@ -189,6 +194,93 @@ module VmShepherd
189
194
  it 'fails if improper paths are given' do
190
195
  expect { manager.deploy(paths: ['FIRST_FAKE_PATH']) }.to raise_error(ArgumentError)
191
196
  end
197
+
198
+ context 'when the ASSETS_HOME path is available' do
199
+ let(:first_config) do
200
+ settings.dig('vm_shepherd', 'vm_configs').first.tap do |vm_config|
201
+ vm_config.dig('vm').merge!({ 'public_ssh_key' => 'subdir/pub.key' })
202
+ end
203
+ end
204
+ let(:system_env) { { 'ASSETS_HOME' => assets_home } }
205
+ let(:assets_home) { Dir.mktmpdir }
206
+
207
+ before do
208
+ assets_subdir = File.join(assets_home, 'subdir')
209
+ Dir.mkdir(assets_subdir)
210
+ File.open(File.join(assets_subdir, 'pub.key'), 'w') do |f|
211
+ f.write('public key contents')
212
+ end
213
+ end
214
+
215
+ after do
216
+ FileUtils.rm_rf(assets_home)
217
+ end
218
+
219
+ it 'reads the value from the relative path in ASSETS_HOME' do
220
+ expect(VsphereManager).to receive(:new).with(
221
+ first_config.dig('vcenter_creds', 'ip'),
222
+ first_config.dig('vcenter_creds', 'username'),
223
+ first_config.dig('vcenter_creds', 'password'),
224
+ first_config.dig('vsphere', 'datacenter'),
225
+ instance_of(Logger),
226
+ ).and_return(first_ova_manager)
227
+
228
+ expect(VsphereManager).to receive(:new).with(
229
+ last_config.dig('vcenter_creds', 'ip'),
230
+ last_config.dig('vcenter_creds', 'username'),
231
+ last_config.dig('vcenter_creds', 'password'),
232
+ last_config.dig('vsphere', 'datacenter'),
233
+ instance_of(Logger),
234
+ ).and_return(last_ova_manager)
235
+
236
+ expect(first_ova_manager).to receive(:deploy).with(
237
+ 'FIRST_FAKE_PATH',
238
+ {
239
+ ip: first_config.dig('vm', 'ip'),
240
+ gateway: first_config.dig('vm', 'gateway'),
241
+ netmask: first_config.dig('vm', 'netmask'),
242
+ dns: first_config.dig('vm', 'dns'),
243
+ ntp_servers: first_config.dig('vm', 'ntp_servers'),
244
+ cpus: first_config.dig('vm', 'cpus'),
245
+ ram_mb: first_config.dig('vm', 'ram_mb'),
246
+ vm_password: first_config.dig('vm', 'vm_password'),
247
+ public_ssh_key: 'public key contents',
248
+ custom_hostname: first_config.dig('vm', 'custom_hostname')
249
+ },
250
+ {
251
+ cluster: first_config.dig('vsphere', 'cluster'),
252
+ resource_pool: first_config.dig('vsphere', 'resource_pool'),
253
+ datastore: first_config.dig('vsphere', 'datastore'),
254
+ network: first_config.dig('vsphere', 'network'),
255
+ folder: first_config.dig('vsphere', 'folder'),
256
+ },
257
+ )
258
+
259
+ expect(last_ova_manager).to receive(:deploy).with(
260
+ 'LAST_FAKE_PATH',
261
+ {
262
+ ip: last_config.dig('vm', 'ip'),
263
+ gateway: last_config.dig('vm', 'gateway'),
264
+ netmask: last_config.dig('vm', 'netmask'),
265
+ dns: last_config.dig('vm', 'dns'),
266
+ ntp_servers: last_config.dig('vm', 'ntp_servers'),
267
+ vm_password: 'tempest',
268
+ public_ssh_key: nil,
269
+ cpus: last_config.dig('vm', 'cpus'),
270
+ ram_mb: last_config.dig('vm', 'ram_mb'),
271
+ },
272
+ {
273
+ cluster: last_config.dig('vsphere', 'cluster'),
274
+ resource_pool: last_config.dig('vsphere', 'resource_pool'),
275
+ datastore: last_config.dig('vsphere', 'datastore'),
276
+ network: last_config.dig('vsphere', 'network'),
277
+ folder: last_config.dig('vsphere', 'folder'),
278
+ },
279
+ )
280
+
281
+ manager.deploy(paths: ['FIRST_FAKE_PATH', 'LAST_FAKE_PATH'])
282
+ end
283
+ end
192
284
  end
193
285
 
194
286
  context 'with AWS settings' do
@@ -97,6 +97,27 @@ module VmShepherd
97
97
  subject.deploy(ova_path, vm_config, vsphere_config)
98
98
  end
99
99
  end
100
+
101
+ context 'when the ssh key is set' do
102
+ let(:vm_config) { { ip: '10.0.0.1', public_ssh_key: 'ssh-key-contents' } }
103
+ it 'sets the ssh key' do
104
+ expect(vsphere_manager).to receive(:create_vm_from_template).and_return(vm1)
105
+ allow(subject).to receive(:power_on_vm)
106
+ allow(task).to receive(:wait_for_completion)
107
+
108
+ expect(vm1).to receive(:ReconfigVM_Task) do |options|
109
+ ssh_key_property = options[:spec].vAppConfig.property.find do |prop|
110
+ prop.instance_variable_get(:@props)[:info].instance_variable_get(:@props)[:label] == 'public_ssh_key'
111
+ end
112
+ expect(ssh_key_property).to_not be_nil
113
+ ssh_key_value = ssh_key_property.instance_variable_get(:@props)[:info].instance_variable_get(:@props)[:value]
114
+ expect(ssh_key_value).to eq('ssh-key-contents')
115
+ task
116
+ end
117
+
118
+ subject.deploy(ova_path, vm_config, vsphere_config)
119
+ end
120
+ end
100
121
  end
101
122
 
102
123
  describe 'clean_environment' do
@@ -19,11 +19,11 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_dependency 'aws-sdk-v1'
21
21
  spec.add_dependency 'fog', '1.34.0'
22
- spec.add_dependency 'net-ssh' # because fog uses this but doesn't require it
22
+ spec.add_dependency 'net-ssh', '4.2.0' # because fog uses this but doesn't require it
23
23
 
24
24
  spec.add_dependency 'ruby_vcloud_sdk', '0.7.4'
25
25
 
26
- spec.add_dependency 'rbvmomi'
26
+ spec.add_dependency 'rbvmomi', '1.11.3'
27
27
 
28
28
  spec.add_development_dependency 'bundler'
29
29
  spec.add_development_dependency 'rake'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vm_shepherd
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.3
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ops Manager Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-17 00:00:00.000000000 Z
11
+ date: 2018-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-v1
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: net-ssh
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 4.2.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 4.2.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: ruby_vcloud_sdk
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: rbvmomi
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 1.11.3
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 1.11.3
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement