Module: Morpheus::Cli::RemoteHelper
Overview
Mixin for Morpheus::Cli command classes Provides common methods for working with remotes
Class Method Summary collapse
Instance Method Summary collapse
- #format_appliance_name(appliance) ⇒ Object
- #format_appliance_secure(app_map, return_color = cyan) ⇒ Object
- #format_appliance_slug(appliance) ⇒ Object
- #format_appliance_status(appliance, return_color = cyan, show_current = false) ⇒ Object
- #format_appliance_status_color(appliance) ⇒ Object
- #format_is_current(return_color = cyan) ⇒ Object
-
#get_appliance_session_blurbs(app_map) ⇒ Object
get display info about the current and past sessions.
Class Method Details
.included(klass) ⇒ Object
7 8 9 |
# File 'lib/morpheus/cli/mixins/remote_helper.rb', line 7 def self.included(klass) klass.send :include, Morpheus::Cli::PrintHelper end |
Instance Method Details
#format_appliance_name(appliance) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/morpheus/cli/mixins/remote_helper.rb', line 11 def format_appliance_name(appliance) app_name = appliance[:name] if app_name == 'remote-url' "(remote-url)" else app_name end end |
#format_appliance_secure(app_map, return_color = cyan) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/morpheus/cli/mixins/remote_helper.rb', line 59 def format_appliance_secure(app_map, return_color=cyan) return "" if !app_map out = "" app_url = (app_map[:url] || app_map[:host]).to_s is_ssl = app_url =~ /^https/ if !is_ssl # out << "No (no SSL)" out << "No" else if app_map[:insecure] # out << "No (Ignore SSL Errors)" out << "No" else # should have a flag that gets set when everything actually looks good.. out << "Yes" end end out end |
#format_appliance_slug(appliance) ⇒ Object
20 21 22 |
# File 'lib/morpheus/cli/mixins/remote_helper.rb', line 20 def format_appliance_slug(appliance) "[#{format_appliance_name(appliance)}] #{appliance[:url]}" end |
#format_appliance_status(appliance, return_color = cyan, show_current = false) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/morpheus/cli/mixins/remote_helper.rb', line 24 def format_appliance_status(appliance, return_color=cyan, show_current=false) return "" if !appliance status_str = appliance[:status] || appliance['status'] || "unknown" # get_object_value(appliance, :status) status_str = status_str.to_s # Symbols getting in here? status_str = status_str.empty? ? "unknown" : status_str.to_s.downcase status_str = status_str.gsub("-", " ") # change "http-error" to "http error" out = "" status_color = format_appliance_status_color(appliance) out << "#{status_color}#{status_str.upcase}#{return_color}" # meh, probably keep this separate if show_current && appliance[:active] out << " " + format_is_current() + return_color end out end |
#format_appliance_status_color(appliance) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/morpheus/cli/mixins/remote_helper.rb', line 40 def format_appliance_status_color(appliance) status = appliance[:status].to_s.downcase if status == 'ready' green elsif status == 'fresh' magenta elsif status == 'new' cyan elsif ['error', 'http-error', 'net-error', 'ssl-error', 'http-timeout', 'unreachable', 'unrecognized'].include?(status) red else yellow end end |
#format_is_current(return_color = cyan) ⇒ Object
55 56 57 |
# File 'lib/morpheus/cli/mixins/remote_helper.rb', line 55 def format_is_current(return_color=cyan) "#{cyan}#{bold}(current)#{reset}#{return_color}" end |
#get_appliance_session_blurbs(app_map) ⇒ Object
get display info about the current and past sessions
81 82 83 84 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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/morpheus/cli/mixins/remote_helper.rb', line 81 def get_appliance_session_blurbs(app_map) # app_map = OStruct.new(app_map) blurbs = [] # Current User # username = app_map[:username] # if app_map[:active] # blurbs << "(current)" # end if app_map[:status] == 'ready' if app_map[:authenticated] #blurbs << app_map[:username] ? "Authenticated as #{app_map[:username]}" : "Authenticated" # blurbs << "Authenticated." if app_map[:last_login_at] blurbs << "Logged in #{format_duration_ago(app_map[:last_login_at])}" end else if app_map[:last_logout_at] blurbs << "Logged out #{format_duration_ago(app_map[:last_logout_at])}" else #blurbs << "Logged out" end if app_map[:last_login_at] blurbs << "Last login #{format_duration_ago(app_map[:last_login_at])}" end end if app_map[:last_success_at] blurbs << "Last success #{format_duration_ago(app_map[:last_success_at])}" end else if app_map[:last_check] if app_map[:last_check][:timestamp] blurbs << "Last checked #{format_duration_ago(app_map[:last_check][:timestamp])}" end if app_map[:last_check][:error] last_error_msg = truncate_string(app_map[:last_check][:error], 250) blurbs << "Error: #{last_error_msg}" end if app_map[:last_check][:http_status] blurbs << "HTTP #{app_map[:last_check][:http_status]}" end end if app_map[:last_success_at] blurbs << "Last Success: #{format_duration_ago(app_map[:last_success_at])}" end end return blurbs end |