components_ttl = None
components = []
slices = []
- policies = {}
+ policy = {}
timestamp = None
threshold = None
shell = None
self.slices_file = os.sep.join([server_basedir, 'components', 'slicemgr' + hrn + '.slices'])
self.timestamp_file = os.sep.join([server_basedir, 'components', 'slicemgr' + hrn + '.timestamp'])
self.components_ttl = components_ttl
+ self.policy['whitelist'] = []
+ self.policy['blacklist'] = []
self.connect()
def load_aggregates(self, aggregates_file):
delta = datetime.timedelta(hours=self.components_ttl)
self.threshold = self.timestamp + delta
f.close()
+
+ def load_policy(self):
+ """
+ Read the list of blacklisted and whitelisted nodes.
+ """
+ whitelist = []
+ blacklist = []
+ if os.path.exists(self.whitelist_file):
+ f = open(self.whitelist_file, 'r')
+ lines = f.readlines()
+ f.close()
+ for line in lines:
+ line = line.strip().replace(" ", "").replace("\n", "")
+ whitelist.extend(line.split(","))
+
+
+ if os.path.exists(self.blacklist_file):
+ f = open(self.blacklist_file, 'r')
+ lines = f.readlines()
+ f.close()
+ for line in lines:
+ line = line.strip().replace(" ", "").replace("\n", "")
+ blacklist.extend(line.split(","))
+
+ self.policy['whitelist'] = whitelist
+ self.policy['blacklist'] = blacklist
def load_slices(self):
"""
# hrn is assumed to be a component hrn
if hrn not in self.slices:
- raise Exception, hrn + " not found"
+ raise RecordNotFound(hrn)
return self.slices[hrn]
return rspec
- def create_slice(self, slice_hrn, rspec):
+ def create_slice(self, slice_hrn, rspec, attributes):
"""
Instantiate the specified slice according to whats defined in the rspec.
"""
slicename = self.hrn_to_plcslicename(slice_hrn)
#spec = Rspec(rspec)
- #components = spec.components()
- #shell.AddSliceToNodes(self.auth, slicename, components)
+ node_hrns = []
+ #for netspec in spec['networks]:
+ # networkname = netspec['name']
+ # nodespec = spec['networks']['nodes']
+ # nodes = [nspec['name'] for nspec in nodespec]
+ # node_hrns = [networkname + node for node in nodes]
+ #
+ self.db.AddSliceToNodes(slice_hrn, node_hrns)
return 1
def delete_slice_(self, slice_hrn):
Remove this slice from all components it was previouly associated with and
free up the resources it was using.
"""
- slicename = self.hrn_to_plcslicename(slice_hrn)
- rspec = self.get_resources(slice_hrn)
- components = rspec.components()
- shell.DeleteSliceFromNodes(self.auth, slicename, components)
+ self.db.DeleteSliceFromNodes(self.auth, slicename, self.components)
return 1
def start_slice(self, slice_hrn):
def get_policy(self):
"""
- Return this aggregates policy as an rspec
+ Return the policy of this slice manager.
"""
- rspec = self.get_rspec(self.hrn, 'aggregate')
- return rspec
+
+ return self.policy