2020-01-14 10:05:42 +00:00
|
|
|
import argparse
|
|
|
|
|
2020-01-14 10:22:04 +00:00
|
|
|
from uncloud.hack.vm import VM
|
2020-01-14 13:23:26 +00:00
|
|
|
from uncloud.hack.config import Config
|
2020-01-14 18:02:15 +00:00
|
|
|
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
|
2020-01-14 10:22:04 +00:00
|
|
|
|
2020-01-14 10:05:42 +00:00
|
|
|
arg_parser = argparse.ArgumentParser('hack', add_help=False)
|
2020-01-14 10:25:06 +00:00
|
|
|
#description="Commands that are unfinished - use at own risk")
|
2020-01-14 10:22:04 +00:00
|
|
|
arg_parser.add_argument('--create-vm', action='store_true')
|
2020-01-14 18:02:15 +00:00
|
|
|
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
|
|
|
|
|
|
|
arg_parser.add_argument('--init-network', help="Initialise networking")
|
2020-01-15 12:26:05 +00:00
|
|
|
arg_parser.add_argument('--management-network', help="IPv6 management network")
|
|
|
|
arg_parser.add_argument('--run-dns-ra', action='store_true',
|
|
|
|
help="Provide router advertisements and DNS resolution via dnsmasq")
|
|
|
|
|
|
|
|
|
2020-01-14 10:05:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main(arguments):
|
2020-01-14 10:09:45 +00:00
|
|
|
print(arguments)
|
2020-01-14 13:23:26 +00:00
|
|
|
config = Config(arguments)
|
|
|
|
|
2020-01-14 10:22:04 +00:00
|
|
|
if arguments['create_vm']:
|
|
|
|
print("Creating VM")
|
2020-01-14 13:23:26 +00:00
|
|
|
vm = VM(config)
|
2020-01-14 10:22:04 +00:00
|
|
|
vm.create()
|
2020-01-14 18:02:15 +00:00
|
|
|
|
|
|
|
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 08:16:29 +00:00
|
|
|
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()
|
|
|
|
|
2020-01-15 12:26:05 +00:00
|
|
|
if arguments['run_dns_ra']:
|
|
|
|
if not arguments['management_network']:
|
|
|
|
raise UncloudException("Providing DNS/RAs requires a /64 IPv6 network. You can use fd00::/64 for testing (non production!)")
|
2020-01-19 08:16:29 +00:00
|
|
|
|
|
|
|
dnsra = DNSRA(arguments['management_network'])
|
|
|
|
dnsra.setup()
|