本文整理汇总了Python中search.conf.SECURITY_ENABLED.get方法的典型用法代码示例。如果您正苦于以下问题:Python SECURITY_ENABLED.get方法的具体用法?Python SECURITY_ENABLED.get怎么用?Python SECURITY_ENABLED.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类search.conf.SECURITY_ENABLED
的用法示例。
在下文中一共展示了SECURITY_ENABLED.get方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_collection
# 需要导入模块: from search.conf import SECURITY_ENABLED [as 别名]
# 或者: from search.conf.SECURITY_ENABLED import get [as 别名]
def create_collection(self, name, fields, unique_key_field='id', df='text'):
"""
Create solr collection or core and instance dir.
Create schema.xml file so that we can set UniqueKey field.
"""
if self.is_solr_cloud_mode():
# solrcloud mode
# Need to remove path afterwards
tmp_path, solr_config_path = utils.copy_configs(fields, unique_key_field, df, True)
# Create instance directory.
solrctl_path = get_solrctl_path()
process = subprocess.Popen([solrctl_path, "instancedir", "--create", name, solr_config_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env={
'SOLR_ZK_ENSEMBLE': conf.SOLR_ZK_ENSEMBLE.get()
})
status = process.wait()
# Don't want directories laying around
shutil.rmtree(tmp_path)
if status != 0:
LOG.error("Could not create instance directory.\nOutput: %s\nError: %s" % process.communicate())
raise PopupException(_('Could not create instance directory. '
'Check if solr_zk_ensemble and solrctl_path are correct in Hue config [indexer].'))
api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())
if not api.create_collection(name):
# Delete instance directory if we couldn't create a collection.
process = subprocess.Popen([solrctl_path, "instancedir", "--delete", name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env={
'SOLR_ZK_ENSEMBLE': conf.SOLR_ZK_ENSEMBLE.get()
})
if process.wait() != 0:
LOG.error("Cloud not delete collection.\nOutput: %s\nError: %s" % process.communicate())
raise PopupException(_('Could not create collection. Check error logs for more info.'))
else:
# Non-solrcloud mode
# Create instance directory locally.
instancedir = os.path.join(conf.CORE_INSTANCE_DIR.get(), name)
if os.path.exists(instancedir):
raise PopupException(_("Instance directory %s already exists! Please remove it from the file system.") % instancedir)
tmp_path, solr_config_path = utils.copy_configs(fields, unique_key_field, df, False)
shutil.move(solr_config_path, instancedir)
shutil.rmtree(tmp_path)
api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())
if not api.create_core(name, instancedir):
# Delete instance directory if we couldn't create a collection.
shutil.rmtree(instancedir)
raise PopupException(_('Could not create collection. Check error logs for more info.'))
示例2: get_fields
# 需要导入模块: from search.conf import SECURITY_ENABLED [as 别名]
# 或者: from search.conf.SECURITY_ENABLED import get [as 别名]
def get_fields(self, collection_or_core_name):
try:
field_data = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get()).fields(collection_or_core_name)
fields = self._format_flags(field_data['schema']['fields'])
except:
LOG.exception(_('Could not fetch fields for collection %s.') % collection_or_core_name)
raise PopupException(_('Could not fetch fields for collection %s. See logs for more info.') % collection_or_core_name)
try:
uniquekey = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get()).uniquekey(collection_or_core_name)
except:
LOG.exception(_('Could not fetch unique key for collection %s.') % collection_or_core_name)
raise PopupException(_('Could not fetch unique key for collection %s. See logs for more info.') % collection_or_core_name)
return uniquekey, fields
示例3: create_collection
# 需要导入模块: from search.conf import SECURITY_ENABLED [as 别名]
# 或者: from search.conf.SECURITY_ENABLED import get [as 别名]
def create_collection(self, name, fields, unique_key_field='id', df='text'):
"""
Create solr collection or core and instance dir.
Create schema.xml file so that we can set UniqueKey field.
"""
if self.is_solr_cloud_mode():
# solrcloud mode
# Need to remove path afterwards
tmp_path, solr_config_path = copy_configs(fields, unique_key_field, df, True)
zc = ZookeeperClient(hosts=get_solr_ensemble(), read_only=False)
root_node = '%s/%s' % (ZK_SOLR_CONFIG_NAMESPACE, name)
config_root_path = '%s/%s' % (solr_config_path, 'conf')
try:
zc.copy_path(root_node, config_root_path)
except Exception, e:
zc.delete_path(root_node)
raise PopupException(_('Error in copying Solr configurations.'), detail=e)
# Don't want directories laying around
shutil.rmtree(tmp_path)
api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())
if not api.create_collection(name):
# Delete instance directory if we couldn't create a collection.
try:
zc.delete_path(root_node)
except Exception, e:
raise PopupException(_('Error in deleting Solr configurations.'), detail=e)
示例4: __init__
# 需要导入模块: from search.conf import SECURITY_ENABLED [as 别名]
# 或者: from search.conf.SECURITY_ENABLED import get [as 别名]
def __init__(self, solr_url, user, security_enabled=SECURITY_ENABLED.get()):
self._url = solr_url
self._user = user
self._client = HttpClient(self._url, logger=LOG)
self.security_enabled = security_enabled
if self.security_enabled:
self._client.set_kerberos_auth()
self._root = resource.Resource(self._client)
示例5: is_solr_cloud_mode
# 需要导入模块: from search.conf import SECURITY_ENABLED [as 别名]
# 或者: from search.conf.SECURITY_ENABLED import get [as 别名]
def is_solr_cloud_mode(self):
api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())
if not hasattr(self, '_solr_cloud_mode'):
try:
api.collections()
setattr(self, '_solr_cloud_mode', True)
except:
setattr(self, '_solr_cloud_mode', False)
return getattr(self, '_solr_cloud_mode')
示例6: create_or_edit_alias
# 需要导入模块: from search.conf import SECURITY_ENABLED [as 别名]
# 或者: from search.conf.SECURITY_ENABLED import get [as 别名]
def create_or_edit_alias(request):
if request.method != 'POST':
raise PopupException(_('POST request required.'))
response = {'status': -1}
alias = request.POST.get('alias', '')
collections = json.loads(request.POST.get('collections', '[]'))
api = SolrApi(SOLR_URL.get(), request.user, SECURITY_ENABLED.get())
try:
api.create_or_modify_alias(alias, collections)
response['status'] = 0
response['message'] = _('Alias created or modified!')
except Exception, e:
response['message'] = _('Alias could not be created or modified: %s') % e
示例7: __init__
# 需要导入模块: from search.conf import SECURITY_ENABLED [as 别名]
# 或者: from search.conf.SECURITY_ENABLED import get [as 别名]
def __init__(self, solr_url, user, security_enabled=SECURITY_ENABLED.get()):
self._url = solr_url
self._user = user
self._client = HttpClient(self._url, logger=LOG)
self.security_enabled = security_enabled
if self.security_enabled:
self._client.set_kerberos_auth()
self._root = resource.Resource(self._client)
# The Kerberos handshake requires two requests in order to authenticate,
# but if our first request is a PUT/POST, it might flat-out reject the
# first request if the body is too large. So, connect here in order to get
# a cookie so future PUT/POSTs will be pre-authenticated.
if self.security_enabled:
self._root.invoke('HEAD', '/')
示例8: delete_collection
# 需要导入模块: from search.conf import SECURITY_ENABLED [as 别名]
# 或者: from search.conf.SECURITY_ENABLED import get [as 别名]
def delete_collection(self, name):
"""
Delete solr collection and instance dir
"""
api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())
if api.remove_collection(name):
# Delete instance directory.
process = subprocess.Popen([conf.SOLRCTL_PATH.get(), "instancedir", "--delete", name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env={
'SOLR_HOME': conf.SOLR_HOME.get(),
'SOLR_ZK_ENSEMBLE': conf.SOLR_ZK_ENSEMBLE.get()
})
if process.wait() != 0:
LOG.error("Cloud not delete instance directory.\nOutput stream: %s\nError stream: %s" % process.communicate())
raise PopupException(_('Could not create instance directory. Check error logs for more info.'))
else:
raise PopupException(_('Could not create collection. Check error logs for more info.'))
示例9: delete_collection
# 需要导入模块: from search.conf import SECURITY_ENABLED [as 别名]
# 或者: from search.conf.SECURITY_ENABLED import get [as 别名]
def delete_collection(self, name, core):
"""
Delete solr collection/core and instance dir
"""
api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())
if core:
raise PopupException(_('Cannot remove Solr cores.'))
if api.remove_collection(name):
# Delete instance directory.
solrctl_path = get_solrctl_path()
process = subprocess.Popen([solrctl_path, "--zk", get_solr_ensemble(), "instancedir", "--delete", name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
if process.wait() != 0:
LOG.error("Cloud not delete instance directory.\nOutput stream: %s\nError stream: %s" % process.communicate())
raise PopupException(_('Could not create instance directory. Check error logs for more info.'))
else:
raise PopupException(_('Could not remove collection. Check error logs for more info.'))
示例10: create_collection
# 需要导入模块: from search.conf import SECURITY_ENABLED [as 别名]
# 或者: from search.conf.SECURITY_ENABLED import get [as 别名]
def create_collection(self, name, fields, unique_key_field='id', df='text'):
"""
Create solr collection and instance dir.
Create schema.xml file so that we can set UniqueKey field.
"""
# Need to remove path afterwards
tmp_path, solr_config_path = utils.copy_configs(fields, unique_key_field, df)
# Create instance directory.
process = subprocess.Popen([conf.SOLRCTL_PATH.get(), "instancedir", "--create", name, solr_config_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env={
'SOLR_HOME': conf.SOLR_HOME.get(),
'SOLR_ZK_ENSEMBLE': conf.SOLR_ZK_ENSEMBLE.get()
})
status = process.wait()
shutil.rmtree(tmp_path)
if status != 0:
LOG.error("Cloud not create instance directory.\nOutput stream: %s\nError stream: %s" % process.communicate())
raise PopupException(_('Could not create instance directory. Check error logs for more info.'))
api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())
if not api.create_collection(name):
# Delete instance directory.
process = subprocess.Popen([conf.SOLRCTL_PATH.get(), "instancedir", "--delete", name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env={
'SOLR_HOME': conf.SOLR_HOME.get(),
'SOLR_ZK_ENSEMBLE': conf.SOLR_ZK_ENSEMBLE.get()
})
if process.wait() != 0:
LOG.error("Cloud not delete instance directory.\nOutput stream: %s\nError stream: %s" % process.communicate())
raise PopupException(_('Could not create collection. Check error logs for more info.'))
示例11: __init__
# 需要导入模块: from search.conf import SECURITY_ENABLED [as 别名]
# 或者: from search.conf.SECURITY_ENABLED import get [as 别名]
def __init__(self, user):
self.user = user
self.api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())
示例12: PopupException
# 需要导入模块: from search.conf import SECURITY_ENABLED [as 别名]
# 或者: from search.conf.SECURITY_ENABLED import get [as 别名]
# Delete instance directory if we couldn't create a collection.
try:
zc.delete_path(root_node)
except Exception, e:
raise PopupException(_('Error in deleting Solr configurations.'), detail=e)
else:
# Non-solrcloud mode
# Create instance directory locally.
instancedir = os.path.join(CORE_INSTANCE_DIR.get(), name)
if os.path.exists(instancedir):
raise PopupException(_("Instance directory %s already exists! Please remove it from the file system.") % instancedir)
tmp_path, solr_config_path = copy_configs(fields, unique_key_field, df, False)
shutil.move(solr_config_path, instancedir)
shutil.rmtree(tmp_path)
api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())
if not api.create_core(name, instancedir):
# Delete instance directory if we couldn't create a collection.
shutil.rmtree(instancedir)
raise PopupException(_('Could not create collection. Check error logs for more info.'))
def delete_collection(self, name, core):
"""
Delete solr collection/core and instance dir
"""
api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())
if core:
raise PopupException(_('Cannot remove Solr cores.'))
if api.remove_collection(name):
# Delete instance directory.
示例13: __init__
# 需要导入模块: from search.conf import SECURITY_ENABLED [as 别名]
# 或者: from search.conf.SECURITY_ENABLED import get [as 别名]
def __init__(self, solr_url):
self._url = solr_url
self._client = HttpClient(self._url, logger=LOG)
if SECURITY_ENABLED.get():
self._client.set_kerberos_auth()
self._root = Resource(self._client)
示例14: is_enabled
# 需要导入模块: from search.conf import SECURITY_ENABLED [as 别名]
# 或者: from search.conf.SECURITY_ENABLED import get [as 别名]
def is_enabled():
try:
from search.conf import SECURITY_ENABLED
return SECURITY_ENABLED.get()
except ImportError, e:
LOG.warn("Search app is not enabled")