Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
storagedriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c7e54d3d
authored
Oct 03, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix Ubuntu 12.04 support (tarokkk)
parent
1bf2e9c2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
2 deletions
+40
-2
disk.py
+40
-2
No files found.
disk.py
View file @
c7e54d3d
...
@@ -9,10 +9,16 @@ from zlib import decompressobj, MAX_WBITS
...
@@ -9,10 +9,16 @@ from zlib import decompressobj, MAX_WBITS
from
bz2
import
BZ2Decompressor
from
bz2
import
BZ2Decompressor
from
time
import
sleep
from
time
import
sleep
import
re
import
requests
import
requests
logger
=
logging
.
getLogger
(
__name__
)
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\)|'
r'backing file: \S+ \(actual path: (?P<base>\S+)\))$'
)
class
AbortException
(
Exception
):
class
AbortException
(
Exception
):
pass
pass
...
@@ -79,7 +85,30 @@ class Disk(object):
...
@@ -79,7 +85,30 @@ class Disk(object):
self
.
size
,
self
.
get_base
())
self
.
size
,
self
.
get_base
())
@classmethod
@classmethod
def
get
(
cls
,
dir
,
name
):
def
get_legacy
(
cls
,
dir
,
name
):
''' Create disk from path
'''
path
=
os
.
path
.
realpath
(
dir
+
'/'
+
name
)
output
=
subprocess
.
check_output
([
'qemu-img'
,
'info'
,
path
])
type
=
'normal'
base_name
=
None
for
line
in
output
.
split
(
'
\n
'
):
m
=
re_qemu_img
.
search
(
line
)
if
m
:
res
=
m
.
groupdict
()
if
res
.
get
(
'format'
,
None
)
is
not
None
:
format
=
res
[
'format'
]
if
res
.
get
(
'size'
,
None
)
is
not
None
:
size
=
float
(
res
[
'size'
])
if
res
.
get
(
'base'
,
None
)
is
not
None
:
base_name
=
os
.
path
.
basename
(
res
[
'base'
])
type
=
'snapshot'
actual_size
=
size
return
Disk
(
dir
,
name
,
format
,
type
,
size
,
base_name
,
actual_size
)
@classmethod
def
get_new
(
cls
,
dir
,
name
):
"""Create disk from path."""
"""Create disk from path."""
path
=
os
.
path
.
realpath
(
dir
+
'/'
+
name
)
path
=
os
.
path
.
realpath
(
dir
+
'/'
+
name
)
output
=
subprocess
.
check_output
(
output
=
subprocess
.
check_output
(
...
@@ -100,6 +129,14 @@ class Disk(object):
...
@@ -100,6 +129,14 @@ class Disk(object):
type
=
'normal'
type
=
'normal'
return
Disk
(
dir
,
name
,
format
,
type
,
size
,
base_name
,
actual_size
)
return
Disk
(
dir
,
name
,
format
,
type
,
size
,
base_name
,
actual_size
)
@classmethod
def
get
(
cls
,
dir
,
name
):
from
platform
import
dist
if
dist
()[
1
]
<
'14.04'
:
return
Disk
.
get_legacy
(
dir
,
name
)
else
:
return
Disk
.
get_new
(
dir
,
name
)
def
create
(
self
):
def
create
(
self
):
""" Creating new image format specified at self.format.
""" Creating new image format specified at self.format.
self.format can be "qcow2-normal"
self.format can be "qcow2-normal"
...
@@ -252,6 +289,7 @@ class Disk(object):
...
@@ -252,6 +289,7 @@ class Disk(object):
subprocess
.
check_output
(
cmdline
)
subprocess
.
check_output
(
cmdline
)
def
merge_disk_with_base
(
self
,
task
,
new_disk
,
parent_id
=
None
):
def
merge_disk_with_base
(
self
,
task
,
new_disk
,
parent_id
=
None
):
proc
=
None
try
:
try
:
cmdline
=
[
cmdline
=
[
'qemu-img'
,
'convert'
,
self
.
get_path
(),
'qemu-img'
,
'convert'
,
self
.
get_path
(),
...
@@ -303,7 +341,7 @@ class Disk(object):
...
@@ -303,7 +341,7 @@ class Disk(object):
raise
raise
def
merge_disk_without_base
(
self
,
task
,
new_disk
,
parent_id
=
None
,
def
merge_disk_without_base
(
self
,
task
,
new_disk
,
parent_id
=
None
,
length
=
1024
*
1024
):
length
=
1024
*
1024
):
try
:
try
:
fsrc
=
open
(
self
.
get_path
(),
'rb'
)
fsrc
=
open
(
self
.
get_path
(),
'rb'
)
fdst
=
open
(
new_disk
.
get_path
(),
'wb'
)
fdst
=
open
(
new_disk
.
get_path
(),
'wb'
)
...
...
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