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
Hide 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):
...
@@ -166,8 +166,10 @@ class Disk(AclBase, TimeStampedModel):
if
self
.
type
not
in
type_mapping
.
keys
():
if
self
.
type
not
in
type_mapping
.
keys
():
raise
self
.
WrongDiskTypeError
(
self
.
type
)
raise
self
.
WrongDiskTypeError
(
self
.
type
)
if
self
.
type
==
'iso'
:
filename
=
self
.
filename
if
self
.
type
==
'iso'
else
str
(
uuid
.
uuid4
())
filename
=
self
.
filename
else
:
self
.
generate_filename
()
new_type
=
type_mapping
[
self
.
type
]
new_type
=
type_mapping
[
self
.
type
]
return
Disk
.
objects
.
create
(
base
=
self
,
datastore
=
self
.
datastore
,
return
Disk
.
objects
.
create
(
base
=
self
,
datastore
=
self
.
datastore
,
...
@@ -208,6 +210,8 @@ class Disk(AclBase, TimeStampedModel):
...
@@ -208,6 +210,8 @@ class Disk(AclBase, TimeStampedModel):
def
clean
(
self
,
*
args
,
**
kwargs
):
def
clean
(
self
,
*
args
,
**
kwargs
):
if
self
.
size
==
""
and
self
.
base
:
if
self
.
size
==
""
and
self
.
base
:
self
.
size
=
self
.
base
.
size
self
.
size
=
self
.
base
.
size
if
self
.
filename
is
None
:
self
.
generate_filename
()
super
(
Disk
,
self
)
.
clean
(
*
args
,
**
kwargs
)
super
(
Disk
,
self
)
.
clean
(
*
args
,
**
kwargs
)
def
deploy
(
self
,
user
=
None
,
task_uuid
=
None
):
def
deploy
(
self
,
user
=
None
,
task_uuid
=
None
):
...
@@ -274,6 +278,11 @@ class Disk(AclBase, TimeStampedModel):
...
@@ -274,6 +278,11 @@ class Disk(AclBase, TimeStampedModel):
return
local_tasks
.
create_empty
.
apply_async
(
return
local_tasks
.
create_empty
.
apply_async
(
args
=
[
instance
,
params
,
user
],
queue
=
"localhost.man"
)
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
@classmethod
def
create_empty
(
cls
,
instance
=
None
,
params
=
None
,
def
create_empty
(
cls
,
instance
=
None
,
params
=
None
,
user
=
None
,
task_uuid
=
None
):
user
=
None
,
task_uuid
=
None
):
...
@@ -291,6 +300,8 @@ class Disk(AclBase, TimeStampedModel):
...
@@ -291,6 +300,8 @@ class Disk(AclBase, TimeStampedModel):
disk
=
cls
()
disk
=
cls
()
if
params
:
if
params
:
disk
.
__dict__
.
update
(
params
)
disk
.
__dict__
.
update
(
params
)
if
disk
.
filename
is
None
:
disk
.
generate_filename
()
disk
.
save
()
disk
.
save
()
act
.
disk
=
disk
act
.
disk
=
disk
act
.
save
()
act
.
save
()
...
@@ -337,7 +348,7 @@ class Disk(AclBase, TimeStampedModel):
...
@@ -337,7 +348,7 @@ class Disk(AclBase, TimeStampedModel):
:rtype: AsyncResult
:rtype: AsyncResult
"""
"""
disk
=
cls
()
disk
=
cls
()
disk
.
filename
=
str
(
uuid
.
uuid4
()
)
disk
.
generate_filename
(
)
disk
.
type
=
"iso"
disk
.
type
=
"iso"
disk
.
size
=
1
disk
.
size
=
1
# TODO get proper datastore
# TODO get proper datastore
...
@@ -421,12 +432,11 @@ class Disk(AclBase, TimeStampedModel):
...
@@ -421,12 +432,11 @@ class Disk(AclBase, TimeStampedModel):
with
disk_activity
(
code_suffix
=
'save_as'
,
disk
=
self
,
with
disk_activity
(
code_suffix
=
'save_as'
,
disk
=
self
,
task_uuid
=
task_uuid
,
user
=
user
):
task_uuid
=
task_uuid
,
user
=
user
):
filename
=
str
(
uuid
.
uuid4
())
new_type
,
new_base
=
mapping
[
self
.
type
]
new_type
,
new_base
=
mapping
[
self
.
type
]
disk
=
Disk
.
objects
.
create
(
base
=
new_base
,
datastore
=
self
.
datastore
,
disk
=
Disk
.
objects
.
create
(
base
=
new_base
,
datastore
=
self
.
datastore
,
filename
=
filename
,
name
=
self
.
nam
e
,
name
=
self
.
name
,
size
=
self
.
siz
e
,
size
=
self
.
size
,
type
=
new_type
)
type
=
new_type
)
queue_name
=
self
.
get_remote_queue_name
(
'storage'
)
queue_name
=
self
.
get_remote_queue_name
(
'storage'
)
remote_tasks
.
merge
.
apply_async
(
args
=
[
self
.
get_disk_desc
(),
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