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
ea2cc1cb
authored
Apr 09, 2020
by
Máhonfai Bálint
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add import disk feature
parent
b171f0a4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
9 deletions
+32
-9
disk.py
+25
-9
storagedriver.py
+7
-0
No files found.
disk.py
View file @
ea2cc1cb
...
@@ -266,14 +266,29 @@ class Disk(object):
...
@@ -266,14 +266,29 @@ 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
,
url
):
r
=
requests
.
get
(
url
,
stream
=
True
)
downloaded_file
=
os
.
path
.
join
(
self
.
dir
,
url
.
split
(
'/'
)[
-
1
])
with
open
(
downloaded_file
,
'wb'
)
as
f
:
f
.
write
(
r
.
content
)
cmdline
=
[
'qemu-img'
,
'convert'
,
'-O'
,
'qcow2'
,
downloaded_file
,
self
.
get_path
()]
subprocess
.
check_output
(
cmdline
)
os
.
unlink
(
downloaded_file
)
if
not
self
.
check_valid_image
():
os
.
unlink
(
self
.
get_path
())
raise
Exception
(
"Invalid file format."
)
self
.
size
=
Disk
.
get
(
self
.
dir
,
self
.
name
)
.
size
def
export
(
self
,
format
,
exported_name
,
upload_link
):
def
export
(
self
,
format
,
exported_name
,
upload_link
):
format_dict
=
{
exported_path
=
self
.
get_path
()
+
'.'
+
format
'vmdk'
:
'vmdk'
,
'qcow2'
:
'qcow2'
,
'vdi'
:
'vdi'
,
'vpc'
:
'vhd'
,
}
exported_path
=
self
.
get_path
()
+
'.'
+
format_dict
[
format
]
cmdline
=
[
'qemu-img'
,
cmdline
=
[
'qemu-img'
,
'convert'
,
'convert'
,
'-O'
,
format
,
'-O'
,
format
,
...
@@ -285,14 +300,15 @@ class Disk(object):
...
@@ -285,14 +300,15 @@ class Disk(object):
with
open
(
exported_path
,
'rb'
)
as
exported_disk
:
with
open
(
exported_path
,
'rb'
)
as
exported_disk
:
try
:
try
:
m
=
MultipartEncoder
(
m
=
MultipartEncoder
(
{
'data'
:
(
exported_name
+
'.'
+
format
_dict
[
format
]
,
{
'data'
:
(
exported_name
+
'.'
+
format
,
exported_disk
)}
exported_disk
)}
)
)
response
=
requests
.
post
(
response
=
requests
.
post
(
upload_link
,
upload_link
,
data
=
m
,
data
=
m
,
headers
=
{
'Content-Type'
:
m
.
content_type
},
headers
=
{
'Content-Type'
:
m
.
content_type
},
params
=
{
'no_redirect'
:
''
})
params
=
{
'no_redirect'
:
''
}
)
if
response
.
status_code
!=
200
:
if
response
.
status_code
!=
200
:
raise
Exception
(
"Invalid response status code:
%
s"
%
raise
Exception
(
"Invalid response status code:
%
s"
%
response
.
status_code
)
response
.
status_code
)
...
...
storagedriver.py
View file @
ea2cc1cb
...
@@ -42,6 +42,13 @@ class download(AbortableTask):
...
@@ -42,6 +42,13 @@ class download(AbortableTask):
@celery.task
()
@celery.task
()
def
import_disk
(
disk_desc
,
url
):
disk
=
Disk
.
deserialize
(
disk_desc
)
disk
.
import_disk
(
url
)
return
disk
.
size
@celery.task
()
def
export
(
disk_desc
,
format
,
exported_name
,
upload_link
):
def
export
(
disk_desc
,
format
,
exported_name
,
upload_link
):
disk
=
Disk
.
deserialize
(
disk_desc
)
disk
=
Disk
.
deserialize
(
disk_desc
)
disk
.
export
(
format
,
exported_name
,
upload_link
)
disk
.
export
(
format
,
exported_name
,
upload_link
)
...
...
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