Class: OsCtl::Cli::KernelKeyring
- Inherits:
-
Object
- Object
- OsCtl::Cli::KernelKeyring
- Includes:
- Lib::Utils::Humanize
- Defined in:
- lib/osctl/cli/kernel_keyring.rb
Constant Summary collapse
- PREFIX =
'keyring.'.freeze
- PARAMS =
%w[nkeys nikeys qnkeys qnbytes].freeze
Instance Method Summary collapse
- #add_param_values(data, params, precise) ⇒ Object protected
- #add_values(data, cols, precise: false) ⇒ Object (also: #add_container_values, #add_user_values)
- #keyring ⇒ Object protected
- #list_param_names ⇒ Object
- #name_to_cli(v) ⇒ Object protected
- #name_to_internal(v) ⇒ Object protected
- #param_value(param, v, precise) ⇒ Object protected
- #selected_params(cols) ⇒ Object protected
Instance Method Details
#add_param_values(data, params, precise) ⇒ Object (protected)
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/osctl/cli/kernel_keyring.rb', line 33 def add_param_values(data, params, precise) uid_map = OsCtl::Lib::IdMap.from_hash_list(data[:uid_map]) key_users = keyring.for_id_map(uid_map) params.each do |param| # Key users are tracked per UID, so one container/mapping can have many # key users, we sum them all. sum = key_users.inject(0) { |acc, ku| acc + ku.send(param) } data[name_to_cli(param).to_sym] = param_value(param, sum, precise) end end |
#add_values(data, cols, precise: false) ⇒ Object Also known as: add_container_values, add_user_values
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/osctl/cli/kernel_keyring.rb', line 15 def add_values(data, cols, precise: false) params = selected_params(cols) return if params.empty? if data.is_a?(::Hash) add_param_values(data, params, precise) elsif data.is_a?(::Array) data.each do |ct| add_param_values(ct, params, precise) end end end |
#keyring ⇒ Object (protected)
59 60 61 |
# File 'lib/osctl/cli/kernel_keyring.rb', line 59 def keyring @keyring ||= OsCtl::Lib::KernelKeyring.new end |
#list_param_names ⇒ Object
11 12 13 |
# File 'lib/osctl/cli/kernel_keyring.rb', line 11 def list_param_names PARAMS.map { |v| name_to_cli(v) } end |
#name_to_cli(v) ⇒ Object (protected)
63 64 65 |
# File 'lib/osctl/cli/kernel_keyring.rb', line 63 def name_to_cli(v) "#{PREFIX}#{v}" end |
#name_to_internal(v) ⇒ Object (protected)
67 68 69 |
# File 'lib/osctl/cli/kernel_keyring.rb', line 67 def name_to_internal(v) v[PREFIX.length..] end |
#param_value(param, v, precise) ⇒ Object (protected)
71 72 73 74 75 76 77 78 79 |
# File 'lib/osctl/cli/kernel_keyring.rb', line 71 def param_value(param, v, precise) case param when 'nkeys', 'nikeys', 'qnkeys' OsCtl::Lib::Cli::Presentable.new(v, formatted: precise ? nil : humanize_number(v)) when 'qnbytes' OsCtl::Lib::Cli::Presentable.new(v, formatted: precise ? nil : humanize_data(v)) end end |