Skip to content

Commit e3decbc

Browse files
committed
add "--new-address" CLI option
1 parent 5c94288 commit e3decbc

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ip_pool/cli.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
def parse_args():
77
parser = ArgumentParser()
88
parser.add_argument("pool_db_json", help="Path to ip pool database json file")
9-
parser.add_argument("--initialize", metavar="cidr_address", help="Initialize IP pool with the provided CIDR address/netmask")
9+
parser.add_argument(
10+
"--new-address",
11+
metavar="HOSTNAME",
12+
help="Allocate next unused address to HOSTNAME",
13+
)
1014
parsed = parser.parse_args()
1115
return parsed
1216

@@ -16,7 +20,10 @@ def ip_pool_main():
1620
pool = IPAddressPool(options.pool_db_json)
1721
if options.initialize:
1822
pool.initialize(options.initialize)
19-
for addr in pool.addresses:
23+
24+
if options.new_address:
25+
hostname = options.new_address
26+
addr = pool.new_address(hostname)
2027
print(addr)
2128

2229

0 commit comments

Comments
 (0)