--- /dev/null
+class GacksCalendar:
+ def __init__(self):
+ pass
+
+ def query(self, id, unitStart, unitStop, timeStart, timeStop):
+ pass
+
+ def insert_record(self, item):
+ pass
+
+class GacksListCalendar(GacksCalendar):
+ def __init__(self):
+ self.items = []
+
+ def test_id(x, y):
+ if not x:
+ return True
+ else:
+ return (x == y)
+
+ def test_lesser(x, y):
+ if not x:
+ return True
+ else if y==INFINITY:
+ return True
+ else:
+ return (x<y)
+
+ def test_greater_equal(x, y):
+ if not x:
+ return True
+ else if x==INFINITY:
+ return True
+ else if y==INFINITY:
+ return False
+ else:
+ return (x>=y)
+
+ def query(self, id, unitStart=0, unitStop=INFINITY, timeStart=0, timeStop=INFINITY):
+ list = []
+ for item in self.items:
+ if test_id(id, item.id) and
+ test_lesser(unitStart, item.unitStop) and
+ test_greater_equal(unitStop, item.unitStart) and
+ test_lesser(timeStart, item.timeStop) and
+ test_greater_equal(timeStop, item.timeStart):
+ list = list + item
+ return list
+
+ def insert_record(self, item):
+ conflicts = self.query(item.id, item.unitStart, item.unitStop, item.timeStart, item.timeStop)
+ for conflict in conflicts:
+ self.items.remove(conflict)
+
+ self.items.append(item)
+
--- /dev/null
+##
+# This module implements Gacks handles
+##
+
+import sys
+
+##
+# GacksHandle is an object representing a handle. A handle is the following
+# tuple:
+#
+# (id, unitstart, unitstop, timestart, timestop)
+#
+# id is a text identifier for the resource, for example "CPU"
+#
+# unitstart and unitstop form an interval [unitstart, unitstop) in unit
+# space. For example, [0, 10) could represent 10% of a CPU.
+#
+# timestart and timestop form an interval [timestart, timestop) in time
+# space.
+#
+# If unitstop==INFINITY, or timestop==INFINITY, then it is treated as infinity
+#
+# The GacksHandle also doubles as an RSPEC
+
+INFINITY = "inf" #sys.maxint
+
+class GacksHandle:
+ def __init__(self, id=None, unitStart=0, unitStop=INFINITY, timeStart=0, timeStop=INFINITY, string=None):
+ self.id = id
+ self.unitStart = unitStart
+ self.unitStop = unitStop
+ self.timeStart = timeStart
+ self.timeStop = timeStop
+ if string:
+ self.load_from_string(string)
+
+ def as_string(self):
+ return str(self.id) + "#" + \
+ str(self.unitStart) + "-" + str(self.unitStop) + "#" + \
+ str(self.timeStart) + "-" + str(self.timeStop)
+
+ def parse_range(self, str):
+ parts = str.split("-")
+ if len(parts)!=2:
+ raise ValueError
+
+ if parts[0] != INFINITY:
+ parts[0] = int(parts[0])
+
+ if parts[1] != INFINITY:
+ parts[1] = int(parts[1])
+
+ return parts
+
+ def load_from_string(self, str):
+ parts = str.split("#")
+
+ self.id = parts[0]
+
+ if len(parts) > 1:
+ (self.unitStart, self.unitStop) = self.parse_range(parts[1])
+
+ if len(parts) > 2:
+ (self.timeStart, self.timeStop) = self.parse_range(parts[2])
+
+ def get_quantity(self):
+ if self.unitStop == INFINITY:
+ return INFINITY
+ else:
+ return self.unitStop-self.unitStart
+
+ def get_duration(self):
+ if self.timeStop == INFINITY:
+ return INFINITY
+ else:
+ return self.timeStop-self.timeStart
+
+ def dump(self):
+ print str(self.id) + ": " + \
+ "units " + str(self.unitStart) + "-" + str(self.unitStop) + \
+ "time " + str(self.timeStart) + "-" + str(self.timeStop)
+
+ def clone(self):
+ return GacksHandle(self.id, self.unitStart, self.unitStop,
+ self.timeStart, self.timeStop)
+
+ def split(self, unit=None, time=None):
+ h1 = self.clone()
+ h2 = self.clone()
+
+ if unit:
+ h1.unitStop = unit
+ h2.unitStart = unit
+
+ if time:
+ h1.timeStop = time
+ h2.timeStart = time
+
+ return (h1, h2)
+
+
+class GacksRecord(GacksHandle):
+ def __init__(self, id=None, unitStart=0, unitStop=INFINITY, timeStart=0, timeStop=INFINITY, allocatorHRNs=[], consumerHRN=None):
+ GacksHandle.__init__(self, id, unitStart, unitStop, timeStart, timeStop)
+ self.allocatorHRNs = allocatorHRNs
+ self.consumerHRN = consumerHRN
+
+ def dump(self):
+ GacksHandle.dump(self)
+ print " allocators:", ", ".join(self.allocatorHRNs)
+ print " consumer:", self.consumerHRN
+
+ def clone(self):
+ return GacksRecord(self.id, self.unitStart, self.unitStop,
+ self.timeStart, self.timeStop,
+ self.allocatorHRNs, self.consumerHRN)
+
+ def set_allocator(self, callerHRN, allocatorHRN, which, where):
+ # build up a list of the positions of callerHRN inside of the
+ # allocator list
+
+ positions = []
+ for i, hrn in enumerate(self.allocatorHRNs):
+ if hrn == callerHRN:
+ positions.append(i)
+
+ pos = positions[which]
+
+ # truncate the allocator list at the appropriate place.
+ # if where==True,
+ # keep callerHRN in the list and append allocatorHRN after
+ # otherwise,
+ # remove callerHRN and replace with allocatorHRN
+
+ if where:
+ self.allocatorHRNs = self.allocatorHRNs[:(pos+1)]
+ else:
+ self.allocatorHRNs = self.allocatorHRNs[:pos]
+
+ self.allocatorHRNs.append(allocatorHRN)
+
+ def get_allocators(self):
+ return self.allocatorHRNs[:]
+
+ def set_consumer(self, consumerHRN):
+ self.consumerHRN = consumerHRN
+
+ def get_consumer(self):
+ return self.consumerHRN
+
+
--- /dev/null
+##
+# Gacks Server
+##
+
+import tempfile
+import os
+
+import sys
+
+from cert import *
+from gid import *
+from geniserver import *
+from excep import *
+from trustedroot import *
+from misc import *
+from record import *
+from geniticket import *
+
+##
+# GacksServer is a GeniServer that serves component interface requests.
+#
+
+class GacksServer(GeniServer):
+
+ ##
+ # Create a new GacksServer object.
+ #
+ # @param ip the ip address to listen on
+ # @param port the port to listen on
+ # @param key_file private key filename of registry
+ # @param cert_file certificate filename containing public key (could be a GID file)
+
+ def __init__(self, ip, port, key_file, cert_file):
+ GeniServer.__init__(self, ip, port, key_file, cert_file)
+
+ ##
+ # Register the server RPCs for Gacks
+
+ def register_functions(self):
+ GeniServer.register_functions(self)
+ self.server.register_function(self.get_handle)
+
+ def get_handle(self, rspec):
+ pass
+
+ def set_allocator(self, callerGid, Handle, allocatorGid, which, where, reqsig)
+ pass
+
+if __name__ == "__main__":
+ global TrustedRoots
+
+ key_file = "gacksserver.key"
+ cert_file = "gacksserver.cert"
+
+ # if no key is specified, then make one up
+ if (not os.path.exists(key_file)) or (not os.path.exists(cert_file)):
+ key = Keypair(create=True)
+ key.save_to_file(key_file)
+
+ cert = Certificate(subject="component")
+ cert.set_issuer(key=key, subject="component")
+ cert.set_pubkey(key)
+ cert.sign()
+ cert.save_to_file(cert_file)
+
+ TrustedRoots = TrustedRootList()
+
+ s = ComponentManager("", 12346, key_file, cert_file)
+ s.trusted_cert_list = TrustedRoots.get_list()
+ s.run()
+