本文整理汇总了Python中fabric.api.env.roledefs方法的典型用法代码示例。如果您正苦于以下问题:Python env.roledefs方法的具体用法?Python env.roledefs怎么用?Python env.roledefs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fabric.api.env
的用法示例。
在下文中一共展示了env.roledefs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: chef_query
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import roledefs [as 别名]
def chef_query(query, api=None, hostname_attr=DEFAULT_HOSTNAME_ATTR, environment=_default_environment):
"""A decorator to use an arbitrary Chef search query to find nodes to execute on.
This is used like Fabric's ``roles()`` decorator, but accepts a Chef search query.
Example::
from chef.fabric import chef_query
@chef_query('roles:web AND tags:active')
@task
def deploy():
pass
.. versionadded:: 0.2.1
"""
api = _api(api)
if api.version_parsed < Environment.api_version_parsed and environment is not None:
raise ChefAPIVersionError('Environment support requires Chef API 0.10 or greater')
rolename = 'query_'+query
env.setdefault('roledefs', {})[rolename] = Roledef(query, api, hostname_attr, environment)
return lambda fn: roles(rolename)(fn)
示例2: validate
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import roledefs [as 别名]
def validate(conf):
validate_presto_conf(conf)
if 'coordinator' not in conf['config.properties']:
raise ConfigurationError('Must specify coordinator=false in '
'worker\'s config.properties')
if conf['config.properties']['coordinator'] != 'false':
raise ConfigurationError('Coordinator must be false in the '
'worker\'s config.properties')
uri = urlparse.urlparse(conf['config.properties']['discovery.uri'])
if Worker.is_localhost(uri.hostname) and len(env.roledefs['all']) > 1:
raise ConfigurationError(
'discovery.uri should not be localhost in a '
'multi-node cluster, but found ' + urlparse.urlunparse(uri) +
'. You may have encountered this error by '
'choosing a coordinator that is localhost and a worker that '
'is not. The default discovery-uri is '
'http://<coordinator>:8080')
return conf
示例3: test_collect_node_information
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import roledefs [as 别名]
def test_collect_node_information(self, mock_ext_ip, mock_service,
mock_version, mock_presto_config):
env.roledefs = {
'coordinator': ['Node1'],
'all': ['Node1']
}
mock_ext_ip.side_effect = ['IP1', 'IP3', 'IP4']
mock_service.side_effect = [True, False, Exception('Not running')]
mock_version.side_effect = ['', 'Presto not installed', '', '']
self.assertEqual(('IP1', True, ''), server.collect_node_information())
self.assertEqual(('Unknown', False, 'Presto not installed'),
server.collect_node_information())
self.assertEqual(('IP3', False, ''), server.collect_node_information())
self.assertEqual(('IP4', False, ''),
server.collect_node_information())
示例4: test_collect_query_info
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import roledefs [as 别名]
def test_collect_query_info(self, requests_url_mock, requests_get_mock,
mkdir_mock, open_mock,
req_json_mock, json_dumps_mock):
query_id = "1234_abcd"
query_info_file_name = path.join(TMP_PRESTO_DEBUG,
"query_info_" + query_id + ".json")
file_obj = open_mock.return_value.__enter__.return_value
requests_get_mock.return_value.json.return_value = req_json_mock
requests_get_mock.return_value.status_code = requests.codes.ok
env.host = "myhost"
env.roledefs["coordinator"] = ["myhost"]
collect.query_info(query_id)
mkdir_mock.assert_called_with(TMP_PRESTO_DEBUG)
open_mock.assert_called_with(query_info_file_name, "w")
json_dumps_mock.assert_called_with(req_json_mock, indent=4)
file_obj.write.assert_called_with(json_dumps_mock.return_value)
示例5: chef_environment
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import roledefs [as 别名]
def chef_environment(name, api=None):
"""A Fabric task to set the current Chef environment context.
This task works alongside :func:`~chef.fabric.chef_roledefs` to set the
Chef environment to be used in future role queries.
Example::
from chef.fabric import chef_environment, chef_roledefs
env.roledefs = chef_roledefs()
.. code-block:: bash
$ fab env:production deploy
The task can be configured slightly via Fabric ``env`` values.
``env.chef_environment_task_alias`` sets the task alias, defaulting to "env".
This value must be set **before** :mod:`chef.fabric` is imported.
``env.chef_environment_validate`` sets if :class:`~chef.Environment` names
should be validated before use. Defaults to True.
.. versionadded:: 0.2
"""
if env.get('chef_environment_validate', True):
api = _api(api)
chef_env = Environment(name, api=api)
if not chef_env.exists:
raise ChefError('Unknown Chef environment: %s' % name)
env['chef_environment'] = name
示例6: decommissioned_host
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import roledefs [as 别名]
def decommissioned_host(host):
more_than_one_webworker = len(env.roledefs['django_app']) > 1
if more_than_one_webworker:
execute(_decommission_host, host)
yield
if more_than_one_webworker:
execute(_recommission_host, host)
示例7: get_roles_for
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import roledefs [as 别名]
def get_roles_for(host):
roles = []
for role in ['coordinator', 'worker']:
if host in env.roledefs[role]:
roles.append(role)
return roles
示例8: set_env_from_conf
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import roledefs [as 别名]
def set_env_from_conf(self, conf):
self.config = conf
env.user = conf['username']
env.port = conf['port']
try:
env.java8_home = conf['java8_home']
except KeyError:
env.java8_home = None
env.roledefs['coordinator'] = [conf['coordinator']]
env.roledefs['worker'] = conf['workers']
env.roledefs['all'] = self._dedup_list(util.get_coordinator_role() +
util.get_worker_role())
env.hosts = env.roledefs['all'][:]
env.conf = conf
示例9: default_config
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import roledefs [as 别名]
def default_config(self, filename):
try:
conf = copy.deepcopy(self.DEFAULT_PROPERTIES[filename])
except KeyError:
raise ConfigurationError('Invalid configuration file name: %s' %
filename)
if filename == 'config.properties':
coordinator = env.roledefs['coordinator'][0]
workers = env.roledefs['worker']
if coordinator in workers:
conf['node-scheduler.include-coordinator'] = 'true'
conf['discovery.uri'] = 'http://%s:8080' % coordinator
return conf
示例10: get_coordinator_role
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import roledefs [as 别名]
def get_coordinator_role():
return env.roledefs['coordinator']
示例11: by_rolename
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import roledefs [as 别名]
def by_rolename(host, rolename, f, *args, **kwargs):
if rolename is None:
f(*args, **kwargs)
else:
if rolename not in env.roledefs.keys():
abort("Invalid role name %s. Valid rolenames are %s" %
(rolename, env.roledefs.keys()))
if host in env.roledefs[rolename]:
return f(*args, **kwargs)
示例12: test_check_success_status
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import roledefs [as 别名]
def test_check_success_status(self, mock_run_sql, string_config_mock, mock_run, mock_presto_config):
env.roledefs = {
'coordinator': ['Node1'],
'worker': ['Node1', 'Node2', 'Node3', 'Node4'],
'all': ['Node1', 'Node2', 'Node3', 'Node4']
}
env.hosts = env.roledefs['all']
env.host = 'Node1'
string_config_mock.return_value = 'Node1'
mock_run_sql.return_value = [['Node2', 'some stuff'], ['Node1', 'some other stuff']]
self.assertEqual(server.check_server_status(), True)
示例13: test_check_success_fail
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import roledefs [as 别名]
def test_check_success_fail(self, mock_query_for_status, string_config_mock, mock_run,
mock_presto_config):
env.roledefs = {
'coordinator': ['Node1'],
'worker': ['Node1', 'Node2', 'Node3', 'Node4'],
'all': ['Node1', 'Node2', 'Node3', 'Node4']
}
env.hosts = env.roledefs['all']
env.host = 'Node1'
string_config_mock.return_value = 'Node1'
mock_query_for_status.return_value = False
self.assertEqual(server.check_server_status(), False)
示例14: test_status_from_each_node
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import roledefs [as 别名]
def test_status_from_each_node(
self, mock_run_sql, mock_presto_installed, mock_get_presto_version, mock_execute, mock_presto_config):
env.roledefs = {
'coordinator': ['Node1'],
'worker': ['Node1', 'Node2', 'Node3', 'Node4'],
'all': ['Node1', 'Node2', 'Node3', 'Node4']
}
env.hosts = env.roledefs['all']
mock_get_presto_version.return_value = '0.97-SNAPSHOT'
mock_run_sql.side_effect = [
[['select * from system.runtime.nodes']],
[['hive'], ['system'], ['tpch']],
[['http://active/statement', 'presto-main:0.97-SNAPSHOT', True]],
[['http://inactive/stmt', 'presto-main:0.99-SNAPSHOT', False]],
[[]],
[['http://servrdown/statement', 'any', True]]
]
mock_execute.side_effect = [{
'Node1': ('IP1', True, ''),
'Node2': ('IP2', True, ''),
'Node3': ('IP3', True, ''),
'Node4': Exception('Timed out trying to connect to Node4')
}]
env.host = 'Node1'
server.status()
expected = self.read_file_output('/resources/server_status_out.txt')
self.assertEqual(
expected.splitlines(),
self.test_stdout.getvalue().splitlines()
)
示例15: test_build_defaults
# 需要导入模块: from fabric.api import env [as 别名]
# 或者: from fabric.api.env import roledefs [as 别名]
def test_build_defaults(self):
env.roledefs['coordinator'] = 'a'
env.roledefs['workers'] = ['b', 'c']
actual_default = workers.Worker().build_all_defaults()
expected = {'node.properties':
{'node.environment': 'presto',
'node.data-dir': '/var/lib/presto/data',
'node.launcher-log-file': '/var/log/presto/launcher.log',
'node.server-log-file': '/var/log/presto/server.log',
'catalog.config-dir': '/etc/presto/catalog',
'plugin.dir': '/usr/lib/presto/lib/plugin'},
'jvm.config': ['-server',
'-Xmx16G',
'-XX:-UseBiasedLocking',
'-XX:+UseG1GC',
'-XX:G1HeapRegionSize=32M',
'-XX:+ExplicitGCInvokesConcurrent',
'-XX:+HeapDumpOnOutOfMemoryError',
'-XX:+UseGCOverheadLimit',
'-XX:+ExitOnOutOfMemoryError',
'-XX:ReservedCodeCacheSize=512M',
'-DHADOOP_USER_NAME=hive'],
'config.properties': {'coordinator': 'false',
'discovery.uri': 'http://a:8080',
'http-server.http.port': '8080',
'query.max-memory': '50GB',
'query.max-memory-per-node': '8GB'}
}
self.assertEqual(actual_default, expected)