Revision d328a525 snf-cyclades-app/synnefo/api/servers.py

b/snf-cyclades-app/synnefo/api/servers.py
170 170
        d["config_drive"] = ""
171 171
        d["accessIPv4"] = ""
172 172
        d["accessIPv6"] = ""
173
        d["SNF:fqdn"] = get_server_fqdn(vm)
173 174

  
174 175
    return d
175 176

  
176 177

  
178
def get_server_fqdn(vm):
179
    fqdn_setting = settings.CYCLADES_SERVERS_FQDN
180
    if fqdn_setting is None:
181
        public_nics = vm.nics.filter(network__public=True, state="ACTIVE")
182
        # Return the first public IPv4 address if exists
183
        ipv4_nics = public_nics.exclude(ipv4=None)
184
        if ipv4_nics:
185
            return ipv4_nics[0].ipv4
186
        # Else return the first public IPv6 address if exists
187
        ipv6_nics = public_nics.exclude(ipv6=None)
188
        if ipv6_nics:
189
            return ipv6_nics[0].ipv6
190
        return ""
191
    elif isinstance(fqdn_setting, basestring):
192
        return fqdn_setting % {"id": vm.id}
193
    else:
194
        msg = ("Invalid setting: CYCLADES_SERVERS_FQDN."
195
               " Value must be a string.")
196
        raise faults.InternalServerError(msg)
197

  
198

  
177 199
def diagnostics_to_dict(diagnostics):
178 200
    """
179 201
    Extract api data from diagnostics QuerySet.

Also available in: Unified diff