Class: Bosh::Director::Jobs::Ssh

Inherits:
BaseJob show all
Defined in:
lib/bosh/director/jobs/ssh.rb

Defined Under Namespace

Classes: Target

Constant Summary collapse

DEFAULT_SSH_DATA_LIFETIME =
300
SSH_TAG =
"ssh"

Instance Attribute Summary

Attributes inherited from BaseJob

#task_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseJob

#begin_stage, #dns_manager, #event_manager, #logger, perform, #result_file, schedule_message, #single_step_stage, #task_cancelled?, #task_checkpoint, #track_and_log, #username

Constructor Details

#initialize(deployment_id, options = {}) ⇒ Ssh

Returns a new instance of Ssh.



13
14
15
16
17
18
19
20
# File 'lib/bosh/director/jobs/ssh.rb', line 13

def initialize(deployment_id, options = {})
  @deployment_id = deployment_id
  @target_payload = options["target"]
  @command = options["command"]
  @params = options["params"]
  @blobstore = options.fetch(:blobstore) { App.instance.blobstores.blobstore }
  @instance_manager = Api::InstanceManager.new
end

Class Method Details

.job_typeObject



9
10
11
# File 'lib/bosh/director/jobs/ssh.rb', line 9

def self.job_type
  :ssh
end

Instance Method Details

#performObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/bosh/director/jobs/ssh.rb', line 22

def perform
  target = Target.new(@target_payload)

  filter = {}
  filter[:job] = target.job if target.job
  filter.merge!(target.id_filter)

  deployment = Models::Deployment[@deployment_id]
  instances = @instance_manager.filter_by(deployment, filter)

  ssh_info = instances.map do |instance|
    begin
      agent = @instance_manager.agent_client_for(instance)

      logger.info("ssh #{@command} '#{instance.job}/#{instance.uuid}'")
      result = agent.ssh(@command, @params)
      if target.ids_provided?
        result["id"] = instance.uuid
      else
        result["index"] = instance.index
      end

      if Config.default_ssh_options
        result["gateway_host"] = Config.default_ssh_options["gateway_host"]
        result["gateway_user"] = Config.default_ssh_options["gateway_user"]
      end

      result
    rescue Exception => e
      raise e
    ensure
      add_event(deployment.name, instance.name, e)
    end
  end

  result_file.write(JSON.generate(ssh_info))
  result_file.write("\n")

  # task result
  nil
end