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
c495e5d3
authored
Jun 13, 2014
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed docstrings
parent
3f72953c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
10 deletions
+32
-10
disk.py
+13
-10
miscellaneous/storage.conf
+19
-0
No files found.
disk.py
View file @
c495e5d3
...
...
@@ -44,12 +44,14 @@ class Disk(object):
@classmethod
def
deserialize
(
cls
,
desc
):
"""Create cls object from JSON."""
logging
.
info
(
desc
)
if
isinstance
(
desc
,
basestring
):
desc
=
json
.
loads
(
desc
)
return
cls
(
**
desc
)
def
get_desc
(
self
):
"""Create dict from Disk object."""
return
{
'name'
:
self
.
name
,
'dir'
:
self
.
dir
,
...
...
@@ -59,9 +61,11 @@ class Disk(object):
}
def
get_path
(
self
):
"""Get absolute path for disk."""
return
os
.
path
.
realpath
(
self
.
dir
+
'/'
+
self
.
name
)
def
get_base
(
self
):
"""Get absolute path for disk's base image."""
return
os
.
path
.
realpath
(
self
.
dir
+
'/'
+
self
.
base_name
)
def
__unicode__
(
self
):
...
...
@@ -70,8 +74,7 @@ class Disk(object):
@classmethod
def
get
(
cls
,
dir
,
name
):
''' Create disk from path
'''
"""Create disk from path."""
path
=
os
.
path
.
realpath
(
dir
+
'/'
+
name
)
output
=
subprocess
.
check_output
([
'qemu-img'
,
'info'
,
path
])
...
...
@@ -92,9 +95,9 @@ class Disk(object):
return
Disk
(
dir
,
name
,
format
,
size
,
base
,
type
)
def
create
(
self
):
'''
Creating new image format specified at self.format.
self.format
v
an be "qcow2-normal"
'''
"""
Creating new image format specified at self.format.
self.format
c
an be "qcow2-normal"
"""
# Check if type is avaliable to create
if
self
.
format
not
in
self
.
CREATE_FORMATS
:
raise
Exception
(
'Invalid format:
%
s'
%
self
.
format
)
...
...
@@ -114,7 +117,7 @@ class Disk(object):
subprocess
.
check_output
(
cmdline
)
def
download
(
self
,
task
,
url
,
parent_id
=
None
):
# noqa
''' Download image from 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
)
...
...
@@ -221,8 +224,8 @@ class Disk(object):
subprocess
.
check_output
(
cmdline
)
def
merge
(
self
,
new_disk
):
'''
Merging a new_disk from the actual disk and its base.
'''
"""
Merging a new_disk from the actual disk and its base.
"""
# Check if file already exists
if
os
.
path
.
isfile
(
new_disk
.
get_path
()):
raise
Exception
(
'File already exists:
%
s'
%
self
.
get_path
())
...
...
@@ -240,11 +243,11 @@ class Disk(object):
copy
(
self
.
get_path
(),
new_disk
.
get_path
())
def
delete
(
self
):
''' Delete file
'''
""" Delete file. """
if
os
.
path
.
isfile
(
self
.
get_path
()):
os
.
unlink
(
self
.
get_path
())
@classmethod
def
list
(
cls
,
dir
):
""" List all files in <dir> directory."""
return
[
cls
.
get
(
dir
,
file
)
for
file
in
os
.
listdir
(
dir
)]
miscellaneous/storage.conf
0 → 100644
View file @
c495e5d3
description
"IK Cloud Django Development Server"
start
on
runlevel
[
2345
]
stop
on
runlevel
[!
2345
]
pre
-
start
script
hostname
=$(
hostname
-
s
)
for
inst
in
storage
.
fast
storage
.
slow
do
start
storagecelery
NAME
=$
hostname
.$
inst
|| :
done
end
script
post
-
stop
script
for
inst
in
`
initctl
list
|
grep
"^storagecelery "
|
awk
'{print $2}'
|
tr
-
d
')'
|
tr
-
d
'('
`
do
stop
vmcelery
NAME
=$
inst
|| :
done
end
script
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