Commit ddfe345d by Őry Máté

one: refactor _change_state body to _update_vm

parent eb25f6f3
...@@ -443,20 +443,16 @@ class Instance(models.Model): ...@@ -443,20 +443,16 @@ class Instance(models.Model):
self.firewall_host.delete() self.firewall_host.delete()
reload_firewall_lock() reload_firewall_lock()
""" def _update_vm(self, template):
Change host state in OpenNebula.
"""
def _change_state(self, new_state):
from django.template.defaultfilters import escape
out = "" out = ""
with tempfile.NamedTemporaryFile(delete=False) as f: with tempfile.NamedTemporaryFile(delete=False) as f:
os.chmod(f.name, stat.S_IRUSR|stat.S_IWUSR|stat.S_IRGRP|stat.S_IROTH) os.chmod(f.name, stat.S_IRUSR|stat.S_IWUSR|stat.S_IRGRP|stat.S_IROTH)
tpl = u""" tpl = u"""
<COMPUTE> <COMPUTE>
<ID>%(id)d</ID> <ID>%(id)d</ID>
<STATE>%(state)s</STATE> %(template)s
</COMPUTE>""" % {"id": self.one_id, </COMPUTE>""" % {"id": self.one_id,
"state": new_state} "template": template}
f.write(tpl) f.write(tpl)
f.close() f.close()
import subprocess import subprocess
...@@ -467,6 +463,12 @@ class Instance(models.Model): ...@@ -467,6 +463,12 @@ class Instance(models.Model):
os.unlink(f.name) os.unlink(f.name)
print "out: " + out print "out: " + out
"""
Change host state in OpenNebula.
"""
def _change_state(self, new_state):
self._update_vm("<STATE>" + new_state + "</STATE>")
def stop(self): def stop(self):
self._change_state("STOPPED") self._change_state("STOPPED")
def resume(self): def resume(self):
......
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