Class: Wakame::Cli::Subcommand::AgentStatus

Inherits:
Object
  • Object
show all
Includes:
Wakame::Cli::Subcommand
Defined in:
lib/wakame/runner/administrator_command.rb

Constant Summary collapse

STATUS_TMPL =
<<__E__
Agent :<%= agent["agent_id"]%> load=<%= agent["attr"]["uptime"]%>, <%= (Time.now - Time.parse(agent["last_ping_at"])).to_i%> sec(s), placement=<%= agent["attr"]["availability_zone"]%><%= agent["root_path"] %> (<%= trans_svc_status(agent["status"]) %>)
  Instance ID : <%= agent["attr"]["instance_id"]%>
  AMI ID : <%= agent["attr"]["ami_id"]%>
  Public DNS Name : <%= agent["attr"]["public_hostname"]%>
  Private DNS Name : <%= agent["attr"]["local_hostname"]%>
  Instance Type : <%= agent["attr"]["instance_type"]%>
  Availability Zone : <%= agent["attr"]["availability_zone"]%>

<%- if !agent["services"].nil? && agent["services"].size > 0 -%>
Services (<%= agent["services"].size%>):
  <%- agent["services"].each {|id| -%>
      <%= service_cluster["instances"][id]["instance_id"]%> : <%= service_cluster["instances"][id]["property"]%> (<%= trans_svc_status(service_cluster["instances"][id]["status"])%>)
  <%- } -%>
<%- end -%>
__E__
SVC_STATUS_MSG =
{
  Wakame::Service::STATUS_OFFLINE=>'Offline',
  Wakame::Service::STATUS_ONLINE=>'ONLINE',
  Wakame::Service::STATUS_UNKNOWN=>'Unknown',
  Wakame::Service::STATUS_FAIL=>'Fail',
  Wakame::Service::STATUS_STARTING=>'Starting...',
  Wakame::Service::STATUS_STOPPING=>'Stopping...',
  Wakame::Service::STATUS_RELOADING=>'Reloading...',
  Wakame::Service::STATUS_MIGRATING=>'Migrating...',
}

Instance Method Summary collapse

Methods included from Wakame::Cli::Subcommand

#create_parser, included

Instance Method Details

#parse(args) ⇒ Object



773
774
775
776
777
778
779
780
781
782
# File 'lib/wakame/runner/administrator_command.rb', line 773

def parse(args)
  @params = {}
  blk = Proc.new 
  cmd = create_parser(args) {|opts|
    opts.banner = "Usage: AgentStatus [options] \"Agent ID\""
    opts.separator ""
    opts.separator "options:"
  }
  @params[:agent_id] = args.shift || abort("[ERROR]: Agent ID was not given")
end


788
789
790
791
792
793
# File 'lib/wakame/runner/administrator_command.rb', line 788

def print_result(res)
  require 'time'
  agent = @res[1]["data"]["agent_status"]
  service_cluster = res[1]["data"]["service_cluster"]
  puts ERB.new(STATUS_TMPL, nil, '-').result(binding)
end

#run(requester) ⇒ Object



784
785
786
# File 'lib/wakame/runner/administrator_command.rb', line 784

def run(requester)
  @res = requester.request(@params)
end