|
|
|
@ -201,41 +201,45 @@ def monty_provision( config, args, routers ):
|
|
|
|
|
else:
|
|
|
|
|
disabled = 'yes'
|
|
|
|
|
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:
|
|
|
|
|
v4addr = { 'interface': vlan[ 'name' ],
|
|
|
|
|
'disabled': disabled,
|
|
|
|
|
'comment': comment,
|
|
|
|
|
}
|
|
|
|
|
if args.ipv4.network.prefixlen == 32:
|
|
|
|
|
v4addr[ 'address' ] = config[ 'default_ipv4_loopback' ]
|
|
|
|
|
v4addr[ 'network' ] = str( args.ipv4.network.network_address )
|
|
|
|
|
for addr in args.address:
|
|
|
|
|
if args.dry_run:
|
|
|
|
|
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' ], 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' ], 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:
|
|
|
|
|
v4addr[ 'address' ] = str( args.ipv4 )
|
|
|
|
|
ip_address.add( **v4addr )
|
|
|
|
|
if isinstance( addr, ipaddress.IPv4Interface ):
|
|
|
|
|
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:
|
|
|
|
|
v6addr = { 'interface': vlan[ 'name' ],
|
|
|
|
|
'disabled': disabled,
|
|
|
|
|
'comment': comment,
|
|
|
|
|
}
|
|
|
|
|
if args.static:
|
|
|
|
|
v6addr[ 'address' ] = str( args.ipv6 )
|
|
|
|
|
else:
|
|
|
|
|
v6addr[ 'address' ] = str( args.ipv6.network )
|
|
|
|
|
v6addr[ 'eui-64' ] = 'yes'
|
|
|
|
|
v6addr[ 'advertise' ] = 'yes'
|
|
|
|
|
ipv6_address.add( **v6addr )
|
|
|
|
|
elif isinstance( addr, ipaddress.IPv6Interface ):
|
|
|
|
|
v6addr = { 'interface': vlan[ 'name' ],
|
|
|
|
|
'disabled': disabled,
|
|
|
|
|
'comment': comment,
|
|
|
|
|
}
|
|
|
|
|
if args.static:
|
|
|
|
|
v6addr[ 'address' ] = str( addr )
|
|
|
|
|
else:
|
|
|
|
|
v6addr[ 'address' ] = str( addr.network )
|
|
|
|
|
v6addr[ 'eui-64' ] = 'yes'
|
|
|
|
|
v6addr[ 'advertise' ] = 'yes'
|
|
|
|
|
ipv6_address.add( **v6addr )
|
|
|
|
|
|
|
|
|
|
if args.dry_run:
|
|
|
|
|
print()
|
|
|
|
@ -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()
|
|
|
|
|