Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f8478254
authored
Aug 26, 2018
by
Szabolcs Gelencsér
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add connection details if floating ip is available
parent
4cc50dd2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
8 deletions
+35
-8
circle/dashboard/templates/dashboard/vm-detail.html
+3
-5
circle/dashboard/views/vm.py
+32
-3
No files found.
circle/dashboard/templates/dashboard/vm-detail.html
View file @
f8478254
...
...
@@ -114,12 +114,10 @@
<dd>
{{ access_method|upper }}
</dd>
<dt>
{% trans "Host" %}
</dt>
<dd>
{% if instance.get_connect_port %}
{{ instance.get_connect_host }}:
<strong>
{{ instance.get_connect_port }}
</strong>
{% elif instance.interface_set.count
<
1
%}
<
strong
>
{% trans "The VM doesn't have any network interface." %}
</strong>
{% if connection_port %}
{{ connection_host }}:
<strong>
{{ connection_port }}
</strong>
{% 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 %}
</dd>
...
...
circle/dashboard/views/vm.py
View file @
f8478254
...
...
@@ -100,6 +100,17 @@ logger = logging.getLogger(__name__)
class
VmDetailView
(
LoginRequiredMixin
,
GraphMixin
,
DetailView
):
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
):
if
self
.
request
.
is_ajax
():
return
JsonResponse
(
self
.
get_json_data
())
...
...
@@ -108,9 +119,14 @@ class VmDetailView(LoginRequiredMixin, GraphMixin, DetailView):
def
get_json_data
(
self
):
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
,
"host"
:
instance
.
get_connect_host
()
,
"port"
:
instance
.
get_connect_port
()
,
"host"
:
connenction_host
,
"port"
:
connection_port
,
"password"
:
instance
.
pw
}
def
get_object
(
self
,
queryset
=
None
):
...
...
@@ -135,15 +151,28 @@ class VmDetailView(LoginRequiredMixin, GraphMixin, DetailView):
except
:
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
({
'graphite_enabled'
:
settings
.
GRAPHITE_URL
is
not
None
,
'vnc_url'
:
vnc_console
.
url
if
vnc_console
else
None
,
'ops'
:
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
,
'fav'
:
Favourite
.
objects
.
filter
(
user
=
user
.
id
,
instance
=
instance
.
id
)
.
exists
(),
'instance'
:
self
.
object
,
"connection_host"
:
connection_host
,
"connection_port"
:
connection_port
,
'access_method'
:
'ssh'
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment