Merge branch 'master' of https://github.com/open-cloud/xos
diff --git a/xos/core/xoslib/methods/loginview.py b/xos/core/xoslib/methods/loginview.py
new file mode 100644
index 0000000..f485aa0
--- /dev/null
+++ b/xos/core/xoslib/methods/loginview.py
@@ -0,0 +1,58 @@
+from rest_framework.decorators import api_view
+from rest_framework.response import Response
+from rest_framework.reverse import reverse
+from rest_framework import serializers
+from rest_framework import generics
+from rest_framework.views import APIView
+from core.models import *
+from services.hpc.models import *
+from services.requestrouter.models import *
+from django.forms import widgets
+from django.core.exceptions import PermissionDenied
+from django.contrib.contenttypes.models import ContentType
+import json
+import socket
+import time
+import django.middleware.csrf
+from xos.exceptions import *
+
+class LoginView(APIView):
+    method_kind = "list"
+    method_name = "login"
+
+    def do_login(self, request, username, password):
+        if not username:
+            raise XOSMissingField("No username specified")
+
+        if not password:
+            raise XOSMissingField("No password specified")
+
+        u = User.objects.filter(email=username)
+        if not u:
+            raise XOSNotFound("User %s does not exist" % username)
+
+        u=u[0]
+
+        if not u.check_password(password):
+            raise PermissionDenied("Incorrect password")
+
+        auth = {"username": username, "password": password}
+        request.session["auth"] = auth
+        request.session.save()
+
+        return Response({"xoscsrftoken": django.middleware.csrf.get_token(request),
+                         "xossessionid": request.session.session_key})
+
+    def get(self, request, format=None):
+        username = request.GET.get("username", None)
+        password = request.GET.get("password", None)
+
+        return self.do_login(request, username, password)
+
+    def post(self, request, format=None):
+        username = request.DATA.get("username", None)
+        password = request.DATA.get("password", None)
+
+        return self.do_login(request, username, password)
+
+
diff --git a/xos/synchronizers/base/xos-synchronizer.py b/xos/synchronizers/base/xos-synchronizer.py
index 3fffd33..493b94a 100644
--- a/xos/synchronizers/base/xos-synchronizer.py
+++ b/xos/synchronizers/base/xos-synchronizer.py
@@ -8,7 +8,7 @@
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
 from synchronizers.base.backend import Backend
 from xos.config import Config, DEFAULT_CONFIG_FN
-from core.models import Instance
+from core.models import Instance,NetworkTemplate
 from xos.logger import Logger, logging, logger
 from django.db import ProgrammingError
 import time
@@ -67,9 +67,12 @@
     while not models_active:
         try:
             _ = Instance.objects.first()
+            _ = NetworkTemplate.objects.first()
             models_active = True
-        except ProgrammingError:
+        except Exception,e:
+            logger.info(str(e))
             logger.info('Waiting for data model to come up before starting...')
+            time.sleep(10)
             wait = True
 
     if (wait):
diff --git a/xos/synchronizers/openstack/xos-synchronizer.py b/xos/synchronizers/openstack/xos-synchronizer.py
index 3fffd33..493b94a 100644
--- a/xos/synchronizers/openstack/xos-synchronizer.py
+++ b/xos/synchronizers/openstack/xos-synchronizer.py
@@ -8,7 +8,7 @@
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
 from synchronizers.base.backend import Backend
 from xos.config import Config, DEFAULT_CONFIG_FN
-from core.models import Instance
+from core.models import Instance,NetworkTemplate
 from xos.logger import Logger, logging, logger
 from django.db import ProgrammingError
 import time
@@ -67,9 +67,12 @@
     while not models_active:
         try:
             _ = Instance.objects.first()
+            _ = NetworkTemplate.objects.first()
             models_active = True
-        except ProgrammingError:
+        except Exception,e:
+            logger.info(str(e))
             logger.info('Waiting for data model to come up before starting...')
+            time.sleep(10)
             wait = True
 
     if (wait):