Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
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
aab4fb6c
authored
Apr 28, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: implement abortable ShutdownOperation
parent
6586d87e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
12 deletions
+17
-12
circle/vm/models/instance.py
+15
-4
circle/vm/operations.py
+2
-8
No files found.
circle/vm/models/instance.py
View file @
aab4fb6c
...
...
@@ -5,6 +5,8 @@ from logging import getLogger
from
string
import
ascii_lowercase
from
warnings
import
warn
from
celery.exceptions
import
TimeoutError
from
celery.contrib.abortable
import
AbortableAsyncResult
import
django.conf
from
django.contrib.auth.models
import
User
from
django.core
import
signing
...
...
@@ -22,6 +24,7 @@ from taggit.managers import TaggableManager
from
acl.models
import
AclBase
from
common.operations
import
OperatedMixin
from
manager.mancelery
import
celery
from
..tasks
import
vm_tasks
,
agent_tasks
from
.activity
import
(
ActivityInProgressError
,
instance_activity
,
InstanceActivity
)
...
...
@@ -813,13 +816,21 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
queue
=
queue_name
)
.
get
(
timeout
=
timeout
)
def
shutdown_vm
(
self
,
t
imeout
=
120
):
def
shutdown_vm
(
self
,
t
ask
=
None
,
step
=
5
):
queue_name
=
self
.
get_remote_queue_name
(
'vm'
)
logger
.
debug
(
"RPC Shutdown at queue:
%
s, for vm:
%
s."
,
queue_name
,
self
.
vm_name
)
return
vm_tasks
.
shutdown
.
apply_async
(
kwargs
=
{
'name'
:
self
.
vm_name
},
queue
=
queue_name
)
.
get
(
timeout
=
timeout
)
remote
=
vm_tasks
.
shutdown
.
apply_async
(
kwargs
=
{
'name'
:
self
.
vm_name
},
queue
=
queue_name
)
while
True
:
try
:
return
remote
.
get
(
timeout
=
step
)
except
TimeoutError
:
if
task
is
not
None
and
task
.
is_aborted
():
AbortableAsyncResult
(
remote
.
id
,
backend
=
celery
.
backend
)
.
abort
()
raise
Exception
(
"Shutdown aborted by user."
)
def
suspend_vm
(
self
,
timeout
=
60
):
queue_name
=
self
.
get_remote_queue_name
(
'vm'
)
...
...
circle/vm/operations.py
View file @
aab4fb6c
...
...
@@ -321,17 +321,11 @@ class ShutdownOperation(InstanceOperation):
if
self
.
instance
.
status
not
in
[
'RUNNING'
]:
raise
self
.
instance
.
WrongStateError
(
self
.
instance
)
def
on_abort
(
self
,
activity
,
error
):
if
isinstance
(
error
,
TimeLimitExceeded
):
activity
.
resultant_state
=
None
else
:
activity
.
resultant_state
=
'ERROR'
def
on_commit
(
self
,
activity
):
activity
.
resultant_state
=
'STOPPED'
def
_operation
(
self
,
t
imeout
=
120
):
self
.
instance
.
shutdown_vm
(
t
imeout
=
timeout
)
def
_operation
(
self
,
t
ask
=
None
):
self
.
instance
.
shutdown_vm
(
t
ask
=
task
)
self
.
instance
.
yield_node
()
self
.
instance
.
yield_vnc_port
()
...
...
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