Commit f8478254 by Szabolcs Gelencsér

Add connection details if floating ip is available

parent 4cc50dd2
...@@ -114,12 +114,10 @@ ...@@ -114,12 +114,10 @@
<dd>{{ access_method|upper }}</dd> <dd>{{ access_method|upper }}</dd>
<dt>{% trans "Host" %}</dt> <dt>{% trans "Host" %}</dt>
<dd> <dd>
{% if instance.get_connect_port %} {% if connection_port %}
{{ instance.get_connect_host }}:<strong>{{ instance.get_connect_port }}</strong> {{ connection_host }}:<strong>{{ connection_port }}</strong>
{% elif instance.interface_set.count < 1%}
<strong>{% trans "The VM doesn't have any network interface." %}</strong>
{% else %} {% else %}
<strong>{% trans "The required port for this protocol is not forwarded." %}</strong> <strong>{% trans "The VM doesn't have any public network interface." %}</strong>
{% endif %} {% endif %}
</dd> </dd>
......
...@@ -100,6 +100,17 @@ logger = logging.getLogger(__name__) ...@@ -100,6 +100,17 @@ logger = logging.getLogger(__name__)
class VmDetailView(LoginRequiredMixin, GraphMixin, DetailView): class VmDetailView(LoginRequiredMixin, GraphMixin, DetailView):
template_name = "dashboard/vm-detail.html" template_name = "dashboard/vm-detail.html"
def get_instance_connection(self):
all_floating_ips = openstack_api.neutron.tenant_floating_ip_list(self.request)
instance_floating_ips = [ip for ip in all_floating_ips if ip.instance_id == self.object.id]
if len(instance_floating_ips) > 0:
return instance_floating_ips[0].ip, 22
all_ports = openstack_api.neutron.port_list(self.request)
instance_ports = [p for p in all_ports if p.instance_id == self.object.id]
return None, None
def get(self, *args, **kwargs): def get(self, *args, **kwargs):
if self.request.is_ajax(): if self.request.is_ajax():
return JsonResponse(self.get_json_data()) return JsonResponse(self.get_json_data())
...@@ -108,9 +119,14 @@ class VmDetailView(LoginRequiredMixin, GraphMixin, DetailView): ...@@ -108,9 +119,14 @@ class VmDetailView(LoginRequiredMixin, GraphMixin, DetailView):
def get_json_data(self): def get_json_data(self):
instance = self.get_object() instance = self.get_object()
connenction_host, connection_port = self.get_instance_connection()
try:
self.object.pw = ServerPassword.objects.get(os_server_id=self.object.id).password
except:
pass
return {"status": instance.status, return {"status": instance.status,
"host": instance.get_connect_host(), "host": connenction_host,
"port": instance.get_connect_port(), "port": connection_port,
"password": instance.pw} "password": instance.pw}
def get_object(self, queryset=None): def get_object(self, queryset=None):
...@@ -135,15 +151,28 @@ class VmDetailView(LoginRequiredMixin, GraphMixin, DetailView): ...@@ -135,15 +151,28 @@ class VmDetailView(LoginRequiredMixin, GraphMixin, DetailView):
except: except:
pass pass
try:
self.object.pw = ServerPassword.objects.get(os_server_id=self.object.id).password
except:
pass
connection_host, connection_port = self.get_instance_connection()
connection_cmd = {
"cmd": "sshpass -p %s ssh -o StrictHostKeyChecking=no cloud@%s -p %s" % (
self.object.pw, connection_host, connection_port)
}
context.update({ context.update({
'graphite_enabled': settings.GRAPHITE_URL is not None, 'graphite_enabled': settings.GRAPHITE_URL is not None,
'vnc_url': vnc_console.url if vnc_console else None, 'vnc_url': vnc_console.url if vnc_console else None,
'ops': ops, 'ops': ops,
'op': {i.op: i for i in ops}, 'op': {i.op: i for i in ops},
# 'connect_commands': user.profile.get_connect_commands(instance), 'connect_commands': [connection_cmd,],
'hide_tutorial': hide_tutorial, 'hide_tutorial': hide_tutorial,
'fav': Favourite.objects.filter(user=user.id, instance=instance.id).exists(), 'fav': Favourite.objects.filter(user=user.id, instance=instance.id).exists(),
'instance': self.object, 'instance': self.object,
"connection_host": connection_host,
"connection_port": connection_port,
'access_method': 'ssh' 'access_method': 'ssh'
}) })
......
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