forked from uncloud/uncloud
Cleanup networking
This commit is contained in:
parent
30be791312
commit
bd9dbb12b7
2 changed files with 50 additions and 18 deletions
|
@ -13,8 +13,11 @@ arg_parser.add_argument('--create-vm', action='store_true')
|
|||
arg_parser.add_argument('--last-used-mac', action='store_true')
|
||||
arg_parser.add_argument('--get-new-mac', action='store_true')
|
||||
|
||||
arg_parser.add_argument('--init-network', help="Initialise networking")
|
||||
arg_parser.add_argument('--management-network', help="IPv6 management network")
|
||||
arg_parser.add_argument('--init-network', help="Initialise networking", action='store_true')
|
||||
arg_parser.add_argument('--create-vxlan', help="Initialise networking", action='store_true')
|
||||
arg_parser.add_argument('--network', help="/64 IPv6 network")
|
||||
arg_parser.add_argument('--vxlan-uplink-device', help="The VXLAN underlay device, i.e. eth0")
|
||||
arg_parser.add_argument('--vni', help="VXLAN ID (decimal)", type=int)
|
||||
arg_parser.add_argument('--run-dns-ra', action='store_true',
|
||||
help="Provide router advertisements and DNS resolution via dnsmasq")
|
||||
|
||||
|
@ -37,15 +40,17 @@ def main(arguments):
|
|||
if arguments['get_new_mac']:
|
||||
print(MAC(config).get_next())
|
||||
|
||||
if arguments['init_networking!']:
|
||||
if not arguments['management_network']:
|
||||
raise UncloudException("Initialising the network requires an IPv6 network. You can use fd00::/64 for testing (non production!)")
|
||||
vb = VXLANBridge(arguments['management_network'])
|
||||
vb.setup()
|
||||
#if arguments['init_network']:
|
||||
if arguments['create_vxlan']:
|
||||
if not arguments['network'] or not arguments['vni'] or not arguments['vxlan_uplink_device']:
|
||||
raise UncloudException("Initialising the network requires an IPv6 network and a VNI. You can use fd00::/64 and vni=1 for testing (non production!)")
|
||||
vb = VXLANBridge(vni=arguments['vni'],
|
||||
uplinkdev=arguments['vxlan_uplink_device'])
|
||||
vb._setup_vxlan()
|
||||
|
||||
if arguments['run_dns_ra']:
|
||||
if not arguments['management_network']:
|
||||
if not arguments['network']:
|
||||
raise UncloudException("Providing DNS/RAs requires a /64 IPv6 network. You can use fd00::/64 for testing (non production!)")
|
||||
|
||||
dnsra = DNSRA(arguments['management_network'])
|
||||
dnsra = DNSRA(arguments['network'])
|
||||
dnsra.setup()
|
||||
|
|
|
@ -1,21 +1,48 @@
|
|||
import subprocess
|
||||
import ipaddress
|
||||
|
||||
from uncloud import UncloudException
|
||||
|
||||
class ManagementBridge(VXLANBridge):
|
||||
pass
|
||||
|
||||
class VXLANBridge(object):
|
||||
def __init__(self, vni, bridgedev=None, uplinkdev=None):
|
||||
self.management_vni = 1
|
||||
|
||||
cmd_create_vxlan = "ip -6 link add {vxlandev} type vxlan id {netid} dstport 4789 group ff05::{netid} dev {uplinkdev} ttl 5"
|
||||
cmd_create_vxlan = "ip -6 link add {vxlandev} type vxlan id {vni_dec} dstport 4789 group {multicast_address} dev {uplinkdev} ttl 5"
|
||||
cmd_up_dev = "ip link set {dev} up"
|
||||
cmd_create_bridge="ip link add {bridgedev} type bridge"
|
||||
cmd_add_to_bridge="ip link set {vxlandev} master {bridgedev} up"
|
||||
cmd_add_addr="ip addr add {ip} dev {bridgedev}"
|
||||
|
||||
def setup_networking(dev=wlan0, v6net):
|
||||
vxlandev=vxlan${netid}
|
||||
bridgedev=br${netid}
|
||||
# VXLAN ids are at maximum 24 bit - use a /104
|
||||
multicast_network = ipaddress.IPv6Network("ff05::/104")
|
||||
max_vni = (2**24)-1
|
||||
|
||||
def __init__(self,
|
||||
vni,
|
||||
uplinkdev):
|
||||
self.config = {}
|
||||
|
||||
if vni > self.max_vni:
|
||||
raise UncloudException("VNI must be in the range of 0 .. {}".format(self.max_vni))
|
||||
|
||||
self.config['vni_dec'] = vni
|
||||
self.config['vni_hex'] = "{:x}".format(vni)
|
||||
self.config['multicast_address'] = self.multicast_network[vni]
|
||||
|
||||
self.config['uplinkdev'] = uplinkdev
|
||||
self.config['vxlandev'] = "vx{}".format(self.config['vni_hex'])
|
||||
self.config['bridgedev'] = "br{}".format(self.config['vni_hex'])
|
||||
|
||||
|
||||
def setup_networking(self):
|
||||
pass
|
||||
|
||||
def _setup_vxlan(self):
|
||||
# check for device first (?)
|
||||
cmd = self.cmd_create_vxlan.format(**self.config)
|
||||
print(cmd)
|
||||
subprocess.run(cmd.split())
|
||||
|
||||
class ManagementBridge(VXLANBridge):
|
||||
pass
|
||||
|
||||
|
||||
class DNSRA(object):
|
||||
|
|
Loading…
Reference in a new issue