After a long time watching closely the evolution of Spacewalk (you know, the open source Redhat Satellite server), I decided to move on to its version 1.0. I have a working installation with more than 40 clients since version 0.2 and I followed all upgrades until version 0.8. At some time there I decided to wait for version 1.0 to move to a new server with adequate resources to handle the load. I must admit that I had a secret hope of not installing Oracle again.
I proceeded to the installation as per the spacewalk instructions and everything went smoothly. The I wanted to create my software channel. The plan is to create a Base channel of every CentOS and Redhat Update release and then have additional repos as child channels for each. This created a need for almost 20 channels with tens of clicks and repeated input. Ok, I can’t do it… I am not a Windows admin thus I hate anything that has to be completed with more than 2-3 clicks… Time for scripting!
I have downloaded the extended_create_channel.py from Spacewalk Wiki in order to use it in a simple bash script. For my disappointment it created channels without essential data such as the GPG keys and Yum Repositories information. It was high time for me to refresh my python to extend the script. The script is here and I believe is quite self explained.
#
# Copyright (c) 2008 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.
#
# Note: Alexandros Soumplis - 09 June 2010
# Changes: * Support for GPG info definition
# * Support for Yum Repositories definition
# * Support for Checksum Type definition
# * Command Line Arguments Error Handling
# * Comments and beautification of code
#
# Note: by JonW 3/7/08
# I have extended the original script to include arch and parent channels
# to allow child channels to be created by this script.
import struct
import xmlrpclib
from optparse import OptionParser
# options parsing
usage = "%prog [options]"
parser = OptionParser(usage=usage, description="")
parser.add_option("--user", dest="user",
help="Spacewalk user with administrative privileges")
parser.add_option("--password", dest="password",
help="Spacewalk password")
parser.add_option("--host", dest="host",
help="Spacewalk hostname")
parser.add_option("--label", dest="label",
help="Channel label")
parser.add_option("--name", dest="name",
help="Channel name")
parser.add_option("--summary", dest="summary",
help="Channel summary")
parser.add_option("--parent", dest="parent", default='',
help="Parent channel label")
parser.add_option("--arch", dest="arch", default="channel-ia32",
help="Channel architecture (channel-x86_64, channel-ia32, channel-ia64)")
parser.add_option("--gpgurl", dest="gpgurl", default="http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5",
help="GPG Key Url")
parser.add_option("--gpgid", dest="gpgid", default="E8562897",
help="GPG Key ID")
parser.add_option("--gpgfinger", dest="gpgfinger", default="473D 66D5 2122 71FD 51CC 17B1 A8A4 47DC E856 2897",
help="GPG Fingerprint")
parser.add_option("--checksumType", dest="checksumType", default="sha1",
help="Yum Repository Checksum Type")
parser.add_option("--yumurl", dest="yumurl",
help="Yum Repository URL")
parser.add_option("--yumlabel", dest="yumlabel",
help="Yum Repository Label")
parser.add_option("--yumsync", dest="yumsync", default=True,
help="Yum Repository Sync")
parser.add_option("--debug", dest="debug", default=False,
help="Enable debug output")
(options, terms) = parser.parse_args()
# Check the mandatory options have been defined
mandatories = ["user", "password", "host", "label", "name", "summary", "yumurl", "yumlabel"]
for m in mandatories:
if not options.__dict__[m]:
print "\nRequired option --%s is missing\n" % m
parser.print_help()
parser.exit(-1)
SPACEWALK_URL = "http://%s/rpc/api" % options.host
client = xmlrpclib.Server(SPACEWALK_URL, verbose=0)
# Login to spacewalk server
def login(name = options.user, password = options.password):
return client.auth.login(name, password)
# Logout from spacewalk server
def logout(key):
client.auth.logout(key)
# Define the gpgKey value
def gpgKey():
gpgKey = {}
gpgKey['url'] = options.gpgurl
gpgKey['id'] = options.gpgid
gpgKey['fingerprint'] = options.gpgfinger
return gpgKey
# Define Yum Repository options
def yumrepo():
yum = {}
yum['url'] = options.yumurl
yum['label'] = options.yumlabel
yum['sync'] = bool(options.yumsync)
return yum
# Create the software channels
def create(key, label, name, summary, arch = options.arch, parent = options.parent, checksumType = options.checksumType, gpg = gpgKey(), yum = yumrepo() ):
return client.channel.software.create(key, label, name, summary, arch, parent, checksumType, gpg, yum)
def main():
key = login(options.user,options.password)
create(key, label = options.label, name = options.name, summary = options.summary)
logout(key)
if __name__ == "__main__":
main()
Soumplis' Personal Web Site
Leave a Reply