rhn_channel: PEP8 compliancy and doc fixes (#30912)

This PR includes:
- PEP8 compliancy fixes
- Documentation fixes
This commit is contained in:
Dag Wieers 2017-10-03 09:50:44 +02:00 committed by GitHub
parent 4a358b5396
commit 17fbeeb2f0
2 changed files with 15 additions and 24 deletions

View file

@ -1,26 +1,24 @@
#!/usr/bin/python #!/usr/bin/python
# (c) Vincent Van de Kussen # Copyright: (c) Vincent Van de Kussen
#
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'], 'status': ['preview'],
'supported_by': 'core'} 'supported_by': 'core'}
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
module: rhn_channel module: rhn_channel
short_description: Adds or removes Red Hat software channels short_description: Adds or removes Red Hat software channels
description: description:
- Adds or removes Red Hat software channels - Adds or removes Red Hat software channels.
version_added: "1.1" version_added: "1.1"
author: "Vincent Van der Kussen (@vincentvdk)" author:
- Vincent Van der Kussen (@vincentvdk)
notes: notes:
- This module fetches the system id from RHN. - This module fetches the system id from RHN.
- This module doesn't support I(check_mode). - This module doesn't support I(check_mode).
@ -43,11 +41,11 @@ options:
required: true required: true
user: user:
description: description:
- RHN/Satellite login - RHN/Satellite login.
required: true required: true
password: password:
description: description:
- RHN/Satellite password - RHN/Satellite password.
required: true required: true
''' '''
@ -58,14 +56,13 @@ EXAMPLES = '''
url: https://rhn.redhat.com/rpc/api url: https://rhn.redhat.com/rpc/api
user: rhnuser user: rhnuser
password: guessme password: guessme
delegate_to: localhost
''' '''
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves import xmlrpc_client from ansible.module_utils.six.moves import xmlrpc_client
# ------------------------------------------------------- #
def get_systemid(client, session, sysname): def get_systemid(client, session, sysname):
systems = client.system.listUserSystems(session) systems = client.system.listUserSystems(session)
for system in systems: for system in systems:
@ -74,21 +71,18 @@ def get_systemid(client, session, sysname):
idd = int(idres) idd = int(idres)
return idd return idd
# ------------------------------------------------------- #
def subscribe_channels(channelname, client, session, sysname, sys_id): def subscribe_channels(channelname, client, session, sysname, sys_id):
channels = base_channels(client, session, sys_id) channels = base_channels(client, session, sys_id)
channels.append(channelname) channels.append(channelname)
return client.system.setChildChannels(session, sys_id, channels) return client.system.setChildChannels(session, sys_id, channels)
# ------------------------------------------------------- #
def unsubscribe_channels(channelname, client, session, sysname, sys_id): def unsubscribe_channels(channelname, client, session, sysname, sys_id):
channels = base_channels(client, session, sys_id) channels = base_channels(client, session, sys_id)
channels.remove(channelname) channels.remove(channelname)
return client.system.setChildChannels(session, sys_id, channels) return client.system.setChildChannels(session, sys_id, channels)
# ------------------------------------------------------- #
def base_channels(client, session, sys_id): def base_channels(client, session, sys_id):
basechan = client.channel.software.listSystemChannels(session, sys_id) basechan = client.channel.software.listSystemChannels(session, sys_id)
@ -98,19 +92,17 @@ def base_channels(client, session, sys_id):
chans = [item['channel_label'] for item in basechan] chans = [item['channel_label'] for item in basechan]
return chans return chans
# ------------------------------------------------------- #
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec = dict( argument_spec=dict(
state = dict(default='present', choices=['present', 'absent']), state=dict(type='str', default='present', choices=['present', 'absent']),
name = dict(required=True), name=dict(type='str', required=True),
sysname = dict(required=True), sysname=dict(type='str', required=True),
url = dict(required=True), url=dict(type='str', required=True),
user = dict(required=True), user=dict(type='str', required=True),
password = dict(required=True, aliases=['pwd'], no_log=True), password=dict(type='str', required=True, aliases=['pwd'], no_log=True),
) )
) )
@ -140,7 +132,7 @@ def main():
module.exit_json(changed=True, msg="Channel %s added" % channelname) module.exit_json(changed=True, msg="Channel %s added" % channelname)
if state == 'absent': if state == 'absent':
if not channelname in chans: if channelname not in chans:
module.exit_json(changed=False, msg="Not subscribed to channel %s." % channelname) module.exit_json(changed=False, msg="Not subscribed to channel %s." % channelname)
else: else:
unsubscribe_channels(channelname, client, session, systname, sys_id) unsubscribe_channels(channelname, client, session, systname, sys_id)

View file

@ -361,7 +361,6 @@ lib/ansible/modules/packaging/os/pkgng.py
lib/ansible/modules/packaging/os/pkgutil.py lib/ansible/modules/packaging/os/pkgutil.py
lib/ansible/modules/packaging/os/portage.py lib/ansible/modules/packaging/os/portage.py
lib/ansible/modules/packaging/os/portinstall.py lib/ansible/modules/packaging/os/portinstall.py
lib/ansible/modules/packaging/os/rhn_channel.py
lib/ansible/modules/packaging/os/rpm_key.py lib/ansible/modules/packaging/os/rpm_key.py
lib/ansible/modules/packaging/os/sorcery.py lib/ansible/modules/packaging/os/sorcery.py
lib/ansible/modules/packaging/os/svr4pkg.py lib/ansible/modules/packaging/os/svr4pkg.py