X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=gacks%2Fgacksserver.py;h=5c58999191aad5995fd717132242c5b1965e578f;hb=305a4e0a30e68c0ca8b8b079c35230031dd88b98;hp=730fc26f90c6018d15c4d0bd30b74c058f3bd12f;hpb=7c267b1e803bf3b4cd709832c93427da81a2f926;p=sfa.git diff --git a/gacks/gacksserver.py b/gacks/gacksserver.py index 730fc26f..5c589991 100644 --- a/gacks/gacksserver.py +++ b/gacks/gacksserver.py @@ -16,6 +16,9 @@ from misc import * from record import * from geniticket import * +from gacksexcep import * +from gackscalendar import * + ## # GacksServer is a GeniServer that serves component interface requests. # @@ -41,10 +44,73 @@ class GacksServer(GeniServer): self.server.register_function(self.get_handle) def get_handle(self, rspec): - pass + handles = rspec_to_handles(rspec) + return handles_to_strings(handles) + + def set_allocator(self, callerGID_str, handle_strs, allocatorGID_str, which, where, reqsig) + callerGID = GID(callerGID_str) + allocatorGID = GID(allocatorGID_str) + + # TODO: verify callerGID ssl key + + callerGID.verify_chain(self.trusted_cert_list) + allocatorGID.verify_chain(self.trusted_cert_list) + + handles = strings_to_handles(handle_strs) + for handle in handles: + # find the existing records that overlap the handle + existing_recs = self.calendar.query_handles([handle]) + + if not existing_recs: + raise GacksResourceNotFound(hand.as_string()) + + # TODO: Merge existing_recs + + for item in existing_recs: + if not item.contains_allocator(callerGID->get_name()): + raise CallerNotAllocator(item.as_string()) + if not item.is_superset(handle): + raise RequestSpansReservations(handle.as_string() + " on " + item.as_string()) + + leftovers = [] + results = [] + for item in existing_recs: + if item.is_proper_supserset(handle): + parts = item.clone().split_subset(handle.unitStart, handle.unitStop, handle.timeStart, handle.timeStop) + results.extend(parts[0]) + leftovers.extend(parts[1:]) + else: + results.extend(item) + + for item in existing_recs: + calendar.remove_record(item) + + for item in leftovers: + calendar.insert_record(item) + + for item in results: + item.set_allocator(callerGID->get_name(), allocatorGID->get_name(), which, where) + calendar.insert_record(item) + + def set_consumer(self, callerGID_str, handle_strs, cred_str, reqsig): + callerGID = GID(string = callerGID_str) + cred = Credential(string = cred_str) + + # TODO: verify callerGID ssl key + + callerGID.verify_chain(self.trusted_cert_list) + cred.verify_chain(self.trusted_cert_list) + + handles = strings_to_handles(handle_strs) + for handle in handles: + existing_recs = self.calendar.query_handles([handle]) + + if not existing_recs: + raise GacksResourceNotFound(hand.as_string()) - def set_allocator(self, callerGid, Handle, allocatorGid, which, where, reqsig) - pass + for rec in existing_recs: + rec.set_consumer(cred.objectGID.get_name()) + calendar.update_record(rec) if __name__ == "__main__": global TrustedRoots