Refactor to /opt/planetstack, final tweaks to make sure planetstack can run in non-openstack mode, adjustments to GUI for model focus changes
diff --git a/planetstack/importer/plclassic/__init__.py b/planetstack/importer/plclassic/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/planetstack/importer/plclassic/__init__.py
diff --git a/planetstack/importer/plclassic/importer.py b/planetstack/importer/plclassic/importer.py
new file mode 100644
index 0000000..3a65dc3
--- /dev/null
+++ b/planetstack/importer/plclassic/importer.py
@@ -0,0 +1,70 @@
+import os
+#os.environ.setdefault("DJANGO_SETTINGS_MODULE", "planetstack.settings")
+import sys
+from optparse import OptionParser
+from getpass import getpass
+import xmlrpclib
+from plclassic.site_importer import SiteImporter
+from plclassic.user_importer import UserImporter
+from plclassic.slice_importer import SliceImporter
+from plclassic.sliver_importer import SliverImporter
+
+
+class Call:
+ def __init__(self, callable, auth):
+ self.callable = callable
+ self.auth = auth
+
+ def __call__(self, *args, **kwds):
+ a = [self.auth] + list(args)
+ return self.callable(*a)
+
+class API():
+ def __init__(self, username, password, url):
+ self.auth = {'AuthMethod': 'password',
+ 'Username': username,
+ 'AuthString': password}
+ self.server = xmlrpclib.ServerProxy(url, allow_none=True)
+
+ def __getattr__(self, name):
+ return Call(getattr(self.server, name), self.auth)
+
+class Importer:
+
+ def __init__(self, username, password, url):
+ api = API(username, password, url)
+ self.sites = SiteImporter(api)
+ self.slices = SliceImporter(api)
+ self.users = UserImporter(api)
+ self.slivers = SliverImporter(api)
+
+ def run(self):
+ self.sites.run()
+ self.users.run()
+ self.slices.run(remote_sites=self.sites.remote_sites,
+ local_sites=self.sites.local_sites)
+ self.slivers.run()
+
+
+
+if __name__ == '__main__':
+ parser = OptionParser()
+
+ parser.add_option("-u", "--username", dest="username",
+ help="PLC username with which to authenticate")
+ parser.add_option("", "--url", dest="url",
+ help="PLC url to contact")
+
+ (config, args) = parser.parse_args()
+ if len(sys.argv) == 1:
+ parser.print_help()
+ sys.exit(1)
+
+ password = None
+ try:
+ password = getpass()
+ except (EOFError, KeyboardInterrupt):
+ print
+ sys.exit(0)
+
+ Importer(config.username, password, config.url).run()
diff --git a/planetstack/importer/plclassic/role_importer.py b/planetstack/importer/plclassic/role_importer.py
new file mode 100644
index 0000000..107587a
--- /dev/null
+++ b/planetstack/importer/plclassic/role_importer.py
@@ -0,0 +1,9 @@
+class RoleImporter:
+
+ def __init__(self, api):
+ self.api = api
+
+ def run(self):
+
+ return
+
diff --git a/planetstack/importer/plclassic/site_importer.py b/planetstack/importer/plclassic/site_importer.py
new file mode 100644
index 0000000..2ee8157
--- /dev/null
+++ b/planetstack/importer/plclassic/site_importer.py
@@ -0,0 +1,33 @@
+from core.models import Site
+
+class SiteImporter:
+
+ def __init__(self, api):
+ self.api = api
+ self.remote_sites = {}
+ self.local_sites = {}
+
+ def run(self):
+ db_sites = Site.objects.all()
+ for db_site in db_sites:
+ self.local_sites[db_site.login_base] = db_site
+ print "%s local sites" % len(db_sites)
+
+ sites = self.api.GetSites({'peer_id': None})
+ print "%s remote sites" % len(sites)
+ count = 0
+ for site in sites:
+ self.remote_sites[site['site_id']] = site
+ if site['login_base'] not in self.local_sites:
+ new_site = Site(name=site['name'],
+ login_base=site['login_base'],
+ site_url=site['url'],
+ enabled=site['enabled'],
+ longitude=site['longitude'],
+ latitude=site['latitude'],
+ is_public=site['is_public'],
+ abbreviated_name=site['abbreviated_name'])
+ new_site.save()
+ count += 1
+ self.local_sites[new_site.login_base] = new_site
+ print "imported %s sites" % count
diff --git a/planetstack/importer/plclassic/slice_importer.py b/planetstack/importer/plclassic/slice_importer.py
new file mode 100644
index 0000000..b25b483
--- /dev/null
+++ b/planetstack/importer/plclassic/slice_importer.py
@@ -0,0 +1,47 @@
+from core.models import Slice
+
+class SliceImporter:
+
+ def __init__(self, api):
+ self.api = api
+ self.remote_slices = {}
+ self.local_slices = {}
+
+ def run(self, remote_sites={}, local_sites={}):
+ if not remote_sites:
+ sites = self.api.GetSites({'peer_id': None})
+ for site in sites:
+ remote_sites[site['site_id']] = site
+
+
+ if not local_sites:
+ from core.models import Site
+ sites = Site.objects.all()
+ for site in sites:
+ local_sites[site.login_base] = site
+
+ db_slices = Slice.objects.all()
+ for db_slice in db_slices:
+ self.local_slices[db_slice.name] = db_slice
+ print "%s local slices" % len(db_slices)
+
+ slices = self.api.GetSlices({'peer_id': None})
+ print "%s remote slices" % len(slices)
+ count = 0
+ for slice in slices:
+ self.remote_slices[slice['slice_id']] = slice
+ if slice['name'] not in self.local_slices:
+ site = local_sites[remote_sites[slice['site_id']]['login_base']]
+ new_slice = Slice(name=slice['name'],
+ instantiation=slice['instantiation'],
+ omf_friendly = False,
+ description = slice['description'],
+ slice_url = slice['url'],
+ site = site)
+ new_slice.save()
+ count += 1
+ self.local_slices[new_slice.name] = new_slice
+ print "Imported %s slices" % count
+
+
+
diff --git a/planetstack/importer/plclassic/sliver_importer.py b/planetstack/importer/plclassic/sliver_importer.py
new file mode 100644
index 0000000..3f7912f
--- /dev/null
+++ b/planetstack/importer/plclassic/sliver_importer.py
@@ -0,0 +1,9 @@
+from PLC.Nodes import Nodes
+
+class SliverImporter:
+
+ def __init__(self, api):
+ self.api = api
+
+ def run(self):
+ return
diff --git a/planetstack/importer/plclassic/user_importer.py b/planetstack/importer/plclassic/user_importer.py
new file mode 100644
index 0000000..21d74b6
--- /dev/null
+++ b/planetstack/importer/plclassic/user_importer.py
@@ -0,0 +1,19 @@
+
+class UserImporter:
+
+ def __init__(self, api):
+ self.api = api
+ self.users = {}
+
+ def run(self):
+ users = self.api.GetPersons()
+
+ def save_site_privs(self, user):
+ # update site roles
+ pass
+
+ def save_slice_privs(self, user):
+ # update slice roles
+ pass
+
+