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_log, #logger, perform, #result_file, schedule_message, #single_step_stage, #task_cancelled?, #task_checkpoint, #track_and_log

Constructor Details

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

Returns a new instance of Ssh.



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

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



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

def self.job_type
  :ssh
end

Instance Method Details

#performObject



21
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
# File 'lib/bosh/director/jobs/ssh.rb', line 21

def perform
  target = Target.new(@target_payload)

  filter = { deployment_id: @deployment_id }
  filter[:job] = target.job if target.job

  filter.merge!(target.id_filter)

  instances = @instance_manager.filter_by(filter)

  ssh_info = instances.map do |instance|
    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
  end

  result_file.write(Yajl::Encoder.encode(ssh_info))
  result_file.write("\n")

  # task result
  nil
end