From ea12790d094ff00d0b1f14fc6b756c26aeff62de Mon Sep 17 00:00:00 2001 From: amine Date: Wed, 19 Mar 2008 17:50:58 +0000 Subject: [PATCH] first draft for writing a migration script a start point for lip6 --- migration_scripts/Migration.py | 105 +++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100755 migration_scripts/Migration.py diff --git a/migration_scripts/Migration.py b/migration_scripts/Migration.py new file mode 100755 index 0000000..3e4ddee --- /dev/null +++ b/migration_scripts/Migration.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python +#this script is for migrating sites, user from PLC to PLE +import os,sys, time +import xmlrpclib +from optparse import OptionParser +from pprint import PrettyPrinter + + + +class Migration: + subversion_id = "$Id Amine" + + def __init__(self): + try: + #Remote(PLC) Api connexion + self.remote_name="PLC" + self.remote_url="https://tac.inria.fr:443/PLCAPI/" + self.remote_server=xmlrpclib.Server(self.remote_url,allow_none=True) + #local(PLE) Api connexion + self.local_name="PLE" + self.local_url="https://garfield.inria.fr:443/PLCAPI/" + self.local_server=xmlrpclib.Server(self.local_url,allow_none=True) + except : raise + + def local_auth(self): + return {'Username': 'root@plc2.inria.fr', + 'AuthMethod':'password', + 'AuthString':'*****', + 'Role' : 'root' + } + + def remote_auth(self): + return {'Username': 'root@plc1.inria.fr', + 'AuthMethod':'password', + 'AuthString':'******', + 'Role' : 'root' + } + + def header(self,message): + now=time.strftime("%H:%M:%S", time.localtime()) + print "*",now,'--',message + + def migrate_persons(self, person_ids, site_id): + self.header("Dealing with persons migration") + for person_id in person_ids: + remote_person=self.remote_server.GetPersons(self.remote_auth(),{'person_id':person_id}) + remote_person[0]['peer_id']= None + self.header("Migrating from %s to %s the person %s \n"%(self.remote_name,self.local_name, + remote_person[0])) + local_person=self.local_server.AddPerson(self.local_auth(),remote_person[0]) + self.header("Add %s to Site %d \n"%(remote_person[0]['email'],site_id)) + status=self.local_server.AddPersonToSite(self.local_auth(), + remote_person[0]['email'],site_id) + #to be coded + #Add roles to person the same that he has in his remote platform + #Adding keys + #Adding person to slice + + def migrate_sites(self,sites_names): + self.header("Dealing with sites migration") + for site_name in sites_names: + remote_site=self.remote_server.GetSites(self.remote_auth(),{'name':site_name}) + self.header("Migrating from %s the site %s \n"%(self.remote_name,remote_site)) + remote_persons_ids=remote_site[0]['person_ids'] + peer_site_id=remote_site[0]['site_id'] + #make some changes to the new incoming site + remote_site[0]['peer_site_id']=peer_site_id + remote_site[0]['peer_id']= None + remote_site[0]['login_base']=remote_site[0]['login_base']+'ple' + remote_site[0]['enabled']=True + local_site=self.local_server.AddSite(self.local_auth(),remote_site[0]) + #May be we have to manage the site address too.... to be coded + self.header("Getting in %s a new site %s\n"%(self.local_name, + self.local_server.GetSites(self.local_auth(), + {'site_id':local_site}))) + #getting person involved in the remote site + self.migrate_persons(remote_persons_ids,local_site) + return True + + def run (self): + usage = """usage: %%prog sites_names [site_name1][site_name2]....... + """ + parser=OptionParser(usage=usage,version=self.subversion_id) + parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=False, + help="Run in verbose mode") + (self.options, self.args) = parser.parse_args() + + if len(self.args) == 0: + print usage + else: + self.migrate_sites(self.args) + + + def main(self): + try: + success=self.run() + if success: + return 0 + else: + return 1 + except SystemExit: + raise + +if __name__ == "__main__": + sys.exit(Migration().main()) -- 2.43.0