Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
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
2ff6b951
authored
Jul 06, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: move renew to a new operation
fixes #184
parent
44430db0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
31 deletions
+22
-31
circle/vm/models/instance.py
+6
-31
circle/vm/operations.py
+16
-0
No files found.
circle/vm/models/instance.py
View file @
2ff6b951
...
...
@@ -439,10 +439,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
for
cps
in
customized_params
]
def
clean
(
self
,
*
args
,
**
kwargs
):
if
self
.
time_of_suspend
is
None
:
self
.
_do_renew
(
which
=
'suspend'
)
if
self
.
time_of_delete
is
None
:
self
.
_do_renew
(
which
=
'delete'
)
self
.
time_of_suspend
,
self
.
time_of_delete
=
self
.
get_renew_times
()
super
(
Instance
,
self
)
.
clean
(
*
args
,
**
kwargs
)
def
manual_state_change
(
self
,
new_state
=
"NOSTATE"
,
reason
=
None
,
user
=
None
):
...
...
@@ -715,36 +712,14 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
else
:
return
False
def
get_renew_times
(
self
):
def
get_renew_times
(
self
,
lease
=
None
):
"""Returns new suspend and delete times if renew would be called.
"""
if
lease
is
None
:
lease
=
self
.
lease
return
(
timezone
.
now
()
+
self
.
lease
.
suspend_interval
,
timezone
.
now
()
+
self
.
lease
.
delete_interval
)
def
_do_renew
(
self
,
which
=
'both'
):
"""Set expiration times to renewed values.
"""
time_of_suspend
,
time_of_delete
=
self
.
get_renew_times
()
if
which
in
(
'suspend'
,
'both'
):
self
.
time_of_suspend
=
time_of_suspend
if
which
in
(
'delete'
,
'both'
):
self
.
time_of_delete
=
time_of_delete
def
renew
(
self
,
which
=
'both'
,
base_activity
=
None
,
user
=
None
):
"""Renew virtual machine instance leases.
"""
if
base_activity
is
None
:
act_ctx
=
instance_activity
(
code_suffix
=
'renew'
,
instance
=
self
,
user
=
user
)
else
:
act_ctx
=
base_activity
.
sub_activity
(
'renew'
)
with
act_ctx
:
if
which
not
in
(
'suspend'
,
'delete'
,
'both'
):
raise
ValueError
(
'No such expiration type.'
)
self
.
_do_renew
(
which
)
self
.
save
()
timezone
.
now
()
+
lease
.
suspend_interval
,
timezone
.
now
()
+
lease
.
delete_interval
)
def
change_password
(
self
,
user
=
None
):
"""Generate new password for the vm
...
...
circle/vm/operations.py
View file @
2ff6b951
...
...
@@ -619,6 +619,22 @@ class WakeUpOperation(InstanceOperation):
register_operation
(
WakeUpOperation
)
class
RenewOperation
(
InstanceOperation
):
activity_code_suffix
=
'renew'
id
=
'renew'
name
=
_
(
"renew"
)
description
=
_
(
"Renew expiration times"
)
acl_level
=
"operator"
def
_operation
(
self
,
lease
=
None
):
(
self
.
instance
.
time_of_suspend
,
self
.
instance
.
time_of_delete
)
=
self
.
instance
.
get_renew_times
(
lease
)
self
.
save
()
register_operation
(
RenewOperation
)
class
NodeOperation
(
Operation
):
async_operation
=
abortable_async_node_operation
host_cls
=
Node
...
...
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