change address_pool_name to address_pool_id; fix misc bugs
diff --git a/xos/configurations/frontend/Makefile b/xos/configurations/frontend/Makefile
index f372662..ee2739c 100644
--- a/xos/configurations/frontend/Makefile
+++ b/xos/configurations/frontend/Makefile
@@ -36,7 +36,7 @@
mock-cord-pod:
echo "make sure to add '../vtn/files/xos_vtn_config:/opt/xos/xos_configuration/xos_vtn_config:ro' to volumes section of docker-compose.yml"
sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/common/fixtures.yaml
- sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/cord-pod/mgmt-net.yaml"
- sudo docker-compose run xos bash -c "echo somekey > /opt/xos/synchronizers/vcpe/vcpe_public_key; python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/cord-pod/cord-vtn-vsg.yaml
+ sudo docker-compose run xos python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/cord-pod/mgmt-net.yaml
+ sudo docker-compose run xos bash -c "echo somekey > /opt/xos/synchronizers/vcpe/vcpe_public_key; python /opt/xos/tosca/run.py padmin@vicci.org /opt/xos/configurations/cord-pod/cord-vtn-vsg.yaml"
sudo docker exec frontend_xos_1 cp /opt/xos/configurations/cord/xos_cord_config /opt/xos/xos_configuration/
sudo docker exec frontend_xos_1 touch /opt/xos/xos/settings.py
diff --git a/xos/services/cord/models.py b/xos/services/cord/models.py
index bca422c..6e7a917 100644
--- a/xos/services/cord/models.py
+++ b/xos/services/cord/models.py
@@ -877,8 +877,8 @@
def delete(self, *args, **kwargs):
self.cleanup_vbng()
+ self.cleanup_vrouter()
self.cleanup_container()
- self.cleanup_wan_container_ip()
super(VSGTenant, self).delete(*args, **kwargs)
def model_policy_vcpe(pk):
diff --git a/xos/services/vrouter/admin.py b/xos/services/vrouter/admin.py
index 046b897..0731fe6 100644
--- a/xos/services/vrouter/admin.py
+++ b/xos/services/vrouter/admin.py
@@ -10,6 +10,7 @@
from django.utils import timezone
from django.contrib.contenttypes import generic
from suit.widgets import LinkedSelect
+from core.models import AddressPool
from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline
from core.middleware import get_request
@@ -63,7 +64,7 @@
public_mac = forms.CharField(required=True)
gateway_ip = forms.CharField(required=False)
gateway_mac = forms.CharField(required=False)
- address_pool_name = forms.CharField(required=True)
+ address_pool = forms.ModelChoiceField(queryset=AddressPool.objects.all(),required=False)
def __init__(self,*args,**kwargs):
super (VRouterTenantForm,self ).__init__(*args,**kwargs)
@@ -71,7 +72,7 @@
self.fields['provider_service'].queryset = VRouterService.get_service_objects().all()
if self.instance:
# fields for the attributes
- self.fields['address_pool_name'].initial = self.instance.address_pool_name
+ self.fields['address_pool'].initial = self.instance.address_pool
self.fields['public_ip'].initial = self.instance.public_ip
self.fields['public_mac'].initial = self.instance.public_mac
self.fields['gateway_ip'].initial = self.instance.gateway_ip
@@ -85,7 +86,7 @@
def save(self, commit=True):
self.instance.public_ip = self.cleaned_data.get("public_ip")
self.instance.public_mac = self.cleaned_data.get("public_mac")
- self.instance.address_pool_name = self.cleaned_data.get("address_pool_name")
+ self.instance.address_pool = self.cleaned_data.get("address_pool")
return super(VRouterTenantForm, self).save(commit=commit)
class Meta:
@@ -95,7 +96,7 @@
list_display = ('backend_status_icon', 'id', 'subscriber_tenant' )
list_display_links = ('backend_status_icon', 'id')
fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'provider_service', 'subscriber_tenant', 'service_specific_id', # 'service_specific_attribute',
- 'address_pool_name', 'public_ip', 'public_mac', 'gateway_ip', 'gateway_mac'],
+ 'address_pool', 'public_ip', 'public_mac', 'gateway_ip', 'gateway_mac'],
'classes':['suit-tab suit-tab-general']})]
readonly_fields = ('backend_status_text', 'service_specific_attribute', 'gateway_ip', 'gateway_mac')
form = VRouterTenantForm
diff --git a/xos/services/vrouter/models.py b/xos/services/vrouter/models.py
index ab9c90e..ec65a91 100644
--- a/xos/services/vrouter/models.py
+++ b/xos/services/vrouter/models.py
@@ -23,7 +23,7 @@
KIND = VROUTER_KIND
class Meta:
- app_label = "cord"
+ app_label = "vrouter"
verbose_name = "vRouter Service"
proxy = True
@@ -58,7 +58,7 @@
t = VRouterTenant(**kwargs)
t.public_ip = ip
t.public_mac = self.ip_to_mac(ip)
- t.address_pool_name = ap.name
+ t.address_pool_id = ap.id
t.save()
return t
@@ -73,14 +73,51 @@
simple_attributes = ( ("public_ip", None),
("public_mac", None),
- ("address_pool_name", None),
+ ("address_pool_id", None),
)
@property
def gateway_ip(self):
+ if not self.address_pool:
+ return None
return self.address_pool.gateway_ip
@property
def gateway_mac(self):
+ if not self.address_pool:
+ return None
return self.address_pool.gateway_mac
+ @property
+ def address_pool(self):
+ if getattr(self, "cached_address_pool", None):
+ return self.cached_address_pool
+ if not self.address_pool_id:
+ return None
+ aps=AddressPool.objects.filter(id=self.address_pool_id)
+ if not aps:
+ return None
+ ap=aps[0]
+ self.cached_address_pool = ap
+ return ap
+
+ @address_pool.setter
+ def address_pool(self, value):
+ if value:
+ value = value.id
+ if (value != self.get_attribute("address_pool_id", None)):
+ self.cached_address_pool=None
+ self.set_attribute("address_pool_id", value)
+
+ def cleanup_addresspool(self):
+ if self.address_pool_id:
+ ap = AddressPool.objects.filter(id=self.address_pool_id)
+ if ap:
+ ap[0].put_address(addr)
+
+ def delete(self, *args, **kwargs):
+ self.cleanup_addresspool()
+ super(VRouterTenant, self).delete(*args, **kwargs)
+
+VRouterTenant.setup_simple_attributes()
+