2 # -*- coding: utf-8 -*-
4 # This file is part of Karesansui.
6 # Copyright (C) 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
27 from karesansui.lib.utils import load_locale
28 from karesansui.lib.const import STORAGE_POOL_TYPE
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=_('Storage pool name'))
40 return optp.parse_args()
44 raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name')
46 class StartStorage(KssCommand):
49 (opts, args) = getopts()
52 conn = KaresansuiVirtConnection(readonly=False)
56 inactive_storage_pools = conn.list_inactive_storage_pool()
57 active_storage_pools = conn.list_active_storage_pool()
61 if not (opts.name in active_storage_pools or opts.name in inactive_storage_pools):
62 raise KssCommandException(
63 'Specified storage pool does not exist. - pool=%s' % opts.name)
65 if opts.name in active_storage_pools:
66 raise KssCommandException('Storage pool is already running. - pool=%s' % opts.name)
69 if conn.start_storage_pool(opts.name) is False:
70 raise KssCommandException(
71 'Failed to start storage pool. (libvirt) - pool=%s' % (opts.name))
75 inactive_storage_pools = conn.list_inactive_storage_pool()
76 active_storage_pools = conn.list_active_storage_pool()
77 if not (opts.name in active_storage_pools):
78 raise KssCommandException(
79 'Could not start the storage pool. - pool=%s' % (opts.name))
81 self.logger.info('Start storage pool. - pool=%s' % (opts.name))
82 print >>sys.stdout, _('Start storage pool. - pool=%s') % (opts.name)
84 except KssCommandException, e:
89 if __name__ == "__main__":
90 target = StartStorage()
91 sys.exit(target.run())