update importers
diff --git a/plstackapi/importer/plclassic/importer.py b/plstackapi/importer/plclassic/importer.py
index 3a2113f..4cf5fb9 100644
--- a/plstackapi/importer/plclassic/importer.py
+++ b/plstackapi/importer/plclassic/importer.py
@@ -1,9 +1,9 @@
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
+from plstackapi.importer.plclassic.role_importer import RoleImporter
+from plstackapi.importer.plclassic.site_importer import SiteImporter
+from plstackapi.importer.plclassic.user_importer import UserImporter
+from plstackapi.importer.plclassic.slice_importer import SliceImporter
+from plstackapi.importer.plclassic.sliver_importer import SliverImporter
class Call:
@@ -28,12 +28,12 @@
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)
+ api = API()
+ self.roles = RoleImporter(api)
+ self.sites = SiteImporter(api)
+ self.slices = SliceImporter(api, remote_sites=self.sites.remote_sites, local_sites=self.sites.local_sites)
+ self.users = UserImporter(api)
+ self.slivers = SliverImporter(api)
def run(self):
self.roles.run()
diff --git a/plstackapi/importer/plclassic/role_importer.py b/plstackapi/importer/plclassic/role_importer.py
index 7404ce3..107587a 100644
--- a/plstackapi/importer/plclassic/role_importer.py
+++ b/plstackapi/importer/plclassic/role_importer.py
@@ -1,21 +1,9 @@
-from PLC.Roles import Roles
-from model import Role
-
class RoleImporter:
- def __init__(self, importer):
- self.importer = importer
- self.roles = {}
+ def __init__(self, api):
+ self.api = api
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
-
+ return
diff --git a/plstackapi/importer/plclassic/site_importer.py b/plstackapi/importer/plclassic/site_importer.py
index efd3933..c7bdf21 100644
--- a/plstackapi/importer/plclassic/site_importer.py
+++ b/plstackapi/importer/plclassic/site_importer.py
@@ -1,18 +1,21 @@
-from PLC.Sites import Sites
-from models import Site
+from plstackapi.core.models import Site
class SiteImporter:
- def __init__(self, importer):
- self.importer = importer
- self.sites = {}
+ def __init__(self, api):
+ self.api = api
+ self.remote_sites = {}
+ self.local_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 db_site in db_sites:
+ self.local_sites[db_site.login_base] = db_site
+
+ sites = self.api.GetSites()
for site in sites:
- if site['login_base'] not in db_site_names:
+ self.remote_sites[site['site_id']] = site
+ if site['login_base'] not in self.local_sites:
new_site = Site(name=site['name'],
site_url=site['url'],
enabled=site['enabled'],
@@ -21,7 +24,4 @@
is_public=site['is_public'],
abbreviated_name=site['abbreviated_name'])
new_site.save()
- self.sites[site['site_id']] = site
-
-
-
+ self.local_sites[new_site.login_base] = new_site
diff --git a/plstackapi/importer/plclassic/slice_importer.py b/plstackapi/importer/plclassic/slice_importer.py
index 02247f1..4f7504d 100644
--- a/plstackapi/importer/plclassic/slice_importer.py
+++ b/plstackapi/importer/plclassic/slice_importer.py
@@ -1,25 +1,41 @@
-from PLC.Slices import Slices
-from models import Slice
+from plstackapi.core.models import Slice
class SliceImporter:
- def __init__(self, importer):
- self.importer = importer
- self.slices = {}
+ def __init__(self, api):
+ self.api = api
+ self.remote_slices = {}
+ self.local_slices = {}
- def run(self):
- slices = Slices(self.importer.api)
+ def run(self, remote_sites={}, local_sites={}):
+ if not remote_sites:
+ sites = self.api.GetSites()
+ for site in sites:
+ remote_sites[site['site_id']] = site
+
+ if not local_sites:
+ from models import Site
+ sites = Site.objects.all()
+ for site in sites:
+ local_sites[site.login_base] = site
+
db_slices = Slice.objects.all()
- slice_names = [s['name'] for s in db_slices]
+ for db_slice in db_slices:
+ self.local_slices[db_slice.name] = db_slice
+
+ slices = api.GetSlices()
for slice in slices:
- if slice['name'] not in slice_names:
+ self.remote_slice[slice['slice_id']] = slice
+ if slice['name'] not in self.local_slices:
+ site = local_sites[remote_sites[slice['site_id']]['login_base']]
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
+ slice_url = slice['url'],
+ site = site)
+ new_slice.save()
+ self.local_slices[new_slice.name] = new_slice
diff --git a/plstackapi/importer/plclassic/sliver_importer.py b/plstackapi/importer/plclassic/sliver_importer.py
index 3bce228..3f7912f 100644
--- a/plstackapi/importer/plclassic/sliver_importer.py
+++ b/plstackapi/importer/plclassic/sliver_importer.py
@@ -2,13 +2,8 @@
class SliverImporter:
- def __init__(self, importer):
- self.importer = importer
- self.slivers = {}
+ def __init__(self, api):
+ self.api = api
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
-
+ return
diff --git a/plstackapi/importer/plclassic/user_importer.py b/plstackapi/importer/plclassic/user_importer.py
index 7476967..21d74b6 100644
--- a/plstackapi/importer/plclassic/user_importer.py
+++ b/plstackapi/importer/plclassic/user_importer.py
@@ -1,28 +1,12 @@
-from PLC.Persons import Persons
-from models import User
class UserImporter:
- def __init__(self, importer):
- self.importer = importer
+ def __init__(self, api):
+ self.api = api
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
+ users = self.api.GetPersons()
def save_site_privs(self, user):
# update site roles
diff --git a/setup.py b/setup.py
index 12e94ec..5a29e4a 100644
--- a/setup.py
+++ b/setup.py
@@ -8,4 +8,5 @@
scripts=['plstackapi/plstackapi-debug-server.py'],
data_files=[
('/etc/planetstack/', ['config/plstackapi_config']),
+ ('/opt/planetstack/', glob('plstackapi/planetstack/*')),
])