Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ec23470e
authored
Feb 06, 2014
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: raise exception if state is inappropriate for operation
parent
e2e113f6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
0 deletions
+18
-0
circle/vm/models/instance.py
+18
-0
No files found.
circle/vm/models/instance.py
View file @
ec23470e
...
...
@@ -241,6 +241,18 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
self
.
instance
=
instance
class
WrongStateError
(
Exception
):
def
__init__
(
self
,
instance
,
message
=
None
):
if
message
is
None
:
message
=
(
"The instance's current state (
%
s) is "
"inappropriate for the invoked operation."
%
instance
.
state
)
Exception
.
__init__
(
self
,
message
)
self
.
instance
=
instance
def
__unicode__
(
self
):
parts
=
[
self
.
name
,
"("
+
str
(
self
.
id
)
+
")"
]
return
" "
.
join
([
s
for
s
in
parts
if
s
!=
""
])
...
...
@@ -710,6 +722,9 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
def
sleep
(
self
,
user
=
None
,
task_uuid
=
None
):
"""Suspend virtual machine with memory dump.
"""
if
self
.
state
not
in
[
'RUNNING'
]:
raise
self
.
WrongStateError
(
self
)
with
instance_activity
(
code_suffix
=
'sleep'
,
instance
=
self
,
task_uuid
=
task_uuid
,
user
=
user
):
...
...
@@ -725,6 +740,9 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
queue
=
"localhost.man"
)
def
wake_up
(
self
,
user
=
None
,
task_uuid
=
None
):
if
self
.
state
not
in
[
'SUSPENDED'
]:
raise
self
.
WrongStateError
(
self
)
with
instance_activity
(
code_suffix
=
'wake_up'
,
instance
=
self
,
task_uuid
=
task_uuid
,
user
=
user
):
...
...
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