mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
[XEND] XendVDI saves configuration on change.
Added a base class called AutoSaveObject that will attempt to call save_config() if any attribute in the object changes. It isn't particularly efficient, but we do not expect VDI to change much. Signed-off-by: Alastair Tse <atse@xensource.com>
This commit is contained in:
1 parent
76b24ff4e2
commit
5d179b7561
2 files changed
+35
-3
No files matched your search
@@ -37,6 +37,7 @@ COMMANDS = {
|
||||
'sr-list': ('', 'List all SRs'),
|
||||
'vbd-create': ('<domname> <pycfg>', 'Create VBD attached to domname'),
|
||||
'vdi-list' : ('', 'List all VDI'),
|
||||
'vdi-rename': ('<vdi_uuid> <new_name>', 'Rename VDI'),
|
||||
'vdi-delete': ('<vdi_uuid>', 'Delete VDI'),
|
||||
'vif-create': ('<domname> <pycfg>', 'Create VIF attached to domname'),
|
||||
|
||||
@@ -303,6 +304,17 @@ def xapi_vdi_delete(*args):
|
||||
print 'Deleting VDI %s' % vdi_uuid
|
||||
result = execute(server.VDI.destroy, session, vdi_uuid)
|
||||
print 'Done.'
|
||||
|
||||
def xapi_vdi_rename(*args):
|
||||
server, session = _connect()
|
||||
if len(args) < 2:
|
||||
raise OptionError('Not enough arguments')
|
||||
|
||||
vdi_uuid = args[0]
|
||||
vdi_name = args[1]
|
||||
print 'Renaming VDI %s to %s' % (vdi_uuid, vdi_name)
|
||||
result = execute(server.VDI.set_name_label, session, vdi_uuid, vdi_name)
|
||||
print 'Done.'
|
||||
|
||||
|
||||
#
|
||||
|
||||
@@ -27,7 +27,25 @@ from xmlrpclib import dumps, loads
|
||||
KB = 1024
|
||||
MB = 1024 * 1024
|
||||
|
||||
class XendVDI:
|
||||
class AutoSaveObject(object):
|
||||
|
||||
def __init__(self):
|
||||
self.cfg_path = None
|
||||
self.auto_save = True
|
||||
object
|
||||
|
||||
def save_config(self, cfg_file = None):
|
||||
raise NotImplementedError()
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
"""A very simple way of making sure all attribute changes are
|
||||
flushed to disk.
|
||||
"""
|
||||
object.__setattr__(self, name, value)
|
||||
if name != 'auto_save' and getattr(self, 'auto_save', False):
|
||||
self.save_config()
|
||||
|
||||
class XendVDI(AutoSaveObject):
|
||||
"""Generic Xen API compatible VDI representation.
|
||||
|
||||
@cvar SAVED_CFG: list of configuration attributes to save.
|
||||
@@ -60,20 +78,20 @@ class XendVDI:
|
||||
self.read_only = False
|
||||
self.type = "system"
|
||||
|
||||
self.cfg_path = None
|
||||
|
||||
def load_config_dict(self, cfg):
|
||||
"""Loads configuration into the object from a dict.
|
||||
|
||||
@param cfg: configuration dict
|
||||
@type cfg: dict
|
||||
"""
|
||||
self.auto_save = False
|
||||
for key in self.SAVED_CFG:
|
||||
if key in cfg:
|
||||
if key in self.SAVED_CFG_INT:
|
||||
setattr(self, key, int(cfg[key]))
|
||||
else:
|
||||
setattr(self, key, cfg[key])
|
||||
self.auto_save = True
|
||||
|
||||
def load_config(self, cfg_path):
|
||||
"""Loads configuration from an XMLRPC parameter format.
|
||||
@@ -128,10 +146,12 @@ class XendQCOWVDI(XendVDI):
|
||||
def __init__(self, uuid, sr_uuid, qcow_path, image_path, cfg_path,
|
||||
vsize, psize):
|
||||
XendVDI.__init__(self, uuid, sr_uuid)
|
||||
self.auto_save = False
|
||||
self.qcow_path = qcow_path
|
||||
self.image_path = image_path
|
||||
self.cfg_path = cfg_path
|
||||
self.physical_utilisation = psize
|
||||
self.virtual_size = vsize
|
||||
self.sector_size = 1
|
||||
self.auto_save = True
|
||||
|
||||