From 6f6994bdd67b563d948364c67ea08693194634c4 Mon Sep 17 00:00:00 2001 From: smbaker Date: Thu, 25 Jul 2013 07:13:38 -0700 Subject: [PATCH] automatically assign unused subnet address --- planetstack/core/models/network.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/planetstack/core/models/network.py b/planetstack/core/models/network.py index c55bae6..be13ea7 100644 --- a/planetstack/core/models/network.py +++ b/planetstack/core/models/network.py @@ -1,4 +1,5 @@ import os +import socket from django.db import models from core.models import PlCoreBase, Site, Slice, Sliver from django.contrib.contenttypes.models import ContentType @@ -6,6 +7,19 @@ from django.contrib.contenttypes import generic # Create your models here. +SUBNET_BASE = "10.0.0.0" +SUBNET_NODE_BITS = 12 # enough for 4096 bits per subnet +SUBNET_SUBNET_BITS = 12 # enough for 4096 private networks + +def find_unused_subnet(base, subnet_bits, node_bits, existing_subnets): + i=0 + while True: + subnet_i = (i<