Class: Opsmgr::BoshCommandRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/opsmgr/bosh_command_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(bosh_command:, logger:) ⇒ BoshCommandRunner

Returns a new instance of BoshCommandRunner.



3
4
5
6
# File 'lib/opsmgr/bosh_command_runner.rb', line 3

def initialize(bosh_command:, logger:)
  @bosh_command = bosh_command
  @logger = logger
end

Instance Method Details

#run(command) ⇒ Object



8
9
10
11
12
13
# File 'lib/opsmgr/bosh_command_runner.rb', line 8

def run(command)
  system_or_fail(
    "#{bosh_command_prefix} #{command}",
    "bosh #{command} failed"
  )
end

#run_and_capture_output(command) ⇒ Object



15
16
17
18
19
20
# File 'lib/opsmgr/bosh_command_runner.rb', line 15

def run_and_capture_output(command)
  capture_output_or_fail(
    "#{bosh_command_prefix} #{command}",
    "bosh #{command} failed"
  )
end

#run_with_deployment(command, deployment) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/opsmgr/bosh_command_runner.rb', line 22

def run_with_deployment(command, deployment)
  bosh_deployment = bosh_deployments[/#{deployment}-[0-9a-f]{8,}/]
  fail 'Deployment not found' unless bosh_deployment

  deployment_file = "#{ENV.fetch('TMPDIR', '/tmp')}/#{deployment}.yml"

  begin
    run(
      "-n download manifest #{bosh_deployment} #{deployment_file}"
    )
  rescue RuntimeError
    raise 'bosh download manifest failed'
  end

  run("-d #{deployment_file} #{command}")
end