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
08b1192a
authored
Jan 28, 2013
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
one: add stop/resume and poweroff/restart methods to Instance
parent
7a4c4881
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
+34
-0
one/models.py
+34
-0
No files found.
one/models.py
View file @
08b1192a
...
@@ -413,6 +413,40 @@ class Instance(models.Model):
...
@@ -413,6 +413,40 @@ class Instance(models.Model):
self
.
firewall_host
.
delete
()
self
.
firewall_host
.
delete
()
reload_firewall_lock
()
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
:
class
Meta
:
verbose_name
=
_
(
'instance'
)
verbose_name
=
_
(
'instance'
)
verbose_name_plural
=
_
(
'instances'
)
verbose_name_plural
=
_
(
'instances'
)
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