Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
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
5fc37cc6
authored
Apr 04, 2013
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
one: Added Instance.nat()
parent
2a0ffb7d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
5 deletions
+11
-5
one/models.py
+10
-1
one/views.py
+1
-4
No files found.
one/models.py
View file @
5fc37cc6
...
...
@@ -429,7 +429,7 @@ class Instance(models.Model):
def
get_port
(
self
,
use_ipv6
=
False
):
"""Get public port number for default access method."""
proto
=
self
.
template
.
access_type
if
self
.
template
.
network
.
nat
and
not
use_ipv6
:
if
self
.
nat
and
not
use_ipv6
:
return
{
"rdp"
:
23000
,
"nx"
:
22000
,
"ssh"
:
22000
}[
proto
]
+
int
(
self
.
ip
.
split
(
'.'
)[
2
])
*
256
+
int
(
self
.
ip
.
split
(
'.'
)[
3
])
else
:
return
{
"rdp"
:
3389
,
"nx"
:
22
,
"ssh"
:
22
}[
proto
]
...
...
@@ -483,6 +483,15 @@ class Instance(models.Model):
self
.
check_if_is_save_as_done
()
return
x
@property
def
nat
(
self
):
if
self
.
firewall_host
is
not
None
:
return
self
.
firewall_host
.
shared_ip
elif
self
.
template
is
not
None
:
return
self
.
template
.
network
.
nat
else
:
return
False
def
get_age
(
self
):
"""Get age of VM in seconds."""
from
datetime
import
datetime
...
...
one/views.py
View file @
5fc37cc6
...
...
@@ -108,7 +108,6 @@ def vm_credentials(request, iid):
vm
.
hostname_v4
=
vm
.
get_connect_host
(
use_ipv6
=
False
)
vm
.
hostname_v6
=
vm
.
get_connect_host
(
use_ipv6
=
True
)
vm
.
is_ipv6
=
is_ipv6
vm
.
nat
=
vm
.
template
.
network
.
nat
vm
.
port_v4
=
vm
.
get_port
(
use_ipv6
=
False
)
vm
.
port_v6
=
vm
.
get_port
(
use_ipv6
=
True
)
return
render_to_response
(
'vm-credentials.html'
,
RequestContext
(
request
,
{
'i'
:
vm
}))
...
...
@@ -372,7 +371,6 @@ def vm_show(request, iid):
inst
.
is_ipv6
=
is_ipv6
inst
.
hostname_v4
=
inst
.
get_connect_host
(
use_ipv6
=
False
)
inst
.
hostname_v6
=
inst
.
get_connect_host
(
use_ipv6
=
True
)
inst
.
nat
=
inst
.
template
.
network
.
nat
inst
.
port_v4
=
inst
.
get_port
(
use_ipv6
=
False
)
inst
.
port_v6
=
inst
.
get_port
(
use_ipv6
=
True
)
return
render_to_response
(
"show.html"
,
RequestContext
(
request
,{
...
...
@@ -425,7 +423,7 @@ class VmPortAddView(View):
try
:
port
=
int
(
request
.
POST
[
'port'
])
inst
=
get_object_or_404
(
Instance
,
id
=
iid
,
owner
=
request
.
user
)
if
inst
.
firewall_host
.
shared_ip
:
if
inst
.
nat
:
inst
.
firewall_host
.
add_port
(
proto
=
request
.
POST
[
'proto'
],
public
=
None
,
private
=
port
)
else
:
...
...
@@ -434,7 +432,6 @@ class VmPortAddView(View):
except
:
messages
.
error
(
request
,
_
(
u"Adding port failed."
))
raise
else
:
messages
.
success
(
request
,
_
(
u"Port
%
d successfully added."
)
%
port
)
return
redirect
(
'/vm/show/
%
d/'
%
int
(
iid
))
...
...
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