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
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
cfdc07d9
authored
Feb 17, 2014
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
disk: added download function
parent
75467ac1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
disk.py
+28
-0
requirements/base.txt
+1
-0
No files found.
disk.py
View file @
cfdc07d9
...
...
@@ -3,6 +3,9 @@ import os
import
subprocess
import
re
import
logging
import
requests
logger
=
logging
.
getLogger
(
__name__
)
re_qemu_img
=
re
.
compile
(
r'(file format: (?P<format>(qcow2|raw))|'
r'virtual size: \w+ \((?P<size>[0-9]+) bytes\)|'
...
...
@@ -102,6 +105,31 @@ class Disk(object):
# Call subprocess
subprocess
.
check_output
(
cmdline
)
def
download
(
self
,
task
,
url
):
''' Download image from url. '''
disk_path
=
self
.
get_path
()
logger
.
info
(
"Downloading image from
%
s to
%
s"
,
url
,
disk_path
)
r
=
requests
.
get
(
url
,
stream
=
True
)
if
r
.
status_code
==
200
:
class
AbortException
(
Exception
):
pass
try
:
with
open
(
disk_path
,
'wb'
)
as
f
:
for
chunk
in
r
.
iter_content
(
chunk_size
=
4096
):
if
task
.
is_aborted
():
raise
AbortException
()
if
chunk
:
f
.
write
(
chunk
)
f
.
flush
()
self
.
size
=
os
.
path
.
getsize
(
disk_path
)
logger
.
debug
(
"Download finished
%
s (
%
s bytes)"
,
self
.
name
,
self
.
size
)
except
AbortException
:
# Cleanup file:
os
.
unlink
(
self
.
get_path
())
logger
.
info
(
"Download
%
s aborted
%
s removed."
,
url
,
disk_path
)
def
snapshot
(
self
):
''' Creating qcow2 snapshot with base image.
'''
...
...
requirements/base.txt
View file @
cfdc07d9
celery==3.0.23
requests==2.2.1
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