Class: SlurmHost

Inherits:
Host
  • Object
show all
Defined in:
lib/slurm_host.rb

Overview

This class represents a Slurm-controllable host.

Constant Summary

Constants included from LoggedClass

LoggedClass::LoggedClasses

Instance Attribute Summary collapse

Attributes inherited from Host

#hostname, #port, #user

Instance Method Summary collapse

Methods inherited from Host

#copy_file, #copy_file_from_host, #get_dead_slurm_hostnames, #get_file_contents, #write_file

Methods included from LoggedClass

#debug, #error, #fatal, generate_outputter_config, included, #info, #warn

Constructor Details

#initialize(user, hostname, slurm_host, partition, port = 22) ⇒ SlurmHost

Create a new SlurmHost. Optionally it can also be used as a SSH host.

Parameters:

  • user (String)

    User to be used for authentication.

  • hostname (String)

    Hostname of the node.

  • slurm_host (Host)

    Host object of the Slurm control host.

  • port (Fixnum) (defaults to: 22)

    Port that the SSH server listens to on this node. This is only useful if you intend to use this a ssh-controllable host too. If you want to dispatch commands via SSH use the Host#ssh_run and Host#ssh_run_with_streams.


14
15
16
17
18
# File 'lib/slurm_host.rb', line 14

def initialize(user, hostname, slurm_host, partition, port = 22)
  super(user, hostname, port)
  @slurm_host = slurm_host
  @partition = partition
end

Instance Attribute Details

#slurm_hostObject (readonly)

Returns the value of attribute slurm_host


7
8
9
# File 'lib/slurm_host.rb', line 7

def slurm_host
  @slurm_host
end

Instance Method Details

#run(command, input = "") ⇒ Object Also known as: slurm_run

Runs a command with some optional input.

Parameters:

  • command (String)

    The command to run.

  • input (String) (defaults to: "")

    Some optional input to the process.

Raises:

  • (RemoteFailure)

    if the SSH process returns with a non-zero return value. This could indicate an non-zero return value of the executed command or some connection issue.


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/slurm_host.rb', line 43

def run(command, input="")
  command_with_input = "echo #{Shellwords.escape(input)} | (#{command})"
  handles = slurm_run_with_streams command_with_input

  output = handles[:out].read
  id = output.scan(/Submitted batch job (\d+)/)[0][0]

  wait_for_job id

  get_output id
end

#run_with_streams(command) ⇒ Object Also known as: slurm_run_with_streams

Deprecated.

This command is useless with SlurmHosts, since they don't have input or output streams.


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

def run_with_streams(command)
  info "running #{command} on #{hostname} via Slurm"

  # build a script
  script = ""
  script << "#!/bin/bash\n"
  script << "#SBATCH -w #{@hostname}\n"
  script << command + ?\n

  # run it!
  output = @slurm_host.ssh_run "sbatch -p #{@partition}", script

  { :thread => nil,
    :out => StringIO.new(output),
    :err => StringIO.new(""),
    :in => nil }
end