Class: Packageiq::Provider::RHEL
- Inherits:
-
Object
- Object
- Packageiq::Provider::RHEL
- Defined in:
- lib/packageiq/provider/rhel.rb
Overview
rhel based system package provider
Constant Summary collapse
- RPM_INFO_KEY =
mapping of yum info query tags to symbol
{ :name => '%{NAME}', :epoch => '%{EPOCH}', :version => '%{VERSION}', :release => '%{RELEASE}', :arch => '%{ARCH}', :install_date => '%{INSTALLTIME:date}', :group => '%{GROUP}', :size => '%{SIZE}', :license => '%{LICENSE}', :signature => '%|DSAHEADER?{%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{%{RSAHEADER:pgpsig}}:{%|SIGGPG?{%{SIGGPG:pgpsig}}:{%|SIGPGP?{%{SIGPGP:pgpsig}}:{(none)}|}|}|}|', :source_rpm => '%{SOURCERPM}', :build_date => '%{BUILDTIME:date}', :build_host => '%{BUILDHOST}', :packager => '%{PACKAGER}', :vendor => '%{VENDOR}', :url => '%{URL}', :summary => '%{SUMMARY}' }
Instance Attribute Summary collapse
-
#command_handler ⇒ Object
readonly
Returns the value of attribute command_handler.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#os_release ⇒ Object
readonly
Returns the value of attribute os_release.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
-
#build_inventory ⇒ Object
build full package inventory returns array of package_entry hashes.
-
#info(package) ⇒ Object
returns hash of rpm info.
-
#initialize ⇒ RHEL
constructor
A new instance of RHEL.
-
#installed ⇒ Object
returns array of installed packages.
-
#rhel_release ⇒ Object
returns redhat relase string.
-
#server_info ⇒ Object
returns hash of server info.
-
#updateable(package_info, updates) ⇒ Object
adds available update info to package_info hash.
-
#updates ⇒ Object
returns array of available yum update hashes.
Constructor Details
Instance Attribute Details
#command_handler ⇒ Object (readonly)
Returns the value of attribute command_handler.
29 30 31 |
# File 'lib/packageiq/provider/rhel.rb', line 29 def command_handler @command_handler end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
29 30 31 |
# File 'lib/packageiq/provider/rhel.rb', line 29 def hostname @hostname end |
#os_release ⇒ Object (readonly)
Returns the value of attribute os_release.
29 30 31 |
# File 'lib/packageiq/provider/rhel.rb', line 29 def os_release @os_release end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
29 30 31 |
# File 'lib/packageiq/provider/rhel.rb', line 29 def @timestamp end |
Instance Method Details
#build_inventory ⇒ Object
build full package inventory returns array of package_entry hashes
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/packageiq/provider/rhel.rb', line 79 def build_inventory inventory = [] updates_array = updates installed.each do |package| package_info = info(package) package_entry = updateable(package_info, updates_array) package_entry.merge!(server_info) inventory << package_entry end inventory end |
#info(package) ⇒ Object
returns hash of rpm info
51 52 53 54 55 56 57 58 |
# File 'lib/packageiq/provider/rhel.rb', line 51 def info(package) queryformat = '' RPM_INFO_KEY.each do |symbol, query| queryformat += "#{symbol}: #{query}\\n" end info = run("rpm -q --queryformat \"#{queryformat}\" #{package}") parse_info(info) end |
#installed ⇒ Object
returns array of installed packages
39 40 41 42 |
# File 'lib/packageiq/provider/rhel.rb', line 39 def installed installed = run('rpm -qa') installed.split("\n") end |
#rhel_release ⇒ Object
returns redhat relase string
61 62 63 |
# File 'lib/packageiq/provider/rhel.rb', line 61 def rhel_release run('cat /etc/redhat-release') end |
#server_info ⇒ Object
returns hash of server info
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/packageiq/provider/rhel.rb', line 66 def server_info { server: { hostname: hostname, os_release: os_release, collection_time: } } end |
#updateable(package_info, updates) ⇒ Object
adds available update info to package_info hash
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/packageiq/provider/rhel.rb', line 92 def updateable(package_info, updates) update_info = { update: { available: 'no', version: '-', repo: '-' } } updates.each do |update| next unless update[:name] == package_info[:package][:name] update_info[:update][:available] = 'yes' update_info[:update][:version] = update[:version] update_info[:update][:repo] = update[:repo] break end package_info.merge(update_info) end |
#updates ⇒ Object
returns array of available yum update hashes
45 46 47 48 |
# File 'lib/packageiq/provider/rhel.rb', line 45 def updates updates = run('yum list updates') parse_list(updates) end |