Add CORDUser object and samples
diff --git a/xos/tosca/custom_types/xos.m4 b/xos/tosca/custom_types/xos.m4
index 0ee69a0..fbc8f13 100644
--- a/xos/tosca/custom_types/xos.m4
+++ b/xos/tosca/custom_types/xos.m4
@@ -118,6 +118,16 @@
type: boolean
default: true
+ tosca.nodes.CORDUser:
+ derived_from: tosca.nodes.Root
+ properties:
+ level:
+ type: string
+ default: PG_13
+ mac:
+ type: string
+ required: true
+
tosca.nodes.User:
derived_from: tosca.nodes.Root
@@ -414,6 +424,9 @@
derived_from: tosca.relationships.Root
valid_target_types: [ tosca.capabiltys.xos.Site ]
+ tosca.relationships.SubscriberDevice:
+ derived_from: tosca.relationships.Root
+
tosca.capabilities.xos.Service:
derived_from: tosca.capabilities.Root
description: An XOS Service
@@ -449,3 +462,4 @@
tosca.capabilities.xos.Subscriber:
derived_from: tosca.capabilities.Root
description: An XOS Subscriber
+
diff --git a/xos/tosca/resources/CORDSubscriber.py b/xos/tosca/resources/CORDSubscriber.py
index 951b1f4..ebd842b 100644
--- a/xos/tosca/resources/CORDSubscriber.py
+++ b/xos/tosca/resources/CORDSubscriber.py
@@ -20,5 +20,5 @@
pass
def can_delete(self, obj):
- return super(XOSService, self).can_delete(obj)
+ return super(XOSCORDSubscriber, self).can_delete(obj)
diff --git a/xos/tosca/resources/CORDUser.py b/xos/tosca/resources/CORDUser.py
new file mode 100644
index 0000000..78883f2
--- /dev/null
+++ b/xos/tosca/resources/CORDUser.py
@@ -0,0 +1,63 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+import pdb
+
+from core.models import User
+from cord.models import CordSubscriberRoot
+
+from xosresource import XOSResource
+
+class XOSCORDUser(XOSResource):
+ provides = "tosca.nodes.CORDUser"
+
+ def get_model_class_name(self):
+ return "CORDUser"
+
+ def get_subscriber_root(self, throw_exception=True):
+ sub_name = self.get_requirement("tosca.relationships.SubscriberDevice", throw_exception=throw_exception)
+ sub = self.get_xos_object(CordSubscriberRoot, name=sub_name, throw_exception=throw_exception)
+ return sub
+
+ def get_existing_objs(self):
+ result = []
+ sub = self.get_subscriber_root(throw_exception=False)
+ if not sub:
+ return []
+ for user in sub.users:
+ if user["name"] == self.nodetemplate.name:
+ result.append(user)
+ return result
+
+ def get_xos_args(self):
+ args = {"name": self.nodetemplate.name,
+ "level": self.get_property("level"),
+ "mac": self.get_property("mac")}
+ return args
+
+
+ def create(self):
+ xos_args = self.get_xos_args()
+ sub = self.get_subscriber_root()
+
+ sub.create_user(**xos_args)
+ sub.save()
+
+ self.info("Created CORDUser %s for Subscriber %s" % (self.nodetemplate.name, sub.name))
+
+ def update(self, obj):
+ pass
+
+ def delete(self, obj):
+ if (self.can_delete(obj)):
+ self.info("destroying CORDUser %s" % obj["name"])
+ sub = self.get_subscriber_root()
+ sub.delete_user(obj["id"])
+ sub.save()
+
+ def can_delete(self, obj):
+ return True
+
diff --git a/xos/tosca/resources/xosresource.py b/xos/tosca/resources/xosresource.py
index 159156b..2268024 100644
--- a/xos/tosca/resources/xosresource.py
+++ b/xos/tosca/resources/xosresource.py
@@ -71,10 +71,13 @@
def get_xos_args(self):
return {}
+ def get_model_class_name(self):
+ return self.xos_model.__name__
+
def create_or_update(self):
existing_objs = self.get_existing_objs()
if existing_objs:
- self.info("%s %s already exists" % (self.xos_model.__name__, self.nodetemplate.name))
+ self.info("%s %s already exists" % (self.get_model_class_name(), self.nodetemplate.name))
self.update(existing_objs[0])
else:
self.create()
diff --git a/xos/tosca/samples/cord.yaml b/xos/tosca/samples/cord.yaml
index 5a11e5f..d1a2af5 100644
--- a/xos/tosca/samples/cord.yaml
+++ b/xos/tosca/samples/cord.yaml
@@ -72,7 +72,7 @@
# Now let's add a subscriber
- The Baker Household:
+ My House:
type: tosca.nodes.CORDSubscriber
properties:
firewall_enable: true
@@ -80,3 +80,43 @@
url_filter_enable: true
url_filter_level: R
+ Mom's PC:
+ type: tosca.nodes.CORDUser
+ properties:
+ mac: 010203040506
+ level: PG_13
+ requirements:
+ - household:
+ node: My House
+ relationship: tosca.relationships.SubscriberDevice
+
+ Dad's PC:
+ type: tosca.nodes.CORDUser
+ properties:
+ mac: 90E2Ba82F975
+ level: PG_13
+ requirements:
+ - household:
+ node: My House
+ relationship: tosca.relationships.SubscriberDevice
+
+ Jack's Laptop:
+ type: tosca.nodes.CORDUser
+ properties:
+ mac: 685B359D91D5
+ level: PG_13
+ requirements:
+ - household:
+ node: My House
+ relationship: tosca.relationships.SubscriberDevice
+
+ Jill's Laptop:
+ type: tosca.nodes.CORDUser
+ properties:
+ mac: 34363BC9B6A6
+ level: PG_13
+ requirements:
+ - household:
+ node: My House
+ relationship: tosca.relationships.SubscriberDevice
+