Sha256: d5f67576d06394add1d798e79a4b1b09cb28e0b9e837309c045009602cc81121

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

require "ohai"

module Baton
  class Server

    attr_accessor :environment, :fqdn, :app_names

    # Public: Initialize a Server. ALso, configures the server by reading Baton's configuration
    # file.
    def initialize
      @ohai = Ohai::System.new
      @ohai.all_plugins
      configure
    end

    # Public: Method that configures the server. It sets the fqdn, environment and a list
    # of app names specified by the ohai config file.
    #
    # Returns nothing.
    def configure
      @environment = facts.fetch("chef_environment"){"development"}.downcase
      @fqdn        = facts.fetch("fqdn"){""}
      @app_names   = facts.fetch("trebuchet"){[]}
    end

    # Public: Method that reads facts from the file specified by facts_file.
    #
    # Examples
    #
    #   facts
    #   # => {"fqdn" => "server.dsci.it", "chef_environment" => "production", "trebuchet" => []}
    #
    # Returns a hash with server information.
    def facts
      @facts ||= @ohai.data
    end

    # Public: Method that provides an hash of attributes for a server.
    #
    # Examples
    #
    #   attributes
    #   # => {environment: "production", fqdn: "server.dsci.it", app_names: ["app1","app2"]}
    #
    # Returns Output depends on the implementation.
    def attributes
      {environment: environment, fqdn: fqdn, app_names: app_names}
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
baton-0.4.2 lib/baton/server.rb
baton-0.4.1 lib/baton/server.rb