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:
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
def refresh_components(self):
"""
- Update the cached list of nodes and slices.
+ Update the cached list of nodes.
"""
print "refreshing"
# 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)
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()
"""
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')
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):
"""
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']: