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
8ae27f21
authored
Aug 01, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: fail renew if it shortens expiration
unless forced
parent
9ea843e9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
9 deletions
+27
-9
circle/dashboard/forms.py
+7
-5
circle/vm/operations.py
+20
-4
No files found.
circle/dashboard/forms.py
View file @
8ae27f21
...
...
@@ -697,16 +697,18 @@ class LeaseForm(forms.ModelForm):
class
VmRenewForm
(
forms
.
Form
):
force
=
forms
.
BooleanField
(
required
=
False
,
label
=
_
(
"Set expiration times even if they are shorter than "
"the current value."
))
def
__init__
(
self
,
*
args
,
**
kwargs
):
choices
=
kwargs
.
pop
(
'choices'
)
default
=
kwargs
.
pop
(
'default'
)
super
(
VmRenewForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
fields
[
'lease'
]
=
forms
.
ModelChoiceField
(
queryset
=
choices
,
initial
=
default
,
required
=
False
,
empty_label
=
None
,
label
=
_
(
'Length'
))
self
.
fields
.
insert
(
0
,
'lease'
,
forms
.
ModelChoiceField
(
queryset
=
choices
,
initial
=
default
,
required
=
False
,
empty_label
=
None
,
label
=
_
(
'Length'
)))
if
len
(
choices
)
<
2
:
self
.
fields
[
'lease'
]
.
widget
=
HiddenInput
()
...
...
circle/vm/operations.py
View file @
8ae27f21
...
...
@@ -28,7 +28,9 @@ from sizefield.utils import filesizeformat
from
celery.exceptions
import
TimeLimitExceeded
from
common.models
import
create_readable
,
humanize_exception
from
common.models
import
(
create_readable
,
humanize_exception
,
HumanReadableException
)
from
common.operations
import
Operation
,
register_operation
from
.tasks.local_tasks
import
(
abortable_async_instance_operation
,
abortable_async_node_operation
,
...
...
@@ -716,10 +718,24 @@ class RenewOperation(InstanceOperation):
required_perms
=
()
concurrency_check
=
False
def
_operation
(
self
,
lease
=
None
):
(
self
.
instance
.
time_of_suspend
,
self
.
instance
.
time_of_delete
)
=
self
.
instance
.
get_renew_times
(
lease
)
def
_operation
(
self
,
activity
,
lease
=
None
,
force
=
False
):
suspend
,
delete
=
self
.
instance
.
get_renew_times
(
lease
)
if
(
not
force
and
suspend
and
self
.
instance
.
time_of_suspend
and
suspend
<
self
.
instance
.
time_of_suspend
):
raise
HumanReadableException
.
create
(
ugettext_noop
(
"Renewing the machine with the selected lease would result "
"in its suspension time get earlier than before."
))
if
(
not
force
and
delete
and
self
.
instance
.
time_of_delete
and
delete
<
self
.
instance
.
time_of_delete
):
raise
HumanReadableException
.
create
(
ugettext_noop
(
"Renewing the machine with the selected lease would result "
"in its delete time get earlier than before."
))
self
.
instance
.
time_of_suspend
=
suspend
self
.
instance
.
time_of_delete
=
delete
self
.
instance
.
save
()
activity
.
result
=
create_readable
(
ugettext_noop
(
"Renewed to suspend at
%(suspend)
s and destroy at
%(delete)
s."
),
suspend
=
suspend
,
delete
=
delete
)
register_operation
(
RenewOperation
)
...
...
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