|
|
@ -201,38 +201,42 @@ 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 )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for addr in args.address:
|
|
|
|
if args.dry_run:
|
|
|
|
if args.dry_run:
|
|
|
|
if args.ipv4.network.prefixlen == 32:
|
|
|
|
if isinstance( addr, ipaddress.IPv4Interface ):
|
|
|
|
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 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:
|
|
|
|
else:
|
|
|
|
print( '/ip address add interface="%s" address="%s" disabled=%s comment="%s"' % ( vlan[ 'name' ], args.ipv4, disabled, comment ) )
|
|
|
|
print( '/ip address add interface="%s" address="%s" disabled=%s comment="%s"' % ( vlan[ 'name' ], addr, disabled, comment ) )
|
|
|
|
if args.ipv6:
|
|
|
|
elif isinstance( addr, ipaddress.IPv6Interface ):
|
|
|
|
if args.static:
|
|
|
|
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:
|
|
|
|
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:
|
|
|
|
else:
|
|
|
|
|
|
|
|
if isinstance( addr, ipaddress.IPv4Interface ):
|
|
|
|
v4addr = { 'interface': vlan[ 'name' ],
|
|
|
|
v4addr = { 'interface': vlan[ 'name' ],
|
|
|
|
'disabled': disabled,
|
|
|
|
'disabled': disabled,
|
|
|
|
'comment': comment,
|
|
|
|
'comment': comment,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if args.ipv4.network.prefixlen == 32:
|
|
|
|
if addr.network.prefixlen == 32:
|
|
|
|
v4addr[ 'address' ] = config[ 'default_ipv4_loopback' ]
|
|
|
|
v4addr[ 'address' ] = config[ 'default_ipv4_loopback' ]
|
|
|
|
v4addr[ 'network' ] = str( args.ipv4.network.network_address )
|
|
|
|
v4addr[ 'network' ] = str( addr.network.network_address )
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
v4addr[ 'address' ] = str( args.ipv4 )
|
|
|
|
v4addr[ 'address' ] = str( addr )
|
|
|
|
ip_address.add( **v4addr )
|
|
|
|
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 )
|
|
|
@ -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()
|
|
|
|