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
5dd8ad59
authored
Mar 06, 2014
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage: refactored disk creation
parent
a710e628
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
22 deletions
+11
-22
circle/storage/models.py
+11
-22
No files found.
circle/storage/models.py
View file @
5dd8ad59
...
@@ -172,12 +172,11 @@ class Disk(AclBase, TimeStampedModel):
...
@@ -172,12 +172,11 @@ 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
)
filename
=
self
.
filename
if
self
.
type
==
'iso'
else
None
new_type
=
type_mapping
[
self
.
type
]
new_type
=
type_mapping
[
self
.
type
]
return
Disk
.
objects
.
create
(
base
=
self
,
datastore
=
self
.
datastore
,
return
Disk
.
create
(
base
=
self
,
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
)
def
get_vmdisk_desc
(
self
):
def
get_vmdisk_desc
(
self
):
"""Serialize disk object to the vmdriver."""
"""Serialize disk object to the vmdriver."""
...
@@ -215,11 +214,6 @@ class Disk(AclBase, TimeStampedModel):
...
@@ -215,11 +214,6 @@ class Disk(AclBase, TimeStampedModel):
self
.
size
=
self
.
base
.
size
self
.
size
=
self
.
base
.
size
super
(
Disk
,
self
)
.
clean
(
*
args
,
**
kwargs
)
super
(
Disk
,
self
)
.
clean
(
*
args
,
**
kwargs
)
def
save
(
self
,
*
args
,
**
kwargs
):
if
self
.
filename
is
None
:
self
.
generate_filename
()
return
super
(
Disk
,
self
)
.
save
(
*
args
,
**
kwargs
)
def
deploy
(
self
,
user
=
None
,
task_uuid
=
None
,
timeout
=
15
):
def
deploy
(
self
,
user
=
None
,
task_uuid
=
None
,
timeout
=
15
):
"""Reify the disk model on the associated data store.
"""Reify the disk model on the associated data store.
...
@@ -250,7 +244,7 @@ class Disk(AclBase, TimeStampedModel):
...
@@ -250,7 +244,7 @@ class Disk(AclBase, TimeStampedModel):
# Delegate create / snapshot jobs
# Delegate create / snapshot jobs
queue_name
=
self
.
get_remote_queue_name
(
'storage'
)
queue_name
=
self
.
get_remote_queue_name
(
'storage'
)
disk_desc
=
self
.
get_disk_desc
()
disk_desc
=
self
.
get_disk_desc
()
if
self
.
type
==
'qcow2-snap'
:
if
self
.
base
is
not
None
:
with
act
.
sub_activity
(
'creating_snapshot'
):
with
act
.
sub_activity
(
'creating_snapshot'
):
remote_tasks
.
snapshot
.
apply_async
(
args
=
[
disk_desc
],
remote_tasks
.
snapshot
.
apply_async
(
args
=
[
disk_desc
],
queue
=
queue_name
queue
=
queue_name
...
@@ -272,10 +266,11 @@ class Disk(AclBase, TimeStampedModel):
...
@@ -272,10 +266,11 @@ class Disk(AclBase, TimeStampedModel):
return
local_tasks
.
deploy
.
apply_async
(
args
=
[
self
,
user
],
return
local_tasks
.
deploy
.
apply_async
(
args
=
[
self
,
user
],
queue
=
"localhost.man"
)
queue
=
"localhost.man"
)
def
generate_filename
(
self
):
@classmethod
"""Generate a unique filename and set it on the object.
def
create
(
cls
,
**
params
):
"""
disk
=
cls
(
filename
=
str
(
uuid
.
uuid4
()),
**
params
)
self
.
filename
=
str
(
uuid
.
uuid4
())
disk
.
save
()
return
disk
@classmethod
@classmethod
def
create_empty
(
cls
,
instance
=
None
,
user
=
None
,
**
kwargs
):
def
create_empty
(
cls
,
instance
=
None
,
user
=
None
,
**
kwargs
):
...
@@ -288,13 +283,8 @@ class Disk(AclBase, TimeStampedModel):
...
@@ -288,13 +283,8 @@ class Disk(AclBase, TimeStampedModel):
:return: Disk object without a real image, to be .deploy()ed later.
:return: Disk object without a real image, to be .deploy()ed later.
"""
"""
with
disk_activity
(
code_suffix
=
"create"
,
user
=
user
)
as
act
:
disk
=
cls
.
create
(
**
kwargs
)
disk
=
cls
(
**
kwargs
)
with
disk_activity
(
code_suffix
=
"create"
,
user
=
user
,
disk
=
disk
):
if
disk
.
filename
is
None
:
disk
.
generate_filename
()
disk
.
save
()
act
.
disk
=
disk
act
.
save
()
if
instance
:
if
instance
:
instance
.
disks
.
add
(
disk
)
instance
.
disks
.
add
(
disk
)
return
disk
return
disk
...
@@ -337,7 +327,6 @@ class Disk(AclBase, TimeStampedModel):
...
@@ -337,7 +327,6 @@ class Disk(AclBase, TimeStampedModel):
"""
"""
kwargs
.
setdefault
(
'name'
,
url
.
split
(
'/'
)[
-
1
])
kwargs
.
setdefault
(
'name'
,
url
.
split
(
'/'
)[
-
1
])
disk
=
cls
(
**
kwargs
)
disk
=
cls
(
**
kwargs
)
disk
.
generate_filename
()
disk
.
type
=
"iso"
disk
.
type
=
"iso"
disk
.
size
=
1
disk
.
size
=
1
# TODO get proper datastore
# TODO get proper datastore
...
...
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