|
| 1 | +import sys |
1 | 2 | from argparse import ArgumentParser
|
2 | 3 |
|
3 |
| -from .ip_pool import IPAddressPool |
| 4 | +from .ip_pool import IPAddressPool, IPAddressPoolException |
4 | 5 |
|
5 | 6 |
|
6 | 7 | def parse_args():
|
@@ -32,23 +33,28 @@ def parse_args():
|
32 | 33 |
|
33 | 34 | def ip_pool_main():
|
34 | 35 | options = parse_args()
|
35 |
| - pool = IPAddressPool(options.pool_db_json) |
36 |
| - if options.initialize: |
37 |
| - pool.initialize(options.initialize) |
38 |
| - |
39 |
| - if options.release_address: |
40 |
| - hostname = options.release_address |
41 |
| - pool.release_address(hostname) |
42 |
| - |
43 |
| - if options.new_address: |
44 |
| - hostname = options.new_address |
45 |
| - addr = pool.new_address(hostname) |
46 |
| - print(addr) |
47 |
| - |
48 |
| - if options.address_for: |
49 |
| - hostname = options.address_for |
50 |
| - addr = pool.address_for(hostname) |
51 |
| - print(addr) |
| 36 | + try: |
| 37 | + pool = IPAddressPool(options.pool_db_json) |
| 38 | + if options.initialize: |
| 39 | + pool.initialize(options.initialize) |
| 40 | + |
| 41 | + if options.release_address: |
| 42 | + hostname = options.release_address |
| 43 | + pool.release_address(hostname) |
| 44 | + |
| 45 | + if options.new_address: |
| 46 | + hostname = options.new_address |
| 47 | + addr = pool.new_address(hostname) |
| 48 | + print(addr) |
| 49 | + |
| 50 | + if options.address_for: |
| 51 | + hostname = options.address_for |
| 52 | + addr = pool.address_for(hostname) |
| 53 | + print(addr) |
| 54 | + except IPAddressPoolException as e: |
| 55 | + print(e, file=sys.stderr) |
| 56 | + return -1 |
| 57 | + return 0 |
52 | 58 |
|
53 | 59 |
|
54 | 60 | if __name__ == "__main__":
|
|
0 commit comments