checkin importer
diff --git a/plstackapi/importer/plclassic/__init__.py b/plstackapi/importer/plclassic/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/plstackapi/importer/plclassic/__init__.py
diff --git a/plstackapi/importer/plclassic/importer.py b/plstackapi/importer/plclassic/importer.py
new file mode 100644
index 0000000..88ea1b1
--- /dev/null
+++ b/plstackapi/importer/plclassic/importer.py
@@ -0,0 +1,43 @@
+import xmlrpclib
+from importer.planetstack.role_importer import RoleImporter
+from importer.planetstack.site_importer import SiteImporter
+from importer.planetstack.user_importer import UserImporter
+from importer.planetstack.slice_importer import SliceImporter
+from importer.planetstack.sliver_importer import SliverImporter
+
+
+class Call:
+ def __init__(self, callable, auth):
+ self.callable = callable
+ self.auth = auth
+
+ def __call__(self, *args, **kwds):
+ a = [auth] + args
+ return self.callable(*a)
+
+class API():
+ def __init__(self):
+ self.auth = {}
+ 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):
+ self.api = API()
+ self.roles = RoleImporter(self)
+ self.sites = SiteImporter(self)
+ self.users = UserImporter(self)
+ self.slices = SliceImporter(self)
+ self.slivers = SliverImporter(self)
+
+ def run(self):
+ self.roles.run()
+ self.sites.run()
+ self.users.run()
+ self.slices.run()
+ self.slivers.run()
+
+
diff --git a/plstackapi/importer/plclassic/role_importer.py b/plstackapi/importer/plclassic/role_importer.py
new file mode 100644
index 0000000..7404ce3
--- /dev/null
+++ b/plstackapi/importer/plclassic/role_importer.py
@@ -0,0 +1,21 @@
+from PLC.Roles import Roles
+from model import Role
+
+class RoleImporter:
+
+ def __init__(self, importer):
+ self.importer = importer
+ self.roles = {}
+
+ def run(self):
+ roles = self.importer.api.GetRoles()
+ db_roles = Role.objects.all()
+ db_roles_list = [db_role['name'] for db_role in db_roles]
+ for role in roles:
+ if role['name'] not in db_roles_list:
+ new_role = Role(name=role['name'])
+ new_role.save()
+ self.roles[role['role_id']] = role
+
+
+
diff --git a/plstackapi/importer/plclassic/site_importer.py b/plstackapi/importer/plclassic/site_importer.py
new file mode 100644
index 0000000..efd3933
--- /dev/null
+++ b/plstackapi/importer/plclassic/site_importer.py
@@ -0,0 +1,27 @@
+from PLC.Sites import Sites
+from models import Site
+
+class SiteImporter:
+
+ def __init__(self, importer):
+ self.importer = importer
+ self.sites = {}
+
+ def run(self):
+ sites = Sites(self.importer.api)
+ db_sites = Site.objects.all()
+ db_site_names = [s['login_base'] for s in db_sites]
+ for site in sites:
+ if site['login_base'] not in db_site_names:
+ new_site = Site(name=site['name'],
+ 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()
+ self.sites[site['site_id']] = site
+
+
+
diff --git a/plstackapi/importer/plclassic/slice_importer.py b/plstackapi/importer/plclassic/slice_importer.py
new file mode 100644
index 0000000..02247f1
--- /dev/null
+++ b/plstackapi/importer/plclassic/slice_importer.py
@@ -0,0 +1,25 @@
+from PLC.Slices import Slices
+from models import Slice
+
+class SliceImporter:
+
+ def __init__(self, importer):
+ self.importer = importer
+ self.slices = {}
+
+ def run(self):
+ slices = Slices(self.importer.api)
+ db_slices = Slice.objects.all()
+ slice_names = [s['name'] for s in db_slices]
+ for slice in slices:
+ if slice['name'] not in slice_names:
+ new_slices = Slice(name=slice['name'],
+ instantiation=slice['instantiation'],
+ omf_friendly = False,
+ description = slice['description'],
+ slice_url = slice['url'])
+ new_slice.save();
+ self.slices[slice['slice_id']] = slice
+
+
+
diff --git a/plstackapi/importer/plclassic/sliver_importer.py b/plstackapi/importer/plclassic/sliver_importer.py
new file mode 100644
index 0000000..3bce228
--- /dev/null
+++ b/plstackapi/importer/plclassic/sliver_importer.py
@@ -0,0 +1,14 @@
+from PLC.Nodes import Nodes
+
+class SliverImporter:
+
+ def __init__(self, importer):
+ self.importer = importer
+ self.slivers = {}
+
+ def run(self):
+ nodes = Nodes(self.importer.api)
+ for node in nodes:
+ slice_id in node['slice_ids']:
+ self.slivers[(slice['slice_id'], node['node_id'])] = slice
+
diff --git a/plstackapi/importer/plclassic/user_importer.py b/plstackapi/importer/plclassic/user_importer.py
new file mode 100644
index 0000000..7476967
--- /dev/null
+++ b/plstackapi/importer/plclassic/user_importer.py
@@ -0,0 +1,35 @@
+from PLC.Persons import Persons
+from models import User
+
+class UserImporter:
+
+ def __init__(self, importer):
+ self.importer = importer
+ self.users = {}
+
+ def run(self):
+ users = Persons(self.importer.api)
+ db_users = User.objects.all()
+ usernames = [u['email'] for u in db_users]
+ for user in users:
+ if user['email'] not in usernames:
+ new_user = User(firstname=user['first_name'],
+ lastname=user['last_name'],
+ email=user['email'],
+ phone=user['phone'],
+ user_url = user['url'],
+ site = user['sites_ids'][0])
+ new_user.save()
+ self.save_site_privs(user)
+ self.save_slice_privs(user)
+ self.users[user['person_id']] = user
+
+ def save_site_privs(self, user):
+ # update site roles
+ pass
+
+ def save_slice_privs(self, user):
+ # update slice roles
+ pass
+
+