2 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "plstackapi.planetstack.settings")
4 from optparse import OptionParser
5 from getpass import getpass
7 from plstackapi.importer.plclassic.site_importer import SiteImporter
8 from plstackapi.importer.plclassic.user_importer import UserImporter
9 from plstackapi.importer.plclassic.slice_importer import SliceImporter
10 from plstackapi.importer.plclassic.sliver_importer import SliverImporter
14 def __init__(self, callable, auth):
15 self.callable = callable
18 def __call__(self, *args, **kwds):
19 a = [self.auth] + list(args)
20 return self.callable(*a)
23 def __init__(self, username, password, url):
24 self.auth = {'AuthMethod': 'password',
26 'AuthString': password}
27 self.server = xmlrpclib.ServerProxy(url, allow_none=True)
29 def __getattr__(self, name):
30 return Call(getattr(self.server, name), self.auth)
34 def __init__(self, username, password, url):
35 api = API(username, password, url)
36 self.sites = SiteImporter(api)
37 self.slices = SliceImporter(api)
38 self.users = UserImporter(api)
39 self.slivers = SliverImporter(api)
44 self.slices.run(remote_sites=self.sites.remote_sites,
45 local_sites=self.sites.local_sites)
50 if __name__ == '__main__':
51 parser = OptionParser()
53 parser.add_option("-u", "--username", dest="username",
54 help="PLC username with which to authenticate")
55 parser.add_option("", "--url", dest="url",
56 help="PLC url to contact")
58 (config, args) = parser.parse_args()
59 if len(sys.argv) == 1:
66 except (EOFError, KeyboardInterrupt):
70 Importer(config.username, password, config.url).run()