Class: CloudFlock::Task::ServerProfile
- Inherits:
-
Object
- Object
- CloudFlock::Task::ServerProfile
- Defined in:
- lib/cloudflock/task/server-profile.rb
Defined Under Namespace
Constant Summary collapse
- DISTRO_NAMES =
Public: List of linux distributions supported by CloudFlock
%w{Arch CentOS Debian Gentoo Scientific SUSE Ubuntu RedHat}
Instance Attribute Summary collapse
-
#cpe ⇒ Object
readonly
Returns the value of attribute cpe.
-
#process_list ⇒ Object
readonly
Returns the value of attribute process_list.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#initialize(shell) ⇒ ServerProfile
constructor
Public: Initialize the Profile object.
-
#select(&block) ⇒ Object
Public: Select from the info Array, passing Section titles to the block provided and returning a list of entries contained within matching sections.
-
#select_entries(section, name) ⇒ Object
Public: Select values from within entries, specifying both section and entry names.
-
#to_hash ⇒ Object
Public: Return server information and warnings as a Hash.
Constructor Details
#initialize(shell) ⇒ ServerProfile
Public: Initialize the Profile object.
shell - An SSH object which is open to the host which will be profiled.
22 23 24 25 26 27 28 29 |
# File 'lib/cloudflock/task/server-profile.rb', line 22 def initialize(shell) @shell = shell @cpe = nil @warnings = [] @info = [] build end |
Instance Attribute Details
#cpe ⇒ Object (readonly)
Returns the value of attribute cpe.
15 16 17 |
# File 'lib/cloudflock/task/server-profile.rb', line 15 def cpe @cpe end |
#process_list ⇒ Object (readonly)
Returns the value of attribute process_list.
17 18 19 |
# File 'lib/cloudflock/task/server-profile.rb', line 17 def process_list @process_list end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
16 17 18 |
# File 'lib/cloudflock/task/server-profile.rb', line 16 def warnings @warnings end |
Instance Method Details
#select(&block) ⇒ Object
Public: Select from the info Array, passing Section titles to the block provided and returning a list of entries contained within matching sections.
Examples
profile.select { |title| title == 'Memory Statistics' }
# => [...]
profile.select { |title| /Memory/.match title }
# => [...]
Yields titles of Section structs (Strings).
Returns an Array of Entry structs.
53 54 55 56 57 |
# File 'lib/cloudflock/task/server-profile.rb', line 53 def select(&block) sections = @info.select { |section| block.call(section.title) } sections.map! { |section| section.entries } sections.flatten end |
#select_entries(section, name) ⇒ Object
Public: Select values from within entries, specifying both section and entry names.
section - String or Regexp specifying the section name. name - String or Regexp specifying the desired entry’s name.
Examples
profile.select_entries('Memory Statistics', 'Used RAM')
# => [...]
profile.select_entries(/Memory/, 'Used RAM')
# => [...]
Returns an Array of Strings.
74 75 76 77 78 |
# File 'lib/cloudflock/task/server-profile.rb', line 74 def select_entries(section, name) entries = select { |header| header.match section } filtered = entries.select { |entry| name.match entry.name } filtered.map(&:values) end |
#to_hash ⇒ Object
Public: Return server information and warnings as a Hash.
Returns a Hash.
34 35 36 |
# File 'lib/cloudflock/task/server-profile.rb', line 34 def to_hash { info: @info, warnings: @warnings } end |