Commit c785867b by Dudás Ádám

removed jsonification

parent f1db7c23
import json
import os
import subprocess
import re
......@@ -23,6 +22,20 @@ class Disk(object):
raise Exception('Invalid type: %s' % type)
self.type = type
def deserialize(cls, desc):
return cls(**desc)
def get_desc(self):
return {
'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 + '/' +
......@@ -34,12 +47,6 @@ class Disk(object):
self.size, self.get_base())
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'])
def get(cls, dir, name):
path = os.path.realpath(dir + '/' + name)
output = subprocess.check_output(['qemu-img', 'info', path])
......@@ -3,13 +3,13 @@ from storagecelery import celery
def list_disks():
return Disk.list('/home/cloud/images')
def list_disks(dir):
return [d.get_desc() for d in Disk.list(dir)]
def create_disk(json_data):
disk = Disk.import_from_json(json_data)
def create_disk(disk_desc):
disk = Disk.deserialize(disk_desc)
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