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
5ae07b2a
authored
Feb 25, 2021
by
Máhonfai Bálint
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change disk import to SCP
parent
44c50b76
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
21 deletions
+20
-21
disk.py
+15
-19
storagedriver.py
+5
-2
No files found.
disk.py
View file @
5ae07b2a
...
@@ -266,26 +266,22 @@ class Disk(object):
...
@@ -266,26 +266,22 @@ class Disk(object):
raise
Exception
(
"Invalid file format. Only qcow and "
raise
Exception
(
"Invalid file format. Only qcow and "
"iso files are allowed. Image from:
%
s"
%
url
)
"iso files are allowed. Image from:
%
s"
%
url
)
def
import_disk
(
self
,
task
,
url
,
parent_id
):
def
import_disk
(
self
,
task
,
url
,
port
=
None
):
r
=
requests
.
get
(
url
,
stream
=
True
)
downloaded_file
=
os
.
path
.
join
(
self
.
dir
,
re
.
split
(
'[:/]'
,
url
)[
-
1
])
clen
=
int
(
r
.
headers
.
get
(
'content-length'
))
cmdline
=
[
'scp'
,
'-B'
]
downloaded_file
=
os
.
path
.
join
(
self
.
dir
,
url
.
split
(
'/'
)[
-
1
])
if
port
is
not
None
:
percent
=
0
cmdline
.
extend
([
'-P'
,
str
(
port
)])
cmdline
.
extend
([
downloaded_file
,
url
])
proc
=
subprocess
.
Popen
(
cmdline
)
try
:
try
:
with
open
(
downloaded_file
,
'wb'
)
as
f
:
while
proc
.
poll
()
is
None
:
for
chunk
in
r
.
iter_content
(
chunk_size
=
256
*
1024
):
if
task
.
is_aborted
():
f
.
write
(
chunk
)
raise
AbortException
()
current_size
=
f
.
tell
()
sleep
(
1
)
new_percent
=
current_size
*
100
/
clen
if
new_percent
>
percent
:
if
task
.
is_aborted
():
if
task
.
is_aborted
():
raise
AbortException
()
raise
AbortException
()
percent
=
new_percent
task
.
update_state
(
task_id
=
parent_id
,
state
=
task
.
AsyncResult
(
parent_id
)
.
state
,
meta
=
{
'size'
:
current_size
,
'percent'
:
percent
}
)
with
magic
.
Magic
()
as
m
:
with
magic
.
Magic
()
as
m
:
ftype
=
m
.
id_filename
(
downloaded_file
)
ftype
=
m
.
id_filename
(
downloaded_file
)
...
...
storagedriver.py
View file @
5ae07b2a
...
@@ -48,9 +48,12 @@ class import_disk(AbortableTask):
...
@@ -48,9 +48,12 @@ class import_disk(AbortableTask):
def
run
(
self
,
**
kwargs
):
def
run
(
self
,
**
kwargs
):
disk_desc
=
kwargs
[
"disk_desc"
]
disk_desc
=
kwargs
[
"disk_desc"
]
url
=
kwargs
[
"url"
]
url
=
kwargs
[
"url"
]
parent_id
=
kwargs
[
"task"
]
if
"port"
in
kwargs
:
port
=
kwargs
[
"port"
]
else
:
port
=
None
disk
=
Disk
.
deserialize
(
disk_desc
)
disk
=
Disk
.
deserialize
(
disk_desc
)
disk
.
import_disk
(
self
,
url
,
p
arent_id
)
disk
.
import_disk
(
self
,
url
,
p
ort
)
return
{
return
{
"size"
:
disk
.
size
,
"size"
:
disk
.
size
,
"checksum"
:
disk
.
checksum
"checksum"
:
disk
.
checksum
...
...
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