forked from uncloud/uncloud
54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
import subprocess
|
|
import ipaddress
|
|
|
|
from uncloud import UncloudException
|
|
|
|
|
|
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"
|
|
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}"
|
|
|
|
# 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):
|
|
def __init__(self):
|
|
pass
|
|
|
|
|
|
class Firewall(object):
|
|
pass
|