Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
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
Show 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):
...
@@ -158,7 +158,6 @@ class SshKey(models.Model):
TEMPLATE_STATES
=
((
"INIT"
,
_
(
'init'
)),
(
"PREP"
,
_
(
'perparing'
)),
TEMPLATE_STATES
=
((
"INIT"
,
_
(
'init'
)),
(
"PREP"
,
_
(
'perparing'
)),
(
"SAVE"
,
_
(
'saving'
)),
(
"READY"
,
_
(
'ready'
)))
(
"SAVE"
,
_
(
'saving'
)),
(
"READY"
,
_
(
'ready'
)))
TYPES
=
{
"LAB"
:
{
"verbose_name"
:
_
(
'lab'
),
"id"
:
"LAB"
,
TYPES
=
{
"LAB"
:
{
"verbose_name"
:
_
(
'lab'
),
"id"
:
"LAB"
,
"suspend"
:
td
(
hours
=
5
),
"delete"
:
td
(
days
=
15
),
"suspend"
:
td
(
hours
=
5
),
"delete"
:
td
(
days
=
15
),
"help_text"
:
_
(
'For lab or homework with short lifetime.'
)},
"help_text"
:
_
(
'For lab or homework with short lifetime.'
)},
...
@@ -169,6 +168,7 @@ TYPES = {"LAB": {"verbose_name": _('lab'), "id": "LAB",
...
@@ -169,6 +168,7 @@ TYPES = {"LAB": {"verbose_name": _('lab'), "id": "LAB",
"suspend"
:
td
(
days
=
365
),
"delete"
:
None
,
"suspend"
:
td
(
days
=
365
),
"delete"
:
None
,
"help_text"
:
_
(
'For long-term server use.'
)},
"help_text"
:
_
(
'For long-term server use.'
)},
}
}
DEFAULT_TYPE
=
TYPES
[
'LAB'
]
TYPES_L
=
sorted
(
TYPES
.
values
(),
key
=
lambda
m
:
m
[
"suspend"
])
TYPES_L
=
sorted
(
TYPES
.
values
(),
key
=
lambda
m
:
m
[
"suspend"
])
TYPES_C
=
tuple
([(
i
[
0
],
i
[
1
][
"verbose_name"
])
for
i
in
TYPES
.
items
()])
TYPES_C
=
tuple
([(
i
[
0
],
i
[
1
][
"verbose_name"
])
for
i
in
TYPES
.
items
()])
...
@@ -193,13 +193,18 @@ class Share(models.Model):
...
@@ -193,13 +193,18 @@ class Share(models.Model):
verbose_name
=
_
(
'share'
)
verbose_name
=
_
(
'share'
)
verbose_name_plural
=
_
(
'shares'
)
verbose_name_plural
=
_
(
'shares'
)
def
get_type
(
self
):
@classmethod
t
=
TYPES
[
self
.
type
]
def
extend_type
(
cls
,
t
):
t
[
'deletex'
]
=
(
datetime
.
now
()
+
td
(
seconds
=
1
)
+
t
[
'delete'
]
t
[
'deletex'
]
=
(
datetime
.
now
()
+
td
(
seconds
=
1
)
+
t
[
'delete'
]
if
t
[
'delete'
]
else
None
)
if
t
[
'delete'
]
else
None
)
t
[
'suspendx'
]
=
(
datetime
.
now
()
+
td
(
seconds
=
1
)
+
t
[
'suspend'
]
t
[
'suspendx'
]
=
(
datetime
.
now
()
+
td
(
seconds
=
1
)
+
t
[
'suspend'
]
if
t
[
'suspend'
]
else
None
)
if
t
[
'suspend'
]
else
None
)
return
t
return
t
def
get_type
(
self
):
t
=
TYPES
[
self
.
type
]
return
self
.
extend_type
(
t
)
def
get_running_or_stopped
(
self
,
user
=
None
):
def
get_running_or_stopped
(
self
,
user
=
None
):
running
=
(
Instance
.
objects
.
all
()
.
exclude
(
state
=
'DONE'
)
running
=
(
Instance
.
objects
.
all
()
.
exclude
(
state
=
'DONE'
)
.
filter
(
share
=
self
))
.
filter
(
share
=
self
))
...
@@ -658,13 +663,20 @@ class Instance(models.Model):
...
@@ -658,13 +663,20 @@ class Instance(models.Model):
def
renew
(
self
,
which
=
'both'
):
def
renew
(
self
,
which
=
'both'
):
if
which
in
[
'suspend'
,
'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'
]:
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'
]):
if
not
(
which
in
[
'suspend'
,
'delete'
,
'both'
]):
raise
ValueError
(
'No such expiration type.'
)
raise
ValueError
(
'No such expiration type.'
)
self
.
save
()
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
):
def
save_as
(
self
):
"""Save image and shut down."""
"""Save image and shut down."""
imgname
=
"template-
%
d-
%
d"
%
(
self
.
template
.
id
,
self
.
id
)
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