From 698fda3721df907902a4d2de13f15b06fb35ac59 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Tue, 20 Jan 2009 21:05:28 +0000 Subject: [PATCH] maintain slice state at the slice manager --- plc/slicemgr.py | 52 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/plc/slicemgr.py b/plc/slicemgr.py index 16041e86..54df8be6 100644 --- a/plc/slicemgr.py +++ b/plc/slicemgr.py @@ -57,7 +57,7 @@ class SliceMgr(GeniServer): def load_aggregates(self, aggregates_file): """ Get info about the aggregates available to us from file and create - an xmlrpc connection to each. If any info is invalid, skip it. + an xmlrpc connection to each. If any info is invalid, skip it. """ lines = [] try: @@ -81,6 +81,7 @@ class SliceMgr(GeniServer): url = 'https://%(address)s:%(port)s' % locals() self.aggregates[hrn] = GeniClient(url, self.key_file, self.cert_file) + def item_hrns(self, items): """ Take a list of items (components or slices) and return a dictionary where @@ -115,7 +116,7 @@ class SliceMgr(GeniServer): def refresh_components(self): """ - Update the cached list of nodes and slices. + Update the cached list of nodes. """ print "refreshing" @@ -127,9 +128,6 @@ class SliceMgr(GeniServer): # resolve components hostnames nodes = self.aggregates[aggregate].get_components() all_nodes.extend(nodes) - # resolve slices - slices = self.aggregates[aggregate].get_slices() - all_slices.extend(slice) # update timestamp and threshold self.timestamp = datetime.datetime.now() delta = datetime.timedelta(hours=self.components_ttl) @@ -139,13 +137,9 @@ class SliceMgr(GeniServer): pass self.components = all_nodes - self.slices = all_slices f = open(self.components_file, 'w') f.write(str(self.components)) f.close() - f = open(self.slices_file, 'w') - f.write(str(self.slices)) - f.close() f = open(self.timestamp_file, 'w') f.write(str(self.threshold)) f.close() @@ -154,18 +148,13 @@ class SliceMgr(GeniServer): """ Read cached list of nodes and slices. """ - print "loading" + print "loading nodes" # Read component list from cached file if os.path.exists(self.components_file): f = open(self.components_file, 'r') self.components = eval(f.read()) f.close() - if os.path.exists(self.slices_file): - f = open(self.components_file, 'r') - self.slices = eval(f.read()) - f.close() - time_format = "%Y-%m-%d %H:%M:%S" if os.path.exists(self.timestamp_file): f = open(self.timestamp_file, 'r') @@ -173,7 +162,27 @@ class SliceMgr(GeniServer): self.timestamp = datetime.datetime.fromtimestamp(time.mktime(time.strptime(timestamp, time_format))) delta = datetime.timedelta(hours=self.components_ttl) self.threshold = self.timestamp + delta - f.close() + f.close() + + def load_slices(self): + """ + Read current slice instantiation states. + """ + print "loading slices" + if os.path.exists(self.slices_file): + f = open(self.components_file, 'r') + self.slices = eval(f.read()) + f.close() + + def write_slices(self): + """ + Write current slice instantiations to file. + """ + print "writing slices" + f = open(self.slices_file, 'w') + f.write(str(self.slices)) + f.close() + def get_components(self): """ @@ -201,6 +210,17 @@ class SliceMgr(GeniServer): self.load_components() return self.slices + def get_slivers(self, hrn): + """ + Return the list of slices instantiated at the specified component. + """ + + # hrn is assumed to be a component hrn + if hrn not in self.slices: + raise Exception, hrn + " not found" + + return self.slices[hrn] + def get_rspec(self, hrn, type): #rspec = Rspec() if type in ['node']: -- 2.47.0