Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b7f7ac68
authored
Mar 14, 2014
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage: refactored create and save_as method to use activites
parent
f931d0f6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
33 deletions
+45
-33
circle/storage/models.py
+45
-33
No files found.
circle/storage/models.py
View file @
b7f7ac68
...
@@ -300,10 +300,17 @@ class Disk(AclBase, TimeStampedModel):
...
@@ -300,10 +300,17 @@ class Disk(AclBase, TimeStampedModel):
queue
=
"localhost.man"
)
queue
=
"localhost.man"
)
@classmethod
@classmethod
def
create
(
cls
,
**
params
):
def
create
(
cls
,
instance
=
None
,
user
=
None
,
**
params
):
"""Create disk with activity.
"""
datastore
=
params
.
pop
(
'datastore'
,
DataStore
.
objects
.
get
())
datastore
=
params
.
pop
(
'datastore'
,
DataStore
.
objects
.
get
())
disk
=
cls
(
filename
=
str
(
uuid
.
uuid4
()),
datastore
=
datastore
,
**
params
)
disk
=
cls
(
filename
=
str
(
uuid
.
uuid4
()),
datastore
=
datastore
,
**
params
)
disk
.
save
()
disk
.
save
()
with
disk_activity
(
code_suffix
=
"create"
,
user
=
user
,
disk
=
disk
):
if
instance
:
instance
.
disks
.
add
(
disk
)
return
disk
return
disk
@classmethod
@classmethod
...
@@ -317,11 +324,8 @@ class Disk(AclBase, TimeStampedModel):
...
@@ -317,11 +324,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.
"""
"""
disk
=
cls
.
create
(
**
kwargs
)
disk
=
Disk
.
create
(
instance
=
None
,
user
=
None
,
**
kwargs
)
with
disk_activity
(
code_suffix
=
"create"
,
user
=
user
,
disk
=
disk
):
return
disk
if
instance
:
instance
.
disks
.
add
(
disk
)
return
disk
@classmethod
@classmethod
def
create_from_url_async
(
cls
,
url
,
instance
=
None
,
user
=
None
,
**
kwargs
):
def
create_from_url_async
(
cls
,
url
,
instance
=
None
,
user
=
None
,
**
kwargs
):
...
@@ -377,24 +381,24 @@ class Disk(AclBase, TimeStampedModel):
...
@@ -377,24 +381,24 @@ class Disk(AclBase, TimeStampedModel):
class
AbortException
(
Exception
):
class
AbortException
(
Exception
):
pass
pass
with
disk_activity
(
code_suffix
=
'd
ownload
'
,
disk
=
disk
,
with
disk_activity
(
code_suffix
=
'd
eploy
'
,
disk
=
disk
,
task_uuid
=
task_uuid
,
user
=
user
,
task_uuid
=
task_uuid
,
user
=
user
,
on_abort
=
__on_abort
):
on_abort
=
__on_abort
)
as
act
:
result
=
remote_tasks
.
download
.
apply_async
(
with
act
.
sub_activity
(
'downloading_disk'
):
kwargs
=
{
'url'
:
url
,
'parent_id'
:
task_uuid
,
result
=
remote_tasks
.
download
.
apply_async
(
'disk'
:
disk
.
get_disk_desc
()}
,
kwargs
=
{
'url'
:
url
,
'parent_id'
:
task_uuid
,
queue
=
queue_name
)
'disk'
:
disk
.
get_disk_desc
()},
while
True
:
queue
=
queue_name
)
try
:
while
True
:
size
=
result
.
get
(
timeout
=
5
)
try
:
break
size
=
result
.
get
(
timeout
=
5
)
except
TimeoutError
:
break
if
abortable_task
and
abortable_task
.
is_aborted
()
:
except
TimeoutError
:
AbortableAsyncResult
(
result
.
id
)
.
abort
()
if
abortable_task
and
abortable_task
.
is_aborted
():
raise
AbortException
(
"Download aborted by user."
)
AbortableAsyncResult
(
result
.
id
)
.
abort
(
)
disk
.
size
=
size
raise
AbortException
(
"Download aborted by user."
)
disk
.
ready
=
Tru
e
disk
.
size
=
siz
e
disk
.
save
()
disk
.
save
()
return
disk
return
disk
def
destroy
(
self
,
user
=
None
,
task_uuid
=
None
):
def
destroy
(
self
,
user
=
None
,
task_uuid
=
None
):
...
@@ -454,16 +458,15 @@ class Disk(AclBase, TimeStampedModel):
...
@@ -454,16 +458,15 @@ class Disk(AclBase, TimeStampedModel):
disk
.
save
()
disk
.
save
()
with
disk_activity
(
code_suffix
=
"save_as"
,
disk
=
self
,
with
disk_activity
(
code_suffix
=
"save_as"
,
disk
=
self
,
user
=
user
,
task_uuid
=
None
):
user
=
user
,
task_uuid
=
task_uuid
):
queue_name
=
self
.
get_remote_queue_name
(
'storage'
)
with
disk_activity
(
code_suffix
=
"deploy"
,
disk
=
disk
,
remote_tasks
.
merge
.
apply_async
(
args
=
[
self
.
get_disk_desc
(),
user
=
user
,
task_uuid
=
task_uuid
):
disk
.
get_disk_desc
()],
queue_name
=
self
.
get_remote_queue_name
(
'storage'
)
queue
=
queue_name
remote_tasks
.
merge
.
apply_async
(
args
=
[
self
.
get_disk_desc
(),
)
.
get
()
# Timeout
disk
.
get_disk_desc
()],
disk
.
ready
=
True
queue
=
queue_name
disk
.
save
()
)
.
get
()
# Timeout
return
disk
return
disk
class
DiskActivity
(
ActivityModel
):
class
DiskActivity
(
ActivityModel
):
...
@@ -479,6 +482,15 @@ class DiskActivity(ActivityModel):
...
@@ -479,6 +482,15 @@ class DiskActivity(ActivityModel):
act
.
save
()
act
.
save
()
return
act
return
act
def
__unicode__
(
self
):
if
self
.
parent
:
return
'{}({})->{}'
.
format
(
self
.
parent
.
activity_code
,
self
.
disk
,
self
.
activity_code
)
else
:
return
'{}({})'
.
format
(
self
.
activity_code
,
self
.
disk
)
def
create_sub
(
self
,
code_suffix
,
task_uuid
=
None
):
def
create_sub
(
self
,
code_suffix
,
task_uuid
=
None
):
act
=
DiskActivity
(
act
=
DiskActivity
(
activity_code
=
self
.
activity_code
+
'.'
+
code_suffix
,
activity_code
=
self
.
activity_code
+
'.'
+
code_suffix
,
...
...
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