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
27 from __future__ import print_function
29 from sfa.trust.certificate import Certificate
30 from sfa.trust.gid import GID
32 from sfa.util.py23 import xmlrpc_client
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)
42 class SfaTicket(Certificate):
49 def __init__(self, create=False, subject=None, string=None, filename=None):
50 Certificate.__init__(self, create, subject, string, filename)
52 def set_gid_caller(self, gid):
55 def get_gid_caller(self):
56 if not self.gidCaller:
60 def set_gid_object(self, gid):
63 def get_gid_object(self):
64 if not self.gidObject:
68 def set_attributes(self, gid):
71 def get_attributes(self):
72 if not self.attributes:
74 return self.attributes
76 def set_rspec(self, gid):
84 def set_delegate(self, delegate):
85 self.delegate = delegate
87 def get_delegate(self):
93 dict = {"gidCaller": None,
95 "attributes": self.attributes,
97 "delegate": self.delegate}
99 dict["gidCaller"] = self.gidCaller.save_to_string(save_parents=True)
101 dict["gidObject"] = self.gidObject.save_to_string(save_parents=True)
102 str = "URI:" + xmlrpc_client.dumps((dict,), allow_none=True)
106 data = self.get_data()
108 dict = xmlrpc_client.loads(self.get_data()[4:])[0][0]
112 self.attributes = dict.get("attributes", {})
113 self.rspec = dict.get("rspec", {})
114 self.delegate = dict.get("delegate", False)
116 gidCallerStr = dict.get("gidCaller", None)
118 self.gidCaller = GID(string=gidCallerStr)
120 self.gidCaller = None
122 gidObjectStr = dict.get("gidObject", None)
124 self.gidObject = GID(string=gidObjectStr)
126 self.gidObject = None
128 def dump(self, dump_parents=False):
129 print("TICKET", self.get_subject())
132 gidCaller = self.get_gid_caller()
134 gidCaller.dump(8, dump_parents)
137 gidObject = self.get_gid_object()
139 gidObject.dump(8, dump_parents)
141 print(" attributes:")
142 for attrname in self.get_attributes().keys():
143 print(" ", attrname, self.get_attributes()[attrname])
146 print(" ", self.get_rspec())
148 if self.parent and dump_parents:
149 print("PARENT", end=' ')
150 self.parent.dump(dump_parents)