class RHC::Server

Attributes

default[RW]
hostname[RW]
insecure[RW]
login[RW]
nickname[RW]
persisted[RW]
ssl_ca_file[RW]
ssl_client_cert_file[RW]
ssl_client_key_file[RW]
ssl_version[RW]
timeout[RW]
use_authorization_tokens[RW]

Public Class Methods

from_yaml_hash(hash) click to toggle source
# File lib/rhc/servers.rb, line 15
def self.from_yaml_hash(hash)
  hash.symbolize_keys!
  Server.new(hash.delete(:hostname), hash.merge(:persisted => true))
end
new(hostname, args={}) click to toggle source
# File lib/rhc/servers.rb, line 20
def initialize(hostname, args={})
  @hostname = RHC::Servers.to_host(hostname)
  @nickname = args[:nickname]
  @login = args[:login]
  @use_authorization_tokens = RHC::Helpers.to_boolean(args[:use_authorization_tokens], true)
  @insecure = RHC::Helpers.to_boolean(args[:insecure], true)
  @timeout = Integer(args[:timeout]) if args[:timeout].present?
  @ssl_version = RHC::Helpers.parse_ssl_version(args[:ssl_version])
  @ssl_client_cert_file = args[:ssl_client_cert_file]
  @ssl_client_key_file = args[:ssl_client_key_file]
  @ssl_ca_file = args[:ssl_ca_file]
  @default = args[:default]
  @persisted = args[:persisted]
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/rhc/servers.rb, line 68
def <=>(other)
  designation <=> other.designation
end
default?() click to toggle source
# File lib/rhc/servers.rb, line 35
def default?
  !!@default
end
designation() click to toggle source
# File lib/rhc/servers.rb, line 43
def designation
  @nickname || @hostname
end
persisted?() click to toggle source
# File lib/rhc/servers.rb, line 39
def persisted?
  !!@persisted
end
to_config() click to toggle source
# File lib/rhc/servers.rb, line 55
def to_config
  RHC::Vendor::ParseConfig.new.tap do |config| 
    h = to_yaml_hash
    h['default_rhlogin'] = h.delete('login')
    h['libra_server'] = h.delete('hostname')
    h.each{|k, v| config.add(k, v)}
  end
end
to_s() click to toggle source
# File lib/rhc/servers.rb, line 64
def to_s
  @nickname ? "#{@nickname} (#{@hostname})" : @hostname
end
to_yaml_hash() click to toggle source
# File lib/rhc/servers.rb, line 47
def to_yaml_hash
  {}.tap do |h| 
    instance_variables.each do |k| 
      h[k.to_s.delete('@')] = instance_variable_get(k)
    end
  end.reject{|k, v| v.nil? || k == 'default' || k == 'persisted'}.inject({}){|h, (k, v)| h[k] = v.is_a?(String) || v.is_a?(Symbol) ? v.to_s : v; h }
end