From: thierry Date: Thu, 26 Feb 2009 12:26:25 +0000 (+0000) Subject: creation X-Git-Tag: foo~256 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=b60054bf604798bebbfccbefbcf7ab449158ec29;p=infrastructure.git creation --- diff --git a/scripts/alpha-repo.py b/scripts/alpha-repo.py new file mode 100755 index 0000000..cf23223 --- /dev/null +++ b/scripts/alpha-repo.py @@ -0,0 +1,141 @@ +#!/usr/bin/python + +# expected argument is a URL on build.onelab.eu +# this would then update the alpha node repo from that place +# NOTE +# the actual list of rpms that are needed or nodes is hard-coded + +import sys, os, os.path, glob, commands +from optparse import OptionParser + +standard_repo = '/var/www/html/install-rpms/onelab-i386' +alpha_repo = '%s-alpha'%standard_repo + +#################### from module-tools +def prompt (question,default=True): + + choices = [] + if default is True: choices.append('[y]') + else : choices.append('y') + if default is False: choices.append('[n]') + else : choices.append('n') + + try: + answer=raw_input(question + " " + "/".join(choices) + " ? ") + if not answer: + return default + answer=answer[0].lower() + if answer == 'y': + return True + elif answer == 'n': + return False + return prompt(question,default) + except: + raise + +def run (command,options,force=False): + if ( force or not options.dry_run): + print 'Running',command + os.system(command) + else: + print 'Would run',command + +# rewrite the http part into a rsync part +def http_to_rsync (http): + result = http.replace ('http://build.onelab.eu/','root@build.onelab.eu:/build/') + # canonicalize : strip last / if present + while (result[-1]=='/'): result=result[0:-1] + return result + +def rsync_xfer(http,repo,options): + xfer='%s/xfer'%repo + command='mkdir -p %s' % xfer + run(command,options) + + command='rsync -av' + if options.dry_run: command += ' -n' + command += ' ' + http_to_rsync(http) + ' ' + xfer + run (command,options) + +def rpm_name (rpm_file): + status,output = commands.getstatusoutput("rpm -q --qf '%%{NAME}' -p %s " % rpm_file) + return output + +def extract_contents (standard): + patt= '%s/*.rpm' % standard + rpm_files=glob.glob(patt) + contents = [ rpm_name(rpm_file) for rpm_file in rpm_files] + return contents + +def install_xfer (repo,rpm_name,options): + xfer_patt= '%s/xfer/RPMS/*/%s*.rpm' % (repo, rpm_name); + xfer_rpm_names=glob.glob(xfer_patt) + for xfer_rpm_name in xfer_rpm_names: + command = 'mv %s %s' % ( xfer_rpm_name, repo) + if prompt('Adopt %s'%os.path.basename(xfer_rpm_name)): + run(command,options) + +def remaining_rpms (root): + command="find %s -name '*.rpm'"%root + status,output = commands.getstatusoutput(command) + return output.split("\n") + +def scan_remaining (repo,options): + for rpm in remaining_rpms('%s/xfer' % repo): + basename=os.path.basename(rpm) + command="mv %s %s/%s"%(rpm,repo,basename) + if prompt('Adopt %s'%basename,False): + run (command,options) + +def main (): + usage="Usage:%prog http://build.onelab.eu/.../RPMS" + parser=OptionParser(usage=usage) + parser.add_option("-n","--dry-run",action="store_true",dest="dry_run",default=False, + help="dry run") + parser.add_option("-r","--repo",action="store",dest="repo",default=alpha_repo, + help="the repo to populate") + parser.add_option("-s","--std",action="store",dest="standard",default=standard_repo, + help="the standard repo, used to compute the set of rpms") + (options, args) = parser.parse_args() + if len(args) != 1: + parser.print_help() + sys.exit(1) + + http=args[0] + repo=options.repo + standard=options.standard + + xfer='%s/xfer'%repo + if os.path.isdir(xfer): + if prompt('Want to clean up %s'%xfer,False): + run('rm -rf %s'%xfer,options) + + if prompt ('Need to fetch rpms from %s ' % http): + rsync_xfer(http,repo,options) + + if prompt ('Get list of standard rpms from %s ' % standard): + rpm_names=extract_contents(standard) + + if prompt ('Moving standard rpms to %s' % repo): + for rpm_name in rpm_names: + install_xfer(repo,rpm_name,options) + + # once here, we have moved all the rpms that belonged to the standard noderepo + # let's manually scan the other ones as there might be new rpms needed + # the list proposed here contains mostly server-side rpms, + # so the prompt default is False + if prompt ('Scan remaining rpms for double-check'): + scan_remaining(repo,options) + + if prompt ('Nuke repodata (force complete reindexing)'): + command="rm -rf %s/repodata %s/signed-stamps"%(repo,repo) + run(command,options) + + if prompt ('Reindex'): + run('service plc start packages',options) + +if __name__ == '__main__': + main() + + +