Revision 2522e489 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 |
fqdn = get_server_fqdn(vm) |
|
174 |
d["SNF:fqdn"] = fqdn |
|
175 |
d["SNF:port_forwarding"] = get_server_port_forwarding(vm, fqdn) |
|
174 | 176 |
|
175 | 177 |
return d |
176 | 178 |
|
... | ... | |
196 | 198 |
raise faults.InternalServerError(msg) |
197 | 199 |
|
198 | 200 |
|
201 |
def get_server_port_forwarding(vm, fqdn): |
|
202 |
"""Create API 'port_forwarding' attribute from corresponding setting. |
|
203 |
|
|
204 |
Create the 'port_forwarding' API vm attribute based on the corresponding |
|
205 |
setting (CYCLADES_PORT_FORWARDING), which can be either a tuple |
|
206 |
of the form (host, port) or a callable object returning such tuple. In |
|
207 |
case of callable object, must be called with the following arguments: |
|
208 |
* ip_address |
|
209 |
* server_id |
|
210 |
* fqdn |
|
211 |
* owner UUID |
|
212 |
|
|
213 |
""" |
|
214 |
port_forwarding = {} |
|
215 |
for dport, to_dest in settings.CYCLADES_PORT_FORWARDING.items(): |
|
216 |
if hasattr(to_dest, "__call__"): |
|
217 |
public_nics = vm.nics.filter(network__public=True, state="ACTIVE")\ |
|
218 |
.exclude(ipv4=None).order_by('index') |
|
219 |
if public_nics: |
|
220 |
vm_ipv4 = public_nics[0].ipv4 |
|
221 |
else: |
|
222 |
vm_ipv4 = None |
|
223 |
to_dest = to_dest(vm_ipv4, vm.id, fqdn, vm.userid) |
|
224 |
msg = ("Invalid setting: CYCLADES_PORT_FOWARDING." |
|
225 |
" Value must be a tuple of two elements (host, port).") |
|
226 |
if to_dest is None: |
|
227 |
continue |
|
228 |
if not isinstance(to_dest, tuple) or len(to_dest) != 2: |
|
229 |
raise faults.InternalServerError(msg) |
|
230 |
else: |
|
231 |
try: |
|
232 |
host, port = to_dest |
|
233 |
except (TypeError, ValueError): |
|
234 |
raise faults.InternalServerError(msg) |
|
235 |
|
|
236 |
port_forwarding[dport] = {"host": host, "port": str(port)} |
|
237 |
return port_forwarding |
|
238 |
|
|
239 |
|
|
199 | 240 |
def diagnostics_to_dict(diagnostics): |
200 | 241 |
""" |
201 | 242 |
Extract api data from diagnostics QuerySet. |
Also available in: Unified diff