Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
storagedriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
2
Merge Requests
4
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
27f4364e
authored
Dec 23, 2020
by
Máhonfai Bálint
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add progress and handle abort for export disk
parent
e78ee037
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
10 deletions
+29
-10
disk.py
+18
-6
storagedriver.py
+11
-4
No files found.
disk.py
View file @
27f4364e
...
...
@@ -11,7 +11,7 @@ from time import sleep
from
hashlib
import
md5
import
re
from
requests_toolbelt
import
MultipartEncoder
from
requests_toolbelt
import
MultipartEncoder
,
MultipartEncoderMonitor
import
requests
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -312,22 +312,34 @@ class Disk(object):
self
.
size
=
Disk
.
get
(
self
.
dir
,
self
.
name
)
.
size
def
export
(
self
,
format
,
exported_name
,
upload_link
):
exported_path
=
self
.
get_path
()
+
'.'
+
format
def
export
(
self
,
task
,
disk_format
,
exported_name
,
upload_link
,
parent_id
):
exported_path
=
self
.
get_path
()
+
'.'
+
disk_
format
cmdline
=
[
'qemu-img'
,
'convert'
,
'-O'
,
format
,
'-O'
,
disk_
format
,
self
.
get_path
(),
exported_path
]
subprocess
.
check_output
(
cmdline
)
size
=
os
.
path
.
getsize
(
exported_path
)
def
update_state
(
monitor
):
percent
=
monitor
.
bytes_read
*
100
/
size
if
task
.
is_aborted
():
raise
AbortException
()
task
.
update_state
(
task_id
=
parent_id
,
state
=
task
.
AsyncResult
(
parent_id
)
.
state
,
meta
=
{
'percent'
:
percent
}
)
with
open
(
exported_path
,
'rb'
)
as
exported_disk
:
try
:
m
=
MultipartEncoder
(
{
'data'
:
(
exported_name
+
'.'
+
format
,
e
=
MultipartEncoder
(
{
'data'
:
(
exported_name
+
'.'
+
disk_
format
,
exported_disk
)}
)
m
=
MultipartEncoderMonitor
(
e
,
update_state
)
response
=
requests
.
post
(
upload_link
,
data
=
m
,
...
...
storagedriver.py
View file @
27f4364e
...
...
@@ -56,10 +56,17 @@ class import_disk(AbortableTask):
}
@celery.task
()
def
export
(
disk_desc
,
format
,
exported_name
,
upload_link
):
disk
=
Disk
.
deserialize
(
disk_desc
)
disk
.
export
(
format
,
exported_name
,
upload_link
)
class
export_disk
(
AbortableTask
):
time_limit
=
18000
def
run
(
self
,
**
kwargs
):
disk_desc
=
kwargs
[
"disk_desc"
]
disk_format
=
kwargs
[
"disk_format"
]
exported_name
=
kwargs
[
"exported_name"
]
upload_link
=
kwargs
[
"upload_link"
]
parent_id
=
kwargs
[
"task"
]
disk
=
Disk
.
deserialize
(
disk_desc
)
disk
.
export
(
self
,
disk_format
,
exported_name
,
upload_link
,
parent_id
)
@celery.task
()
...
...
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