Changeset View
Changeset View
Standalone View
Standalone View
scap/confctl.py
- This file was moved from scap/pooler.py.
# -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||
""" | """ | ||||
scap.pooler | scap.pooler | ||||
~~~~~~~~~~~ | ~~~~~~~~~~~ | ||||
Wrapper for our pooling/depooling actions, handled via conftool | Wrapper for our pooling/depooling actions, handled via conftool | ||||
""" | """ | ||||
from __future__ import absolute_import | from __future__ import absolute_import | ||||
import re | import re | ||||
from conftool.drivers import BackendError | from conftool.drivers import BackendError | ||||
from conftool.kvobject import KVObject | from conftool.kvobject import KVObject | ||||
from conftool import configuration, node | from conftool import configuration, node, loader | ||||
def setup_conftool(config_file, schema_file): | |||||
KVObject.setup(configuration.get(config_file)) | |||||
return loader.Schema.from_file(schema_file) | |||||
def get_master_dc_nodes(schema, selectors): | |||||
""" | |||||
Gets the list of nodes in the master MediaWiki datacenter | |||||
for a given conftool query. | |||||
All values are read from conftool/etcd. | |||||
""" | |||||
mwconfig = schema.entities['mwconfig'] | |||||
master_dc = mwconfig('common', 'WMFMasterDatacenter').val | |||||
node = schema.entities['node'] | |||||
selectors['dc'] = master_dc | |||||
regex_selectors = dict( | |||||
thcipriani: should this be a list? Or a dict using the selector keys as the keys?
If it should be a dict… | |||||
JoeUnsubmitted Not Done Inline Actionsyes, obviously, I must've deleted it when reformatting. Joe: yes, obviously, I must've deleted it when reformatting. | |||||
map(lambda x: re.compile('^{}$'.format(selectors[x])), selectors) | |||||
) | |||||
return [obj for obj in node.query(regex_selectors)] | |||||
thciprianiAuthorUnsubmitted Not Done Inline ActionsFWIW, fails in beta with ValueError: /conftool/v1/pools is not a directory thcipriani: FWIW, fails in beta with `ValueError: /conftool/v1/pools is not a directory` | |||||
JoeUnsubmitted Not Done Inline ActionsThis means that etcd is misconfigured there. Nothing to do with the code. FWIW I think in beta we should avoid using etcd/conftool. Joe: This means that etcd is misconfigured there. Nothing to do with the code. FWIW I think in beta… | |||||
class Pooler(object): | class Pooler(object): | ||||
""" | """ | ||||
Wrapper to the conftool for our common (de)pooling operations | Wrapper to the conftool for our common (de)pooling operations | ||||
""" | """ | ||||
def __init__(self, config_file, servers): | def __init__(self, servers): | ||||
""" | """ | ||||
Read the conftool configuration and load all the provided nodes | Read the conftool configuration and load all the provided nodes | ||||
:param config_file: The path to a config file for conftool | :param config_file: The path to a config file for conftool | ||||
:param servers: Which servers to work with | :param servers: Which servers to work with | ||||
""" | """ | ||||
KVObject.setup(configuration.get(config_file)) | |||||
node_re = re.compile('({name})'.format(name='|'.join(servers))) | node_re = re.compile('({name})'.format(name='|'.join(servers))) | ||||
self.nodes = [n for n in node.Node.query({'name': node_re})] | self.nodes = [n for n in node.Node.query({'name': node_re})] | ||||
def pool(self): | def pool(self): | ||||
"""Pool services""" | """Pool services""" | ||||
return self._set_state('yes') | return self._set_state('yes') | ||||
def depool(self): | def depool(self): | ||||
Show All 18 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 3.0 (CC-BY-SA) unless otherwise noted; code licensed under GNU General Public License (GPL) or other open source licenses. By using this site, you agree to the Terms of Use, Privacy Policy, and Code of Conduct. · Wikimedia Foundation · Privacy Policy · Code of Conduct · Terms of Use · Disclaimer · CC-BY-SA · GPL
should this be a list? Or a dict using the selector keys as the keys?
If it should be a dict the lambda inside the map below should be: