Tony Mack | 09078f0 | 2013-04-02 07:53:46 -0400 | [diff] [blame] | 1 | import os |
Tony Mack | 59c762a | 2013-04-02 09:42:10 -0400 | [diff] [blame^] | 2 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "plstackapi.planetstack.settings") |
Tony Mack | f593dba | 2013-03-24 13:17:43 -0400 | [diff] [blame] | 3 | import xmlrpclib |
Tony Mack | 743ddf2 | 2013-04-02 07:36:25 -0400 | [diff] [blame] | 4 | from plstackapi.importer.plclassic.site_importer import SiteImporter |
| 5 | from plstackapi.importer.plclassic.user_importer import UserImporter |
| 6 | from plstackapi.importer.plclassic.slice_importer import SliceImporter |
| 7 | from plstackapi.importer.plclassic.sliver_importer import SliverImporter |
Tony Mack | f593dba | 2013-03-24 13:17:43 -0400 | [diff] [blame] | 8 | |
| 9 | |
| 10 | class Call: |
| 11 | def __init__(self, callable, auth): |
| 12 | self.callable = callable |
| 13 | self.auth = auth |
| 14 | |
| 15 | def __call__(self, *args, **kwds): |
| 16 | a = [auth] + args |
| 17 | return self.callable(*a) |
| 18 | |
| 19 | class API(): |
Tony Mack | 59c762a | 2013-04-02 09:42:10 -0400 | [diff] [blame^] | 20 | def __init__(self, username, password, url): |
Tony Mack | 8eeddf9 | 2013-03-26 13:42:59 -0400 | [diff] [blame] | 21 | self.auth = {'AuthMethod': 'password', |
Tony Mack | 59c762a | 2013-04-02 09:42:10 -0400 | [diff] [blame^] | 22 | 'Username': username, |
| 23 | 'AuthString': password} |
| 24 | self.server = xmlrpclib.ServerProxy(url, allow_none=True) |
Tony Mack | f593dba | 2013-03-24 13:17:43 -0400 | [diff] [blame] | 25 | |
| 26 | def __getattr__(self, name): |
| 27 | return Call(getattr(self.server, name), self.auth) |
| 28 | |
| 29 | class Importer: |
| 30 | |
Tony Mack | 59c762a | 2013-04-02 09:42:10 -0400 | [diff] [blame^] | 31 | def __init__(self, username, password, url): |
| 32 | api = API(username, password, url) |
Tony Mack | 743ddf2 | 2013-04-02 07:36:25 -0400 | [diff] [blame] | 33 | self.sites = SiteImporter(api) |
| 34 | self.slices = SliceImporter(api, remote_sites=self.sites.remote_sites, local_sites=self.sites.local_sites) |
| 35 | self.users = UserImporter(api) |
| 36 | self.slivers = SliverImporter(api) |
Tony Mack | f593dba | 2013-03-24 13:17:43 -0400 | [diff] [blame] | 37 | |
| 38 | def run(self): |
| 39 | self.roles.run() |
| 40 | self.sites.run() |
| 41 | self.users.run() |
| 42 | self.slices.run() |
| 43 | self.slivers.run() |
| 44 | |
| 45 | |
Tony Mack | 09078f0 | 2013-04-02 07:53:46 -0400 | [diff] [blame] | 46 | |
| 47 | if __name__ == '__main__': |
Tony Mack | 09078f0 | 2013-04-02 07:53:46 -0400 | [diff] [blame] | 48 | Importer().run() |