from karesansui import __version__
from karesansui.lib.virt.virt import KaresansuiVirtConnection
from karesansui.lib.utils import load_locale
- from karesansui.lib.const import STORAGE_POOL_TYPE, STORAGE_VOLUME_FORMAT, STORAGE_VOLUME_SIZE_MIN_LENGTH
- from karesansui.lib.storage import get_storage_volume_max_size_by_unit
+ from karesansui.lib.const import STORAGE_POOL_TYPE, STORAGE_VOLUME_FORMAT, \
+ STORAGE_VOLUME_SIZE_MIN_LENGTH, STORAGE_VOLUME_SIZE_MAX_LENGTH, STORAGE_VOLUME_UNIT
except ImportError:
print >>sys.stderr, "[Error] karesansui package was not found."
sys.exit(1)
type="int", help=_('Allocation'), default=0)
optp.add_option('-c', '--capacity', dest='capacity', type="int",
help=_('Capacity'), default=0)
- optp.add_option('-u', '--unit', dest='unit', help=_('Volume Size Unit'))
+ optp.add_option('-u', '--unit', dest='unit', help=_('Volume Size Unit'), default=None)
optp.add_option('-o', '--permission_owner', dest='permission_owner', help=_('Permission Owner'))
optp.add_option('-g', '--permission_group', dest='permission_group', help=_('Permission Group'))
optp.add_option('-m', '--permission_mode', dest='permission_mode', help=_('Permission Mode'))
if not opts.format in STORAGE_VOLUME_FORMAT.values():
raise KssCommandOptException('ERROR: Format is not available. '
'raw or qcow2... is available. format=%s' % opts.format)
-
- storage_volume_max_size = get_storage_volume_max_size_by_unit(opts.pool_name, opts.unit)
- if opts.allocation < STORAGE_VOLUME_SIZE_MIN_LENGTH or storage_volume_max_size < opts.allocation:
- raise KssCommandOptException('ERROR: Allocation "%s" is out of available range.' % opts.allocation)
- if opts.capacity < STORAGE_VOLUME_SIZE_MIN_LENGTH or storage_volume_max_size < opts.capacity:
- raise KssCommandOptException('ERROR: Capacity "%s" is out of available range.' % opts.capacity)
-
# TODO permission('s) use
pass
'We already have a storage volume. - pool=%s, vol=%s'
% (opts.pool_name, opts.name))
+ pool_obj = conn.search_kvn_storage_pools(opts.pool_name)[0]
+ pool_info = pool_obj.get_info()
+ if not pool_info['allocation'] or pool_info['allocation'] == 0:
+ storage_volume_max_size = STORAGE_VOLUME_SIZE_MAX_LENGTH
+ elif opts.unit is None:
+ storage_volume_max_size = long(pool_info['allocation'])
+ else:
+ storage_volume_max_size = long(pool_info['allocation']) / STORAGE_VOLUME_UNIT.get(opts.unit, 1)
+
+ if opts.allocation < STORAGE_VOLUME_SIZE_MIN_LENGTH or storage_volume_max_size < opts.allocation:
+ raise KssCommandException('Allocation "%s" is out of available range.' % opts.allocation)
+ if opts.capacity < STORAGE_VOLUME_SIZE_MIN_LENGTH or storage_volume_max_size < opts.capacity:
+ raise KssCommandException('Capacity "%s" is out of available range.' % opts.capacity)
+
if conn.create_storage_volume(opts.name, opts.pool_name,
opts.format,
use=opts.use,
from karesansui.lib.virt.virt import KaresansuiVirtConnection
from karesansui.lib.const import VIRT_COMMAND_CREATE_STORAGE_VOLUME, \
VIRT_COMMAND_DELETE_STORAGE_VOLUME, STORAGE_VOLUME_SIZE_MIN_LENGTH, \
- STORAGE_VOLUME_SIZE_MAX_LENGTH, STORAGE_VOLUME_FORMAT, STORAGE_VOLUME_PWD
+ STORAGE_VOLUME_SIZE_MAX_LENGTH, STORAGE_VOLUME_FORMAT, STORAGE_VOLUME_PWD, \
+ STORAGE_VOLUME_UNIT
from karesansui.db.access.machine import findbyhost1
from karesansui.db.access._2pysilhouette import save_job_collaboration
from pysilhouette.command import dict2command
-from karesansui.lib.storage import get_storage_volume_max_size_by_unit
from karesansui.lib.utils import is_param
from karesansui.lib.checker import Checker, CHECK_EMPTY, CHECK_ONLYSPACE, CHECK_VALID, \
CHECK_MIN, CHECK_MAX
# validate
-def validates_volume(obj, now_pools):
+def validates_volume(obj, now_pools, pool_info):
checker = Checker()
check = True
if is_param(obj.input, 'volume_capacity'):
- if is_param(obj.input, 'volume_pool_name') and is_param(obj.input, 'volume_unit'):
- storage_volume_capacity_size_max = get_storage_volume_max_size_by_unit(obj.input.volume_pool_name, obj.input.volume_unit)
- else:
+ if not pool_info['capacity'] or pool_info['capacity'] == 0:
storage_volume_capacity_size_max = STORAGE_VOLUME_SIZE_MAX_LENGTH
+ elif is_param(obj.input, 'volume_unit'):
+ storage_volume_capacity_size_max = long(pool_info['capacity']) / STORAGE_VOLUME_UNIT.get(obj.input.volume_unit, 1)
+ else:
+ storage_volume_capacity_size_max = long(pool_info['capacity'])
check = checker.check_number(_('Storagepool Volume Capacity'),
obj.input.volume_capacity,
checker.add_error(_('"%s" is required.') % _('Storagepool Volume Capacity'))
if is_param(obj.input, 'volume_allocation'):
- if is_param(obj.input, 'volume_pool_name') and is_param(obj.input, 'volume_unit'):
- storage_volume_allocation_size_max = get_storage_volume_max_size_by_unit(obj.input.volume_pool_name, obj.input.volume_unit)
- else:
+ if not pool_info['allocation'] or pool_info['allocation'] == 0:
storage_volume_allocation_size_max = STORAGE_VOLUME_SIZE_MAX_LENGTH
+ elif is_param(obj.input, 'volume_unit'):
+ storage_volume_allocation_size_max = long(pool_info['allocation']) / STORAGE_VOLUME_UNIT.get(obj.input.volume_unit, 1)
+ else:
+ storage_volume_allocation_size_max = long(pool_info['allocation'])
check = checker.check_number(_('Storagepool Volume Allocation'),
obj.input.volume_allocation,
pools_obj = kvc.get_storage_pool_UUIDString2kvn_storage_pool(param[1])
if len(pools_obj) <= 0:
return web.notfound()
+ pool_info = pools_obj[0].get_info()
finally:
kvc.close()
model = findbyhost1(self.orm, host_id)
- if not validates_volume(self, pools):
+ if not validates_volume(self, pools, pool_info):
return web.badrequest(self.view.alert)
extra_opts = {}
if create_volume_job(self,
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-#
-# This file is part of Karesansui Core.
-#
-# Copyright (C) 2010 HDE, Inc.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-
-
-from karesansui.lib.virt.virt import KaresansuiVirtConnection
-from karesansui.lib.const import STORAGE_VOLUME_SIZE_MAX_LENGTH, STORAGE_VOLUME_UNIT
-
-
-def get_storage_volume_max_size_by_unit(pool_name, unit=None):
- try:
- kvc = KaresansuiVirtConnection()
- pool_obj = kvc.search_kvn_storage_pools(pool_name)[0]
- pool_info = pool_obj.get_info()
- finally:
- kvc.close()
-
- if not pool_info['allocation'] or pool_info['allocation'] == 0:
- storage_volume_max_size = STORAGE_VOLUME_SIZE_MAX_LENGTH
- elif unit is None:
- storage_volume_max_size = long(pool_info['allocation'])
- else:
- storage_volume_max_size = long(pool_info['allocation']) / STORAGE_VOLUME_UNIT.get(unit, 1)
-
- return storage_volume_max_size
-