|
| 1 | +# Copyright (C) 2016 iNuron NV |
| 2 | +# |
| 3 | +# This file is part of Open vStorage Open Source Edition (OSE), |
| 4 | +# as available from |
| 5 | +# |
| 6 | +# http://www.openvstorage.org and |
| 7 | +# http://www.openvstorage.com. |
| 8 | +# |
| 9 | +# This file is free software; you can redistribute it and/or modify it |
| 10 | +# under the terms of the GNU Affero General Public License v3 (GNU AGPLv3) |
| 11 | +# as published by the Free Software Foundation, in version 3 as it comes |
| 12 | +# in the LICENSE.txt file of the Open vStorage OSE distribution. |
| 13 | +# |
| 14 | +# Open vStorage is distributed in the hope that it will be useful, |
| 15 | +# but WITHOUT ANY WARRANTY of any kind. |
| 16 | +from ovs.lib.helpers.toolbox import Toolbox |
| 17 | +from ovs.extensions.generic.logger import Logger |
| 18 | +from ..helpers.storagedriver import StoragedriverHelper |
| 19 | +from ..helpers.vpool import VPoolHelper |
| 20 | + |
| 21 | + |
| 22 | +class StoragedriverSetup(object): |
| 23 | + LOGGER = Logger('setup-ci_storagedriver_setup') |
| 24 | + |
| 25 | + # These will be all possible settings for the StorageDriver. Messing them up is their own responsibility (they should not bypass the API by default!!) |
| 26 | + STORAGEDRIVER_PARAMS = {"volume_manager": (dict, None, False), |
| 27 | + "backend_connection_manager": (dict, None, False)} |
| 28 | + |
| 29 | + @staticmethod |
| 30 | + def change_config(vpool_name, vpool_details, storagerouter_ip, *args, **kwargs): |
| 31 | + |
| 32 | + # Settings volumedriver |
| 33 | + storagedriver_config = vpool_details.get('storagedriver') |
| 34 | + if storagedriver_config is not None: |
| 35 | + Toolbox.verify_required_params(StoragedriverSetup.STORAGEDRIVER_PARAMS, storagedriver_config) |
| 36 | + StoragedriverSetup.LOGGER.info('Updating volumedriver configuration of vPool `{0}` on storagerouter `{1}`.'.format(vpool_name, storagerouter_ip)) |
| 37 | + vpool = VPoolHelper.get_vpool_by_name(vpool_name) |
| 38 | + storagedriver = [sd for sd in vpool.storagedrivers if sd.storagerouter.ip == storagerouter_ip][0] |
| 39 | + if not storagedriver: |
| 40 | + error_msg = 'Unable to find the storagedriver of vPool {0} on storagerouter {1}'.format(vpool_name, storagerouter_ip) |
| 41 | + raise RuntimeError(error_msg) |
| 42 | + StoragedriverHelper.change_config(storagedriver, storagedriver_config) |
| 43 | + vpool.invalidate_dynamics('configuration') |
| 44 | + StoragedriverSetup.LOGGER.info('Updating volumedriver config of vPool `{0}` should have succeeded on storagerouter `{1}`'.format(vpool_name, storagerouter_ip)) |
0 commit comments