Sha256: babfd2a4eed65c73e990221a490234d3af8a386a3fa1c3ac254fce29a55d751f

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 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, "pools, username and password are required" if options[:pools].blank? || options[:username].blank? || options[:password].blank?
      cmd = "rhn-channel -a"

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

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

      run(cmd, :params => params)
    end

    private

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
linux_admin-0.1.3 lib/linux_admin/registration_system/rhn.rb