IP version agnostic

master
Marek Isalski 4 years ago
parent 4ef0eb329c
commit e7d2c458ef

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

Loading…
Cancel
Save