Attempt to add failover servers
diff --git a/xos/core/xoslib/methods/vpnview.py b/xos/core/xoslib/methods/vpnview.py
index 0e2c376..21d97e1 100644
--- a/xos/core/xoslib/methods/vpnview.py
+++ b/xos/core/xoslib/methods/vpnview.py
@@ -29,6 +29,7 @@
clients_can_see_each_other = ReadOnlyField()
ca_crt = ReadOnlyField()
port_number = ReadOnlyField()
+ failover_servers = ReadOnlyField()
creator = ReadOnlyField()
instance = ReadOnlyField()
script_text = ReadOnlyField()
@@ -44,7 +45,7 @@
'service_specific_attribute', 'vpn_subnet',
'server_network', 'creator', 'instance',
'computeNodeName', 'is_persistent', 'clients_can_see_each_other',
- 'ca_crt', 'port_number', 'script_text')
+ 'ca_crt', 'port_number', 'script_text', 'failover_servers')
def getHumanReadableName(self, obj):
return obj.__unicode__()
diff --git a/xos/services/vpn/admin.py b/xos/services/vpn/admin.py
index 0f2c476..bad75e3 100644
--- a/xos/services/vpn/admin.py
+++ b/xos/services/vpn/admin.py
@@ -1,10 +1,9 @@
-import time
-
from core.admin import ReadOnlyAwareAdmin, SliceInline, TenantPrivilegeInline
from core.middleware import get_request
-from core.models import User
+from core.models import TenantPrivilege, User
from django import forms
from django.contrib import admin
+from django.core import serializers
from services.vpn.models import VPN_KIND, VPNService, VPNTenant
from subprocess import Popen, PIPE
@@ -78,7 +77,7 @@
self.fields[
'clients_can_see_each_other'].initial = self.instance.clients_can_see_each_other
self.fields['is_persistent'].initial = self.instance.is_persistent
- self.fields['failover_servers'].initial = self.instance.failover_servers
+ self.fields['failover_servers'].initial = serializers.deserialize('json', self.instance.failover_servers)
if (not self.instance) or (not self.instance.pk):
self.fields['creator'].initial = get_request().user
@@ -97,13 +96,14 @@
self.instance.server_network = self.cleaned_data.get('server_network')
self.instance.clients_can_see_each_other = self.cleaned_data.get(
'clients_can_see_each_other')
- self.instance.failover_servers = self.cleaned_data.get('failover_servers')
+ self.instance.failover_servers = serializers.serialize("json", self.cleaned_data.get('failover_servers'))
+ sorted_tenants = sorted(VPNTenant.get_tenant_objects().all(), key=lambda tenant: tenant.port_number)
prev = 1000
- for (tenant : VPNTenant.get_tenant_objects().order_by('port_number')):
+ for tenant in sorted_tenants:
if (tenant.port_number != prev):
break
- prev++
+ prev += 1
self.instance.port_number = prev
if (not self.instance.ca_crt):
@@ -129,7 +129,7 @@
fieldsets = [(None, {'fields': ['backend_status_text', 'kind',
'provider_service', 'instance', 'creator',
'server_network', 'vpn_subnet', 'is_persistent',
- 'clients_can_see_each_other'],
+ 'clients_can_see_each_other', 'failover_servers'],
'classes': ['suit-tab suit-tab-general']})]
readonly_fields = ('backend_status_text', 'instance')
form = VPNTenantForm
diff --git a/xos/services/vpn/models.py b/xos/services/vpn/models.py
index 3e98047..1c7af1b 100644
--- a/xos/services/vpn/models.py
+++ b/xos/services/vpn/models.py
@@ -1,5 +1,3 @@
-import time
-
from core.models import Service, TenantWithContainer
from django.db import transaction
diff --git a/xos/synchronizers/vpn/steps/sync_vpntenant.py b/xos/synchronizers/vpn/steps/sync_vpntenant.py
index add52fb..2e1fc1a 100644
--- a/xos/synchronizers/vpn/steps/sync_vpntenant.py
+++ b/xos/synchronizers/vpn/steps/sync_vpntenant.py
@@ -1,6 +1,5 @@
import os
import sys
-import time
from django.db.models import F, Q
from services.vpn.models import VPNTenant