blob: 1534be85de8576f3c05b1b036d17e5f0f6bb612c [file] [log] [blame]
Scott Baker8e6647a2016-06-20 17:16:20 -07001from core.models import User
Scott Bakerc15556d2017-05-06 09:55:01 -07002from services.rcord.models import CordSubscriberRoot
Scott Baker8e6647a2016-06-20 17:16:20 -07003
4from xosresource import XOSResource
5
6class XOSCORDUser(XOSResource):
7 provides = "tosca.nodes.CORDUser"
8
9 def get_model_class_name(self):
10 return "CORDUser"
11
12 def get_subscriber_root(self, throw_exception=True):
13 sub_name = self.get_requirement("tosca.relationships.SubscriberDevice", throw_exception=throw_exception)
14 sub = self.get_xos_object(CordSubscriberRoot, name=sub_name, throw_exception=throw_exception)
15 return sub
16
17 def get_existing_objs(self):
18 result = []
19 sub = self.get_subscriber_root(throw_exception=False)
20 if not sub:
21 return []
22 for user in sub.devices:
23 if user["name"] == self.obj_name:
24 result.append(user)
25 return result
26
27 def get_xos_args(self):
28 args = {"name": self.obj_name,
29 "level": self.get_property("level"),
30 "mac": self.get_property("mac")}
31 return args
32
33
34 def create(self):
35 xos_args = self.get_xos_args()
36 sub = self.get_subscriber_root()
37
38 sub.create_device(**xos_args)
39 sub.save()
40
41 self.info("Created CORDUser %s for Subscriber %s" % (self.obj_name, sub.name))
42
43 def update(self, obj):
44 pass
45
46 def delete(self, obj):
47 if (self.can_delete(obj)):
48 self.info("destroying CORDUser %s" % obj["name"])
49 sub = self.get_subscriber_root()
50 sub.delete_user(obj["id"])
51 sub.save()
52
53 def can_delete(self, obj):
54 return True
55