From 8593409767f78074bbda61e35fb577d18add9c06 Mon Sep 17 00:00:00 2001 From: James Laska Date: Fri, 7 Jun 2013 14:15:06 -0400 Subject: [PATCH] Minor adjustments to subscription_manager and rhnreg_ks --- packaging/rhnreg_ks | 36 +++++++++++++++++----------------- packaging/subscription_manager | 5 ++--- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/packaging/rhnreg_ks b/packaging/rhnreg_ks index 3d40b7d77ad..8ca8de8bcc6 100644 --- a/packaging/rhnreg_ks +++ b/packaging/rhnreg_ks @@ -309,15 +309,15 @@ class Rhn(RegistrationBase): def main(): - # Load RHSM configuration from file - reg = Rhn() + # Read system RHN configuration + rhn = Rhn() module = AnsibleModule( argument_spec = dict( state = dict(default='present', choices=['present', 'absent']), username = dict(default=None, required=False), password = dict(default=None, required=False), - server_url = dict(default=reg.config.get_option('serverURL'), required=False), + server_url = dict(default=rhn.config.get_option('serverURL'), required=False), activationkey = dict(default=None, required=False), enable_eus = dict(default=False, type='bool'), channels = dict(default=[], type='list'), @@ -325,9 +325,9 @@ def main(): ) state = module.params['state'] - reg.username = module.params['username'] - reg.password = module.params['password'] - reg.configure(module.params['server_url']) + rhn.username = module.params['username'] + rhn.password = module.params['password'] + rhn.configure(module.params['server_url']) activationkey = module.params['activationkey'] channels = module.params['channels'] @@ -335,35 +335,35 @@ def main(): if state == 'present': # Check for missing parameters ... - if not (activationkey or reg.username or reg.password): - module.fail_json(msg="Missing arguments, must supply an activationkey (%s) or username (%s) and password (%s)" % (activationkey, reg.username, reg.password)) - if not activationkey and not (reg.username and reg.password): + if not (activationkey or rhn.username or rhn.password): + module.fail_json(msg="Missing arguments, must supply an activationkey (%s) or username (%s) and password (%s)" % (activationkey, rhn.username, rhn.password)) + if not activationkey and not (rhn.username and rhn.password): module.fail_json(msg="Missing arguments, If registering without an activationkey, must supply username or password") # Register system - if reg.is_registered: + if rhn.is_registered: module.exit_json(changed=False, msg="System already registered.") else: try: - reg.enable() - reg.register(module.params['enable_eus'] == True, activationkey) - reg.subscribe(channels) + rhn.enable() + rhn.register(module.params['enable_eus'] == True, activationkey) + rhn.subscribe(channels) except CommandException, e: - module.fail_json(msg="Failed to register with '%s': %s" % (reg.hostname, e)) + module.fail_json(msg="Failed to register with '%s': %s" % (rhn.hostname, e)) else: - module.exit_json(changed=True, msg="System successfully registered to '%s'." % reg.hostname) + module.exit_json(changed=True, msg="System successfully registered to '%s'." % rhn.hostname) # Ensure system is *not* registered if state == 'absent': - if not reg.is_registered: + if not rhn.is_registered: module.exit_json(changed=False, msg="System already unregistered.") else: try: - reg.unregister() + rhn.unregister() except CommandException, e: module.fail_json(msg="Failed to unregister: %s" % e) else: - module.exit_json(changed=True, msg="System successfully unregistered from %s." % reg.hostname) + module.exit_json(changed=True, msg="System successfully unregistered from %s." % rhn.hostname) # include magic from lib/ansible/module_common.py diff --git a/packaging/subscription_manager b/packaging/subscription_manager index 8a991a6f955..f0dbe025c69 100644 --- a/packaging/subscription_manager +++ b/packaging/subscription_manager @@ -145,7 +145,7 @@ class Rhsm(RegistrationBase): RegistrationBase.__init__(self, username, password) self.config = self._read_config() - def _read_config(rhsm_conf='/etc/rhsm/rhsm.conf'): + def _read_config(self, rhsm_conf='/etc/rhsm/rhsm.conf'): ''' Load RHSM configuration from /etc/rhsm/rhsm.conf. Returns: @@ -154,8 +154,7 @@ class Rhsm(RegistrationBase): # Read RHSM defaults ... cp = ConfigParser.ConfigParser() - if os.path.isfile(rhsm_conf): - cp.read(rhsm_conf) + cp.read(rhsm_conf) # Add support for specifying a default value w/o having to standup some configuration # Yeah, I know this should be subclassed ... but, oh well