Commit ddaf8b1d authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Change behaviour of servers fqdn

Change behaviour of 'CYCLADES_SERVERS_FQDN' setting:
  * If this setting is set to 'None', do not fall back to the public IP
    address of the machine.
  * Return the value of the setting even if the machine has no public
    IP address.
parent 40f62bb3
......@@ -126,8 +126,7 @@
#CYCLADES_ASTAKOSCLIENT_POOLSIZE = 50
#
## Template to use to build the FQDN of VMs. The setting will be formated with
## the id of the VM. If set to 'None' the first public IPv4 or IPv6 address
## of the VM will be used.
## the id of the VM.
#CYCLADES_SERVERS_FQDN = 'snf-%(id)s.vm.example.synnefo.org'
#
## Description of applied port forwarding rules (DNAT) for Cyclades VMs. This
......
......@@ -219,13 +219,9 @@ def get_server_public_ip(vm_nics, version=4):
def get_server_fqdn(vm, vm_nics):
public_ip = get_server_public_ip(vm_nics)
if public_ip is None:
return ""
fqdn_setting = settings.CYCLADES_SERVERS_FQDN
if fqdn_setting is None:
return public_ip.address
return None
elif isinstance(fqdn_setting, basestring):
return fqdn_setting % {"id": vm.id}
else:
......
......@@ -161,18 +161,19 @@ class ServerAPITest(ComputeAPITest):
def test_server_fqdn(self):
vm = mfactory.VirtualMachineFactory()
# test no public ip
# Setting set to None
with override_settings(settings,
CYCLADES_SERVERS_FQDN="vm.example.org"):
CYCLADES_SERVERS_FQDN=None):
response = self.myget("servers/%d" % vm.id, vm.userid)
server = json.loads(response.content)['server']
self.assertEqual(server["SNF:fqdn"], "")
mfactory.IPv4AddressFactory(nic__machine=vm, network__public=True)
self.assertEqual(server["SNF:fqdn"], None)
# Unformated setting
with override_settings(settings,
CYCLADES_SERVERS_FQDN="vm.example.org"):
response = self.myget("servers/%d" % vm.id, vm.userid)
server = json.loads(response.content)['server']
self.assertEqual(server["SNF:fqdn"], "vm.example.org")
# Formatted settings
with override_settings(settings, CYCLADES_SERVERS_FQDN=
"snf-%(id)s.vm.example.org"):
response = self.myget("servers/%d" % vm.id, vm.userid)
......@@ -187,32 +188,6 @@ class ServerAPITest(ComputeAPITest):
self.assertEqual(server["SNF:fqdn"], "snf-%d.vm-%d.example.org" %
(vm.id, vm.id))
vm = mfactory.VirtualMachineFactory()
# No setting, no NICs
with override_settings(settings,
CYCLADES_SERVERS_FQDN=None):
response = self.myget("servers/%d" % vm.id, vm.userid)
server = json.loads(response.content)['server']
self.assertEqual(server["SNF:fqdn"], "")
# IPv6 NIC
ipv6_address = mfactory.IPv6AddressFactory(nic__machine=vm,
network__public=True)
with override_settings(settings,
CYCLADES_SERVERS_FQDN=None):
response = self.myget("servers/%d" % vm.id, vm.userid)
server = json.loads(response.content)['server']
self.assertEqual(server["SNF:fqdn"], ipv6_address.address)
# IPv4 NIC
ipv4_address = mfactory.IPv4AddressFactory(nic__machine=vm,
network__public=True)
with override_settings(settings,
CYCLADES_SERVERS_FQDN=None):
response = self.myget("servers/%d" % vm.id, vm.userid)
server = json.loads(response.content)['server']
self.assertEqual(server["SNF:fqdn"], ipv4_address.address)
def test_server_port_forwarding(self):
vm = mfactory.VirtualMachineFactory()
# test None if the server has no public IP
......
......@@ -123,8 +123,7 @@ SECRET_ENCRYPTION_KEY = "Password Encryption Key"
CYCLADES_SERVICE_TOKEN = ''
# Template to use to build the FQDN of VMs. The setting will be formated with
# the id of the VM. If set to 'None' the first public IPv4 or IPv6 address
# of the VM will be used.
# the id of the VM.
CYCLADES_SERVERS_FQDN = 'snf-%(id)s.vm.example.synnefo.org'
# Description of applied port forwarding rules (DNAT) for Cyclades VMs. This
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment