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
b478ebb0
authored
Feb 06, 2014
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: set handlers on activities
parent
ec23470e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
3 deletions
+43
-3
circle/vm/models/instance.py
+43
-3
No files found.
circle/vm/models/instance.py
View file @
b478ebb0
...
@@ -15,6 +15,7 @@ from django.dispatch import Signal
...
@@ -15,6 +15,7 @@ from django.dispatch import Signal
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
celery.exceptions
import
TimeoutError
from
model_utils.models
import
TimeStampedModel
from
model_utils.models
import
TimeStampedModel
from
taggit.managers
import
TaggableManager
from
taggit.managers
import
TaggableManager
...
@@ -326,6 +327,11 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
...
@@ -326,6 +327,11 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
inst
.
save
()
inst
.
save
()
inst
.
set_level
(
inst
.
owner
,
'owner'
)
inst
.
set_level
(
inst
.
owner
,
'owner'
)
def
__on_commit
(
activity
):
activity
.
resultant_state
=
'PENDING'
with
instance_activity
(
code_suffix
=
'create'
,
instance
=
inst
,
on_commit
=
__on_commit
,
user
=
inst
.
owner
):
# create related entities
# create related entities
inst
.
disks
.
add
(
*
[
disk
.
get_exclusive
()
for
disk
in
disks
])
inst
.
disks
.
add
(
*
[
disk
.
get_exclusive
()
for
disk
in
disks
])
...
@@ -582,9 +588,12 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
...
@@ -582,9 +588,12 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
if
self
.
destroyed
:
if
self
.
destroyed
:
raise
self
.
InstanceDestroyedError
(
self
)
raise
self
.
InstanceDestroyedError
(
self
)
with
instance_activity
(
code_suffix
=
'deploy'
,
instance
=
self
,
def
__on_commit
(
activity
):
task_uuid
=
task_uuid
,
user
=
user
)
as
act
:
activity
.
resultant_state
=
'RUNNING'
with
instance_activity
(
code_suffix
=
'deploy'
,
instance
=
self
,
on_commit
=
__on_commit
,
task_uuid
=
task_uuid
,
user
=
user
)
as
act
:
self
.
__schedule_vm
(
act
)
self
.
__schedule_vm
(
act
)
...
@@ -697,8 +706,12 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
...
@@ -697,8 +706,12 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
if
self
.
destroyed
:
if
self
.
destroyed
:
return
# already destroyed, nothing to do here
return
# already destroyed, nothing to do here
def
__on_commit
(
activity
):
activity
.
resultant_state
=
'DESTROYED'
with
instance_activity
(
code_suffix
=
'destroy'
,
instance
=
self
,
with
instance_activity
(
code_suffix
=
'destroy'
,
instance
=
self
,
task_uuid
=
task_uuid
,
user
=
user
)
as
act
:
on_commit
=
__on_commit
,
task_uuid
=
task_uuid
,
user
=
user
)
as
act
:
if
self
.
node
:
if
self
.
node
:
self
.
__destroy_vm
(
act
)
self
.
__destroy_vm
(
act
)
...
@@ -725,7 +738,17 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
...
@@ -725,7 +738,17 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
if
self
.
state
not
in
[
'RUNNING'
]:
if
self
.
state
not
in
[
'RUNNING'
]:
raise
self
.
WrongStateError
(
self
)
raise
self
.
WrongStateError
(
self
)
def
__on_abort
(
activity
,
error
):
if
isinstance
(
error
,
TimeoutError
):
activity
.
resultant_state
=
None
else
:
activity
.
resultant_state
=
'ERROR'
def
__on_commit
(
activity
):
activity
.
resultant_state
=
'SUSPENDED'
with
instance_activity
(
code_suffix
=
'sleep'
,
instance
=
self
,
with
instance_activity
(
code_suffix
=
'sleep'
,
instance
=
self
,
on_abort
=
__on_abort
,
on_commit
=
__on_commit
,
task_uuid
=
task_uuid
,
user
=
user
):
task_uuid
=
task_uuid
,
user
=
user
):
queue_name
=
self
.
get_remote_queue_name
(
'vm'
)
queue_name
=
self
.
get_remote_queue_name
(
'vm'
)
...
@@ -743,7 +766,14 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
...
@@ -743,7 +766,14 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
if
self
.
state
not
in
[
'SUSPENDED'
]:
if
self
.
state
not
in
[
'SUSPENDED'
]:
raise
self
.
WrongStateError
(
self
)
raise
self
.
WrongStateError
(
self
)
def
__on_abort
(
activity
,
error
):
activity
.
resultant_state
=
'ERROR'
def
__on_commit
(
activity
):
activity
.
resultant_state
=
'RUNNING'
with
instance_activity
(
code_suffix
=
'wake_up'
,
instance
=
self
,
with
instance_activity
(
code_suffix
=
'wake_up'
,
instance
=
self
,
on_abort
=
__on_abort
,
on_commit
=
__on_commit
,
task_uuid
=
task_uuid
,
user
=
user
):
task_uuid
=
task_uuid
,
user
=
user
):
queue_name
=
self
.
get_remote_queue_name
(
'vm'
)
queue_name
=
self
.
get_remote_queue_name
(
'vm'
)
...
@@ -759,7 +789,17 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
...
@@ -759,7 +789,17 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
def
shutdown
(
self
,
user
=
None
,
task_uuid
=
None
):
def
shutdown
(
self
,
user
=
None
,
task_uuid
=
None
):
"""Shutdown virtual machine with ACPI signal.
"""Shutdown virtual machine with ACPI signal.
"""
"""
def
__on_abort
(
activity
,
error
):
if
isinstance
(
error
,
TimeoutError
):
activity
.
resultant_state
=
None
else
:
activity
.
resultant_state
=
'ERROR'
def
__on_commit
(
activity
):
activity
.
resultant_state
=
'STOPPED'
with
instance_activity
(
code_suffix
=
'shutdown'
,
instance
=
self
,
with
instance_activity
(
code_suffix
=
'shutdown'
,
instance
=
self
,
on_abort
=
__on_abort
,
on_commit
=
__on_commit
,
task_uuid
=
task_uuid
,
user
=
user
):
task_uuid
=
task_uuid
,
user
=
user
):
queue_name
=
self
.
get_remote_queue_name
(
'vm'
)
queue_name
=
self
.
get_remote_queue_name
(
'vm'
)
...
...
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