forked from uncloud/uncloud
64 lines
2.6 KiB
Python
64 lines
2.6 KiB
Python
import argparse
|
|
import logging
|
|
|
|
from uncloud.hack.vm import VM
|
|
from uncloud.hack.config import Config
|
|
from uncloud.hack.mac import MAC
|
|
from uncloud.hack.net import VXLANBridge, DNSRA
|
|
|
|
from uncloud import UncloudException
|
|
|
|
arg_parser = argparse.ArgumentParser('hack', add_help=False)
|
|
#description="Commands that are unfinished - use at own risk")
|
|
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", 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")
|
|
arg_parser.add_argument('--use-sudo', help="Use sudo for command requiring root!", action='store_true')
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
def main(arguments):
|
|
log.debug("args={}".format(arguments))
|
|
config = Config(arguments)
|
|
|
|
if arguments['create_vm']:
|
|
print("Creating VM")
|
|
vm = VM(config)
|
|
vm.create()
|
|
|
|
if arguments['last_used_mac']:
|
|
m = MAC(config)
|
|
print(m.last_used_mac())
|
|
|
|
if arguments['get_new_mac']:
|
|
print(MAC(config).get_next())
|
|
|
|
#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'],
|
|
route=arguments['network'],
|
|
uplinkdev=arguments['vxlan_uplink_device'],
|
|
use_sudo=arguments['use_sudo'])
|
|
vb._setup_vxlan()
|
|
vb._setup_bridge()
|
|
vb._route_network()
|
|
|
|
if arguments['run_dns_ra']:
|
|
if not arguments['network'] or not arguments['vni']:
|
|
raise UncloudException("Providing DNS/RAs requires a /64 IPv6 network and a VNI. You can use fd00::/64 and vni=1 for testing (non production!)")
|
|
|
|
dnsra = DNSRA(route=arguments['network'],
|
|
vni=arguments['vni'],
|
|
use_sudo=arguments['use_sudo'])
|
|
dnsra._setup_dnsmasq()
|