Skip to content

Commit

Permalink
Merge pull request #78 from openvstorage/0.3.x_cherry_pick_voldr
Browse files Browse the repository at this point in the history
Merge pull request #73 from openvstorage/extra_features_setup_json
  • Loading branch information
JeffreyDevloo authored Feb 7, 2018
2 parents 7c2ba4d + 5439826 commit 952f5c6
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 3 deletions.
46 changes: 46 additions & 0 deletions helpers/storagedriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
#
# Open vStorage is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY of any kind.
import json
from ovs.dal.hybrids.storagedriver import StorageDriver
from ovs.dal.lists.storagedriverlist import StorageDriverList
from ovs.extensions.generic.configuration import Configuration
from ovs.extensions.generic.sshclient import SSHClient
from ovs.extensions.services.servicefactory import ServiceFactory
from ovs.log.log_handler import LogHandler


Expand Down Expand Up @@ -73,3 +77,45 @@ def get_storagedrivers():
:rtype: (ovs.dal.hybrids.storagedriver.STORAGEDRIVER)
"""
return StorageDriverList.get_storagedrivers()

@staticmethod
def change_config(storagedriver, config):
"""
Change the config of the volumedriver and reload the config.
Restart will be triggered if no vDisk are running on the volumedriver.
:param storagedriver: StorageDriver object
:type storagedriver: StorageDriver
:param config: Volumedriver config
:type config: dict
:return:
"""
service_manager = ServiceFactory.get_manager()
config_key = '/ovs/vpools/{0}/hosts/{1}/config'.format(storagedriver.vpool.guid, storagedriver.name)
current_config = Configuration.get(config_key)

if 'volume_manager' in config:
volume_manager = current_config['volume_manager']
for key, value in config['volume_manager'].iteritems():
volume_manager[key] = value

if 'backend_connection_manager' in config:
backend_connection_manager = current_config['backend_connection_manager']
for key, value in config['backend_connection_manager'].iteritems():
if key == 'proxy':
for current_config_key, current_config_value in backend_connection_manager.iteritems():
if current_config_key.isdigit():
for proxy_key, proxy_config in config['backend_connection_manager']['proxy'].iteritems():
current_config_value[proxy_key] = proxy_config

else:
backend_connection_manager[key] = value
StoragedriverHelper.LOGGER.info("New config: {0}".format(json.dumps(current_config, indent=4)))
Configuration.set(config_key, json.dumps(current_config, indent=4), raw=True)
client = SSHClient(storagedriver.storagerouter, 'root')
service_name = 'ovs-volumedriver_{0}'.format(storagedriver.vpool.name)

if len(storagedriver.vdisks_guids) == 0:
StoragedriverHelper.LOGGER.info("Restarting service: {0}".format(service_name))
service_manager.restart_service(service_name, client)
else:
StoragedriverHelper.LOGGER.info("Not restarting service: {0}, amount of vdisks: {1}".format(service_name, len(storagedriver.vdisks_guids)))
30 changes: 27 additions & 3 deletions setup/vpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
#
# Open vStorage is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY of any kind.

from ovs.lib.generic import GenericController
from ovs.lib.helpers.toolbox import Toolbox
from ovs.log.log_handler import LogHandler
from ..helpers.backend import BackendHelper
from ..helpers.storagedriver import StoragedriverHelper
from ..helpers.storagerouter import StoragerouterHelper
from ..helpers.vpool import VPoolHelper
from ..validate.decorators import required_roles, check_vpool


Expand All @@ -27,6 +29,10 @@ class VPoolSetup(object):
ADD_VPOOL_TIMEOUT = 500
REQUIRED_VPOOL_ROLES = ['DB', 'WRITE', 'DTL']

# These will be all possible settings for the StorageDriver. Messing them up is their own responsibility (they should not bypass the API by default!!)
STORAGEDRIVER_PARAMS = {"volume_manager": (dict, None, False),
"backend_connection_manager": (dict, None, False)}

def __init__(self):
pass

Expand Down Expand Up @@ -72,7 +78,11 @@ def add_vpool(vpool_name, vpool_details, api, storagerouter_ip, proxy_amount=2,
'parallelism': {'proxies': proxy_amount}
}
api_data = {'call_parameters': call_parameters}


# Setting for mds_safety
if vpool_details.get('mds_safety') is not None:
call_parameters['mds_config_params'] = {'mds_safety': vpool_details['mds_safety']}

# Setting possible alba accelerated alba
if vpool_details['fragment_cache']['location'] == 'backend':
call_parameters['backend_info_aa'] = {'alba_backend_guid': BackendHelper.get_albabackend_by_name(vpool_details['fragment_cache']['backend']['name']).guid,
Expand Down Expand Up @@ -113,7 +123,21 @@ def add_vpool(vpool_name, vpool_details, api, storagerouter_ip, proxy_amount=2,
raise RuntimeError(error_msg)
else:
VPoolSetup.LOGGER.info('Creation of vPool `{0}` should have succeeded on storagerouter `{1}`'.format(vpool_name, storagerouter_ip))
return storagerouter_ip, '/mnt/{0}'.format(vpool_name)

# Settings volumedriver
storagedriver_config = vpool_details.get('storagedriver')
if storagedriver_config is not None:
Toolbox.verify_required_params(VPoolSetup.STORAGEDRIVER_PARAMS, storagedriver_config)
VPoolSetup.LOGGER.info('Updating volumedriver configuration of vPool `{0}` on storagerouter `{1}`.'.format(vpool_name, storagerouter_ip))
vpool = VPoolHelper.get_vpool_by_name(vpool_name)
storagedriver = [sd for sd in vpool.storagedrivers if sd.storagerouter.ip == storagerouter_ip][0]
if not storagedriver:
error_msg = 'Unable to find the storagedriver of vPool {0} on storagerouter {1}'.format(vpool_name, storagerouter_ip)
raise RuntimeError(error_msg)
StoragedriverHelper.change_config(storagedriver, storagedriver_config)
VPoolSetup.LOGGER.info('Updating volumedriver config of vPool `{0}` should have succeeded on storagerouter `{1}`'.format(vpool_name, storagerouter_ip))

return storagerouter_ip, '/mnt/{0}'.format(vpool_name)

@staticmethod
def execute_scrubbing():
Expand Down

0 comments on commit 952f5c6

Please sign in to comment.