2 #this script is for migrating sites, user from PLC to PLE
5 from optparse import OptionParser
6 from pprint import PrettyPrinter
11 subversion_id = "$Id Amine"
15 #Remote(PLC) Api connexion
16 self.remote_name="PLC"
17 self.remote_url="https://tac.inria.fr:443/PLCAPI/"
18 self.remote_server=xmlrpclib.Server(self.remote_url,allow_none=True)
19 #local(PLE) Api connexion
21 self.local_url="https://garfield.inria.fr:443/PLCAPI/"
22 self.local_server=xmlrpclib.Server(self.local_url,allow_none=True)
26 return {'Username': 'root@plc2.inria.fr',
27 'AuthMethod':'password',
32 def remote_auth(self):
33 return {'Username': 'root@plc1.inria.fr',
34 'AuthMethod':'password',
35 'AuthString':'******',
39 def header(self,message):
40 now=time.strftime("%H:%M:%S", time.localtime())
41 print "*",now,'--',message
43 def migrate_persons(self, person_ids, site_id):
44 self.header("Dealing with persons migration")
45 for person_id in person_ids:
46 remote_person=self.remote_server.GetPersons(self.remote_auth(),{'person_id':person_id})
47 remote_person[0]['peer_id']= None
48 self.header("Migrating from %s to %s the person %s \n"%(self.remote_name,self.local_name,
50 local_person=self.local_server.AddPerson(self.local_auth(),remote_person[0])
51 self.header("Add %s to Site %d \n"%(remote_person[0]['email'],site_id))
52 status=self.local_server.AddPersonToSite(self.local_auth(),
53 remote_person[0]['email'],site_id)
55 #Add roles to person the same that he has in his remote platform
57 #Adding person to slice
59 def migrate_sites(self,sites_names):
60 self.header("Dealing with sites migration")
61 for site_name in sites_names:
62 remote_site=self.remote_server.GetSites(self.remote_auth(),{'name':site_name})
63 self.header("Migrating from %s the site %s \n"%(self.remote_name,remote_site))
64 remote_persons_ids=remote_site[0]['person_ids']
65 peer_site_id=remote_site[0]['site_id']
66 #make some changes to the new incoming site
67 remote_site[0]['peer_site_id']=peer_site_id
68 remote_site[0]['peer_id']= None
69 remote_site[0]['login_base']=remote_site[0]['login_base']+'ple'
70 remote_site[0]['enabled']=True
71 local_site=self.local_server.AddSite(self.local_auth(),remote_site[0])
72 #May be we have to manage the site address too.... to be coded
73 self.header("Getting in %s a new site %s\n"%(self.local_name,
74 self.local_server.GetSites(self.local_auth(),
75 {'site_id':local_site})))
76 #getting person involved in the remote site
77 self.migrate_persons(remote_persons_ids,local_site)
81 usage = """usage: %%prog sites_names [site_name1][site_name2].......
83 parser=OptionParser(usage=usage,version=self.subversion_id)
84 parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=False,
85 help="Run in verbose mode")
86 (self.options, self.args) = parser.parse_args()
88 if len(self.args) == 0:
91 self.migrate_sites(self.args)
104 if __name__ == "__main__":
105 sys.exit(Migration().main())