paul@938 | 1 | #!/usr/bin/env python |
paul@938 | 2 | |
paul@938 | 3 | """ |
paul@938 | 4 | Common scheduling functionality. |
paul@938 | 5 | |
paul@1025 | 6 | Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk> |
paul@938 | 7 | |
paul@938 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@938 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@938 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@938 | 11 | version. |
paul@938 | 12 | |
paul@938 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@938 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@938 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@938 | 16 | details. |
paul@938 | 17 | |
paul@938 | 18 | You should have received a copy of the GNU General Public License along with |
paul@938 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@938 | 20 | """ |
paul@938 | 21 | |
paul@1028 | 22 | from imiptools.handlers.scheduling.manifest import scheduling_functions |
paul@938 | 23 | |
paul@1025 | 24 | def apply_scheduling_functions(functions, handler): |
paul@1025 | 25 | |
paul@1025 | 26 | """ |
paul@1025 | 27 | Apply the given scheduling 'functions' in the current object of the given |
paul@1025 | 28 | 'handler'. |
paul@1025 | 29 | """ |
paul@1025 | 30 | |
paul@1025 | 31 | response = "ACCEPTED" |
paul@1025 | 32 | |
paul@1025 | 33 | for fn in functions: |
paul@1025 | 34 | |
paul@1025 | 35 | # NOTE: Should signal an error for incorrectly configured resources. |
paul@1025 | 36 | |
paul@1025 | 37 | if not fn: |
paul@1025 | 38 | return "DECLINED" |
paul@1025 | 39 | |
paul@1025 | 40 | # Keep evaluating scheduling functions, stopping only if one |
paul@1025 | 41 | # declines or gives a null response. |
paul@1025 | 42 | |
paul@1025 | 43 | else: |
paul@1025 | 44 | result = fn(handler) |
paul@1025 | 45 | |
paul@1025 | 46 | # Return a negative result immediately. |
paul@1025 | 47 | |
paul@1025 | 48 | if not result or result == "DECLINED": |
paul@1025 | 49 | return result |
paul@1025 | 50 | |
paul@1025 | 51 | # Modify the eventual response from acceptance if a countering |
paul@1025 | 52 | # result is obtained. |
paul@1025 | 53 | |
paul@1025 | 54 | elif response == "ACCEPTED": |
paul@1025 | 55 | response = result |
paul@1025 | 56 | |
paul@1025 | 57 | return response |
paul@1025 | 58 | |
paul@938 | 59 | # vim: tabstop=4 expandtab shiftwidth=4 |