当前位置: 首页>>代码示例>>Python>>正文


Python consul.Consul方法代码示例

本文整理汇总了Python中consul.Consul方法的典型用法代码示例。如果您正苦于以下问题:Python consul.Consul方法的具体用法?Python consul.Consul怎么用?Python consul.Consul使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在consul的用法示例。


在下文中一共展示了consul.Consul方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_kv_encoding

# 需要导入模块: import consul [as 别名]
# 或者: from consul import Consul [as 别名]
def test_kv_encoding(self, consul_port):
        c = consul.Consul(port=consul_port)

        # test binary
        c.kv.put('foo', struct.pack('i', 1000))
        index, data = c.kv.get('foo')
        assert struct.unpack('i', data['Value']) == (1000,)

        # test unicode
        c.kv.put('foo', u'bar')
        index, data = c.kv.get('foo')
        assert data['Value'] == six.b('bar')

        # test empty-string comes back as `None`
        c.kv.put('foo', '')
        index, data = c.kv.get('foo')
        assert data['Value'] is None

        # test None
        c.kv.put('foo', None)
        index, data = c.kv.get('foo')
        assert data['Value'] is None

        # check unencoded values raises assert * Python3 don't need
        # pytest.raises(AssertionError, c.kv.put, 'foo', {1: 2}) 
开发者ID:poppyred,项目名称:python-consul2,代码行数:27,代码来源:test_std.py

示例2: test_kv_acquire_release

# 需要导入模块: import consul [as 别名]
# 或者: from consul import Consul [as 别名]
def test_kv_acquire_release(self, consul_port):
        c = consul.Consul(port=consul_port)

        pytest.raises(
            consul.ConsulException, c.kv.put, 'foo', 'bar', acquire='foo')

        s1 = c.session.create()
        s2 = c.session.create()

        assert c.kv.put('foo', '1', acquire=s1) is True
        assert c.kv.put('foo', '2', acquire=s2) is False
        assert c.kv.put('foo', '1', acquire=s1) is True
        assert c.kv.put('foo', '1', release='foo') is False
        assert c.kv.put('foo', '2', release=s2) is False
        assert c.kv.put('foo', '2', release=s1) is True

        c.session.destroy(s1)
        c.session.destroy(s2) 
开发者ID:poppyred,项目名称:python-consul2,代码行数:20,代码来源:test_std.py

示例3: test_service_dereg_issue_156

# 需要导入模块: import consul [as 别名]
# 或者: from consul import Consul [as 别名]
def test_service_dereg_issue_156(self, consul_port):
        # https://github.com/cablehead/python-consul/issues/156
        service_name = 'app#127.0.0.1#3000'
        c = consul.Consul(port=consul_port)
        c.agent.service.register(service_name)

        time.sleep(80 / 1000.0)

        index, nodes = c.health.service(service_name)
        assert [node['Service']['ID'] for node in nodes] == [service_name]

        # Clean up tasks
        assert c.agent.service.deregister(service_name) is True

        time.sleep(40 / 1000.0)

        index, nodes = c.health.service(service_name)
        assert [node['Service']['ID'] for node in nodes] == [] 
开发者ID:poppyred,项目名称:python-consul2,代码行数:20,代码来源:test_std.py

示例4: test_agent_register_check_no_service_id

# 需要导入模块: import consul [as 别名]
# 或者: from consul import Consul [as 别名]
def test_agent_register_check_no_service_id(self, consul_port):
        c = consul.Consul(port=consul_port)
        index, nodes = c.health.service("foo1")
        assert nodes == []

        pytest.raises(consul.std.base.ConsulException,
                      c.agent.check.register,
                      'foo', Check.ttl('100ms'),
                      service_id='foo1')

        time.sleep(40 / 1000.0)

        assert c.agent.checks() == {}

        # Cleanup tasks
        c.agent.check.deregister('foo')

        time.sleep(40 / 1000.0) 
开发者ID:poppyred,项目名称:python-consul2,代码行数:20,代码来源:test_std.py

示例5: test_agent_node_maintenance

# 需要导入模块: import consul [as 别名]
# 或者: from consul import Consul [as 别名]
def test_agent_node_maintenance(self, consul_port):
        c = consul.Consul(port=consul_port)

        c.agent.maintenance('true', "test")

        time.sleep(40 / 1000.0)

        checks_pre = c.agent.checks()
        assert '_node_maintenance' in checks_pre.keys()
        assert 'test' == checks_pre['_node_maintenance']['Notes']

        c.agent.maintenance('false')

        time.sleep(40 / 1000.0)

        checks_post = c.agent.checks()
        assert '_node_maintenance' not in checks_post.keys() 
开发者ID:poppyred,项目名称:python-consul2,代码行数:19,代码来源:test_std.py

示例6: test_health_checks

# 需要导入模块: import consul [as 别名]
# 或者: from consul import Consul [as 别名]
def test_health_checks(self, consul_port):
        c = consul.Consul(port=consul_port)

        c.agent.service.register(
            'foobar', service_id='foobar', check=Check.ttl('10s'))

        time.sleep(40 / 1000.00)

        index, checks = c.health.checks('foobar')

        assert [check['ServiceID'] for check in checks] == ['foobar']
        assert [check['CheckID'] for check in checks] == ['service:foobar']

        c.agent.service.deregister('foobar')

        time.sleep(40 / 1000.0)

        index, checks = c.health.checks('foobar')
        assert len(checks) == 0 
开发者ID:poppyred,项目名称:python-consul2,代码行数:21,代码来源:test_std.py

示例7: test_session_delete_ttl_renew

# 需要导入模块: import consul [as 别名]
# 或者: from consul import Consul [as 别名]
def test_session_delete_ttl_renew(self, consul_port):
        c = consul.Consul(port=consul_port)

        s = c.session.create(behavior='delete', ttl=20)

        # attempt to renew an unknown session
        pytest.raises(consul.NotFound, c.session.renew, '1' * 36)

        session = c.session.renew(s)
        assert session['Behavior'] == 'delete'
        assert session['TTL'] == '20s'

        # trying out the behavior
        assert c.kv.put('foo', '1', acquire=s) is True
        index, data = c.kv.get('foo')
        assert data['Value'] == six.b('1')

        c.session.destroy(s)
        index, data = c.kv.get('foo')
        assert data is None 
开发者ID:poppyred,项目名称:python-consul2,代码行数:22,代码来源:test_std.py

示例8: test_operator_autopilot

# 需要导入模块: import consul [as 别名]
# 或者: from consul import Consul [as 别名]
def test_operator_autopilot(self, consul_port):
        time.sleep(2)  # http code 429 Too Many Requests
        c = consul.Consul(port=consul_port)
        assert c.operator.autopilot.configuration()['MaxTrailingLogs'] == 250
        assert not c.operator.autopilot.health()['FailureTolerance']
        payload = {
            "CleanupDeadServers": True,
            "LastContactThreshold": "200ms",
            "MaxTrailingLogs": 251,
            "ServerStabilizationTime": "10s",
            "RedundancyZoneTag": "",
            "DisableUpgradeMigration": False,
            "UpgradeVersionTag": "",
            "CreateIndex": 4,
            "ModifyIndex": 4
        }
        assert c.operator.autopilot.update(payload)

        config = c.operator.autopilot.configuration()

        assert config['MaxTrailingLogs'] == 251 
开发者ID:poppyred,项目名称:python-consul2,代码行数:23,代码来源:test_std.py

示例9: test_acl_translate

# 需要导入模块: import consul [as 别名]
# 或者: from consul import Consul [as 别名]
def test_acl_translate(self, acl_consul):
        c = consul.Consul(port=acl_consul.port, token=acl_consul.token)

        payload = """
        agent "" {
            policy = "write"
        }
        """

        translate = c.acl.create_translate(
            payload=payload, token=acl_consul.token)
        assert translate == b'agent_prefix "" {\n  policy = "write"\n}'

        # fixme
        pytest.raises(consul.ConsulException,
                      c.acl.get_translate,
                      c.acl.self()['AccessorID'],
                      acl_consul.token) 
开发者ID:poppyred,项目名称:python-consul2,代码行数:20,代码来源:test_std_acl.py

示例10: test_acl_operator_area

# 需要导入模块: import consul [as 别名]
# 或者: from consul import Consul [as 别名]
def test_acl_operator_area(self, acl_consul):
        c = consul.Consul(port=acl_consul.port, token=acl_consul.token)
        payload = {
            "PeerDatacenter": "dc1",
            "RetryJoin": ["10.1.2.3", "10.1.2.4", "10.1.2.5"],
            "UseTLS": False
        }
        area1 = c.operator.area.create(payload)
        c.operator.area.get(area1['ID'])
        payload["PeerDatacenter"] = "dc1"
        c.operator.area.update(payload, area1['ID'])
        c.operator.area.list()
        payload2 = ["10.1.2.3", "10.1.2.4", "10.1.2.5"]
        c.operator.area.join(payload2, area1['ID'])
        c.operator.area.members()
        c.operator.area.delete(area1['ID'])
        c.operator.area.list() 
开发者ID:poppyred,项目名称:python-consul2,代码行数:19,代码来源:test_std_acl.py

示例11: test_kv_recurse

# 需要导入模块: import consul [as 别名]
# 或者: from consul import Consul [as 别名]
def test_kv_recurse(self, acl_consul):
        c = consul.Consul(port=acl_consul.port, token=acl_consul.token)
        index, data = c.kv.get('foo/', recurse=True)
        assert data is None

        c.kv.put('foo/', None)
        index, data = c.kv.get('foo/', recurse=True)
        assert len(data) == 1

        c.kv.put('foo/bar1', '1')
        c.kv.put('foo/bar2', '2')
        c.kv.put('foo/bar3', '3')
        index, data = c.kv.get('foo/', recurse=True)
        assert [x['Key'] for x in data] == [
            'foo/', 'foo/bar1', 'foo/bar2', 'foo/bar3']
        assert [x['Value'] for x in data] == [
            None, six.b('1'), six.b('2'), six.b('3')]
        c.kv.delete('foo')
        c.kv.delete('foo/')
        c.kv.delete('foo/bar1')
        c.kv.delete('foo/bar2')
        c.kv.delete('foo/bar3') 
开发者ID:poppyred,项目名称:python-consul2,代码行数:24,代码来源:test_std_token.py

示例12: test_kv_acquire_release

# 需要导入模块: import consul [as 别名]
# 或者: from consul import Consul [as 别名]
def test_kv_acquire_release(self, acl_consul):
        c = consul.Consul(port=acl_consul.port, token=acl_consul.token)

        pytest.raises(
            consul.ConsulException, c.kv.put, 'foo', 'bar', acquire='foo')

        s1 = c.session.create()
        s2 = c.session.create()

        assert c.kv.put('foo', '1', acquire=s1) is True
        assert c.kv.put('foo', '2', acquire=s2) is False
        assert c.kv.put('foo', '1', acquire=s1) is True
        assert c.kv.put('foo', '1', release='foo') is False
        assert c.kv.put('foo', '2', release=s2) is False
        assert c.kv.put('foo', '2', release=s1) is True

        c.session.destroy(s1)
        c.session.destroy(s2) 
开发者ID:poppyred,项目名称:python-consul2,代码行数:20,代码来源:test_std_token.py

示例13: test_service_dereg_issue_156

# 需要导入模块: import consul [as 别名]
# 或者: from consul import Consul [as 别名]
def test_service_dereg_issue_156(self, acl_consul):
        # https://github.com/cablehead/python-consul/issues/156
        service_name = 'app#127.0.0.1#3000'
        c = consul.Consul(port=acl_consul.port, token=acl_consul.token)
        c.agent.service.register(service_name)

        time.sleep(80 / 1000.0)

        index, nodes = c.health.service(service_name)
        assert [node['Service']['ID'] for node in nodes] == [service_name]

        # Clean up tasks
        assert c.agent.service.deregister(service_name) is True

        time.sleep(40 / 1000.0)

        index, nodes = c.health.service(service_name)
        assert [node['Service']['ID'] for node in nodes] == [] 
开发者ID:poppyred,项目名称:python-consul2,代码行数:20,代码来源:test_std_token.py

示例14: test_session_delete_ttl_renew

# 需要导入模块: import consul [as 别名]
# 或者: from consul import Consul [as 别名]
def test_session_delete_ttl_renew(self, acl_consul):
        c = consul.Consul(port=acl_consul.port, token=acl_consul.token)

        s = c.session.create(behavior='delete', ttl=20)

        # attempt to renew an unknown session
        pytest.raises(consul.NotFound, c.session.renew, '1' * 36)

        session = c.session.renew(s)
        assert session['Behavior'] == 'delete'
        assert session['TTL'] == '20s'

        # trying out the behavior
        assert c.kv.put('foo', '1', acquire=s) is True
        index, data = c.kv.get('foo')
        assert data['Value'] == six.b('1')

        c.session.destroy(s)
        index, data = c.kv.get('foo')
        assert data is None 
开发者ID:poppyred,项目名称:python-consul2,代码行数:22,代码来源:test_std_token.py

示例15: test_config

# 需要导入模块: import consul [as 别名]
# 或者: from consul import Consul [as 别名]
def test_config(self, acl_consul):
        c = consul.Consul(port=acl_consul.port, token=acl_consul.token)
        payload = {
            "Kind": "service-defaults",
            "Name": "web",
            "Protocol": "http",
        }
        assert c.config.put(payload)

        config = c.config.get(kind=payload['Kind'], name=payload['Name'])
        assert config['Kind'] == 'service-defaults'
        assert config['Name'] == 'web'
        assert config['Protocol'] == 'http'

        configs = c.config.list(kind=payload['Kind'])
        assert configs[0]['Kind'] == 'service-defaults'
        assert configs[0]['Name'] == 'web'
        assert configs[0]['Protocol'] == 'http'

        isdel = c.config.delete(kind=payload['Kind'], name=payload['Name'])

        assert isdel
        config = c.config.get(kind=payload['Kind'], name=payload['Name'])
        assert config[1] is None 
开发者ID:poppyred,项目名称:python-consul2,代码行数:26,代码来源:test_std_token.py


注:本文中的consul.Consul方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。