Sha256: dde061afdf3d63a691f9f5fc9e7e97661e0cf7eb4e5d9a7234661f4cccb52915

Contents?: true

Size: 1.85 KB

Versions: 6

Compression:

Stored size: 1.85 KB

Contents

require 'nokogiri'

class LinuxAdmin
  class Rhn < RegistrationSystem
    def registered?
      id = ""
      if File.exists?(systemid_file)
        xml = Nokogiri.XML(File.read(systemid_file))
        id = xml.xpath('/params/param/value/struct/member[name="system_id"]/value/string').text
      end
      id.length > 0
    end

    def register(options)
      cmd    = "rhnreg_ks"
      params = {}

      if options[:activationkey]
        params["--activationkey="]  = options[:activationkey]
      elsif options[:username] && options[:password]
        params["--username="]       = options[:username]
        params["--password="]       = options[:password]
      else
        raise ArgumentError, "activation key or username and password are required"
      end

      params["--proxy="]          = options[:proxy_address]   if options[:proxy_address]
      params["--proxyUser="]      = options[:proxy_username]  if options[:proxy_username]
      params["--proxyPassword="]  = options[:proxy_password]  if options[:proxy_password]
      params["--serverUrl="]      = options[:server_url]      if options[:server_url]

      run!(cmd, :params => params)
    end

    def subscribe(options)
      raise ArgumentError, "channels, username and password are required" if options[:channels].blank? || options[:username].blank? || options[:password].blank?
      cmd = "rhn-channel -a"

      channels = options[:channels].collect {|channel| ["--channel=", channel]}

      params                = {}
      params["--user="]     = options[:username]
      params["--password="] = options[:password]
      params                = params.to_a + channels

      run!(cmd, :params => params)
    end

    def subscribed_products
      cmd = "rhn-channel -l"
      run!(cmd).output.split("\n").compact
    end

    private

    def systemid_file
      "/etc/sysconfig/rhn/systemid"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
linux_admin-0.5.1 lib/linux_admin/registration_system/rhn.rb
linux_admin-0.5.0 lib/linux_admin/registration_system/rhn.rb
linux_admin-0.4.1 lib/linux_admin/registration_system/rhn.rb
linux_admin-0.4.0 lib/linux_admin/registration_system/rhn.rb
linux_admin-0.3.0 lib/linux_admin/registration_system/rhn.rb
linux_admin-0.2.3 lib/linux_admin/registration_system/rhn.rb