Module: Settings

Defined in:
lib/settings.rb

Overview

This module allows the user to load settings from file.

Class Method Summary collapse

Class Method Details

.init_flagsetsObject


89
90
91
# File 'lib/settings.rb', line 89

def Settings.init_flagsets()
  $FLAGSETS = {} if $FLAGSETS.nil?
end

.init_hostgroupsetObject


94
95
96
# File 'lib/settings.rb', line 94

def Settings.init_hostgroupset()
  $HOSTGROUPSET = HostGroupSet.new($HOSTSET) if $HOSTGROUPSET.nil?
end

.init_hostsetObject


84
85
86
# File 'lib/settings.rb', line 84

def Settings.init_hostset()
  $HOSTSET = HostSet.new if $HOSTSET.nil?
end

.init_jobmanagerObject


99
100
101
# File 'lib/settings.rb', line 99

def Settings.init_jobmanager()
  $JOBMANAGER = JobManager.new $HOSTGROUPSET
end

.load_callbacks(xml_element) ⇒ Object


104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/settings.rb', line 104

def Settings.load_callbacks(xml_element)
  callbacks = []

  type = case xml_element.attributes["type"]
         when "group_complete"
           :group_complete
         else
           raise ArgumentError,
             "currently only \"group_complete\" allowed for callback type"
         end

  callback_type = xml_element.attributes["callback-type"]

  arguments = {}
  xml_element.elements.each("argument") do |arg|
    arguments[arg.attributes["name"]] = arg.text.chomp
  end

  selector = xml_element.attributes[selector]

  case callback_type
  when "mail"
    CallbackFactory.generate_mail_for_batch_callback type, selector,
      arguments["batch_size"].to_i,  arguments["to"]
  else
    raise ArgumentError, "unknown callback-type #{callback_type}"
  end
end

.load_flags(xml_element) ⇒ Object


70
71
72
73
74
75
# File 'lib/settings.rb', line 70

def Settings.load_flags(xml_element)
  init_flagsets
  flagset = FlagSet.new
  flagset.read_from_file File.expand_path(xml_element.text)
  $FLAGSETS[flagset.name] = flagset
end

.load_hostgroups(xml_element) ⇒ Object


78
79
80
81
# File 'lib/settings.rb', line 78

def Settings.load_hostgroups(xml_element)
  init_hostgroupset
  $HOSTGROUPSET.read_from_file File.expand_path(xml_element.text)
end

.load_hosts(xml_element) ⇒ Object


64
65
66
67
# File 'lib/settings.rb', line 64

def Settings.load_hosts(xml_element)
  init_hostset
  $HOSTSET.read_from_file File.expand_path(xml_element.text)
end

.load_settings(load_ssh_settings = true, filename = "settings.xml") ⇒ Object

Reads the settings from a file. For the file format see the format documentation.

Parameters:

  • filename (String) (defaults to: "settings.xml")

    The name of the file to be read from.

See Also:

  • Format documentation}.

16
17
18
19
20
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
# File 'lib/settings.rb', line 16

def Settings.load_settings(load_ssh_settings=true, filename = "settings.xml")
  doc = REXML::Document.new open(filename)
  $SLURM_POLL_DELAY = doc.elements["settings/slurm-poll-delay"].text.to_i
  
  if load_ssh_settings then
    ssh_agent_element = doc.elements["settings/ssh-agent"]
    if !ssh_agent_element.nil? then
      load_ssh_agent_settings ssh_agent_element
    end
  end

  doc.elements.each("settings/hostset-file") do |elem|
    load_hosts elem
  end
  doc.elements.each("settings/flagset-file") do |elem|
    load_flags elem
  end
  doc.elements.each("settings/hostgroupset-file") do |elem|
    load_hostgroups elem
  end

  init_jobmanager

  doc.elements.each("settings/callbacks/callback") do |elem|
    load_callbacks elem
  end

  doc.elements.each("settings/pre-exec") do |elem|
    run_pre_exec elem
  end
end

.load_ssh_agent_settings(xml_element) ⇒ Object


49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/settings.rb', line 49

def Settings.load_ssh_agent_settings(xml_element)
  SSHUtil.start_agent

  askpass = xml_element.attributes["askpass"]

  xml_element.elements.each("add-key") do |elem|
    if askpass.nil? then
      SSHUtil.add_key(elem.text)
    else
      SSHUtil.add_key(elem.text, askpass)
    end
  end
end

.run_pre_exec(xml_element) ⇒ Object


134
135
136
# File 'lib/settings.rb', line 134

def Settings.run_pre_exec(xml_element)
  eval xml_element.text
end