2 # -*- coding: utf-8 -*-
4 # This file is part of Karesansui.
6 # Copyright (C) 2009-2010 HDE, Inc.
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
17 @file: apply_snapshot.py
18 @author: Taizo ITO <taizo@karesansui-project.info>
24 使用方法: apply_snapshot.py [オプション]
27 --version プログラムのバージョンを表示
29 -n NAME, --name=NAME ドメイン名を指定
30 -i ID, --id=ID スナップショットのIDを指定
35 usage: apply_snapshot.py [options]
38 --version show program's version number and exit
39 -h, --help show this help message and exit
40 -n NAME, --name=NAME Domain name
41 -i ID, --id=ID Snapshot serial ID
48 from optparse import OptionParser
50 from ksscommand import KssCommand, KssCommandException
56 from karesansui import __version__
57 from karesansui.lib.virt.snapshot import KaresansuiVirtSnapshot
58 from karesansui.lib.utils import load_locale
60 print >>sys.stderr, "[Error] karesansui package was not found."
65 usage = '%prog [options]'
68 optp = OptionParser(usage=usage, version=__version__)
69 optp.add_option('-n', '--name', dest='name', help=_('Domain name'))
70 optp.add_option('-i', '--id', dest='id', help=_('Snapshot serial ID'))
71 return optp.parse_args()
75 raise KssCommandOptException('ERROR: -n or --name option is required.')
77 raise KssCommandOptException('ERROR: -i or --id option is required.')
79 class ApplySnapshot(KssCommand):
82 (opts, args) = getopts()
87 kvs = KaresansuiVirtSnapshot(readonly=False)
92 domain = kvs.whichDomain(opts.id)
94 msg = _("Snapshot '%s' not found in domain '%s'.") % (opts.id,opts.name,)
95 self.logger.error(msg)
96 raise KssCommandException(msg)
98 if domain != opts.name:
99 msg = _("Snapshot '%s' not found in domain '%s'.") % (opts.id,opts.name,)
100 self.logger.error(msg)
101 raise KssCommandException(msg)
103 ret = kvs.revertSnapshot(opts.id)
105 msg = _("Can't revert to snapshot '%s'.") % (opts.id,)
106 self.logger.error(msg)
107 raise KssCommandException(msg)
111 msg = _("Domain snapshot '%s' reverted.") % (opts.id,)
112 self.logger.info(msg)
113 print >>sys.stderr, msg
115 except KssCommandException, e:
116 raise KssCommandException(''.join(e.args))
118 msg = _("Failed to revert to snapshot '%s'.") % (opts.id,)
119 msg += ": detail %s" % ''.join(str(e.args))
120 self.logger.error(msg)
121 raise KssCommandException(msg)
128 if __name__ == "__main__":
129 target = ApplySnapshot()
130 sys.exit(target.run())