Commit f816770a by Bach Dániel

dashboard: fix Host.list_ports()

parent dc5425b3
......@@ -80,9 +80,9 @@
{% endif %}
</dd>
{% if instance.ipv6 %}
{% if instance.ipv6 and instance.get_connect_port %}
<dt>{% trans "Host (IPv6)" %}</dt>
<dd>{{ ipv6_host }}:<strong>{{ instance.ipv6_port }}</strong></dd>
<dd>{{ ipv6_host }}:<strong>{{ ipv6_port }}</strong></dd>
{% endif %}
<dt>{% trans "Username" %}</dt>
......
......@@ -92,7 +92,7 @@
{% if l.ipv4 %}
<tr>
<td>
{% display_portforward l %}
{% display_portforward4 l %}
</td>
<td><i class="icon-long-arrow-right"></i></td>
<td>
......@@ -124,7 +124,7 @@
{% if l.ipv6 %}
<tr>
<td>
{% display_portforward l %}
{% display_portforward6 l %}
</td>
<td><i class="icon-long-arrow-right"></i></td>
<td>
......
......@@ -6,10 +6,18 @@ register = template.Library()
LINKABLE_PORTS = {80: "http", 8080: "http", 443: "https", 21: "ftp"}
@register.simple_tag(name="display_portforward")
def display_pf(ports):
is_ipv6 = "ipv6" in ports
data = ports["ipv6" if is_ipv6 else "ipv4"]
@register.simple_tag(name="display_portforward4")
def display_pf4(ports):
return display_pf(ports, 'ipv4')
@register.simple_tag(name="display_portforward6")
def display_pf6(ports):
return display_pf(ports, 'ipv6')
def display_pf(ports, proto):
data = ports[proto]
if ports['private'] in LINKABLE_PORTS.keys():
href = "%s:%d" % (data['host'], data['port'])
......
......@@ -696,8 +696,7 @@ class Host(models.Model):
:param private: Port number of host in subject.
"""
self.rules.filter(owner=self.owner, proto=proto, host=self,
dport=private).delete()
self.rules.filter(proto=proto, dport=private).delete()
def get_hostname(self, proto, public=True):
"""
......@@ -729,7 +728,7 @@ class Host(models.Model):
Return a list of ports with forwarding rules set.
"""
retval = []
for rule in self.rules.filter(owner=self.owner):
for rule in self.rules.all():
forward = {
'proto': rule.proto,
'private': rule.dport,
......@@ -771,9 +770,7 @@ class Host(models.Model):
if public_port else
None)
# IPv6
blocked = self.incoming_rules.exclude(
action='accept').filter(dport=port, proto=protocol).exists()
endpoints['ipv6'] = (self.ipv6, port) if not blocked else None
endpoints['ipv6'] = (self.ipv6, port) if public_port else None
return endpoints
@models.permalink
......
......@@ -574,11 +574,10 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
def get_connect_host(self, use_ipv6=False):
"""Get public hostname.
"""
if not self.interface_set.exclude(host=None):
return _('None')
if not self.primary_host:
return None
proto = 'ipv6' if use_ipv6 else 'ipv4'
return self.interface_set.exclude(host=None)[0].host.get_hostname(
proto=proto)
return self.primary_host.get_hostname(proto=proto)
def get_connect_command(self, use_ipv6=False):
"""Returns a formatted connect string.
......
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 sign in to comment