Class: Morpheus::Cli::RecentActivityCommand
- Inherits:
-
Object
- Object
- Morpheus::Cli::RecentActivityCommand
- Includes:
- CliCommand
- Defined in:
- lib/morpheus/cli/recent_activity_command.rb
Instance Method Summary collapse
- #connect(opts) ⇒ Object
- #handle(args) ⇒ Object
-
#initialize ⇒ RecentActivityCommand
constructor
A new instance of RecentActivityCommand.
- #list(args) ⇒ Object
- #usage ⇒ Object
Methods included from CliCommand
#build_common_options, included
Constructor Details
#initialize ⇒ RecentActivityCommand
Returns a new instance of RecentActivityCommand.
11 12 13 14 |
# File 'lib/morpheus/cli/recent_activity_command.rb', line 11 def initialize() @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance @active_groups = ::Morpheus::Cli::Groups.load_group_file end |
Instance Method Details
#connect(opts) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/morpheus/cli/recent_activity_command.rb', line 16 def connect(opts) @access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).load_saved_credentials() if @access_token.empty? print_red_alert "Invalid Credentials. Unable to acquire access token. Please verify your credentials and try again." exit 1 end @api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url) @dashboard_interface = @api_client.dashboard end |
#handle(args) ⇒ Object
30 31 32 |
# File 'lib/morpheus/cli/recent_activity_command.rb', line 30 def handle(args) list(args) end |
#list(args) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/morpheus/cli/recent_activity_command.rb', line 34 def list(args) = {} optparse = OptionParser.new do|opts| opts. = usage opts.on(nil,'--start', "Start timestamp. Default is 30 days ago.") do |val| [:start_ts] = val end opts.on(nil,'--end', "End timestamp. Default is now.") do |val| [:end_ts] = val end (opts, , [:list, :json]) end optparse.parse(args) connect() begin params = {} [:phrase, :offset, :max, :sort, :direction, :start, :end].each do |k| params[k] = [k] unless [k].nil? end json_response = @dashboard_interface.recent_activity(params) if [:json] print JSON.pretty_generate(json_response) print "\n" else # todo: impersonate command and show that info here print "\n" ,cyan, bold, "Dashboard\n","==================", reset, "\n\n" print cyan print "\n" puts "Coming soon.... see --json" print "\n" print reset,"\n" end rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |
#usage ⇒ Object
26 27 28 |
# File 'lib/morpheus/cli/recent_activity_command.rb', line 26 def usage "Usage: morpheus recent-activity" end |