def notify(self, new_maxrate, new_maxexemptrate, usedbytes, usedi2bytes): """ Notify the slice it's being capped. """ # Prepare message parameters from the template message = "" params = {'slice': self.name, 'hostname': socket.gethostname(), 'since': time.asctime(time.gmtime(self.time)) + " GMT", 'until': time.asctime(time.gmtime(self.time + period)) + " GMT", 'date': time.asctime(time.gmtime()) + " GMT", 'period': format_period(period)} if new_maxrate != (self.MaxRate * 1000): # Format template parameters for low bandwidth message params['class'] = "low bandwidth" params['bytes'] = format_bytes(usedbytes - self.bytes) params['limit'] = format_bytes(self.MaxKByte * 1024) params['new_maxrate'] = bwlimit.format_tc_rate(new_maxrate) # Cap low bandwidth burst rate message += template % params logger.log("bwmon: ** %(slice)s %(class)s capped at %(new_maxrate)s/s " % params) if new_maxexemptrate != (self.Maxi2Rate * 1000): # Format template parameters for high bandwidth message params['class'] = "high bandwidth" params['bytes'] = format_bytes(usedi2bytes - self.i2bytes) params['limit'] = format_bytes(self.Maxi2KByte * 1024) params['new_maxrate'] = bwlimit.format_tc_rate(new_maxexemptrate) message += template % params logger.log("bwmon: ** %(slice)s %(class)s capped at %(new_maxrate)s/s " % params) # Notify slice if self.emailed == False: subject = "pl_mom capped bandwidth of slice %(slice)s on %(hostname)s" % params if DEBUG: logger.log("bwmon: "+ subject) logger.log("bwmon: "+ message + (footer % params)) else: self.emailed = True logger.log("bwmon: Emailing %s" % self.name) slicemail(self.name, subject, message + (footer % params))
def reset(self, runningrates, rspec): """ Begin a new recording period. Remove caps by restoring limits to their default values. """ # Cache share for later comparison self.Share = runningrates.get('share', 1) # Query Node Manager for max rate overrides self.updateSliceTags(rspec) # Reset baseline time self.time = time.time() # Reset baseline byte coutns self.bytes = runningrates.get('usedbytes', 0) self.i2bytes = runningrates.get('usedi2bytes', 0) # Reset email self.emailed = False # Reset flag self.capped = False # Reset rates. maxrate = self.MaxRate * 1000 minrate = self.MinRate * 1000 maxi2rate = self.Maxi2Rate * 1000 mini2rate = self.Mini2Rate * 1000 if (maxrate != runningrates.get('maxrate', 0)) or \ (minrate != runningrates.get('maxrate', 0)) or \ (maxi2rate != runningrates.get('maxexemptrate', 0)) or \ (mini2rate != runningrates.get('minexemptrate', 0)) or \ (self.Share != runningrates.get('share', 0)): logger.log("bwmon: %s reset to %s/%s" % \ (self.name, bwlimit.format_tc_rate(maxrate), bwlimit.format_tc_rate(maxi2rate))) bwlimit.set(xid = self.xid, dev = dev_default, minrate = self.MinRate * 1000, maxrate = self.MaxRate * 1000, maxexemptrate = self.Maxi2Rate * 1000, minexemptrate = self.Mini2Rate * 1000, share = self.Share)