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
c785867b
authored
Sep 10, 2013
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed jsonification
parent
f1db7c23
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
11 deletions
+18
-11
disk.py
+14
-7
storagedriver.py
+4
-4
No files found.
disk.py
View file @
c785867b
import
json
import
os
import
subprocess
import
re
...
...
@@ -23,6 +22,20 @@ class Disk(object):
raise
Exception
(
'Invalid type:
%
s'
%
type
)
self
.
type
=
type
@classmethod
def
deserialize
(
cls
,
desc
):
return
cls
(
**
desc
)
def
get_desc
(
self
):
return
{
'name'
:
self
.
name
,
'dir'
:
self
.
dir
,
'format'
:
self
.
format
,
'type'
:
self
.
type
,
'size'
:
self
.
size
,
'base_name'
:
self
.
base_name
,
}
def
get_path
(
self
):
return
os
.
path
.
realpath
(
self
.
dir
+
'/'
+
self
.
name
)
...
...
@@ -34,12 +47,6 @@ class Disk(object):
self
.
size
,
self
.
get_base
())
@classmethod
def
import_from_json
(
cls
,
json_data
):
obj
=
json
.
loads
(
json_data
)
return
Disk
(
obj
[
'dir'
],
obj
[
'name'
],
obj
[
'format'
],
obj
[
'size'
],
obj
[
'base_name'
],
obj
[
'type'
])
@classmethod
def
get
(
cls
,
dir
,
name
):
path
=
os
.
path
.
realpath
(
dir
+
'/'
+
name
)
output
=
subprocess
.
check_output
([
'qemu-img'
,
'info'
,
path
])
...
...
storagedriver.py
View file @
c785867b
...
...
@@ -3,13 +3,13 @@ from storagecelery import celery
@celery.task
()
def
list_disks
():
return
Disk
.
list
(
'/home/cloud/images'
)
def
list_disks
(
dir
):
return
[
d
.
get_desc
()
for
d
in
Disk
.
list
(
dir
)]
@celery.task
()
def
create_disk
(
json_data
):
disk
=
Disk
.
import_from_json
(
json_data
)
def
create_disk
(
disk_desc
):
disk
=
Disk
.
deserialize
(
disk_desc
)
disk
.
create
()
...
...
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