Class: OodCore::Job::Adapters::LinuxSystemd::Launcher Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ood_core/job/adapters/systemd/launcher.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Object used for simplified communication SSH hosts

API:

  • private

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(debug: false, site_timeout: nil, ssh_hosts:, strict_host_checking: false, submit_host:, ssh_keyfile: "", **_) ⇒ Launcher

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Launcher.

Parameters:

  • (defaults to: false)

    Whether the adapter should be used in debug mode

  • (defaults to: nil)

    A period after which the job should be killed or nil

  • List of hosts to check when scanning for running jobs

  • (defaults to: false)

    Allow SSH to perform strict host checking

  • The SSH-able host

API:

  • private



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 23

def initialize(
  debug: false,
  site_timeout: nil,
  ssh_hosts:,
  strict_host_checking: false,
  submit_host:,
  ssh_keyfile: "",
  **_
)
  @debug = !! debug
  @site_timeout = site_timeout.to_i
  @session_name_label = 'ondemand'
  @ssh_hosts = ssh_hosts
  @strict_host_checking = strict_host_checking
  @submit_host = submit_host
  @username = Etc.getlogin
  @ssh_keyfile = ssh_keyfile
end

Instance Attribute Details

#debugObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



12
13
14
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 12

def debug
  @debug
end

#session_name_labelObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



12
13
14
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 12

def session_name_label
  @session_name_label
end

#site_timeoutObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



12
13
14
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 12

def site_timeout
  @site_timeout
end

#ssh_hostsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



12
13
14
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 12

def ssh_hosts
  @ssh_hosts
end

#ssh_keyfileObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



12
13
14
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 12

def ssh_keyfile
  @ssh_keyfile
end

#strict_host_checkingObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



12
13
14
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 12

def strict_host_checking
  @strict_host_checking
end

#usernameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



12
13
14
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 12

def username
  @username
end

Instance Method Details

#list_remote_sessions(host: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



67
68
69
70
71
72
73
74
75
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 67

def list_remote_sessions(host: nil)
  host_list = (host) ? [host] : ssh_hosts

  host_list.map {
    |hostname| list_remote_systemd_session(hostname)
  }.flatten.sort_by {
    |hsh| hsh[:session_name]
  }
end

#start_remote_session(script) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • The hostname to submit the work to

  • The script object defining the work

API:

  • private



44
45
46
47
48
49
50
51
52
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 44

def start_remote_session(script)
  cmd = ssh_cmd(submit_host(script), ['/usr/bin/env', 'bash'])

  session_name = unique_session_name
  output = call(*cmd, stdin: wrapped_script(script, session_name))
  hostname = parse_hostname(output)

  "#{session_name}@#{hostname}"
end

#stop_remote_session(session_name, hostname) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 54

def stop_remote_session(session_name, hostname)
  cmd = ssh_cmd(hostname, ['/usr/bin/env', 'bash'])

  kill_cmd = "  # stop the session by name\n  systemctl --user stop \#{session_name}.service\n  SCRIPT\n\n  call(*cmd, stdin: kill_cmd)\nrescue Error => e\n  interpret_and_raise(e)\nend\n"

#submit_host(script = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



77
78
79
80
81
82
83
# File 'lib/ood_core/job/adapters/systemd/launcher.rb', line 77

def submit_host(script = nil)
  if script && script.native && script.native['submit_host_override']
    script.native['submit_host_override']
  else
    @submit_host
  end
end