2017-09-26 20:08:50 +00:00
|
|
|
from app import app, ip_resolver, config_provider
|
2017-01-31 20:56:25 +00:00
|
|
|
from storage import get_storage_driver
|
|
|
|
from util.config.validators import BaseValidator, ConfigValidationException
|
|
|
|
|
|
|
|
class StorageValidator(BaseValidator):
|
|
|
|
name = "registry-storage"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def validate(cls, config, user, user_password):
|
|
|
|
""" Validates registry storage. """
|
|
|
|
replication_enabled = config.get('FEATURE_STORAGE_REPLICATION', False)
|
|
|
|
|
|
|
|
providers = _get_storage_providers(config).items()
|
|
|
|
if not providers:
|
|
|
|
raise ConfigValidationException('Storage configuration required')
|
|
|
|
|
|
|
|
for name, (storage_type, driver) in providers:
|
|
|
|
try:
|
|
|
|
if replication_enabled and storage_type == 'LocalStorage':
|
|
|
|
raise ConfigValidationException('Locally mounted directory not supported ' +
|
|
|
|
'with storage replication')
|
|
|
|
|
|
|
|
# Run validation on the driver.
|
|
|
|
driver.validate(app.config['HTTPCLIENT'])
|
|
|
|
|
|
|
|
# Run setup on the driver if the read/write succeeded.
|
|
|
|
driver.setup()
|
|
|
|
except Exception as ex:
|
2017-07-27 16:05:06 +00:00
|
|
|
msg = str(ex).strip().split("\n")[0]
|
2017-02-15 18:11:16 +00:00
|
|
|
raise ConfigValidationException('Invalid storage configuration: %s: %s' % (name, msg))
|
2017-01-31 20:56:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _get_storage_providers(config):
|
|
|
|
storage_config = config.get('DISTRIBUTED_STORAGE_CONFIG', {})
|
|
|
|
drivers = {}
|
|
|
|
|
|
|
|
try:
|
|
|
|
for name, parameters in storage_config.items():
|
2017-09-26 20:08:50 +00:00
|
|
|
driver = get_storage_driver(None, None, None, config_provider, ip_resolver, parameters)
|
|
|
|
drivers[name] = (parameters[0], driver)
|
2017-01-31 20:56:25 +00:00
|
|
|
except TypeError:
|
|
|
|
raise ConfigValidationException('Missing required parameter(s) for storage %s' % name)
|
|
|
|
|
|
|
|
return drivers
|