Class: Morpheus::Cli::Hub

Inherits:
Object
  • Object
show all
Includes:
CliCommand
Defined in:
lib/morpheus/cli/commands/hub.rb

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from CliCommand

#add_query_parameter, #apply_options, #build_common_options, #build_get_options, #build_list_options, #build_option_type_options, #build_standard_add_many_options, #build_standard_add_options, #build_standard_api_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #confirm, #confirm!, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #execute_api, #execute_api_payload, #execute_api_request, #find_all, #find_all_json, #find_by_id, #find_by_name, #find_by_name_or_id, #find_record, #find_record_json, #full_command_usage, #get_interface, #get_list_key, #get_object_key, #get_subcommand_description, #handle_each_payload, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_array, #parse_bytes_param, #parse_get_options!, #parse_id_list, #parse_labels, #parse_list_options, #parse_list_options!, #parse_list_subtitles, #parse_options, #parse_parameter_as_resource_id!, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands

Instance Method Details

#checkin(args) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/morpheus/cli/commands/hub.rb', line 85

def checkin(args)
  options = {}
  params = {}
  payload = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage()
    opts.on( nil, '--asynchronous', "Execute the checkin asynchronously" ) do
      params[:async] = true
    end
    build_standard_post_options(opts, options)
    opts.footer = <<-EOT
Checkin with the hub.
This sends the current appliance usage data to the hub and
it is only done if the appliance is registered with the hub
and the appliance license has Stats Reporting enabled.
EOT
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, count:0)
  connect(options)
  payload = parse_payload(options)
  # execute api request
  @hub_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @hub_interface.dry.checkin(payload, params)
    return
  end
  json_response = @hub_interface.checkin(payload, params)
  render_response(json_response, options) do
    msg = json_response["msg"] || "Hub checkin complete"
    print_green_success msg
  end
end

#connect(opts) ⇒ Object



13
14
15
16
# File 'lib/morpheus/cli/commands/hub.rb', line 13

def connect(opts)
  @api_client = establish_remote_appliance_connection(opts)   
  @hub_interface = @api_client.hub
end

#get(args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/morpheus/cli/commands/hub.rb', line 22

def get(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage()
    build_standard_get_options(opts, options)
    opts.footer = "View hub configuration."
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, count:0)
  connect(options)
  params.merge!(parse_query_options(options))
  # execute api request
  @hub_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @hub_interface.dry.get(params)
    return
  end
  json_response = @hub_interface.get(params)
  # render response
  render_response(json_response, options) do
    print_h1 "Morpheus Hub Config", [], options
    print_description_list({
      "Hub URL" => lambda {|it| it['hub']['url'] },
      "Appliance ID" => lambda {|it| it['hub']['applianceUniqueId'] },
      "Registered" => lambda {|it| format_boolean(it['hub']['registered']) },
      "Stats Reporting" => lambda {|it| format_boolean(it['hub']['reportStatus']) },
      "Send Data" => lambda {|it| format_boolean(it['hub']['sendData']) },
    }, json_response, options)
    print reset,"\n"
  end
  return 0, nil
end

#handle(args) ⇒ Object



18
19
20
# File 'lib/morpheus/cli/commands/hub.rb', line 18

def handle(args)
  handle_subcommand(args)
end

#register(args) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/morpheus/cli/commands/hub.rb', line 119

def register(args)
  options = {}
  params = {}
  payload = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage()
    opts.on( '-f', '--force', "Force registration" ) do
      params[:force] = true
    end
    build_standard_post_options(opts, options)
    opts.footer = <<-EOT
Register appliance with the hub to get a unique id for the appliance to checkin with.
The registration is skipped if the appliance is already registered.
The --force option can be used to execute this even if it is already registered.
EOT
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, count:0)
  connect(options)
  payload = parse_payload(options)
  # execute api request
  @hub_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @hub_interface.dry.register(payload, params)
    return
  end
  json_response = @hub_interface.register(payload, params)
  render_response(json_response, options) do
    msg = json_response["msg"] || "Hub registration complete"
    print_green_success msg
  end
end

#usage_data(args) ⇒ Object



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
81
82
83
# File 'lib/morpheus/cli/commands/hub.rb', line 56

def usage_data(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage()
    build_standard_get_options(opts, options)
    opts.footer = "View appliance usage data that is sent to the hub."
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, count:0)
  connect(options)
  params.merge!(parse_query_options(options))
  # execute api request
  @hub_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @hub_interface.dry.usage(params)
    return
  end
  json_response = @hub_interface.usage(params)
  # render response
  render_response(json_response, options) do
    usage_data = json_response['data']
    print_h1 "Morpheus Hub Usage", [], options
    print_hub_usage_data_details(json_response, options)
    print reset,"\n"
  end
  return 0, nil
end