Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
vmdriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f708f27e
authored
Feb 13, 2014
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vmdriver: modified shutdown method to accept interrupts
parent
90504bb9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
21 deletions
+30
-21
vmdriver.py
+30
-21
No files found.
vmdriver.py
View file @
f708f27e
...
@@ -9,6 +9,7 @@ from decorator import decorator
...
@@ -9,6 +9,7 @@ from decorator import decorator
from
psutil
import
NUM_CPUS
,
virtual_memory
,
cpu_percent
from
psutil
import
NUM_CPUS
,
virtual_memory
,
cpu_percent
from
celery.contrib.abortable
import
AbortableTask
from
vm
import
VMInstance
from
vm
import
VMInstance
from
vmcelery
import
celery
,
lib_connection
from
vmcelery
import
celery
,
lib_connection
...
@@ -188,30 +189,38 @@ def create(vm_desc):
...
@@ -188,30 +189,38 @@ def create(vm_desc):
return
domain_info
(
vm
.
name
)
return
domain_info
(
vm
.
name
)
@celery.task
(
time_limit
=
120
)
class
shutdown
(
AbortableTask
):
@req_connection
def
shutdown
(
name
):
""" Shutdown virtual machine (need ACPI support).
""" Shutdown virtual machine (need ACPI support).
Return When domain is missing.
Return When domain is missiing.
This job is abortable:
AbortableAsyncResult(id="<<jobid>>").abort()
"""
"""
from
time
import
sleep
time_limit
=
120
try
:
domain
=
lookupByName
(
name
)
@req_connection
domain
.
shutdown
()
def
run
(
self
,
**
kwargs
):
while
True
:
from
time
import
sleep
try
:
name
=
kwargs
[
'name'
]
Connection
.
get
()
.
lookupByName
(
name
)
try
:
except
Exception
as
e
:
domain
=
lookupByName
(
name
)
if
e
.
get_error_code
()
==
libvirt
.
VIR_ERR_NO_DOMAIN
:
domain
.
shutdown
()
return
while
True
:
try
:
Connection
.
get
()
.
lookupByName
(
name
)
except
libvirt
.
libvirtError
as
e
:
if
e
.
get_error_code
()
==
libvirt
.
VIR_ERR_NO_DOMAIN
:
return
else
:
raise
else
:
else
:
raise
if
self
.
is_aborted
(
**
kwargs
):
else
:
logging
.
info
(
"Shutdown aborted on vm:
%
s"
,
name
)
sleep
(
5
)
return
except
Exception
as
e
:
sleep
(
5
)
new_e
=
Exception
(
e
.
get_error_message
())
except
libvirt
.
libvirtError
as
e
:
new_e
.
libvirtError
=
True
new_e
=
Exception
(
e
.
get_error_message
())
raise
new_e
new_e
.
libvirtError
=
True
raise
new_e
@celery.task
@celery.task
...
...
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