Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra features setup json #73

Merged
merged 3 commits into from
Feb 6, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions helpers/storagedriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@
#
# Open vStorage is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY of any kind.
import json

try:
from ovs.extensions.services.service import ServiceManager
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current master branch points towards FWK 2.11
No need to have this try-except stuff

except ImportError:
from ovs.extensions.services.servicefactory import ServiceFactory
ServiceManager = ServiceFactory.get_manager()

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.generic.logger import Logger


Expand Down Expand Up @@ -73,3 +83,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:
"""

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))
ServiceManager.restart_service(service_name, client)
else:
StoragedriverHelper.LOGGER.info("Not restarting service: {0}, amount of vdisks: {1}".format(service_name, len(storagedriver.vdisks_guids)))
29 changes: 26 additions & 3 deletions setup/vpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
#
# 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.extensions.generic.logger import Logger
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 Down Expand Up @@ -72,7 +73,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 +118,25 @@ 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 = {}
if vpool_details.get('storagedriver').get('volume_manager') is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If storagedriver would be filled in, I'd opt to validate the possible options (see how we validate the call params)
So something like:
storagedriver_config = vpool_details.get('storagedriver')
if storagedriver_config (not None or empty dict) -> validate this item before proceeding

storagedriver_config['volume_manager'] = vpool_details['storagedriver']['volume_manager']
if vpool_details.get('storagedriver').get('backend_connection_manager') is not None:
storagedriver_config['backend_connection_manager'] = vpool_details['storagedriver']['backend_connection_manager']

if 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