Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a51a4115
authored
Apr 04, 2013
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
one: add default sharetype to instance w/o a share
fixes #121
parent
32159b2e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
5 deletions
+17
-5
one/models.py
+17
-5
No files found.
one/models.py
View file @
a51a4115
...
...
@@ -158,7 +158,6 @@ class SshKey(models.Model):
TEMPLATE_STATES
=
((
"INIT"
,
_
(
'init'
)),
(
"PREP"
,
_
(
'perparing'
)),
(
"SAVE"
,
_
(
'saving'
)),
(
"READY"
,
_
(
'ready'
)))
TYPES
=
{
"LAB"
:
{
"verbose_name"
:
_
(
'lab'
),
"id"
:
"LAB"
,
"suspend"
:
td
(
hours
=
5
),
"delete"
:
td
(
days
=
15
),
"help_text"
:
_
(
'For lab or homework with short lifetime.'
)},
...
...
@@ -169,6 +168,7 @@ TYPES = {"LAB": {"verbose_name": _('lab'), "id": "LAB",
"suspend"
:
td
(
days
=
365
),
"delete"
:
None
,
"help_text"
:
_
(
'For long-term server use.'
)},
}
DEFAULT_TYPE
=
TYPES
[
'LAB'
]
TYPES_L
=
sorted
(
TYPES
.
values
(),
key
=
lambda
m
:
m
[
"suspend"
])
TYPES_C
=
tuple
([(
i
[
0
],
i
[
1
][
"verbose_name"
])
for
i
in
TYPES
.
items
()])
...
...
@@ -193,13 +193,18 @@ class Share(models.Model):
verbose_name
=
_
(
'share'
)
verbose_name_plural
=
_
(
'shares'
)
def
get_type
(
self
):
t
=
TYPES
[
self
.
type
]
@classmethod
def
extend_type
(
cls
,
t
):
t
[
'deletex'
]
=
(
datetime
.
now
()
+
td
(
seconds
=
1
)
+
t
[
'delete'
]
if
t
[
'delete'
]
else
None
)
t
[
'suspendx'
]
=
(
datetime
.
now
()
+
td
(
seconds
=
1
)
+
t
[
'suspend'
]
if
t
[
'suspend'
]
else
None
)
return
t
def
get_type
(
self
):
t
=
TYPES
[
self
.
type
]
return
self
.
extend_type
(
t
)
def
get_running_or_stopped
(
self
,
user
=
None
):
running
=
(
Instance
.
objects
.
all
()
.
exclude
(
state
=
'DONE'
)
.
filter
(
share
=
self
))
...
...
@@ -658,13 +663,20 @@ class Instance(models.Model):
def
renew
(
self
,
which
=
'both'
):
if
which
in
[
'suspend'
,
'both'
]:
self
.
time_of_suspend
=
self
.
share
.
get_type
()
[
'suspendx'
]
self
.
time_of_suspend
=
self
.
share
_type
[
'suspendx'
]
if
which
in
[
'delete'
,
'both'
]:
self
.
time_of_delete
=
self
.
share
.
get_type
()
[
'deletex'
]
self
.
time_of_delete
=
self
.
share
_type
[
'deletex'
]
if
not
(
which
in
[
'suspend'
,
'delete'
,
'both'
]):
raise
ValueError
(
'No such expiration type.'
)
self
.
save
()
@property
def
share_type
(
self
):
if
self
.
share
:
return
self
.
share
.
get_type
()
else
:
return
Share
.
extend_type
(
DEFAULT_TYPE
)
def
save_as
(
self
):
"""Save image and shut down."""
imgname
=
"template-
%
d-
%
d"
%
(
self
.
template
.
id
,
self
.
id
)
...
...
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