From: smbaker Date: Thu, 25 Jul 2013 14:13:38 +0000 (-0700) Subject: automatically assign unused subnet address X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=6f6994bdd67b563d948364c67ea08693194634c4;p=plstackapi.git automatically assign unused subnet address --- 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<