Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
cd80926c
authored
Jan 28, 2013
by
Bence Dnyi
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
ssh://giccero.cloud.ik.bme.hu/cloud
parents
f0ffd30b
a627c311
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
0 deletions
+77
-0
cloud/urls.py
+4
-0
one/models.py
+34
-0
one/views.py
+39
-0
No files found.
cloud/urls.py
View file @
cd80926c
...
...
@@ -16,6 +16,10 @@ urlpatterns = patterns('',
url
(
r'^vm/new/(?P<template>\d+)/$'
,
'one.views.vm_new'
,
name
=
'vm_new'
),
url
(
r'^vm/show/(?P<iid>\d+)/$'
,
'one.views.vm_show'
,
name
=
'vm_show'
),
url
(
r'^vm/delete/(?P<iid>\d+)/$'
,
'one.views.vm_delete'
,
name
=
'vm_delete'
),
url
(
r'^vm/stop/(?P<iid>\d+)/$'
,
'one.views.vm_stop'
,
name
=
'vm_stop'
),
url
(
r'^vm/resume/(?P<iid>\d+)/$'
,
'one.views.vm_resume'
,
name
=
'vm_resume'
),
url
(
r'^vm/power_off/(?P<iid>\d+)/$'
,
'one.views.vm_power_off'
,
name
=
'vm_power_off'
),
url
(
r'^vm/restart/(?P<iid>\d+)/$'
,
'one.views.vm_restart'
,
name
=
'vm_restart'
),
url
(
r'^vm/port_add/(?P<iid>\d+)/$'
,
'one.views.vm_port_add'
,
name
=
'vm_port_add'
),
url
(
r'^vm/port_del/(?P<iid>\d+)/(?P<proto>tcp|udp)/(?P<public>\d+)/$'
,
'one.views.vm_port_del'
,
name
=
'vm_port_del'
),
url
(
r'^reload/$'
,
'firewall.views.reload_firewall'
,
name
=
'reload_firewall'
),
...
...
one/models.py
View file @
cd80926c
...
...
@@ -413,6 +413,40 @@ class Instance(models.Model):
self
.
firewall_host
.
delete
()
reload_firewall_lock
()
"""
Change host state in OpenNebula.
"""
def
_change_state
(
self
,
new_state
):
from
django.template.defaultfilters
import
escape
out
=
""
with
tempfile
.
NamedTemporaryFile
(
delete
=
False
)
as
f
:
os
.
chmod
(
f
.
name
,
stat
.
S_IRUSR
|
stat
.
S_IWUSR
|
stat
.
S_IRGRP
|
stat
.
S_IROTH
)
tpl
=
u"""
<COMPUTE>
<ID>
%(id)
d</ID>
<STATE>
%(state)
s</STATE>
</COMPUTE>"""
%
{
"id"
:
self
.
one_id
,
"state"
:
new_state
}
f
.
write
(
tpl
)
f
.
close
()
import
subprocess
proc
=
subprocess
.
Popen
([
"/opt/occi.sh"
,
"compute"
,
"update"
,
f
.
name
],
stdout
=
subprocess
.
PIPE
)
(
out
,
err
)
=
proc
.
communicate
()
os
.
unlink
(
f
.
name
)
print
"out: "
+
out
def
stop
(
self
):
self
.
_change_state
(
"STOPPED"
)
def
resume
(
self
):
self
.
_change_state
(
"RESUME"
)
def
poweroff
(
self
):
self
.
_change_state
(
"POWEROFF"
)
def
restart
(
self
):
self
.
_change_state
(
"RESTART"
)
class
Meta
:
verbose_name
=
_
(
'instance'
)
verbose_name_plural
=
_
(
'instances'
)
one/views.py
View file @
cd80926c
...
...
@@ -162,6 +162,45 @@ class VmDeleteView(View):
vm_delete
=
login_required
(
VmDeleteView
.
as_view
())
@login_required
@require_POST
def
vm_stop
(
request
,
iid
,
*
args
,
**
kwargs
):
try
:
get_object_or_404
(
Instance
,
id
=
iid
,
owner
=
request
.
user
)
.
stop
()
messages
.
success
(
request
,
_
(
'Virtual machine is successfully stopped.'
))
except
:
messages
.
error
(
request
,
_
(
'Failed to stop virtual machine.'
))
return
redirect
(
'/'
)
@login_required
@require_POST
def
vm_resume
(
request
,
iid
,
*
args
,
**
kwargs
):
try
:
get_object_or_404
(
Instance
,
id
=
iid
,
owner
=
request
.
user
)
.
resume
()
messages
.
success
(
request
,
_
(
'Virtual machine is successfully resumed.'
))
except
:
messages
.
error
(
request
,
_
(
'Failed to resume virtual machine.'
))
return
redirect
(
'/'
)
@login_required
@require_POST
def
vm_power_off
(
request
,
iid
,
*
args
,
**
kwargs
):
try
:
get_object_or_404
(
Instance
,
id
=
iid
,
owner
=
request
.
user
)
.
poweroff
()
messages
.
success
(
request
,
_
(
'Virtual machine is successfully powered off.'
))
except
:
messages
.
error
(
request
,
_
(
'Failed to power off virtual machine.'
))
return
redirect
(
'/'
)
@login_required
@require_POST
def
vm_restart
(
request
,
iid
,
*
args
,
**
kwargs
):
try
:
get_object_or_404
(
Instance
,
id
=
iid
,
owner
=
request
.
user
)
.
restart
()
messages
.
success
(
request
,
_
(
'Virtual machine is successfully restarted.'
))
except
:
messages
.
error
(
request
,
_
(
'Failed to restart virtual machine.'
))
return
redirect
(
'/'
)
def
vm_active
(
request
,
token
):
id
=
signing
.
loads
(
token
,
salt
=
'activate'
,
max_age
=
300
)
...
...
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