Index: trunk/pybal/pybal/util.py |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | """ |
3 | 3 | util.py - PyBal utility classes |
4 | | -Copyright (C) 2006 by Mark Bergsma <mark@nedworks.org> |
| 4 | +Copyright (C) 2006-2008 by Mark Bergsma <mark@nedworks.org> |
5 | 5 | |
6 | 6 | LVS Squid balancer/monitor for managing the Wikimedia Squid servers using LVS |
7 | 7 | """ |
— | — | @@ -37,3 +37,41 @@ |
38 | 38 | self.file.close() |
39 | 39 | self.file = file(self.filename, 'a') |
40 | 40 | self.lineEnded = True |
| 41 | + |
| 42 | +class ConfigDict(dict): |
| 43 | + |
| 44 | + def getint(self, key, default=None): |
| 45 | + try: |
| 46 | + return int(self[key]) |
| 47 | + except KeyError: |
| 48 | + if defaut is not None: |
| 49 | + return default |
| 50 | + else: |
| 51 | + raise |
| 52 | + # do not intercept ValueError |
| 53 | + |
| 54 | + def getboolean(self, key, default=None): |
| 55 | + try: |
| 56 | + value = self[key].strip().lower() |
| 57 | + except KeyError: |
| 58 | + if default is not None: |
| 59 | + return default |
| 60 | + else: |
| 61 | + raise |
| 62 | + else: |
| 63 | + if value in ('t', 'true', 'y', 'yes', 'on', '1'): |
| 64 | + return True |
| 65 | + elif value in ('f', 'false', 'n', 'no', 'off', '0'): |
| 66 | + return False |
| 67 | + else: |
| 68 | + raise ValueError |
| 69 | + |
| 70 | + def getfloat(self, key, default=None): |
| 71 | + try: |
| 72 | + return float(self[key]) |
| 73 | + except KeyError: |
| 74 | + if default is not None: |
| 75 | + return default |
| 76 | + else: |
| 77 | + raise |
| 78 | + # do not intercept ValueError |
\ No newline at end of file |
Index: trunk/pybal/pybal/pybal.py |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | |
13 | 13 | import os, sys, signal |
14 | 14 | |
15 | | -import ipvs, monitor, bgp |
| 15 | +import ipvs, monitor, bgp, util |
16 | 16 | |
17 | 17 | from twisted.internet import reactor |
18 | 18 | |
— | — | @@ -388,44 +388,6 @@ |
389 | 389 | @classmethod |
390 | 390 | def addPrefix(cls, prefix): |
391 | 391 | cls.prefixes.add(bgp.IPv4IP(prefix)) # FIXME: IPv6 |
392 | | - |
393 | | -class ConfigDict(dict): |
394 | | - |
395 | | - def getint(self, key, default=None): |
396 | | - try: |
397 | | - return int(self[key]) |
398 | | - except KeyError: |
399 | | - if defaut is not None: |
400 | | - return default |
401 | | - else: |
402 | | - raise |
403 | | - # do not intercept ValueError |
404 | | - |
405 | | - def getboolean(self, key, default=None): |
406 | | - try: |
407 | | - value = self[key].strip().lower() |
408 | | - except KeyError: |
409 | | - if default is not None: |
410 | | - return default |
411 | | - else: |
412 | | - raise |
413 | | - else: |
414 | | - if value in ('t', 'true', 'y', 'yes', 'on', '1'): |
415 | | - return True |
416 | | - elif value in ('f', 'false', 'n', 'no', 'off', '0'): |
417 | | - return False |
418 | | - else: |
419 | | - raise ValueError |
420 | | - |
421 | | - def getfloat(self, key, default=None): |
422 | | - try: |
423 | | - return float(self[key]) |
424 | | - except KeyError: |
425 | | - if default is not None: |
426 | | - return default |
427 | | - else: |
428 | | - raise |
429 | | - # do not intercept ValueError |
430 | 392 | |
431 | 393 | def parseCommandLine(configuration): |
432 | 394 | """ |
— | — | @@ -621,7 +583,7 @@ |
622 | 584 | config.get(section, 'scheduler')) |
623 | 585 | |
624 | 586 | # Read the custom configuration options of the LVS section |
625 | | - configdict = ConfigDict(config.items(section)) |
| 587 | + configdict = util.ConfigDict(config.items(section)) |
626 | 588 | |
627 | 589 | # Override with command line options |
628 | 590 | configdict.update(cliconfig) |