Commit c785867b by Dudás Ádám

removed jsonification

parent f1db7c23
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])
......
...@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment