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
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
os
import
subprocess
import
subprocess
import
re
import
re
...
@@ -23,6 +22,20 @@ class Disk(object):
...
@@ -23,6 +22,20 @@ class Disk(object):
raise
Exception
(
'Invalid type:
%
s'
%
type
)
raise
Exception
(
'Invalid type:
%
s'
%
type
)
self
.
type
=
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
):
def
get_path
(
self
):
return
os
.
path
.
realpath
(
self
.
dir
+
'/'
+
self
.
name
)
return
os
.
path
.
realpath
(
self
.
dir
+
'/'
+
self
.
name
)
...
@@ -34,12 +47,6 @@ class Disk(object):
...
@@ -34,12 +47,6 @@ class Disk(object):
self
.
size
,
self
.
get_base
())
self
.
size
,
self
.
get_base
())
@classmethod
@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
):
def
get
(
cls
,
dir
,
name
):
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
])
...
...
storagedriver.py
View file @
c785867b
...
@@ -3,13 +3,13 @@ from storagecelery import celery
...
@@ -3,13 +3,13 @@ from storagecelery import celery
@celery.task
()
@celery.task
()
def
list_disks
():
def
list_disks
(
dir
):
return
Disk
.
list
(
'/home/cloud/images'
)
return
[
d
.
get_desc
()
for
d
in
Disk
.
list
(
dir
)]
@celery.task
()
@celery.task
()
def
create_disk
(
json_data
):
def
create_disk
(
disk_desc
):
disk
=
Disk
.
import_from_json
(
json_data
)
disk
=
Disk
.
deserialize
(
disk_desc
)
disk
.
create
()
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