Sha256: f7d16a8af564d40af672fe880e1e9f0e235189914fd7027fb82aa1f3215b61d1

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

#! /usr/bin/env ruby
# coding: utf-8

require "yaml"

# 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"
class Comana::ClusterSetting
  attr_reader :groups, :pbs_server

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

  class NoEntryError < Exception; end

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

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

  #Return belonged cluster of the host.
  #Raise NoEntryError if not match.
  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

  #Return settings as a hash for a cluster.
  def settings_group(clustername)
    @groups[clustername]
  end

  #Return settings as a hash for a host belonged to cluster.
  def settings_host(hostname)
    settings_group(belonged_cluster(hostname))
  end

  #Return an array of cluster names.
  def clusters
    @groups.keys
  end


end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comana-0.0.10 lib/comana/clustersetting.rb