client/rhel/rhn-client-tools/man/en/spacewalk-channel.8 | 3 + client/rhel/rhn-client-tools/src/bin/spacewalk-channel.py | 28 +++++++++++++- client/rhel/rhn-client-tools/src/up2date_client/config.py | 12 ++++++ 3 files changed, 42 insertions(+), 1 deletion(-)
New commits: commit b9514bdb221d9635f58c188d3408146f1058f6ba Author: Miroslav Suchý msuchy@redhat.com Date: Fri Jan 14 17:03:07 2011 +0100
651792 - list all available child channels related to system
diff --git a/client/rhel/rhn-client-tools/man/en/spacewalk-channel.8 b/client/rhel/rhn-client-tools/man/en/spacewalk-channel.8 index 4710fd1..5c0edc6 100644 --- a/client/rhel/rhn-client-tools/man/en/spacewalk-channel.8 +++ b/client/rhel/rhn-client-tools/man/en/spacewalk-channel.8 @@ -34,6 +34,9 @@ specified channels via the command line. A visit to the Red Hat Network .IP "\fB-l, --list\fP" Print a list of channel(s) that you are currently subscribed to. .br +.IP "\fB-L, --available-channels\fP" +Print a list of all available child channels. +.br .IP "\fB-a, --add\fP" You are subscribing system to given channel(s). You have to specify --user and --password. .br diff --git a/client/rhel/rhn-client-tools/src/bin/spacewalk-channel.py b/client/rhel/rhn-client-tools/src/bin/spacewalk-channel.py index e76730f..a642718 100644 --- a/client/rhel/rhn-client-tools/src/bin/spacewalk-channel.py +++ b/client/rhel/rhn-client-tools/src/bin/spacewalk-channel.py @@ -13,10 +13,14 @@ # granted to use or replicate Red Hat trademarks that are incorporated # in this software or its documentation. # +import getpass import os +import re import socket import sys -import getpass +import urlparse +import xmlrpclib +from rhn import rpclib
from optparse import Option, OptionParser
@@ -56,6 +60,8 @@ def processCommandline(): help=_('unsubscribe from channel')), Option('-l', '--list', action='store_true', help=_('list channels')), + Option('-L', '--available-channels', action='store_true', + help=_('list all available child channels')), Option('-v', '--verbose', action='store_true', help=_('verbose output')), Option('-u', '--user', action='store', @@ -76,6 +82,22 @@ def processCommandline(): if not OPTIONS.password and not OPTIONS.list: OPTIONS.password = getpass.getpass()
+def get_available_channels(user, password): + """ return list of available child channels """ + cfg = config.initUp2dateConfig() + satellite_url = config.getServerlURL()[0] + parts = urlparse.urlsplit(satellite_url) + satellite_url = urlparse.SplitResult(parts.scheme, parts.netloc, '/rpc/api', + parts.query, parts.fragment).geturl() + + client = xmlrpclib.Server(satellite_url, verbose=0) + key = client.auth.login(user, password) + system_id = re.sub('^ID-', '', rpclib.xmlrpclib.loads(up2dateAuth.getSystemId())[0][0]['system_id']) + result = [] + for channel in client.system.listChildChannels(key, int(system_id)): + result.extend([channel['LABEL']]) + return result + def need_channel(channel): """ die gracefuly if channel is empty """ if not channel: @@ -99,6 +121,10 @@ def main(): systemExit(1, _('This system is not associated with any channel.')) channels.sort() print '\n'.join(channels) + elif OPTIONS.available-channels: + channels = get_available_channels(OPTIONS.user, OPTIONS.password) + channels.sort() + print '\n'.join(channels) else: systemExit(3, _("ERROR: you may want to specify --add, --remove or --list"))
diff --git a/client/rhel/rhn-client-tools/src/up2date_client/config.py b/client/rhel/rhn-client-tools/src/up2date_client/config.py index 99ec8ec..44d24e2 100644 --- a/client/rhel/rhn-client-tools/src/up2date_client/config.py +++ b/client/rhel/rhn-client-tools/src/up2date_client/config.py @@ -280,6 +280,18 @@ def getProxySetting():
return proxy
+def getServerlURL(): + """ return list of serverURL from config + Note: in config may be one value or more values, but this + function always return list + """ + cfg = initUp2dateConfig() + # serverURL may be a list in the config file, so by default, grab the + # first element. + if type(cfg['serverURL']) == type([]): + return cfg['serverURL'] + else: + return [cfg['serverURL']]
def initUp2dateConfig(cfg_file = "/etc/sysconfig/rhn/up2date"): """This function is the right way to get at the up2date config."""
spacewalk-commits@lists.fedorahosted.org