[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] [XEND] XendVDI saves configuration on change.
# HG changeset patch # User Alastair Tse <atse@xxxxxxxxxxxxx> # Node ID 0a8b854697ad77bb16cc87739a89975655086c71 # Parent 91c7ee18c978f7327487b831b9b07428bae80675 [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@xxxxxxxxxxxxx> --- tools/python/scripts/xapi.py | 12 ++++++++++++ tools/python/xen/xend/XendVDI.py | 26 +++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff -r 91c7ee18c978 -r 0a8b854697ad tools/python/scripts/xapi.py --- a/tools/python/scripts/xapi.py Fri Oct 13 15:13:21 2006 +0100 +++ b/tools/python/scripts/xapi.py Fri Oct 13 15:34:01 2006 +0100 @@ -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.' # diff -r 91c7ee18c978 -r 0a8b854697ad tools/python/xen/xend/XendVDI.py --- a/tools/python/xen/xend/XendVDI.py Fri Oct 13 15:13:21 2006 +0100 +++ b/tools/python/xen/xend/XendVDI.py Fri Oct 13 15:34:01 2006 +0100 @@ -27,7 +27,25 @@ KB = 1024 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 _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |