Commit ee6f3995 by Bach Dániel

dashboard: fix get_connect_uri()

parent 3eb0db45
......@@ -34,7 +34,7 @@
<h3>{% trans "Connection" %}</h3>
<!-- TODO RDP -->
<input type="text" value="ssh -p22312" class="form-control" readonly />
<input type="text" value="{{ instance.get_connect_command }}" class="form-control" readonly />
<dl class="dl-horizontal vm-details-pw">
......@@ -650,6 +650,32 @@ class Host(models.Model):
return self.get_hostname('ipv4', public=False)
def get_public_endpoints(self, port, protocol='tcp'):
"""Get public IPv4 and IPv6 endpoints for local port.
Optionally the required protocol (e.g. TCP, UDP) can be specified.
endpoints = {}
# IPv4
public_ipv4 = self.pub_ipv4 if self.pub_ipv4 else self.ipv4
# try get matching port(s) without NAT
ports = self.incoming_rules.filter(accept=True, dport=port,
nat=False, proto=protocol)
if ports.exists():
public_port = ports[0].dport
# try get matching port(s) with NAT
ports = self.incoming_rules.filter(accept=True, nat_dport=port,
nat=True, proto=protocol)
public_port = ports[0].dport if ports.exists() else None
endpoints['ipv4'] = ((public_ipv4, public_port) if public_port else
# IPv6
blocked = self.incoming_rules.filter(accept=False, dport=port,
endpoints['ipv6'] = (self.ipv6, port) if not blocked else None
return endpoints
def get_absolute_url(self):
return ('', None, {'pk':})
......@@ -405,6 +405,24 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
return self.interface_set.exclude(host=None)[0].host.get_hostname(
def get_connect_command(self, use_ipv6=False):
port = self.get_connect_port(use_ipv6=use_ipv6)
host = self.get_connect_host(use_ipv6=use_ipv6)
proto = self.access_method
print proto
if proto == 'rdp':
return 'rdesktop %(host)s:%(port)d -u cloud -p %(pw)s' % {
'port': port, 'proto': proto, 'pw':,
'host': host}
elif proto == 'ssh':
return ('sshpass -p %(pw)s ssh -o StrictHostKeyChecking=n '
'cloud@%(host)s -p %(port)d') % {
'port': port, 'proto': proto, 'pw':,
'host': host}
def get_connect_uri(self, use_ipv6=False):
"""Get access parameters in URI format.
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