uncloud/uncloud/hack/main.py

70 lines
2.9 KiB
Python
Raw Normal View History

import argparse
2020-01-23 17:41:59 +00:00
import logging
from uncloud.hack.vm import VM
2020-01-14 13:23:26 +00:00
from uncloud.hack.config import Config
from uncloud.hack.mac import MAC
2020-01-19 08:16:29 +00:00
from uncloud.hack.net import VXLANBridge, DNSRA
2020-01-15 12:26:05 +00:00
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')
2020-01-19 08:16:29 +00:00
2020-01-19 10:30:41 +00:00
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)
2020-01-15 12:26:05 +00:00
arg_parser.add_argument('--run-dns-ra', action='store_true',
help="Provide router advertisements and DNS resolution via dnsmasq")
2020-01-19 11:55:06 +00:00
arg_parser.add_argument('--use-sudo', help="Use sudo for command requiring root!", action='store_true')
2020-01-24 12:56:08 +00:00
arg_parser.add_argument('--memory', help="Size of memory (GB)", type=int)
arg_parser.add_argument('--cores', help="Amount of CPU cores", type=int)
arg_parser.add_argument('--no-db', help="Disable connection to etcd. For local testing only!", action='store_true')
2020-01-15 12:26:05 +00:00
2020-01-23 17:41:59 +00:00
log = logging.getLogger(__name__)
def main(arguments):
2020-01-23 17:41:59 +00:00
log.debug("args={}".format(arguments))
2020-01-14 13:23:26 +00:00
config = Config(arguments)
if arguments['create_vm']:
print("Creating VM")
2020-01-14 13:23:26 +00:00
vm = VM(config)
2020-01-24 12:56:08 +00:00
vm.commandline()
if arguments['last_used_mac']:
m = MAC(config)
print(m.last_used_mac())
if arguments['get_new_mac']:
2020-01-14 18:10:59 +00:00
print(MAC(config).get_next())
2020-01-15 12:26:05 +00:00
2020-01-19 10:30:41 +00:00
#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'],
2020-01-19 11:55:06 +00:00
route=arguments['network'],
uplinkdev=arguments['vxlan_uplink_device'],
use_sudo=arguments['use_sudo'])
2020-01-19 10:30:41 +00:00
vb._setup_vxlan()
2020-01-19 11:55:06 +00:00
vb._setup_bridge()
vb._add_vxlan_to_bridge()
2020-01-19 11:55:06 +00:00
vb._route_network()
2020-01-19 08:16:29 +00:00
2020-01-15 12:26:05 +00:00
if arguments['run_dns_ra']:
2020-01-23 17:43:41 +00:00
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!)")
2020-01-19 08:16:29 +00:00
dnsra = DNSRA(route=arguments['network'],
2020-01-23 17:43:41 +00:00
vni=arguments['vni'],
use_sudo=arguments['use_sudo'])
dnsra._setup_dnsmasq()