support for users
diff --git a/xos/tosca/resources/user.py b/xos/tosca/resources/user.py
new file mode 100644
index 0000000..0f0c0a1
--- /dev/null
+++ b/xos/tosca/resources/user.py
@@ -0,0 +1,59 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+
+from core.models import User, Site
+
+from xosresource import XOSResource
+
+class XOSUser(XOSResource):
+ provides = "tosca.nodes.User"
+ xos_model = User
+
+ def get_xos_args(self):
+ args = {"email": self.nodetemplate.name}
+
+ # copy simple string properties from the template into the arguments
+ for prop in ["password", "firstname", "lastname", "phone", "user_url", "public_key", "is_active", "is_admin", "login_page"]:
+ v = self.get_property(prop)
+ if v:
+ args[prop] = v
+
+ site_name = self.get_requirement("tosca.relationships.MemberOfSite")
+ if site_name:
+ args["site"] = self.get_xos_object(Site, login_base=site_name)
+
+ return args
+
+ def get_existing_objs(self):
+ return self.xos_model.objects.filter(email = self.nodetemplate.name)
+
+ def postprocess(self, obj):
+ pass
+
+ def create(self):
+ nodetemplate = self.nodetemplate
+
+ xos_args = self.get_xos_args()
+
+ if not xos_args.get("site",None):
+ raise Exception("Site name must be specified when creating user")
+
+ user = User(**xos_args)
+ user.save()
+
+ self.postprocess(user)
+
+ self.info("Created User '%s'" % (str(user), ))
+
+ def delete(self, obj):
+ if obj.slices.exists():
+ self.info("User %s has active slices; skipping delete" % obj.name)
+ return
+ super(XOSUser, self).delete(obj)
+
+
+
diff --git a/xos/tosca/samples/users.yaml b/xos/tosca/samples/users.yaml
new file mode 100644
index 0000000..20da611
--- /dev/null
+++ b/xos/tosca/samples/users.yaml
@@ -0,0 +1,39 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Make some network templates
+
+imports:
+ - custom_types/xos.yaml
+
+topology_template:
+ node_templates:
+ mysite:
+ type: tosca.nodes.Site
+
+ johndoe@foo.bar:
+ type: tosca.nodes.User
+ properties:
+ password: letmein
+ firstname: john
+ lastname: doe
+ requirements:
+ - site:
+ node: mysite
+ relationship: tosca.relationships.MemberOfSite
+
+ janedoe@foo.bar:
+ type: tosca.nodes.User
+ properties:
+ password: letmeintoo
+ firstname: jane
+ lastname: doe
+ phone: 111-222-3333
+ user_url: http://janedoe/
+ public_key: asdlfkjasldkfjasldkjfhaslkdjfhglaskdjfhlaksjdhfkasdfasdf
+ is_active: true
+ is_admin: true
+ requirements:
+ - site:
+ node: mysite
+ relationship: tosca.relationships.MemberOfSite
+