opsmgr 0.27.0 → 0.28.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: 92779c8cfe52a2eb604969894523bda1b3a6d8f4
4
- data.tar.gz: c54dde7aaf031aad52268fc29cc582d04f9dfe1e
3
+ metadata.gz: 8e4c3ef7cacf13a2ef564b5d3311f2c884ccc19c
4
+ data.tar.gz: 11a3a3f6e645425cc1d6cb1cde728bf1a04b0e83
5
5
  SHA512:
6
- metadata.gz: 0ddbbeda6b4db32e31e8f04e2efe4ba99de33718234b8768e514fe2177c81a3f69a1f53157f36ccb8f08ab3ce9168764c67f26b57e4ba343f6e56b4d0cd4fca0
7
- data.tar.gz: 76585c4007685c8396d123c6ac5a6dcf2e60733b05600dbf50335042a71983f2bae8bf06be147f4952a26640dfd6a83e22f0730a5295105b4d882a38101f8608
6
+ metadata.gz: 355a82586a8608b80bfaddabe496edb63c7d3536a077f563ceac99f9f4a31a6976d3964515eaee701c2202b3bf0858394a1ae9774dbc92033d3aa51ded20ca30
7
+ data.tar.gz: 6d6d1cc2c0d3cebd5dc5d4ec77338f691ca10de8211ca43bf73141b98994346c815956eb1079ac63018e31a2aedfd4de468e7ffb2892e099d511b821565e6c5a
@@ -0,0 +1,57 @@
1
+ module Opsmgr
2
+ class BoshCommandRunner
3
+ def initialize(iaas_gateway:, bosh_command:, logger:)
4
+ @iaas_gateway = iaas_gateway
5
+ @bosh_command = bosh_command
6
+ @logger = logger
7
+ end
8
+
9
+ def run(command)
10
+ iaas_gateway.gateway do
11
+ system_or_fail(
12
+ "#{bosh_command_prefix} #{command}",
13
+ "bosh #{command} failed"
14
+ )
15
+ end
16
+ end
17
+
18
+ def run_and_capture_output(command)
19
+ iaas_gateway.gateway do
20
+ capture_output_or_fail(
21
+ "#{bosh_command_prefix} #{command}",
22
+ "bosh #{command} failed"
23
+ )
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def system_or_fail(command, failure_message)
30
+ logger.info("Running #{command}")
31
+ Bundler.clean_system(command) || fail(failure_message)
32
+ end
33
+
34
+ def capture_output_or_fail(command, failure_message)
35
+ logger.info("Running #{command}")
36
+ Bundler.with_clean_env do
37
+ output, status = Open3.capture2(command)
38
+ fail(failure_message) unless status.success?
39
+ output
40
+ end
41
+ end
42
+
43
+ def bosh_command_prefix
44
+ @bosh_command_prefix ||= bosh_command.command
45
+ end
46
+
47
+ attr_reader :iaas_gateway, :bosh_command, :logger
48
+ end
49
+ end
50
+ # Copyright (c) 2014-2015 Pivotal Software, Inc.
51
+ # All rights reserved.
52
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
53
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
54
+ # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
55
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
56
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
57
+ # USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -173,7 +173,7 @@ module Opsmgr
173
173
  'ubuntu',
174
174
  password: 'tempest'
175
175
  ).open(director_ip, 25_555, 25_555) do |_|
176
- logger.info("Opened tunnel to MicroBOSH at #{director_ip}")
176
+ logger.info("Opened tunnel to Director at #{director_ip}")
177
177
  block.call
178
178
  end
179
179
  end
@@ -187,7 +187,7 @@ module Opsmgr
187
187
  'ubuntu',
188
188
  key_data: [ssh_key]
189
189
  ).open(director_ip, 25_555, 25_555) do |_|
190
- logger.info("Opened tunnel to MicroBOSH at #{director_ip}")
190
+ logger.info("Opened tunnel to Director at #{director_ip}")
191
191
  block.call
192
192
  end
193
193
  end
@@ -1,4 +1,4 @@
1
- require 'opsmgr/environments'
1
+ require 'opsmgr/bosh_command_runner'
2
2
  require 'open3'
3
3
 
4
4
  module Opsmgr
@@ -6,63 +6,54 @@ module Opsmgr
6
6
  def initialize(iaas_gateway:, bosh_command:, environment_name:, logger:, product_name:, errand_name:, download_logs:)
7
7
  @iaas_gateway = iaas_gateway
8
8
  @bosh_command = bosh_command
9
- @environment = Opsmgr::Environments.for(environment_name)
9
+ @environment_name = environment_name
10
10
  @logger = logger
11
11
  @product_name = product_name
12
12
  @errand_name = errand_name
13
13
  @download_logs = download_logs ? "--download-logs" : ""
14
+
15
+ @bosh_command_runner = Opsmgr::BoshCommandRunner.new(
16
+ iaas_gateway: @iaas_gateway,
17
+ bosh_command: @bosh_command,
18
+ logger: @logger
19
+ )
14
20
  end
15
21
 
16
22
  def run_errand
17
- iaas_gateway.gateway do
18
- set_bosh_deployment
19
-
20
- system_or_fail(
21
- "#{bosh_command_prefix} run errand #{@errand_name} #{@download_logs}",
22
- "Errand #{@errand_name} failed"
23
- )
23
+ deployments_output = begin
24
+ @bosh_command_runner.run_and_capture_output('deployments')
25
+ rescue RuntimeError
26
+ raise 'bosh deployments failed'
24
27
  end
25
- end
26
-
27
- private
28
28
 
29
- def set_bosh_deployment
30
- system_or_fail(bosh_command.target, 'bosh target failed')
29
+ /#{@product_name}-[0-9a-f]{8,}/.match(deployments_output)
31
30
 
32
- bosh_deployment = bosh_deployment_name(bosh_command_prefix)
31
+ bosh_deployment = $&
33
32
 
34
- deployment_file = "#{ENV.fetch('TMPDIR', '/tmp')}/#{environment.settings.name}.yml"
33
+ fail 'Deployment not found' if bosh_deployment.nil?
35
34
 
36
- system_or_fail(
37
- "#{bosh_command_prefix} -n download manifest #{bosh_deployment} #{deployment_file}",
38
- 'bosh download manifest failed'
39
- )
40
- system_or_fail(
41
- "#{bosh_command_prefix} deployment #{deployment_file}",
42
- 'bosh deployment failed'
43
- )
44
- end
35
+ deployment_file = "#{ENV.fetch('TMPDIR', '/tmp')}/#{environment_name}.yml"
45
36
 
46
- def system_or_fail(command, failure_message)
47
- logger.info("Running #{command}")
48
- Bundler.clean_system(command) || fail(failure_message)
49
- end
37
+ begin
38
+ @bosh_command_runner.run(
39
+ "-n download manifest #{bosh_deployment} #{deployment_file}"
40
+ )
41
+ rescue RuntimeError
42
+ raise 'bosh download manifest failed'
43
+ end
50
44
 
51
- def bosh_deployment_name(command)
52
- @bosh_deployment_name ||= begin
53
- Bundler.with_clean_env do
54
- bosh_deployment, status = Open3.capture2("#{command} deployments | grep -Eoh '#{@product_name}-[0-9a-f]{8,}'")
55
- fail('bosh deployments failed') unless status.success?
56
- bosh_deployment.chomp
57
- end
45
+ begin
46
+ @bosh_command_runner.run(
47
+ "-d #{deployment_file} run errand #{@errand_name} #{@download_logs}"
48
+ )
49
+ rescue RuntimeError
50
+ raise "Errand #{@errand_name} failed"
58
51
  end
59
52
  end
60
53
 
61
- def bosh_command_prefix
62
- @bosh_command_prefix ||= bosh_command.command
63
- end
54
+ private
64
55
 
65
- attr_reader :iaas_gateway, :bosh_command, :environment, :logger, :product_name, :errand_name, :download_logs
56
+ attr_reader :bosh_command, :environment_name, :logger, :product_name, :errand_name, :download_logs
66
57
  end
67
58
  end
68
59
  # Copyright (c) 2014-2015 Pivotal Software, Inc.
@@ -59,6 +59,29 @@ namespace :opsmgr do
59
59
  end
60
60
  system('ls *bosh*.tgz > stemcell_reference.txt')
61
61
  end
62
+
63
+ desc 'run a bosh command'
64
+ task :run_command, [:environment_name, :om_version, :command] do |_, args|
65
+ require 'opsmgr/cmd/bosh_command'
66
+ require 'opsmgr/log'
67
+ require 'opsmgr/bosh_command_runner'
68
+
69
+ logger = Opsmgr.logger_for('Rake')
70
+ bosh_command = Opsmgr::Cmd::BoshCommand.new(
71
+ env_name: args.environment_name,
72
+ om_version: args.om_version
73
+ )
74
+ iaas_gateway = Opsmgr::Cmd::IaasGateway.new(
75
+ bosh_command: bosh_command,
76
+ environment_name: args.environment_name,
77
+ logger: logger
78
+ )
79
+ Opsmgr::BoshCommandRunner.new(
80
+ iaas_gateway: iaas_gateway,
81
+ bosh_command: bosh_command,
82
+ logger: logger
83
+ ).run(args.command)
84
+ end
62
85
  end
63
86
  # Copyright (c) 2014-2015 Pivotal Software, Inc.
64
87
  # All rights reserved.
@@ -1,5 +1,5 @@
1
1
  module Opsmgr
2
- VERSION = '0.27.0'
2
+ VERSION = '0.28.0'
3
3
  end
4
4
  # Copyright (c) 2014-2015 Pivotal Software, Inc.
5
5
  # All rights reserved.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opsmgr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.0
4
+ version: 0.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Release Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-22 00:00:00.000000000 Z
11
+ date: 2015-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -291,6 +291,7 @@ files:
291
291
  - lib/opsmgr/api/http_client.rb
292
292
  - lib/opsmgr/api/results.rb
293
293
  - lib/opsmgr/api/version20/endpoints.rb
294
+ - lib/opsmgr/bosh_command_runner.rb
294
295
  - lib/opsmgr/cmd/bosh_command.rb
295
296
  - lib/opsmgr/cmd/ops_manager.rb
296
297
  - lib/opsmgr/environments.rb