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
3ad100bb
authored
Feb 26, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage: refactor uuid generation to a method
parent
5f8dcc9e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
6 deletions
+16
-6
circle/storage/models.py
+16
-6
No files found.
circle/storage/models.py
View file @
3ad100bb
...
...
@@ -166,8 +166,10 @@ class Disk(AclBase, TimeStampedModel):
if
self
.
type
not
in
type_mapping
.
keys
():
raise
self
.
WrongDiskTypeError
(
self
.
type
)
filename
=
self
.
filename
if
self
.
type
==
'iso'
else
str
(
uuid
.
uuid4
())
if
self
.
type
==
'iso'
:
filename
=
self
.
filename
else
:
self
.
generate_filename
()
new_type
=
type_mapping
[
self
.
type
]
return
Disk
.
objects
.
create
(
base
=
self
,
datastore
=
self
.
datastore
,
...
...
@@ -208,6 +210,8 @@ class Disk(AclBase, TimeStampedModel):
def
clean
(
self
,
*
args
,
**
kwargs
):
if
self
.
size
==
""
and
self
.
base
:
self
.
size
=
self
.
base
.
size
if
self
.
filename
is
None
:
self
.
generate_filename
()
super
(
Disk
,
self
)
.
clean
(
*
args
,
**
kwargs
)
def
deploy
(
self
,
user
=
None
,
task_uuid
=
None
):
...
...
@@ -274,6 +278,11 @@ class Disk(AclBase, TimeStampedModel):
return
local_tasks
.
create_empty
.
apply_async
(
args
=
[
instance
,
params
,
user
],
queue
=
"localhost.man"
)
def
generate_filename
(
self
):
"""Generate a unique filename and set it on the object.
"""
self
.
filename
=
str
(
uuid
.
uuid4
())
@classmethod
def
create_empty
(
cls
,
instance
=
None
,
params
=
None
,
user
=
None
,
task_uuid
=
None
):
...
...
@@ -291,6 +300,8 @@ class Disk(AclBase, TimeStampedModel):
disk
=
cls
()
if
params
:
disk
.
__dict__
.
update
(
params
)
if
disk
.
filename
is
None
:
disk
.
generate_filename
()
disk
.
save
()
act
.
disk
=
disk
act
.
save
()
...
...
@@ -337,7 +348,7 @@ class Disk(AclBase, TimeStampedModel):
:rtype: AsyncResult
"""
disk
=
cls
()
disk
.
filename
=
str
(
uuid
.
uuid4
()
)
disk
.
generate_filename
(
)
disk
.
type
=
"iso"
disk
.
size
=
1
# TODO get proper datastore
...
...
@@ -421,12 +432,11 @@ class Disk(AclBase, TimeStampedModel):
with
disk_activity
(
code_suffix
=
'save_as'
,
disk
=
self
,
task_uuid
=
task_uuid
,
user
=
user
):
filename
=
str
(
uuid
.
uuid4
())
new_type
,
new_base
=
mapping
[
self
.
type
]
disk
=
Disk
.
objects
.
create
(
base
=
new_base
,
datastore
=
self
.
datastore
,
filename
=
filename
,
name
=
self
.
nam
e
,
size
=
self
.
size
,
type
=
new_type
)
name
=
self
.
name
,
size
=
self
.
siz
e
,
type
=
new_type
)
queue_name
=
self
.
get_remote_queue_name
(
'storage'
)
remote_tasks
.
merge
.
apply_async
(
args
=
[
self
.
get_disk_desc
(),
...
...
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