Merge branch 'master' of ssh://git.planet-lab.org/git/plstackapi
diff --git a/opencloud.spec b/opencloud.spec
index 895b9dc..8a3df76 100644
--- a/opencloud.spec
+++ b/opencloud.spec
@@ -49,6 +49,11 @@
 pip-python install django-ipware
 pip-python install django-encrypted-fields
 pip-python install python-keyczar
+pip-python install python-keystoneclient
+pip-python install python-novaclient
+pip-python install python-neutronclient 
+pip-python install python-glanceclient
+
 
 easy_install django_evolution
 easy_install python_gflags
diff --git a/planetstack/apigen/api.template.py b/planetstack/apigen/api.template.py
index f595d2b..a98acb8 100644
--- a/planetstack/apigen/api.template.py
+++ b/planetstack/apigen/api.template.py
@@ -9,17 +9,17 @@
 from rest_framework import filters
 
 """
-	Schema of the generator object:
-		all: Set of all Model objects
-		all_if(regex): Set of Model objects that match regex
-	
-	Model object:
-		plural: English plural of object name
-		camel: CamelCase version of object name
-		refs: list of references to other Model objects
-		props: list of properties minus refs
+    Schema of the generator object:
+        all: Set of all Model objects
+        all_if(regex): Set of Model objects that match regex
+    
+    Model object:
+        plural: English plural of object name
+        camel: CamelCase version of object name
+        refs: list of references to other Model objects
+        props: list of properties minus refs
 
-	TODO: Deal with subnets
+    TODO: Deal with subnets
 """
 
 # Based on api_root.py
@@ -27,8 +27,8 @@
 @api_view(['GET'])
 def api_root(request, format=None):
     return Response({
-		{% for object in generator.all %}'{{ object.plural }}': reverse('{{ object }}-list', request=request, format=format),
-		{% endfor %}
+        {% for object in generator.all %}'{{ object.plural }}': reverse('{{ object }}-list', request=request, format=format),
+        {% endfor %}
     })
 
 # Based on serializers.py
@@ -36,30 +36,30 @@
 {% for object in generator.all %}
 
 class {{ object.camel }}Serializer(serializers.HyperlinkedModelSerializer):
-	id = serializers.Field()
-	{% for ref in object.refs %}
-	{% if ref.multi %}
-	{{ ref.plural }} = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='{{ ref }}-detail')
-	{% else %}
-	{{ ref }} = serializers.HyperlinkedRelatedField(read_only=True, view_name='{{ ref }}-detail')
-	{% endif %}
-	{% endfor %}
-	class Meta:
-		model = {{ object.camel }}
-		fields = ({% for prop in object.props %}'{{ prop }}',{% endfor %}{% for ref in object.refs %}{%if ref.multi %}'{{ ref.plural }}'{% else %}'{{ ref }}'{% endif %},{% endfor %})
+    id = serializers.Field()
+    {% for ref in object.refs %}
+    {% if ref.multi %}
+    {{ ref.plural }} = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='{{ ref }}-detail')
+    {% else %}
+    {{ ref }} = serializers.HyperlinkedRelatedField(read_only=True, view_name='{{ ref }}-detail')
+    {% endif %}
+    {% endfor %}
+    class Meta:
+        model = {{ object.camel }}
+        fields = ({% for prop in object.props %}'{{ prop }}',{% endfor %}{% for ref in object.refs %}{%if ref.multi %}'{{ ref.plural }}'{% else %}'{{ ref }}'{% endif %},{% endfor %})
 
 class {{ object.camel }}IdSerializer(serializers.ModelSerializer):
-	id = serializers.Field()
-	{% for ref in object.refs %}
-	{% if ref.multi %}
-	{{ ref.plural }} = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='{{ ref }}-detail')
-	{% else %}
-	{{ ref }} = serializers.HyperlinkedRelatedField(read_only=True, view_name='{{ ref }}-detail')
-	{% endif %}
-	{% endfor %}
-	class Meta:
-		model = {{ object.camel }}
-		fields = ({% for prop in object.props %}'{{ prop }}',{% endfor %}{% for ref in object.refs %}{%if ref.multi %}'{{ ref.plural }}'{% else %}'{{ ref }}'{% endif %},{% endfor %})
+    id = serializers.Field()
+    {% for ref in object.refs %}
+    {% if ref.multi %}
+    {{ ref.plural }} = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='{{ ref }}-detail')
+    {% else %}
+    {{ ref }} = serializers.HyperlinkedRelatedField(read_only=True, view_name='{{ ref }}-detail')
+    {% endif %}
+    {% endfor %}
+    class Meta:
+        model = {{ object.camel }}
+        fields = ({% for prop in object.props %}'{{ prop }}',{% endfor %}{% for ref in object.refs %}{%if ref.multi %}'{{ ref.plural }}'{% else %}'{{ ref }}'{% endif %},{% endfor %})
 
 
 {% endfor %}
@@ -138,12 +138,15 @@
 
     def create(self, request, *args, **kwargs):
         #obj = {{ object.camel }}().update(request.DATA)
-        obj = self.get_object()
-        obj.caller = request.user
-        if obj.can_update(request.user):
-            return super({{ object.camel }}List, self).create(request, *args, **kwargs)
-        else:
-            return Response(status=status.HTTP_400_BAD_REQUEST)
+        #obj = self.get_object()
+        #obj.caller = request.user
+        ret = super({{ object.camel }}List, self).create(request, *args, **kwargs)
+        if (ret.status_code%100 != 200):
+            raise Exception(ret.data)
+        #if obj.can_update(request.user):
+        #    return super({{ object.camel }}List, self).create(request, *args, **kwargs)
+        #else:
+        #    return Response(status=status.HTTP_400_BAD_REQUEST)
 
 class {{ object.camel }}Detail(PlanetStackRetrieveUpdateDestroyAPIView):
     queryset = {{ object.camel }}.objects.select_related().all()
diff --git a/planetstack/core/models/site.py b/planetstack/core/models/site.py
index 9f183b5..0ade5df 100644
--- a/planetstack/core/models/site.py
+++ b/planetstack/core/models/site.py
@@ -20,7 +20,7 @@
 
         parent_queryset = parent.get_queryset() if hasattr(parent, "get_queryset") else parent.get_query_set()
         if (backend_type):
-            return parent_queryset.filter(Q(deployment__backend_type=backend_type)|Q(backend_type=None))
+            return parent_queryset.filter(Q(deployment__backend_type=backend_type))
         else:
             return parent_queryset
 
@@ -41,7 +41,7 @@
         parent_queryset = parent.get_queryset() if hasattr(parent, "get_queryset") else parent.get_query_set()
 
         if backend_type:
-            return parent_queryset.filter(Q(backend_type=backend_type)|Q(backend_type=None))
+            return parent_queryset.filter(Q(backend_type=backend_type))
         else:
             return parent_queryset
 
@@ -61,7 +61,7 @@
         parent_queryset = parent.get_queryset() if hasattr(parent, "get_queryset") else parent.get_query_set()
 
         if backend_type:
-            return parent_queryset.filter(Q(deployment__backend_type=backend_type)|Q(backend_type=None))
+            return parent_queryset.filter(Q(deployment__backend_type=backend_type))
         else:
             return parent_queryset
 
@@ -82,7 +82,7 @@
         parent_queryset = parent.get_queryset() if hasattr(parent, "get_queryset") else parent.get_query_set()
 
         if backend_type:
-            return parent_queryset.filter(Q(backend_type=backend_type)|Q(backend_type=None))
+            return parent_queryset.filter(Q(backend_type=backend_type))
         else:
             return parent_queryset
 
diff --git a/planetstack/model_policies/model_policy_Slice.py b/planetstack/model_policies/model_policy_Slice.py
index 6fd968c..493975f 100644
--- a/planetstack/model_policies/model_policy_Slice.py
+++ b/planetstack/model_policies/model_policy_Slice.py
@@ -1,6 +1,6 @@
 
 def handle(slice):
-	from core.models import SiteDeployments,SliceDeployments,Deployment
+	from core.models import SiteDeployments,SliceDeployments,Deployment,Network,NetworkSlice,NetworkTemplate
 	from collections import defaultdict
 	site_deployments = SiteDeployments.objects.all()
 	site_deploy_lookup = defaultdict(list)
@@ -22,3 +22,46 @@
 			sd = SliceDeployments(slice=slice, deployment=expected_deployment)
 			sd.save()
 
+	# make sure slice has at least 1 public and 1 private networkd
+	public_net = None
+	private_net = None
+	networks = Network.objects.filter(owner=slice)
+	for network in networks:
+		if network.template.name == 'Public dedicated IPv4':
+			public_net = network
+		elif network.template.name == 'Private':
+			private_net = network 
+	if not public_net:
+		public_net = Network(
+          	name = slice.name+'-public',
+          	template = NetworkTemplate.objects.get(name='Public dedicated IPv4'),
+          	owner = slice
+      		)
+		public_net.save()
+        
+	if not private_net:
+        	private_net = Network(
+          	name = slice.name+'-private',
+          	template = NetworkTemplate.objects.get(name='Private'),
+          	owner = slice
+      		)
+      		private_net.save()
+	# create slice networks
+	public_net_slice = None
+	private_net_slice = None
+	net_slices = NetworkSlice.objects.filter(slice=slice, network__in=[public_net,private_net])
+	for net_slice in net_slices:
+		if net_slice.network == public_net:
+			public_net_slice = net_slice 
+		elif net_slice.network == private_net:
+			private_net_slice = net_slice 
+	if not public_net_slice:
+		public_net_slice = NetworkSlice(slice=slice, network=public_net)
+		public_net_slice.save()
+	if not private_net_slice:
+		private_net_slice = NetworkSlice(slice=slice, network=private_net)
+		private_net_slice.save() 		
+                      
+             
+        
+