class RHC::Commands::Server

Public Instance Methods

add(hostname, nickname) click to toggle source
# File lib/rhc/commands/server.rb, line 87
def add(hostname, nickname)
  raise ArgumentError, "The --use and --skip-wizard options cannot be used together." if options.use && options.skip_wizard

  attrs = [:login, :use_authorization_tokens, :insecure, :timeout, :ssl_version, :ssl_client_cert_file, :ssl_ca_file]

  server = server_configs.add(hostname, 
    attrs.inject({:nickname => nickname}){ |h, (k, v)| h[k] = options[k == :login ? :rhlogin : k]; h })

  unless options.skip_wizard
    (wizard_to_server(server.hostname, options.use, attrs.inject({}){ |h, (k, v)| h[k] = server.send(k); h }) ? 0 : 1).tap do |r|
      paragraph { success "Now using '#{server.hostname}'" } if options.use && r == 0
    end
  else
    say "Saving server configuration to #{system_path(server_configs.path)} ... "
    server_configs.save!
    success "done"
    0
  end
end
configure(server) click to toggle source
# File lib/rhc/commands/server.rb, line 174
def configure(server)
  raise ArgumentError, "The --use and --skip-wizard options cannot be used together." if options.use && options.skip_wizard

  server = server_configs.find(server)

  attrs = [:hostname, :nickname, :login, :use_authorization_tokens, :insecure, :timeout, :ssl_version, :ssl_client_cert_file, :ssl_ca_file].inject({}){ |h, (k, v)| v = options[k == :login ? :rhlogin : k]; h[k] = (v.nil? ? server.send(k) : v); h }

  raise RHC::ServerNicknameExistsException.new(options.nickname) if options.nickname && 
    server_configs.nickname_exists?(options.nickname) && 
    server_configs.find(options.nickname).hostname != server.hostname

  server = server_configs.update(server.hostname, attrs)

  unless options.skip_wizard
    wizard_to_server(attrs[:hostname], options.use, attrs.reject{|k, v| k == :hostname || k == :nickname})
  else
    say "Saving server configuration to #{system_path(server_configs.path)} ... "
    server_configs.save!
    success "done"
    0
  end

  paragraph{ say display_server(server) }
  paragraph { success "Now using '#{server.hostname}'" } if options.use
  0
end
list() click to toggle source
# File lib/rhc/commands/server.rb, line 109
def list
  servers = config.has_configs_from_files? ? server_configs.list : []

  servers.sort.each do |server|
    say display_server(server)
  end

  paragraph do 
    case servers.length
    when 0
      warn "You don't have any servers configured. Use 'rhc setup' to configure your OpenShift server."
    when 1
      say "You have 1 server configured. Use 'rhc server add' to add a new server."
    else
      say "You have #{servers.length} servers configured. Use 'rhc server use <hostname|nickname>' to switch between them."
    end
  end
  0
end
remove(server) click to toggle source
# File lib/rhc/commands/server.rb, line 148
def remove(server)
  server = server_configs.find(server)

  say "Removing '#{server.hostname}' ... "

  if server.default?
    raise RHC::ServerInUseException.new("The '#{server.designation}' server is in use. Please switch to another server before removing it.")
  else
    server_configs.remove(server.hostname)
    server_configs.save!
  end

  success "done"
  0
end
show(server) click to toggle source
# File lib/rhc/commands/server.rb, line 204
def show(server)
  server = server_configs.find(server)
  say display_server(server)
  paragraph{ say "Use 'rhc servers' to display all your servers." } if server_configs.list.length > 1
  0
end
status(server=nil) click to toggle source
# File lib/rhc/commands/server.rb, line 43
def status(server=nil)
  options.server = server.hostname if server && server = (server_configs.find(server) rescue nil)

  say "Connected to #{openshift_server}"

  if openshift_online_server?
    #status = decode_json(get("#{openshift_url}/app/status/status.json").body)
    status = rest_client.request(:method => :get, :url => "#{openshift_url}/app/status/status.json", :lazy_auth => true){ |res| decode_json(res.content) }
    open = status['open']

    (success 'All systems running fine' and return 0) if open.blank?

    open.each do |i|
      i = i['issue']
      say color("%-3s %s" % ["##{i['id']}", i['title']], :bold)
      items = i['updates'].map{ |u| [u['description'], date(u['created_at'])] }
      items.unshift ['Opened', date(i['created_at'])]
      table(items, :align => [nil,:right], :join => '  ').each{ |s| say "    #{s}" }
    end
    say "\n"
    warn pluralize(open.length, "open issue")

    open.length #exit with the count of open items
  else
    success "Using API version #{rest_client.api_version_negotiated}"
    0
  end
end
use(server) click to toggle source
# File lib/rhc/commands/server.rb, line 132
def use(server)
  server = server_configs.find(server)

  attrs = [:login, :use_authorization_tokens, :insecure, :timeout, :ssl_version, :ssl_client_cert_file, :ssl_ca_file]

  if wizard_to_server(server.hostname, true, attrs.inject({}){ |h, (k, v)| h[k] = server.send(k); h })
    paragraph { success "Now using '#{server.hostname}'" }
    0
  else
    1
  end
end

Protected Instance Methods

server_configs() click to toggle source
# File lib/rhc/commands/server.rb, line 224
def server_configs
  @servers ||= RHC::Servers.new(config)
end
wizard_to_server(hostname, set_default, args) click to toggle source
# File lib/rhc/commands/server.rb, line 212
def wizard_to_server(hostname, set_default, args)
  options['server'] = hostname
  options['rhlogin'] = args[:login] if args[:login]
  options['use_authorization_tokens'] = args[:use_authorization_tokens] unless args[:use_authorization_tokens].nil?
  options['insecure'] = args[:insecure] unless args[:insecure].nil?
  options['timeout'] = args[:timeout] unless args[:timeout].nil?
  options['ssl_version'] = args[:ssl_version]
  options['ssl_client_cert_file'] = args[:ssl_client_cert_file]
  options['ssl_ca_file'] = args[:ssl_ca_file]
  RHC::ServerWizard.new(config, options, server_configs, set_default).run
end