Commit 22948bca authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Extend servers info with fqdn attribute

Extend the servers info API response with the 'SNF:fqdn' attribute,
containg the vm's domain name in a DNS. This attribue is configurable by
the 'CYCLADES_SERVERS_FQDN' setting. If this setting is set to None,
then then the first public IPv4 or IPv6 address is returned.
parent 154fe14f
......@@ -41,6 +41,8 @@ Cyclades
* Compute quotas for CPU and memory of running vms.
* Obsolete PUBLIC_USE_POOL setting, since Cyclades manages IP pool for all
type of networks.
* Extend servers info API respones with 'SNF:fqdn' attribute, and introduce
CYCLADES_SERVERS_FQDN to set the template for servers FDQN.
Pithos
------
......
......@@ -107,3 +107,8 @@
# Tune the size of the http connection pool to astakos.
#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.
#CYCLADES_SERVERS_FQDN = 'snf-%(id)s.vm.example.synnefo.org'
......@@ -170,10 +170,32 @@ def vm_to_dict(vm, detail=False):
d["config_drive"] = ""
d["accessIPv4"] = ""
d["accessIPv6"] = ""
d["SNF:fqdn"] = get_server_fqdn(vm)
return d
def get_server_fqdn(vm):
fqdn_setting = settings.CYCLADES_SERVERS_FQDN
if fqdn_setting is None:
public_nics = vm.nics.filter(network__public=True, state="ACTIVE")
# Return the first public IPv4 address if exists
ipv4_nics = public_nics.exclude(ipv4=None)
if ipv4_nics:
return ipv4_nics[0].ipv4
# Else return the first public IPv6 address if exists
ipv6_nics = public_nics.exclude(ipv6=None)
if ipv6_nics:
return ipv6_nics[0].ipv6
return ""
elif isinstance(fqdn_setting, basestring):
return fqdn_setting % {"id": vm.id}
else:
msg = ("Invalid setting: CYCLADES_SERVERS_FQDN."
" Value must be a string.")
raise faults.InternalServerError(msg)
def diagnostics_to_dict(diagnostics):
"""
Extract api data from diagnostics QuerySet.
......
......@@ -107,3 +107,8 @@ CYCLADES_SERVICE_TOKEN = ''
# endpoints. Set this to False if you deploy cyclades-app/astakos-app on the
# same machine.
CYCLADES_PROXY_USER_SERVICES = True
# 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.
CYCLADES_SERVERS_FQDN = 'snf-%(id)s.vm.example.synnefo.org'
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