IP version agnostic

master
Marek Isalski 4 years ago
parent 4ef0eb329c
commit e7d2c458ef

@ -201,38 +201,42 @@ def monty_provision( config, args, routers ):
else:
disabled = 'yes'
comment = make_comment( args.selector, rval, args.hostname )
for addr in args.address:
if args.dry_run:
if args.ipv4.network.prefixlen == 32:
print( '/ip address add interface="%s" address="%s" network="%s" disabled=%s comment="%s"' % ( vlan[ 'name' ], config[ 'default_ipv4_loopback' ], args.ipv4.network.network_address, disabled, comment ) )
if isinstance( addr, ipaddress.IPv4Interface ):
if addr.network.prefixlen == 32:
print( '/ip address add interface="%s" address="%s" network="%s" disabled=%s comment="%s"' % ( vlan[ 'name' ], config[ 'default_ipv4_loopback' ], addr.network.network_address, disabled, comment ) )
else:
print( '/ip address add interface="%s" address="%s" disabled=%s comment="%s"' % ( vlan[ 'name' ], args.ipv4, disabled, comment ) )
if args.ipv6:
print( '/ip address add interface="%s" address="%s" disabled=%s comment="%s"' % ( vlan[ 'name' ], addr, disabled, comment ) )
elif isinstance( addr, ipaddress.IPv6Interface ):
if args.static:
print( '/ipv6 address add interface="%s" address="%s" disabled=%s comment="%s" advertise=no' % ( vlan[ 'name' ], args.ipv6, disabled, comment ) )
print( '/ipv6 address add interface="%s" address="%s" disabled=%s comment="%s" advertise=no' % ( vlan[ 'name' ], addr, disabled, comment ) )
else:
print( '/ipv6 address add interface="%s" address="%s" disabled=%s comment="%s" eui-64=yes advertise=yes' % ( vlan[ 'name' ], args.ipv6.network, disabled, comment ) )
print( '/ipv6 address add interface="%s" address="%s" disabled=%s comment="%s" eui-64=yes advertise=yes' % ( vlan[ 'name' ], addr.network, disabled, comment ) )
else:
if isinstance( addr, ipaddress.IPv4Interface ):
v4addr = { 'interface': vlan[ 'name' ],
'disabled': disabled,
'comment': comment,
}
if args.ipv4.network.prefixlen == 32:
if addr.network.prefixlen == 32:
v4addr[ 'address' ] = config[ 'default_ipv4_loopback' ]
v4addr[ 'network' ] = str( args.ipv4.network.network_address )
v4addr[ 'network' ] = str( addr.network.network_address )
else:
v4addr[ 'address' ] = str( args.ipv4 )
v4addr[ 'address' ] = str( addr )
ip_address.add( **v4addr )
if args.ipv6:
elif isinstance( addr, ipaddress.IPv6Interface ):
v6addr = { 'interface': vlan[ 'name' ],
'disabled': disabled,
'comment': comment,
}
if args.static:
v6addr[ 'address' ] = str( args.ipv6 )
v6addr[ 'address' ] = str( addr )
else:
v6addr[ 'address' ] = str( args.ipv6.network )
v6addr[ 'address' ] = str( addr.network )
v6addr[ 'eui-64' ] = 'yes'
v6addr[ 'advertise' ] = 'yes'
ipv6_address.add( **v6addr )
@ -272,8 +276,7 @@ def main():
parser_provision.add_argument( '--selector', type = str, default = None )
parser_provision.add_argument( 'hostname' )
parser_provision.add_argument( 'vlan', type = int )
parser_provision.add_argument( 'ipv4', type = ipaddress.IPv4Interface )
parser_provision.add_argument( 'ipv6', type = ipaddress.IPv6Interface, nargs = "?" )
parser_provision.add_argument( 'address', type = ipaddress.ip_interface, nargs = "+" )
parser_provision.set_defaults( func = monty_provision )
args = parser.parse_args()

Loading…
Cancel
Save