Skip to content

Instantly share code, notes, and snippets.

@rafaelfelix
Created March 28, 2014 21:10
Show Gist options
  • Save rafaelfelix/9843048 to your computer and use it in GitHub Desktop.
Save rafaelfelix/9843048 to your computer and use it in GitHub Desktop.
A python script to call the syncRepo method from the Spacewalk API (http://www.spacewalkproject.org/documentation/api/2.1/handlers/ChannelSoftwareHandler.html#syncRepo). Configuration file example: https://gist.github.com/rafaelfelix/9844244
#!/usr/bin/python
# Script that calls the channels.software.syncRepo Spacewalk API method
#
# Author: Rafael Felix Correa <rafael.felix@gmail.com>
#
# This script is based on https://raw.githubusercontent.com/angrox/spacewalk-api-scripts/master/spacewalk-rhn-sync/spacewalk-rhn-sync.py
# Special thanks to Martin Zehetmayer <angrox@idle.at>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
import xmlrpclib
import httplib
import ConfigParser
import optparse
import sys
import os
from subprocess import *
from optparse import OptionParser
def parse_args():
parser = OptionParser()
parser.add_option("-s", "--spw-server", type="string", dest="spw_server",
help="Spacewalk Server")
parser.add_option("-u", "--spw-user", type="string", dest="spw_user",
help="Spacewalk User")
parser.add_option("-p", "--spw-pass", type="string", dest="spw_pass",
help="Spacewalk Password")
parser.add_option("-c", "--channel-label", type="string", dest="channel_label",
help="Channel Label: ie.\"rhel-x86_64-server-6\"")
parser.add_option("-f", "--config-file", type="string", dest="cfg_file",
help="Config file for this CLI")
parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False)
parser.add_option("-q", "--quiet", action="store_true", dest="quiet", default=False)
(options,args) = parser.parse_args()
return options
def main():
# Get the options
options = parse_args()
# read the config
if options.cfg_file is None:
print "Need a configurations file!"
print "Try use the --help option!"
sys.exit(2)
config = ConfigParser.ConfigParser()
config.read (options.cfg_file)
if options.spw_server is None:
options.spw_server = config.get ('Spacewalk', 'spw_server')
if options.spw_user is None:
options.spw_user = config.get ('Spacewalk', 'spw_user')
if options.spw_pass is None:
options.spw_pass = config.get ('Spacewalk', 'spw_pass')
if options.channel_label is None:
options.channel_label = config.get ('Spacewalk', 'channel_label')
spacewalk = xmlrpclib.Server("https://%s/rpc/api" % options.spw_server, verbose=0)
spacekey = spacewalk.auth.login(options.spw_user, options.spw_pass)
spacewalk.channel.software.syncRepo(spacekey, options.channel_label)
spacewalk.auth.logout(spacekey)
## MAIN
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment