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
35 # (gidCaller, gidObject, attributes, rspec, delegate)
37 # gidCaller = GID of the caller performing the operation
38 # gidObject = GID of the slice
39 # attributes = slice attributes (keys, vref, instantiation, etc)
43 class SfaTicket(Certificate):
50 def __init__(self, create=False, subject=None, string=None, filename=None):
51 Certificate.__init__(self, create, subject, string, filename)
53 def set_gid_caller(self, gid):
56 def get_gid_caller(self):
57 if not self.gidCaller:
61 def set_gid_object(self, gid):
64 def get_gid_object(self):
65 if not self.gidObject:
69 def set_attributes(self, gid):
72 def get_attributes(self):
73 if not self.attributes:
75 return self.attributes
77 def set_rspec(self, gid):
85 def set_delegate(self, delegate):
86 self.delegate = delegate
88 def get_delegate(self):
94 dict = {"gidCaller": None,
96 "attributes": self.attributes,
98 "delegate": self.delegate}
100 dict["gidCaller"] = self.gidCaller.save_to_string(
103 dict["gidObject"] = self.gidObject.save_to_string(
105 str = "URI:" + xmlrpc.client.dumps((dict,), allow_none=True)
109 data = self.get_data()
111 dict = xmlrpc.client.loads(self.get_data()[4:])[0][0]
115 self.attributes = dict.get("attributes", {})
116 self.rspec = dict.get("rspec", {})
117 self.delegate = dict.get("delegate", False)
119 gidCallerStr = dict.get("gidCaller", None)
121 self.gidCaller = GID(string=gidCallerStr)
123 self.gidCaller = None
125 gidObjectStr = dict.get("gidObject", None)
127 self.gidObject = GID(string=gidObjectStr)
129 self.gidObject = None
131 def dump(self, dump_parents=False):
132 print("TICKET", self.get_subject())
135 gidCaller = self.get_gid_caller()
137 gidCaller.dump(8, dump_parents)
140 gidObject = self.get_gid_object()
142 gidObject.dump(8, dump_parents)
144 print(" attributes:")
145 for attrname in list(self.get_attributes().keys()):
146 print(" ", attrname, self.get_attributes()[attrname])
149 print(" ", self.get_rspec())
151 if self.parent and dump_parents:
152 print("PARENT", end=' ')
153 self.parent.dump(dump_parents)