forked from uncloud/uncloud
in between commit
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
parent
3d2f8574d3
commit
d3f2a3e071
4 changed files with 125 additions and 21 deletions
|
|
@ -13,32 +13,52 @@ log = logging.getLogger(__name__)
|
|||
|
||||
|
||||
wireguard_template="""
|
||||
|
||||
[Interface]
|
||||
ListenPort = 51820
|
||||
PrivateKey = {privatekey}
|
||||
"""
|
||||
|
||||
# Nico, 2019-01-23, Switzerland
|
||||
#[Peer]
|
||||
#PublicKey = kL1S/Ipq6NkFf1MAsNRou4b9VoUsnnb4ZxgiBrH0zA8=
|
||||
#AllowedIPs = 2a0a:e5c1:101::/48
|
||||
peer_template="""
|
||||
# {username}
|
||||
[Peer]
|
||||
PublicKey = {public_key}
|
||||
AllowedIPs = {vpnnetwork}
|
||||
"""
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'General uncloud commands'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--hostname', action='store_true', help='Name of this VPN Host',
|
||||
parser.add_argument('--hostname',
|
||||
action='store_true',
|
||||
help='Name of this VPN Host',
|
||||
required=True)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
# for net
|
||||
if options['bootstrap']:
|
||||
self.bootstrap()
|
||||
|
||||
self.create_vpn_config(options['hostname'])
|
||||
|
||||
def create_vpn_config(self, hostname):
|
||||
for pool in VPNPool.objects.filter(vpn_hostname
|
||||
default_cluster = VPNNetwork.objects.get_or_create(name="default")
|
||||
# local_host =
|
||||
configs = []
|
||||
|
||||
for pool in VPNPool.objects.filter(vpn_hostname=hostname):
|
||||
pool_config = {
|
||||
'private_key': pool.wireguard_private_key,
|
||||
'subnetwork_size': pool.subnetwork_size,
|
||||
'config_file': '/etc/wireguard/{}.conf'.format(pool.network),
|
||||
'peers': []
|
||||
}
|
||||
|
||||
for vpnnetwork in VPNNetworkReservation.objects.filter(vpnpool=pool):
|
||||
pool_config['peers'].append({
|
||||
'vpnnetwork': "{}/{}".format(vpnnetwork.address,
|
||||
pool_config['subnetwork_size']),
|
||||
'public_key': vpnnetwork.wireguard_public_key,
|
||||
}
|
||||
)
|
||||
|
||||
configs.append(pool_config)
|
||||
|
||||
print(configs)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue