Class: Comana::ClusterSetting

Inherits:
Object
  • Object
show all
Defined in:
lib/comana/clustersetting.rb

Overview

Series name is composed only of alphabets. Host name is started by the series name and followed by integers. E.g.,

"Fe", "Fe00", "Fe01" are of series "Fe" and not "F"

Defined Under Namespace

Classes: NoEntryError

Constant Summary collapse

DEFAULT_DATA_FILE =
ENV["HOME"] + "/.clustersetting"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ ClusterSetting

Returns a new instance of ClusterSetting.



18
19
20
21
# File 'lib/comana/clustersetting.rb', line 18

def initialize(settings)
  @pbs_server = settings["pbs_server"]
  @groups = settings["groups"]
end

Instance Attribute Details

#groupsObject (readonly)

Returns the value of attribute groups.



11
12
13
# File 'lib/comana/clustersetting.rb', line 11

def groups
  @groups
end

#pbs_serverObject (readonly)

Returns the value of attribute pbs_server.



11
12
13
# File 'lib/comana/clustersetting.rb', line 11

def pbs_server
  @pbs_server
end

Class Method Details

.load_file(data_file = DEFAULT_DATA_FILE) ⇒ Object



23
24
25
26
# File 'lib/comana/clustersetting.rb', line 23

def self.load_file(data_file = DEFAULT_DATA_FILE)
  settings = YAML.load_file(data_file)
  self.new settings
end

Instance Method Details

#belonged_cluster(hostname) ⇒ Object

Return belonged cluster of the host. Raise NoEntryError if not match.

Raises:



30
31
32
33
34
35
36
# File 'lib/comana/clustersetting.rb', line 30

def belonged_cluster(hostname)
  @groups.each do |group, settings|
    next unless settings["members"]
    return group if settings["members"].include? hostname
  end
  raise NoEntryError, "#{hostname} is not in `@groups': #{@groups.inspect}"
end

#clustersObject

Return an array of cluster names.



49
50
51
# File 'lib/comana/clustersetting.rb', line 49

def clusters
  @groups.keys
end

#settings_group(clustername) ⇒ Object

Return settings as a hash for a cluster.



39
40
41
# File 'lib/comana/clustersetting.rb', line 39

def settings_group(clustername)
  @groups[clustername]
end

#settings_host(hostname) ⇒ Object

Return settings as a hash for a host belonged to cluster.



44
45
46
# File 'lib/comana/clustersetting.rb', line 44

def settings_host(hostname)
  settings_group(belonged_cluster(hostname))
end