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):
raise
Exception
(
"Invalid file format. Only qcow and "
"iso files are allowed. Image from:
%
s"
%
url
)
def
import_disk
(
self
,
task
,
url
,
parent_id
):
r
=
requests
.
get
(
url
,
stream
=
True
)
clen
=
int
(
r
.
headers
.
get
(
'content-length'
))
downloaded_file
=
os
.
path
.
join
(
self
.
dir
,
url
.
split
(
'/'
)[
-
1
])
percent
=
0
def
import_disk
(
self
,
task
,
url
,
port
=
None
):
downloaded_file
=
os
.
path
.
join
(
self
.
dir
,
re
.
split
(
'[:/]'
,
url
)[
-
1
])
cmdline
=
[
'scp'
,
'-B'
]
if
port
is
not
None
:
cmdline
.
extend
([
'-P'
,
str
(
port
)])
cmdline
.
extend
([
downloaded_file
,
url
])
proc
=
subprocess
.
Popen
(
cmdline
)
try
:
with
open
(
downloaded_file
,
'wb'
)
as
f
:
for
chunk
in
r
.
iter_content
(
chunk_size
=
256
*
1024
):
f
.
write
(
chunk
)
current_size
=
f
.
tell
()
new_percent
=
current_size
*
100
/
clen
if
new_percent
>
percent
:
if
task
.
is_aborted
():
raise
AbortException
()
percent
=
new_percent
task
.
update_state
(
task_id
=
parent_id
,
state
=
task
.
AsyncResult
(
parent_id
)
.
state
,
meta
=
{
'size'
:
current_size
,
'percent'
:
percent
}
)
while
proc
.
poll
()
is
None
:
if
task
.
is_aborted
():
raise
AbortException
()
sleep
(
1
)
if
task
.
is_aborted
():
raise
AbortException
()
with
magic
.
Magic
()
as
m
:
ftype
=
m
.
id_filename
(
downloaded_file
)
...
...
storagedriver.py
View file @
5ae07b2a
...
...
@@ -48,9 +48,12 @@ class import_disk(AbortableTask):
def
run
(
self
,
**
kwargs
):
disk_desc
=
kwargs
[
"disk_desc"
]
url
=
kwargs
[
"url"
]
parent_id
=
kwargs
[
"task"
]
if
"port"
in
kwargs
:
port
=
kwargs
[
"port"
]
else
:
port
=
None
disk
=
Disk
.
deserialize
(
disk_desc
)
disk
.
import_disk
(
self
,
url
,
p
arent_id
)
disk
.
import_disk
(
self
,
url
,
p
ort
)
return
{
"size"
:
disk
.
size
,
"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