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