+ if new_maxrate != self.MaxRate:
+ # 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:
+ # 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_maxexemptrate'] = bwlimit.format_tc_rate(new_maxi2rate)
+
+ message += template % params
+ logger.log("bwmon: ** %(slice)s %(class)s capped at %(new_maxrate)s/s " % params)
+
+ # Notify slice
+ if message and 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
+ slicemail(self.name, subject, message + (footer % params))
+
+
+ def update(self, runningmaxrate, runningmaxi2rate, usedbytes, usedi2bytes, runningshare, rspec):
+ """
+ Update byte counts and check if byte thresholds have been
+ exceeded. If exceeded, cap to remaining bytes in limit over remaining in period.
+ Recalculate every time module runs.
+ """
+
+ # Query Node Manager for max rate overrides
+ self.updateSliceAttributes(rspec)
+
+ # Check shares for Sirius loans.
+ if runningshare != self.Share:
+ logger.log("bwmon: Updating share to %s" % self.share)
+ bwlimit.set(xid = self.xid,
+ minrate = self.MinRate * 1000,
+ maxrate = self.MaxRate * 1000,
+ maxexemptrate = self.Maxi2Rate * 1000,
+ minexemptrate = self.Mini2Rate * 1000,
+ share = self.Share)
+
+ # 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)}
+
+ # Check limits.