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 from optparse import OptionParser
19 from ksscommand import KssCommand, KssCommandException, KssCommandOptException
25 from karesansui import __version__
26 from karesansui.lib.virt.virt import KaresansuiVirtConnection, \
28 from karesansui.lib.utils import load_locale
30 print >>sys.stderr, "[Error] karesansui package was not found."
35 usage = '%prog [options]'
38 optp = OptionParser(usage=usage, version=__version__)
39 optp.add_option('-n', '--name', dest='name', help=_('Domain Name'))
40 return optp.parse_args()
44 raise KssCommandOptException('ERROR: -n or --name option is required.')
46 class SuspendGuest(KssCommand):
49 (opts, args) = getopts()
53 conn = KaresansuiVirtConnection(readonly=False)
55 conn.set_domain_name(opts.name)
57 active_guests = conn.list_active_guest()
58 inactive_guests = conn.list_inactive_guest()
60 if opts.name in active_guests or opts.name in inactive_guests:
66 self.logger.error('Failed to suspend guest. - dom=%s' % (opts.name))
70 status = conn.guest.status()
72 if status == VIR_DOMAIN_PAUSED:
73 self.logger.info('Succeeded to suspend guest. - dom=%s' % (opts.name))
74 print >>sys.stderr, _('Succeeded to suspend guest. - dom=%s') % (opts.name)
77 raise KssCommandException(
78 'Could not find guest. - dom=%s' % (opts.name))
86 if __name__ == "__main__":
87 target = SuspendGuest()
88 sys.exit(target.run())