Class: Packageiq::Provider::RHEL

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeRHEL

Returns a new instance of RHEL.



31
32
33
34
35
36
# File 'lib/packageiq/provider/rhel.rb', line 31

def initialize
  @command_handler  = Packageiq::Command.new
  @hostname         = Socket.gethostname
  @timestamp        = Time.new
  @os_release       = rhel_release.strip
end

Instance Attribute Details

#command_handlerObject (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

#hostnameObject (readonly)

Returns the value of attribute hostname.



29
30
31
# File 'lib/packageiq/provider/rhel.rb', line 29

def hostname
  @hostname
end

#os_releaseObject (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

#timestampObject (readonly)

Returns the value of attribute timestamp.



29
30
31
# File 'lib/packageiq/provider/rhel.rb', line 29

def timestamp
  @timestamp
end

Instance Method Details

#build_inventoryObject

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

#installedObject

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_releaseObject

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_infoObject

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: timestamp
    }
  }
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

#updatesObject

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