trigger.changemgmt
— Change management library¶
Abstract interface to bounce windows and moratoria.
-
class
trigger.changemgmt.
BounceStatus
(status_name)¶ An object that represents a bounce window risk-level status.
- green: Low risk
- yellow: Medium risk
- red: High risk
Objects stringify to ‘red’, ‘green’, or ‘yellow’, and can be compared against those strings. Objects can also be compared against each other. ‘red’ > ‘yellow’ > ‘green’.
>>> green = BounceStatus('green') >>> yellow = BounceStatus('yellow') >>> print green green >>> yellow > green True
Parameters: status_name – The colored risk-level status name.
-
class
trigger.changemgmt.
BounceWindow
(status_by_hour=None, green=None, yellow=None, red=None, default='red')¶ Build a bounce window of 24
BounceStatus
objects.You may either specify your own list of 24
BounceStatus
objects usingstatus_by_hour
, or you may omit this argument and specify your ‘green’, ‘yellow’, and ‘red’ risk levels by using hyphenated and comma-separated text strings.You may use digits (“14”) or hyphenated ranges (“0-5”) and may join these together using a comma (“,”) with or without spacing separating them. For example “0-5, 14” will be parsed into
[0, 1, 2, 3, 4, 5, 14]
.The
default
color is used to fill in the gaps between the other colors, so that the total is always 24 in the resultant list status objects.>>> b = BounceWindow(green='0-3, 23', red='10', default='yellow') >>> b.status() <BounceStatus: yellow> >>> b.next_ok('green') datetime.datetime(2012, 12, 5, 4, 0, tzinfo=<UTC>) >>> b.dump() {0: <BounceStatus: green>, 1: <BounceStatus: green>, 2: <BounceStatus: green>, 3: <BounceStatus: green>, 4: <BounceStatus: yellow>, 5: <BounceStatus: yellow>, 6: <BounceStatus: yellow>, 7: <BounceStatus: yellow>, 8: <BounceStatus: yellow>, 9: <BounceStatus: yellow>, 10: <BounceStatus: red>, 11: <BounceStatus: yellow>, 12: <BounceStatus: yellow>, 13: <BounceStatus: yellow>, 14: <BounceStatus: yellow>, 15: <BounceStatus: yellow>, 16: <BounceStatus: yellow>, 17: <BounceStatus: yellow>, 18: <BounceStatus: yellow>, 19: <BounceStatus: yellow>, 20: <BounceStatus: yellow>, 21: <BounceStatus: yellow>, 22: <BounceStatus: yellow>, 23: <BounceStatus: green>}
You may modify the global default fallback color by setting
BOUNCE_DEFAULT_COLOR
in yoursettings.py
.Although the query API is generic and could accomodate any sort of bounce window policy, this constructor knows only about AOL’s bounce windows, which operate on “US/Eastern” time (worldwide), always change on hour boundaries, and are the same every day. If that ever changes, only this class will need to be updated.
End-users are not expected to create new
BounceWindow
objects; instead, usebounce()
orbounce
to get an object, then query its methods.Parameters: - status_by_hour – (Optional) A list of 24
BounceStatus
objects. - green – Representative string of hours.
- yellow – Representative string of hours.
- red – Representative string of hours.
- default – The color used to fill in the gaps between other risk levels.
-
dump
()¶ Dump a mapping of hour to status
-
next_ok
(status, when=None)¶ Return the next time at or after the specified time (default now) that it the bounce status will be at equal to or less than the given status.
For example,
next_ok('yellow')
will return the time that the bounce window becomes ‘yellow’ or ‘green’. Returns UTC time.Parameters: - status – The colored risk-level status name.
- when – A
datetime
object.
-
status
(when=None)¶ Return a
BounceStatus
object for the specified time or now.Parameters: when – A datetime
object.
- status_by_hour – (Optional) A list of 24
-
trigger.changemgmt.
bounce
(device, default=BounceWindow(green='5-7', yellow='0-4, 8-15', red='16-23', default='red'))¶ Return the bounce window for a given device.
Parameters: - device – A
NetDevice
object. - default – A
BounceWindow
object.
- device – A