utils/Makefile | 9 -
utils/spacewalk-common-channels | 269 ++++++++++++++++++++++++++++++++++++
utils/spacewalk-common-channels.ini | 128 +++++++++++++++++
utils/spacewalk-utils.spec | 1
4 files changed, 405 insertions(+), 2 deletions(-)
New commits:
commit 4dc38ecd932b66f98721773ac217adaf8cb84078
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Feb 15 11:36:44 2010 +0100
fixed installation dirs
diff --git a/utils/Makefile b/utils/Makefile
index ad6fd80..821d310 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -20,7 +20,7 @@ BINDIR = /usr/bin
MANDIR ?= /usr/man
CONFDIR = /etc/rhn
-EXTRA_DIRS = $(MANDIR)/man8 $(BINDIR)
+EXTRA_DIRS = $(MANDIR)/man8 $(BINDIR) $(CONFDIR)
include Makefile.defs
diff --git a/utils/spacewalk-utils.spec b/utils/spacewalk-utils.spec
index d13f03f..8976d1c 100644
--- a/utils/spacewalk-utils.spec
+++ b/utils/spacewalk-utils.spec
@@ -47,7 +47,7 @@ rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
-%config %{_sysconfdir}/spacewalk-common-channels.ini
+%config %{_sysconfdir}/rhn/spacewalk-common-channels.ini
%attr(755,root,root) %{_bindir}/*
%dir %{rhnroot}/utils
%{rhnroot}/utils/__init__.py*
commit e0ca94a12ab338d3c4040f9ec73d740260e35e76
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Feb 15 11:27:09 2010 +0100
packed spacewalk-common-channels into rpm
diff --git a/utils/Makefile b/utils/Makefile
index 0fd05ea..ad6fd80 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -7,7 +7,9 @@ NAME := spacewalk-utils
SUBDIR = utils
FILES = __init__ systemSnapshot migrateSystemProfile
-SCRIPTS = sw-system-snapshot migrate-system-profile spacewalk-api apply_errata scr.cgi
+SCRIPTS = sw-system-snapshot migrate-system-profile spacewalk-api apply_errata \
+ scr.cgi spacewalk-common-channels
+CONFIGS = spacewalk-common-channels.ini
DOCBOOK = $(wildcard /usr/bin/docbook2man)
@@ -16,6 +18,7 @@ MANS = $(patsubst %.sgml,%.8,$(SGMLS) )
BINDIR = /usr/bin
MANDIR ?= /usr/man
+CONFDIR = /etc/rhn
EXTRA_DIRS = $(MANDIR)/man8 $(BINDIR)
@@ -32,6 +35,8 @@ all :: $(MANS)
pod2man --section=8 spacewalk-api spacewalk-api.8
install :: $(MANS) $(PREFIX)/$(MANDIR)
$(INSTALL_DATA) $(MANS) spacewalk-api.8* $(PREFIX)/$(MANDIR)/man8
+install :: $(CONFIGS) $(PREFIX)/$(CONFDIR)
+ $(INSTALL_DATA) $(CONFIGS) $(PREFIX)/$(CONFDIR)
endif
%.new : %
diff --git a/utils/spacewalk-utils.spec b/utils/spacewalk-utils.spec
index 93c9569..d13f03f 100644
--- a/utils/spacewalk-utils.spec
+++ b/utils/spacewalk-utils.spec
@@ -47,6 +47,7 @@ rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
+%config %{_sysconfdir}/spacewalk-common-channels.ini
%attr(755,root,root) %{_bindir}/*
%dir %{rhnroot}/utils
%{rhnroot}/utils/__init__.py*
commit f3edba4d6942018eefe8362a3f9b3a8d585ffa8b
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Feb 15 11:19:56 2010 +0100
added spacewalk-common-channels utility
diff --git a/utils/spacewalk-common-channels b/utils/spacewalk-common-channels
new file mode 100755
index 0000000..233de74
--- /dev/null
+++ b/utils/spacewalk-common-channels
@@ -0,0 +1,269 @@
+#!/usr/bin/python
+#
+# Copyright (c) 2010 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+#
+
+import sys
+import xmlrpclib
+import fnmatch
+import ConfigParser
+from optparse import OptionParser, Option
+import re
+
+DEFAULT_SERVER = "localhost"
+DEFAULT_USER = "spacewalk"
+DEFAULT_PASSWORD = "spacewalk"
+
+DEFAULT_CONFIG = '/etc/rhn/spacewalk-common-channels.ini'
+
+channel_arch = {
+ 'i386': 'channel-ia32',
+ 'x86_64': 'channel-x86_64',
+ 'ia64': 'channel-ia64',
+ 'sparc': 'channel-sparc',
+ 'sparc64': 'channel-sparc64',
+ 'alpha': 'channel-alpha',
+ 's390': 'channel-s390',
+ 's390x': 'channel-s390x',
+ 'iSeries': 'channel-iSeries',
+ 'pSeries': 'channel-pSeries',
+ 'x86_64': 'channel-x86_64',
+ 'ppc': 'channel-ppc',
+ 'ppc64': 'channel-ppc64',
+ 'sparc-sun-solaris': 'channel-sparc-sun-solaris',
+ 'i386-sun-solaris': 'channel-i386-sun-solaris',
+ }
+
+SPLIT_PATTERN = '[ ,]+'
+
+def connect(user, password, server):
+ server_url = "http://%s/rpc/api" % server
+
+ if options.verbose > 2:
+ client_verbose = options.verbose - 2
+ else:
+ client_verbose = 0
+ if options.verbose:
+ sys.stdout.write("Connecting to %s\n" % server_url)
+ client = xmlrpclib.Server(server_url, verbose=client_verbose)
+ key = client.auth.login(user, password)
+ return client, key
+
+def setup_channel(section, arch):
+ channels = {}
+ base_channels = ['']
+ optional = ['activationkey']
+ mandatory = ['label', 'name', 'summary', 'checksum',
'arch', 'base_channel']
+
+ if config.has_option(section, 'base_channels'):
+ base_channels = re.split(SPLIT_PATTERN, config.get(section,
'base_channels', 1))
+
+ config.set(section, 'arch', arch)
+ config.set(section, 'section', section)
+ for base_channel in base_channels:
+ channel = {}
+ config.set(section, 'base_channel', base_channel)
+
+ for k in optional:
+ if config.has_option(section,k):
+ channel[k] = config.get(section, k)
+ for k in mandatory:
+ channel[k] = config.get(section, k)
+ channels[channel['label']] = channel
+ return channels
+
+if __name__ == "__main__":
+ # options parsing
+ usage = "usage: %prog [options] <channel1 glob> [<channel2 glob> ...
]"
+
+ option_list = [
+ Option("-c", "--config", help="configuration file",
default=DEFAULT_CONFIG),
+ Option("-u", "--user", help="username",
default=DEFAULT_USER),
+ Option("-p", "--password", help="password",
default=DEFAULT_PASSWORD),
+ Option("-s", "--server", help="your spacewalk
server", default=DEFAULT_SERVER),
+ Option("-k", "--keys", help="activation key limit
(unlimited/number)"),
+ Option("-n", "--dry-run", help="perform a trial run with
no changes made",
+ action="store_true"),
+ Option("-a", "--archs", help="list of
architectures"),
+ Option("-v", "--verbose", help="verbose",
action="count"),
+ Option("-l", "--list", help="print list of available
channels",
+ action="store_true"),
+ ]
+
+ parser = OptionParser(usage=usage, option_list=option_list,
description="")
+ (options, args) = parser.parse_args()
+ config = ConfigParser.ConfigParser()
+ config.read(options.config)
+
+ if options.list:
+ print "Available channels:"
+ channel_list = config.sections()
+ if channel_list:
+ for channel in sorted(channel_list):
+ print " %-20s %s" % (channel + ":",
+ "i386, x86_64") # FIXME: list of archs
+ else:
+ print " [no channel available]"
+ sys.exit(0)
+
+ if not args:
+ print parser.print_help()
+ parser.exit()
+
+ key = None
+ client = None
+ channels = {}
+
+ # read matching channels from config and sort them, base channels first
+ for pattern in args:
+ for section in fnmatch.filter(config.sections(), pattern):
+ archs = re.split(SPLIT_PATTERN, config.get(section, 'archs'))
+ if options.archs:
+ # filter out archs not set on commandline
+ archs = filter(lambda a: a in options.archs, archs)
+ for arch in archs:
+ channel = setup_channel(section, arch)
+ channels.update(channel)
+
+# FIXME debug
+ for (k,v) in channels.items():
+ print k
+ for (kk, vv) in v.items():
+ print " ", kk, "=", vv
+# /FIXME debug
+
+ # list of base_channels to create
+ base_channels = {}
+ # list of child_channels for given base_channel
+ child_channels = {}
+ for (name, attr) in channels.items():
+ if attr['base_channel']:
+ if attr['base_channel'] not in base_channels:
+ base_channels[attr['base_channel']] = False
+ if attr['base_channel'] in child_channels:
+ child_channels[attr['base_channel']].append(name)
+ else:
+ child_channels[attr['base_channel']] = [name]
+ else:
+ # this channel is base channel
+ base_channels[name] = True
+ if name not in child_channels:
+ child_channels[name] = []
+
+
+ for (base_channel_label, create_channel) in sorted(base_channels.items()):
+
+ if key == None:
+ client, key = connect(options.user, options.password, options.server)
+ user_info = client.user.getDetails(key, options.user)
+ org_id = user_info['org_id']
+
+ activationkey = None
+ if create_channel:
+ base_info = channels[base_channel_label]
+ if options.verbose:
+ sys.stdout.write("Base channel '%s' - creating...\n" %
base_info['name'])
+ if options.verbose > 1:
+ sys.stdout.write("* label=%s, summary=%s, arch=%s,
checksum=%s\n" % (
+ base_info['label'],
base_info['summary'],
+ base_info['arch'],
base_info['checksum']))
+
+ if not options.dry_run:
+ try:
+ # create base channel
+ client.channel.software.create(key,
+ base_info['label'], base_info['name'],
base_info['summary'],
+ channel_arch[base_info['arch']], '',
base_info['checksum'])
+ except xmlrpclib.Fault, e:
+ if e.faultCode != 1200: # ignore if channel exists
+ sys.stderr.write("ERROR: %s: %s\n" % (
+ base_info['label'], e.faultString))
+ continue
+
+ if options.keys is not None:
+ if options.verbose:
+ sys.stdout.write("* Activation key '%s' -
creating...\n" % (
+ base_info['label']))
+ if not options.dry_run:
+ # create activation key
+ if options.keys == 'unlimited':
+ ak_args = (key, base_info['activationkey'],
base_info['name'],
+ base_info['label'], [], False)
+ else:
+ ak_args = (key, base_info['activationkey'],
base_info['name'],
+ base_info['label'], int(options.keys),
[], False)
+ try:
+ client.activationkey.create(*ak_args)
+ activationkey = "%s-%s" % (org_id,
base_info['activationkey'])
+ except xmlrpclib.Fault, e:
+ sys.stderr.write("ERROR: %s: %s\n" % (
+ base_info['label'], e.faultString))
+ else:
+ # set this in dry run
+ activationkey = base_info['activationkey']
+ else:
+ # check whether channel exists
+ try:
+ base_info = client.channel.software.getDetails(key, base_channel_label)
+ if options.verbose:
+ sys.stdout.write("Base channel '%s' - exists\n" %
base_info['name'])
+ except xmlrpclib.Fault, e:
+ if e.faultCode != -210: # don't report 'No such channel'
+ sys.stderr.write("ERROR: %s: %s\n" % (
+ base_channel_label, e.faultString))
+ continue
+
+ for child_channel_label in child_channels[base_channel_label]:
+ child_info = channels[child_channel_label]
+ if options.verbose:
+ sys.stdout.write("* Child channel '%s' - creating...\n"
% child_info['name'])
+ if options.verbose > 1:
+ sys.stdout.write("** label=%s, summary=%s, arch=%s, parent=%s,
checksum=%s\n" % (
+ child_info['label'],
child_info['summary'],
+ child_info['arch'], base_channel_label,
+ child_info['checksum']))
+
+ if not options.dry_run:
+ try:
+ # create child channels
+ client.channel.software.create(key,
+ child_info['label'], child_info['name'],
child_info['summary'],
+ channel_arch[child_info['arch']],
base_channel_label,
+ child_info['checksum'])
+ except xmlrpclib.Fault, e:
+ if e.faultCode != 1200: # ignore if channel exists
+ sys.stderr.write("ERROR: %s: %s\n" % (
+ child_info['label'], e.faultString))
+
+ if options.keys is not None:
+ if activationkey:
+ if options.verbose:
+ sys.stdout.write("** Activation key '%s' - adding
child channel...\n" % (
+ activationkey))
+ if not options.dry_run:
+ try:
+ client.activationkey.addChildChannels(key, activationkey,
+
child_info['label'])
+ except xmlrpclib.Fault, e:
+ sys.stderr.write("ERROR: %s: %s\n" % (
+ child_info['label'], e.faultString))
+
+ if options.verbose:
+ # an empty line after channel group
+ sys.stdout.write("\n")
+
+ if client is not None:
+ # logout
+ client.auth.logout(key)
+
diff --git a/utils/spacewalk-common-channels.ini b/utils/spacewalk-common-channels.ini
new file mode 100755
index 0000000..95ad603
--- /dev/null
+++ b/utils/spacewalk-common-channels.ini
@@ -0,0 +1,128 @@
+[DEFAULT]
+label = %(section)s-%(arch)s
+checksum = sha1
+summary = %(name)s
+activationkey = %(label)s
+## now define some "macros"
+#_f11_archs = i386, x86_64, ppc, ppc64, s390x, sparc, sparc64
+_f11_archs = i386, x86_64, ppc, s390x, sparc
+#_f12_archs = i386, x86_64, ppc, ppc64
+_f12_archs = i386, x86_64, ppc
+_x86_archs = i386, x86_64
+
+[fedora11]
+checksum = sha256
+archs = %(_f11_archs)s
+checksum = sha256
+name = Fedora 11 (%(arch)s)
+
+[fedora11-updates]
+label = %(base_channel)s-updates
+name = Fedora 11 Updates (%(arch)s)
+archs = %(_f11_archs)s
+checksum = sha256
+base_channels = fedora11-%(arch)s
+
+[fedora11-debug]
+label = %(base_channel)s-debug
+name = Fedora 11 Debug (%(arch)s)
+archs = %(_f11_archs)s
+checksum = sha256
+base_channels = fedora11-%(arch)s
+
+[fedora12]
+checksum = sha256
+archs = %(_f12_archs)s
+checksum = sha256
+name = Fedora 12 (%(arch)s)
+
+[fedora12-updates]
+label = %(base_channel)s-updates
+name = Fedora 12 Updates (%(arch)s)
+archs = %(_f12_archs)s
+checksum = sha256
+base_channels = fedora12-%(arch)s
+
+[fedora12-debug]
+label = %(base_channel)s-debug
+name = Fedora 12 Debug (%(arch)s)
+archs = %(_f12_archs)s
+checksum = sha256
+base_channels = fedora12-%(arch)s
+
+[spacewalk08-server]
+label = spacewalk08-server-%(base_channel)s
+name = Spacewalk Server 0.8 (%(arch)s)
+archs = i386, x86_64
+base_channels = fedora12-%(arch)s fedora11-%(arch)s centos5-%(arch)s
+
+[spacewalk08-client]
+label = spacewalk08-client-%(base_channel)s
+name = Spacewalk Client 0.8 (%(arch)s)
+archs = i386, x86_64
+base_channels = fedora12-%(arch)s fedora11-%(arch)s centos5-%(arch)s
+
+[centos5]
+archs = %(_x86_archs)s
+name = CentOS-5 (%(arch)s)
+
+
+[centos5-addons]
+label = %(base_channel)s-addons
+archs = %(_x86_archs)s
+name = CentOS 5 Addons (%(arch)s)
+base_channels = centos5-%(arch)s
+
+[centos5-centosplus]
+label = %(base_channel)s-centosplus
+archs = %(_x86_archs)s
+name = CentOS 5 Plus (%(arch)s)
+base_channels = centos5-%(arch)s
+
+[centos5-contrib]
+label = %(base_channel)s-contrib
+archs = %(_x86_archs)s
+name = CentOS 5 Contrib (%(arch)s)
+base_channels = centos5-%(arch)s
+
+[centos5-extras]
+label = %(base_channel)s-extras
+archs = %(_x86_archs)s
+name = CentOS 5 Extras (%(arch)s)
+base_channels = centos5-%(arch)s
+
+[centos5-fasttrack]
+label = %(base_channel)s-fasttrack
+archs = %(_x86_archs)s
+name = CentOS 5 FastTrack (%(arch)s)
+base_channels = centos5-%(arch)s
+
+[centos5-updates]
+label = %(base_channel)s-updates
+archs = %(_x86_archs)s
+name = CentOS 5 Updates (%(arch)s)
+base_channels = centos5-%(arch)s
+
+
+[epel5]
+label = epel5-%(base_channel)s
+name = EPEL 5 (%(arch)s)
+archs = i386, x86_64, ppc
+base_channels = centos5-%(arch)s
+
+# epel5 - for centos
+# vmware tools
+# 'centos4' : [ '',
+# ['alpha', 'i386', 'ia64', 's390',
's390x', 'x86_64'],
+# ['centos4', 'CentOS-4', 'CentOS-4'],
+# [ ['centos4-addons', 'CentOS 4 Addons',
'CentOS 4 Addons'],
+# ['centos4-centosplus', 'CentOS 4 Plus',
'CentOS 4 Plus'],
+# ['centos4-contrib', 'CentOS 4 Contrib',
'CentOS 4 Contrib'],
+# ['centos4-csgfs', 'CentOS 4 CS/GFS',
'CentOS 4 CS/GFS'],
+# ['centos4-extras', 'CentOS 4 Extras',
'CentOS 4 Extras'],
+# ['centos4-fasttrack', 'CentOS 4 FastTrack',
'CentOS 4 FastTrack'],
+# ['centos4-updates', 'CentOS 4 Updates',
'CentOS 4 Updates'],
+# ],
+# ],
+# }
+