Merge branch 'master' of github.com:open-cloud/xos into feature/subscriber-portal
diff --git a/xos/configurations/cord/cord.yaml b/xos/configurations/cord/cord.yaml
index e878322..565c419 100644
--- a/xos/configurations/cord/cord.yaml
+++ b/xos/configurations/cord/cord.yaml
@@ -453,6 +453,18 @@
         path: andybavier/docker-vcpe
         tag: develop
 
+    # Let's add a user who can be administrator of the household
+    johndoe@myhouse.com:
+      type: tosca.nodes.User
+      properties:
+          password: letmein
+          firstname: john
+          lastname: doe
+      requirements:
+          - site:
+              node: mysite
+              relationship: tosca.relationships.MemberOfSite
+
     # A subscriber
     My House:
        type: tosca.nodes.CORDSubscriber
@@ -462,6 +474,10 @@
            cdn_enable: false
            url_filter_enable: false
            url_filter_level: R
+       requirements:
+          - house_admin:
+              node: johndoe@myhouse.com
+              relationship: tosca.relationships.AdminPrivilege
 
     Mom's PC:
        type: tosca.nodes.CORDUser
diff --git a/xos/configurations/opencloud/opencloud.yaml b/xos/configurations/opencloud/opencloud.yaml
index 15142a6..0b4a3ed 100644
--- a/xos/configurations/opencloud/opencloud.yaml
+++ b/xos/configurations/opencloud/opencloud.yaml
@@ -329,6 +329,7 @@
       properties:
           display_name: I2-atl
           site_url: http://opencloud.us/
+          hosts_nodes: false 
       requirements:
           - deployment:
                node: backbone
@@ -343,6 +344,7 @@
       properties:
           display_name: I2-chi
           site_url: http://opencloud.us/
+          hosts_nodes: false 
       requirements:
           - deployment:
                node: backbone
@@ -357,6 +359,7 @@
       properties:
           display_name: I2-hou
           site_url: http://opencloud.us/
+          hosts_nodes: false 
       requirements:
           - deployment:
                node: backbone
@@ -371,6 +374,7 @@
       properties:
           display_name: I2-kas
           site_url: http://opencloud.us/
+          hosts_nodes: false 
       requirements:
           - deployment:
                node: backbone
@@ -385,6 +389,7 @@
       properties:
           display_name: I2-lax
           site_url: http://opencloud.us/
+          hosts_nodes: false 
       requirements:
           - deployment:
                node: backbone
@@ -399,6 +404,7 @@
       properties:
           display_name: I2-nyc
           site_url: http://opencloud.us/
+          hosts_nodes: false 
       requirements:
           - deployment:
                node: backbone
@@ -413,6 +419,7 @@
       properties:
           display_name: I2-slc
           site_url: http://opencloud.us/
+          hosts_nodes: false 
       requirements:
           - deployment:
                node: backbone
@@ -427,6 +434,7 @@
       properties:
           display_name: I2-seae
           site_url: http://opencloud.us/
+          hosts_nodes: false 
       requirements:
           - deployment:
                node: backbone
@@ -441,6 +449,7 @@
       properties:
           display_name: I2-sng
           site_url: http://opencloud.us/
+          hosts_nodes: false 
       requirements:
           - deployment:
                node: backbone
@@ -455,6 +464,7 @@
       properties:
           display_name: I2-wdc
           site_url: http://opencloud.us/
+          hosts_nodes: false 
       requirements:
           - deployment:
                node: backbone
@@ -469,6 +479,7 @@
       properties:
           display_name: Princeton
           site_url: http://opencloud.us/
+          hosts_nodes: true
       requirements:
           - deployment:
                node: campus
@@ -483,6 +494,7 @@
       properties:
           display_name: Stanford
           site_url: http://opencloud.us/
+          hosts_nodes: true 
       requirements:
           - deployment:
                node: campus
@@ -497,6 +509,7 @@
       properties:
           display_name: Washington
           site_url: http://opencloud.us/
+          hosts_nodes: false 
       requirements:
           - deployment:
                node: campus
@@ -511,6 +524,7 @@
       properties:
           display_name: GTech
           site_url: http://opencloud.us/
+          hosts_nodes: false 
       requirements:
           - deployment:
                node: campus
@@ -525,6 +539,7 @@
       properties:
           display_name: Arizona
           site_url: http://opencloud.us/
+          hosts_nodes: false 
       requirements:
           - deployment:
                node: campus
@@ -539,6 +554,7 @@
       properties:
           display_name: Internet2
           site_url: http://opencloud.us/
+          hosts_nodes: false 
       requirements:
           - deployment:
                node: campus
@@ -553,6 +569,7 @@
       properties:
           display_name: Singapore
           site_url: http://opencloud.us/
+          hosts_nodes: false 
       requirements:
           - deployment:
                node: campus
@@ -567,6 +584,7 @@
       properties:
           display_name: ON.Lab
           site_url: http://opencloud.us/
+          hosts_nodes: false 
       requirements:
           - deployment:
                node: campus
diff --git a/xos/core/xoslib/methods/cordsubscriber.py b/xos/core/xoslib/methods/cordsubscriber.py
index 49e32a5..0615024 100644
--- a/xos/core/xoslib/methods/cordsubscriber.py
+++ b/xos/core/xoslib/methods/cordsubscriber.py
@@ -228,7 +228,7 @@
 
     def get_users(self, request, pk=None):
         subscriber = self.get_object()
-        return Response({"users": subscriber.users})
+        return Response(subscriber.users)
 
     def get_user_level(self, request, pk=None, uid=None):
         subscriber = self.get_object()
diff --git a/xos/tosca/resources/CORDSubscriber.py b/xos/tosca/resources/CORDSubscriber.py
index 4097ca9..f013032 100644
--- a/xos/tosca/resources/CORDSubscriber.py
+++ b/xos/tosca/resources/CORDSubscriber.py
@@ -6,7 +6,7 @@
 from translator.toscalib.tosca_template import ToscaTemplate
 import pdb
 
-from core.models import User
+from core.models import User, TenantRootPrivilege, TenantRootRole
 from services.cord.models import CordSubscriberRoot
 
 from xosresource import XOSResource
@@ -17,7 +17,8 @@
     copyin_props = ["service_specific_id", "firewall_enable", "url_filter_enable", "cdn_enable", "url_filter_level"]
 
     def postprocess(self, obj):
-        pass
+        rolemap = ( ("tosca.relationships.AdminPrivilege", "admin"), ("tosca.relationships.AccessPrivilege", "access"), )
+        self.postprocess_privileges(TenantRootRole, TenantRootPrivilege, rolemap, obj, "tenant_root")
 
     def can_delete(self, obj):
         return super(XOSCORDSubscriber, self).can_delete(obj)
diff --git a/xos/tosca/resources/xosresource.py b/xos/tosca/resources/xosresource.py
index fa14380..cc4672b 100644
--- a/xos/tosca/resources/xosresource.py
+++ b/xos/tosca/resources/xosresource.py
@@ -103,10 +103,16 @@
     def postprocess_privileges(self, roleclass, privclass, rolemap, obj, toFieldName):
         for (rel, role) in rolemap:
             for email in self.get_requirements(rel):
-                role = self.get_xos_object(roleclass, role=role)
+                role_obj = self.get_xos_object(roleclass, throw_exception=False, role=role)
+                if not role_obj:
+                    # if the role doesn't exist, make it
+                    self.info("Creating %s %s" % (roleclass.__name__, role))
+                    role_obj = roleclass(role=role)
+                    role_obj.save()
+
                 user = self.get_xos_object(User, email=email)
-                if not privclass.objects.filter(user=user, role=role, **{toFieldName: obj}):
-                    sp = privclass(user=user, role=role, **{toFieldName: obj})
+                if not privclass.objects.filter(user=user, role=role_obj, **{toFieldName: obj}):
+                    sp = privclass(user=user, role=role_obj, **{toFieldName: obj})
                     sp.save()
                     self.info("Added privilege on %s role %s for %s" % (str(obj), str(role), str(user)))
 
diff --git a/xos/tosca/samples/cord.yaml b/xos/tosca/samples/cord.yaml
index 567ced0..a9baf25 100644
--- a/xos/tosca/samples/cord.yaml
+++ b/xos/tosca/samples/cord.yaml
@@ -70,8 +70,19 @@
               node: mysite
               relationship: tosca.relationships.MemberOfSite
 
-    # Now let's add a subscriber
+    # Let's add a user who can be administrator of the household
+    johndoe@myhouse.com:
+      type: tosca.nodes.User
+      properties:
+          password: letmein
+          firstname: john
+          lastname: doe
+      requirements:
+          - site:
+              node: mysite
+              relationship: tosca.relationships.MemberOfSite
 
+    # Now let's add a subscriber
     My House:
        type: tosca.nodes.CORDSubscriber
        properties:
@@ -80,6 +91,10 @@
            cdn_enable: true
            url_filter_enable: true
            url_filter_level: R
+       requirements:
+          - house_admin:
+              node: johndoe@myhouse.com
+              relationship: tosca.relationships.AdminPrivilege
 
     Mom's PC:
        type: tosca.nodes.CORDUser
@@ -137,3 +152,5 @@
 
 
 
+
+