now able to deprovision IPv4
This commit is contained in:
parent
e7d2c458ef
commit
7ce6c483b5
49
automonty
49
automonty
@ -17,6 +17,7 @@ import ipaddress
|
|||||||
# home - this is the normal home-location of the IP
|
# home - this is the normal home-location of the IP
|
||||||
# evacuated - this has been moved from this host to elsewhere
|
# evacuated - this has been moved from this host to elsewhere
|
||||||
# evacuee - this is an evacuated address
|
# evacuee - this is an evacuated address
|
||||||
|
# teardown - being destroyed
|
||||||
|
|
||||||
aM1 = re.compile( r"\[aM ?([^]]*)\]" )
|
aM1 = re.compile( r"\[aM ?([^]]*)\]" )
|
||||||
def parse_comment( comment ):
|
def parse_comment( comment ):
|
||||||
@ -180,6 +181,7 @@ def monty_fixup( config, args, routers ):
|
|||||||
def monty_provision( config, args, routers ):
|
def monty_provision( config, args, routers ):
|
||||||
reverse = {}
|
reverse = {}
|
||||||
statics = {}
|
statics = {}
|
||||||
|
if args.dry_run:
|
||||||
print()
|
print()
|
||||||
for ( name, api ) in routers.items():
|
for ( name, api ) in routers.items():
|
||||||
if args.dry_run:
|
if args.dry_run:
|
||||||
@ -244,6 +246,47 @@ def monty_provision( config, args, routers ):
|
|||||||
if args.dry_run:
|
if args.dry_run:
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
def monty_teardown( config, args, routers ):
|
||||||
|
reverse = {}
|
||||||
|
statics = {}
|
||||||
|
if args.dry_run:
|
||||||
|
print()
|
||||||
|
for ( name, api ) in routers.items():
|
||||||
|
if args.dry_run:
|
||||||
|
print( '#' * ( len( name ) + 2 ) )
|
||||||
|
print( '#', name )
|
||||||
|
print()
|
||||||
|
vlans = api.path( 'interface', 'vlan' )
|
||||||
|
ip_address = api.path( 'ip', 'address' )
|
||||||
|
ipv6_address = api.path( 'ipv6', 'address' )
|
||||||
|
|
||||||
|
for addr in ip_address:
|
||||||
|
( sel, rval, hst ) = parse_comment( addr.get( 'comment', '' ) )
|
||||||
|
rval[ 'teardown' ] = True
|
||||||
|
comment = make_comment( sel, rval, hst )
|
||||||
|
if sel == args.hostname or hst == args.hostname:
|
||||||
|
if args.delete:
|
||||||
|
if rval.get( 'teardown', False ):
|
||||||
|
if args.dry_run:
|
||||||
|
print( '/ip address remove [find where interface="%s" and network="%s" and comment~"teardown" and comment~"%s" ]' % ( addr[ 'interface' ], addr[ 'network' ], hst ) )
|
||||||
|
else:
|
||||||
|
print( "deleting %s %s from %s on %s" % ( addr[ 'address' ], addr[ 'network' ], addr[ 'interface' ], name ) )
|
||||||
|
ip_address.remove( addr[ '.id' ] )
|
||||||
|
else:
|
||||||
|
if args.dry_run:
|
||||||
|
print( "# ignoring %s %s on %s on %s" % ( addr[ 'address' ], addr[ 'network' ], addr[ 'interface' ], name ) )
|
||||||
|
else:
|
||||||
|
print( "ignoring %s %s on %s on %s" % ( addr[ 'address' ], addr[ 'network' ], addr[ 'interface' ], name ) )
|
||||||
|
else:
|
||||||
|
if args.dry_run:
|
||||||
|
print( '/ip address set [find where interface="%s" and network="%s" and comment~"%s" ] disabled=yes comment="%s"' % ( addr[ 'interface' ], addr[ 'network' ], hst, comment ) )
|
||||||
|
else:
|
||||||
|
print( "disabling %s %s on %s on %s" % ( addr[ 'address' ], addr[ 'network' ], addr[ 'interface' ], name ) )
|
||||||
|
ip_address.update( **{ '.id': addr[ '.id' ], 'disabled': 'yes', 'comment': comment } )
|
||||||
|
|
||||||
|
if args.dry_run:
|
||||||
|
print()
|
||||||
|
|
||||||
def load_configuration():
|
def load_configuration():
|
||||||
try:
|
try:
|
||||||
config = open( os.path.expanduser( '~/.automonty.yaml' ), 'r' )
|
config = open( os.path.expanduser( '~/.automonty.yaml' ), 'r' )
|
||||||
@ -279,6 +322,12 @@ def main():
|
|||||||
parser_provision.add_argument( 'address', type = ipaddress.ip_interface, nargs = "+" )
|
parser_provision.add_argument( 'address', type = ipaddress.ip_interface, nargs = "+" )
|
||||||
parser_provision.set_defaults( func = monty_provision )
|
parser_provision.set_defaults( func = monty_provision )
|
||||||
|
|
||||||
|
parser_teardown = subparsers.add_parser( 'teardown' )
|
||||||
|
parser_teardown.add_argument( '--delete', action = 'store_true', default = False )
|
||||||
|
parser_teardown.add_argument( 'hostname' )
|
||||||
|
parser_teardown.add_argument( 'vlan', type = int, default = None, nargs = "?" )
|
||||||
|
parser_teardown.set_defaults( func = monty_teardown )
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
routers = connect_routers( config, args )
|
routers = connect_routers( config, args )
|
||||||
args.func( config, args, routers )
|
args.func( config, args, routers )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user