Class: VMC::App::Base
Direct Known Subclasses
Apps, Crashes, Delete, Deprecated, Env, Files, Health, Instances, Logs, Push, Rename, Restart, Routes, Scale, Start, Stats, Stop
Instance Method Summary collapse
- #app_status(a) ⇒ Object
- #human_mb(num) ⇒ Object
- #human_size(num, precision = 1) ⇒ Object
- #megabytes(str) ⇒ Object
- #memory_choices(exclude = 0) ⇒ Object
-
#state_color(s) ⇒ Object
choose the right color for app/instance state.
Methods inherited from CLI
#check_logged_in, #check_target, #client, client, client=, #client_target, #color_enabled?, #default_action, #ensure_config_dir, #err, #execute, #fail, #force?, #invalidate_client, #log_error, #name_list, #no_v2, #one_of, #precondition, #quiet?, #remove_target_info, #sane_target_url, #save_target_info, #save_targets, #set_target, #table, #target_file, #target_info, #targets_info, #tokens_file, #user_colors, #v2?, #verbose?
Methods included from Spacing
#indented, #justify, #line, #lines, #quiet?, #spaced, #start_line, #tabular, #text_width, #trim_escapes
Methods included from Interactive
#ask, #handler, #input_state, #list_choices, #prompt, #show_default
Instance Method Details
#app_status(a) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/vmc/cli/app/base.rb', line 24 def app_status(a) health = a.health if a.debug_mode == "suspend" && health == "0%" c("suspended", :neutral) else c(health.downcase, state_color(health)) end end |
#human_mb(num) ⇒ Object
50 51 52 |
# File 'lib/vmc/cli/app/base.rb', line 50 def human_mb(num) human_size(num * 1024 * 1024, 0) end |
#human_size(num, precision = 1) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/vmc/cli/app/base.rb', line 54 def human_size(num, precision = 1) sizes = ["G", "M", "K"] sizes.each.with_index do |suf, i| pow = sizes.size - i unit = 1024 ** pow if num >= unit return format("%.#{precision}f%s", num / unit, suf) end end format("%.#{precision}fB", num) end |
#megabytes(str) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/vmc/cli/app/base.rb', line 67 def megabytes(str) if str =~ /T$/i str.to_i * 1024 * 1024 elsif str =~ /G$/i str.to_i * 1024 elsif str =~ /M$/i str.to_i elsif str =~ /K$/i str.to_i / 1024 else # assume megabytes str.to_i end end |
#memory_choices(exclude = 0) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vmc/cli/app/base.rb', line 34 def memory_choices(exclude = 0) info = client.info used = info[:usage][:memory] limit = info[:limits][:memory] available = limit - used + exclude mem = 64 choices = [] until mem > available choices << human_mb(mem) mem *= 2 end choices end |
#state_color(s) ⇒ Object
choose the right color for app/instance state
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vmc/cli/app/base.rb', line 7 def state_color(s) case s when "STARTING" :neutral when "STARTED", "RUNNING" :good when "DOWN" :bad when "FLAPPING" :error when "N/A" :unknown else :warning end end |