1 #----------------------------------------------------------------------
2 # Copyright (c) 2008 Board of Trustees, Princeton University
4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and/or hardware specification (the "Work") to
6 # deal in the Work without restriction, including without limitation the
7 # rights to use, copy, modify, merge, publish, distribute, sublicense,
8 # and/or sell copies of the Work, and to permit persons to whom the Work
9 # is furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be
12 # included in all copies or substantial portions of the Work.
14 # THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS
22 #----------------------------------------------------------------------
24 # implements SFA tickets
29 from sfa.trust.certificate import Certificate
30 from sfa.trust.gid import GID
33 # (gidCaller, gidObject, attributes, rspec, delegate)
35 # gidCaller = GID of the caller performing the operation
36 # gidObject = GID of the slice
37 # attributes = slice attributes (keys, vref, instantiation, etc)
40 class SfaTicket(Certificate):
47 def __init__(self, create=False, subject=None, string=None, filename=None):
48 Certificate.__init__(self, create, subject, string, filename)
50 def set_gid_caller(self, gid):
53 def get_gid_caller(self):
54 if not self.gidCaller:
58 def set_gid_object(self, gid):
61 def get_gid_object(self):
62 if not self.gidObject:
66 def set_attributes(self, gid):
69 def get_attributes(self):
70 if not self.attributes:
72 return self.attributes
74 def set_rspec(self, gid):
82 def set_delegate(self, delegate):
83 self.delegate = delegate
85 def get_delegate(self):
91 dict = {"gidCaller": None,
93 "attributes": self.attributes,
95 "delegate": self.delegate}
97 dict["gidCaller"] = self.gidCaller.save_to_string(save_parents=True)
99 dict["gidObject"] = self.gidObject.save_to_string(save_parents=True)
100 str = "URI:" + xmlrpclib.dumps((dict,), allow_none=True)
104 data = self.get_data()
106 dict = xmlrpclib.loads(self.get_data()[4:])[0][0]
110 self.attributes = dict.get("attributes", {})
111 self.rspec = dict.get("rspec", {})
112 self.delegate = dict.get("delegate", False)
114 gidCallerStr = dict.get("gidCaller", None)
116 self.gidCaller = GID(string=gidCallerStr)
118 self.gidCaller = None
120 gidObjectStr = dict.get("gidObject", None)
122 self.gidObject = GID(string=gidObjectStr)
124 self.gidObject = None
126 def dump(self, dump_parents=False):
127 print "TICKET", self.get_subject()
130 gidCaller = self.get_gid_caller()
132 gidCaller.dump(8, dump_parents)
135 gidObject = self.get_gid_object()
137 gidObject.dump(8, dump_parents)
140 for attrname in self.get_attributes().keys():
141 print " ", attrname, self.get_attributes()[attrname]
144 print " ", self.get_rspec()
146 if self.parent and dump_parents:
148 self.parent.dump(dump_parents)