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
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):
...
@@ -44,12 +44,14 @@ class Disk(object):
@classmethod
@classmethod
def
deserialize
(
cls
,
desc
):
def
deserialize
(
cls
,
desc
):
"""Create cls object from JSON."""
logging
.
info
(
desc
)
logging
.
info
(
desc
)
if
isinstance
(
desc
,
basestring
):
if
isinstance
(
desc
,
basestring
):
desc
=
json
.
loads
(
desc
)
desc
=
json
.
loads
(
desc
)
return
cls
(
**
desc
)
return
cls
(
**
desc
)
def
get_desc
(
self
):
def
get_desc
(
self
):
"""Create dict from Disk object."""
return
{
return
{
'name'
:
self
.
name
,
'name'
:
self
.
name
,
'dir'
:
self
.
dir
,
'dir'
:
self
.
dir
,
...
@@ -59,9 +61,11 @@ class Disk(object):
...
@@ -59,9 +61,11 @@ class Disk(object):
}
}
def
get_path
(
self
):
def
get_path
(
self
):
"""Get absolute path for disk."""
return
os
.
path
.
realpath
(
self
.
dir
+
'/'
+
self
.
name
)
return
os
.
path
.
realpath
(
self
.
dir
+
'/'
+
self
.
name
)
def
get_base
(
self
):
def
get_base
(
self
):
"""Get absolute path for disk's base image."""
return
os
.
path
.
realpath
(
self
.
dir
+
'/'
+
self
.
base_name
)
return
os
.
path
.
realpath
(
self
.
dir
+
'/'
+
self
.
base_name
)
def
__unicode__
(
self
):
def
__unicode__
(
self
):
...
@@ -70,8 +74,7 @@ class Disk(object):
...
@@ -70,8 +74,7 @@ class Disk(object):
@classmethod
@classmethod
def
get
(
cls
,
dir
,
name
):
def
get
(
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
([
'qemu-img'
,
'info'
,
path
])
output
=
subprocess
.
check_output
([
'qemu-img'
,
'info'
,
path
])
...
@@ -92,9 +95,9 @@ class Disk(object):
...
@@ -92,9 +95,9 @@ class Disk(object):
return
Disk
(
dir
,
name
,
format
,
size
,
base
,
type
)
return
Disk
(
dir
,
name
,
format
,
size
,
base
,
type
)
def
create
(
self
):
def
create
(
self
):
'''
Creating new image format specified at self.format.
"""
Creating new image format specified at self.format.
self.format
v
an be "qcow2-normal"
self.format
c
an be "qcow2-normal"
'''
"""
# Check if type is avaliable to create
# Check if type is avaliable to create
if
self
.
format
not
in
self
.
CREATE_FORMATS
:
if
self
.
format
not
in
self
.
CREATE_FORMATS
:
raise
Exception
(
'Invalid format:
%
s'
%
self
.
format
)
raise
Exception
(
'Invalid format:
%
s'
%
self
.
format
)
...
@@ -114,7 +117,7 @@ class Disk(object):
...
@@ -114,7 +117,7 @@ class Disk(object):
subprocess
.
check_output
(
cmdline
)
subprocess
.
check_output
(
cmdline
)
def
download
(
self
,
task
,
url
,
parent_id
=
None
):
# noqa
def
download
(
self
,
task
,
url
,
parent_id
=
None
):
# noqa
''' Download image from url. '''
"""Download image from url."""
disk_path
=
self
.
get_path
()
disk_path
=
self
.
get_path
()
logger
.
info
(
"Downloading image from
%
s to
%
s"
,
url
,
disk_path
)
logger
.
info
(
"Downloading image from
%
s to
%
s"
,
url
,
disk_path
)
r
=
requests
.
get
(
url
,
stream
=
True
)
r
=
requests
.
get
(
url
,
stream
=
True
)
...
@@ -221,8 +224,8 @@ class Disk(object):
...
@@ -221,8 +224,8 @@ class Disk(object):
subprocess
.
check_output
(
cmdline
)
subprocess
.
check_output
(
cmdline
)
def
merge
(
self
,
new_disk
):
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
# Check if file already exists
if
os
.
path
.
isfile
(
new_disk
.
get_path
()):
if
os
.
path
.
isfile
(
new_disk
.
get_path
()):
raise
Exception
(
'File already exists:
%
s'
%
self
.
get_path
())
raise
Exception
(
'File already exists:
%
s'
%
self
.
get_path
())
...
@@ -240,11 +243,11 @@ class Disk(object):
...
@@ -240,11 +243,11 @@ class Disk(object):
copy
(
self
.
get_path
(),
new_disk
.
get_path
())
copy
(
self
.
get_path
(),
new_disk
.
get_path
())
def
delete
(
self
):
def
delete
(
self
):
''' Delete file
""" Delete file. """
'''
if
os
.
path
.
isfile
(
self
.
get_path
()):
if
os
.
path
.
isfile
(
self
.
get_path
()):
os
.
unlink
(
self
.
get_path
())
os
.
unlink
(
self
.
get_path
())
@classmethod
@classmethod
def
list
(
cls
,
dir
):
def
list
(
cls
,
dir
):
""" List all files in <dir> directory."""
return
[
cls
.
get
(
dir
,
file
)
for
file
in
os
.
listdir
(
dir
)]
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