addresspool now has cidr field and can only hold one cidr
diff --git a/xos/core/admin.py b/xos/core/admin.py
index 7f9e8fe..ee6c6bf 100644
--- a/xos/core/admin.py
+++ b/xos/core/admin.py
@@ -2117,13 +2117,13 @@
}
class AddressPoolAdmin(XOSBaseAdmin):
- list_display = ("name",)
+ list_display = ("name", "cidr")
list_display_links = ('name',)
form=AddressPoolForm
fieldsets = [
- (None, {'fields': ['name', 'gateway_ip', 'gateway_mac', 'addresses', 'inuse', 'service'],
+ (None, {'fields': ['name', 'cidr', 'gateway_ip', 'gateway_mac', 'addresses', 'inuse', 'service'],
'classes':['suit-tab suit-tab-general']}),
]
diff --git a/xos/core/models/network.py b/xos/core/models/network.py
index 6ba6810..8373814 100644
--- a/xos/core/models/network.py
+++ b/xos/core/models/network.py
@@ -352,6 +352,7 @@
addresses = models.TextField(blank=True, null=True)
gateway_ip = models.CharField(max_length=32, null=True)
gateway_mac = models.CharField(max_length=32, null=True)
+ cidr = models.CharField(max_length=32, null=True)
inuse = models.TextField(blank=True, null=True)
service = models.ForeignKey(Service, related_name="addresspools", null=True, blank=True)
diff --git a/xos/services/vrouter/admin.py b/xos/services/vrouter/admin.py
index fb9321f..318b3dc 100644
--- a/xos/services/vrouter/admin.py
+++ b/xos/services/vrouter/admin.py
@@ -64,6 +64,7 @@
public_mac = forms.CharField(required=True)
gateway_ip = forms.CharField(required=False)
gateway_mac = forms.CharField(required=False)
+ cidr = forms.CharField(required=False)
address_pool = forms.ModelChoiceField(queryset=AddressPool.objects.all(),required=False)
def __init__(self,*args,**kwargs):
@@ -77,6 +78,7 @@
self.fields['public_mac'].initial = self.instance.public_mac
self.fields['gateway_ip'].initial = self.instance.gateway_ip
self.fields['gateway_mac'].initial = self.instance.gateway_mac
+ self.fields['cidr'].initial = self.instance.cidr
if (not self.instance) or (not self.instance.pk):
# default fields for an 'add' form
self.fields['kind'].initial = VROUTER_KIND
@@ -96,9 +98,9 @@
list_display = ('backend_status_icon', 'id', 'subscriber_tenant', 'public_ip' )
list_display_links = ('backend_status_icon', 'id')
fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_tenant', 'subscriber_service',
- 'address_pool', 'public_ip', 'public_mac', 'gateway_ip', 'gateway_mac'],
+ 'address_pool', 'public_ip', 'public_mac', 'gateway_ip', 'gateway_mac', 'cidr'],
'classes':['suit-tab suit-tab-general']})]
- readonly_fields = ('backend_status_text', 'service_specific_attribute', 'gateway_ip', 'gateway_mac')
+ readonly_fields = ('backend_status_text', 'service_specific_attribute', 'gateway_ip', 'gateway_mac', 'cidr')
form = VRouterTenantForm
suit_form_tabs = (('general','Details'),)
diff --git a/xos/services/vrouter/models.py b/xos/services/vrouter/models.py
index c9dd7b6..5dba838 100644
--- a/xos/services/vrouter/models.py
+++ b/xos/services/vrouter/models.py
@@ -89,6 +89,12 @@
return self.address_pool.gateway_mac
@property
+ def cidr(self):
+ if not self.address_pool:
+ return None
+ return self.address_pool.cidr
+
+ @property
def address_pool(self):
if getattr(self, "cached_address_pool", None):
return self.cached_address_pool
diff --git a/xos/tosca/resources/addresspool.py b/xos/tosca/resources/addresspool.py
index e4a2860..8cd3e83 100644
--- a/xos/tosca/resources/addresspool.py
+++ b/xos/tosca/resources/addresspool.py
@@ -31,20 +31,31 @@
ip = ip & netmask | i
dest.append( socket.inet_ntoa(struct.pack("!L", ip)) )
- return dest
+ return (dest, bits)
def get_xos_args(self):
args = super(XOSAddressPool, self).get_xos_args()
if "addresses" in args:
- dest = []
- for addr in args["addresses"].split():
- addr=addr.strip()
- if "/" in addr:
- dest.extend(self.expand_cidr(addr))
- else:
- dest.append(addr)
- args["addresses"] = " ".join(dest)
+ addr = args["addresses"]
+ if "," in addr:
+ raise Exception("Only one cidr per AddressPool")
+ if not "/" in addr:
+ raise Exception("AddressPool addresses must be a cidr")
+ (cidr_addrs, cidr_netbits) = self.expand_cidr(addr)
+ args["addresses"] = " ".join(cidr_addrs)
+ args["cidr"] = addr
+
+# if "addresses" in args:
+# dest = []
+# for addr in args["addresses"].split():
+# addr=addr.strip()
+# if "/" in addr:
+# (cidr_addrs, cidr_netbits) = self.expand_cidr(addr)
+# dest.extend(cidr_addrs)
+# else:
+# dest.append(addr)
+# args["addresses"] = " ".join(dest)
return args