2020-01-15 11:40:37 +00:00
|
|
|
import subprocess
|
2020-01-19 10:30:41 +00:00
|
|
|
import ipaddress
|
2020-01-15 11:40:37 +00:00
|
|
|
|
2020-01-19 10:30:41 +00:00
|
|
|
from uncloud import UncloudException
|
2020-01-19 08:16:29 +00:00
|
|
|
|
2020-01-15 11:40:37 +00:00
|
|
|
|
2020-01-19 10:30:41 +00:00
|
|
|
class VXLANBridge(object):
|
|
|
|
cmd_create_vxlan = "ip -6 link add {vxlandev} type vxlan id {vni_dec} dstport 4789 group {multicast_address} dev {uplinkdev} ttl 5"
|
2020-01-15 11:40:37 +00:00
|
|
|
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}"
|
|
|
|
|
2020-01-19 10:30:41 +00:00
|
|
|
# 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
|
2020-01-15 11:40:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DNSRA(object):
|
|
|
|
def __init__(self):
|
|
|
|
pass
|
2020-01-15 12:26:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Firewall(object):
|
|
|
|
pass
|