本文整理汇总了Python中charmhelpers.contrib.openstack.context.HAProxyContext方法的典型用法代码示例。如果您正苦于以下问题:Python context.HAProxyContext方法的具体用法?Python context.HAProxyContext怎么用?Python context.HAProxyContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类charmhelpers.contrib.openstack.context
的用法示例。
在下文中一共展示了context.HAProxyContext方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from charmhelpers.contrib.openstack import context [as 别名]
# 或者: from charmhelpers.contrib.openstack.context import HAProxyContext [as 别名]
def __call__(self):
ctxt = super(HAProxyContext, self).__call__()
port = config('port')
# Apache ports
a_cephradosgw_api = determine_apache_port(port, singlenode_mode=True)
port_mapping = {
'cephradosgw-server': [port, a_cephradosgw_api]
}
ctxt['cephradosgw_bind_port'] = determine_api_port(
port,
singlenode_mode=True,
)
# for haproxy.conf
ctxt['service_ports'] = port_mapping
return ctxt
示例2: test_haproxy_context_with_no_peers
# 需要导入模块: from charmhelpers.contrib.openstack import context [as 别名]
# 或者: from charmhelpers.contrib.openstack.context import HAProxyContext [as 别名]
def test_haproxy_context_with_no_peers(self, local_unit, unit_get):
'''Test haproxy context with single unit'''
# peer relations always show at least one peer relation, even
# if unit is alone. should be an incomplete context.
cluster_relation = {
'cluster:0': {
'peer/0': {
'private-address': 'lonely.clusterpeer.howsad',
},
},
}
local_unit.return_value = 'peer/0'
unit_get.return_value = 'lonely.clusterpeer.howsad'
relation = FakeRelation(cluster_relation)
self.relation_ids.side_effect = relation.relation_ids
self.relation_get.side_effect = relation.get
self.related_units.side_effect = relation.relation_units
self.config.return_value = False
haproxy = context.HAProxyContext()
self.assertEquals({}, haproxy())
示例3: __call__
# 需要导入模块: from charmhelpers.contrib.openstack import context [as 别名]
# 或者: from charmhelpers.contrib.openstack.context import HAProxyContext [as 别名]
def __call__(self):
'''
Extends the main charmhelpers HAProxyContext with a port mapping
specific to this charm.
Also used to extend nova.conf context with correct api_listening_ports
'''
from keystone_utils import api_port
ctxt = super(HAProxyContext, self).__call__()
# determine which port api processes should bind to, depending
# on existence of haproxy + apache frontends
listen_ports = {}
listen_ports['admin_port'] = api_port('keystone-admin')
listen_ports['public_port'] = api_port('keystone-public')
# Apache ports
a_admin_port = determine_apache_port(api_port('keystone-admin'),
singlenode_mode=True)
a_public_port = determine_apache_port(api_port('keystone-public'),
singlenode_mode=True)
port_mapping = {
'admin-port': [
api_port('keystone-admin'), a_admin_port],
'public-port': [
api_port('keystone-public'), a_public_port],
}
# for haproxy.conf
ctxt['service_ports'] = port_mapping
# for keystone.conf
ctxt['listen_ports'] = listen_ports
return ctxt
示例4: __call__
# 需要导入模块: from charmhelpers.contrib.openstack import context [as 别名]
# 或者: from charmhelpers.contrib.openstack.context import HAProxyContext [as 别名]
def __call__(self):
'''
Extends the main charmhelpers HAProxyContext with a port mapping
specific to this charm.
Also used to extend nova.conf context with correct api_listening_ports
'''
from neutron_api_utils import api_port
ctxt = super(HAProxyContext, self).__call__()
# Apache ports
a_neutron_api = determine_apache_port(api_port('neutron-server'),
singlenode_mode=True)
port_mapping = {
'neutron-server': [
api_port('neutron-server'), a_neutron_api]
}
ctxt['neutron_bind_port'] = determine_api_port(
api_port('neutron-server'),
singlenode_mode=True,
)
# for haproxy.conf
ctxt['service_ports'] = port_mapping
return ctxt
示例5: test_haproxy_context_with_missing_data
# 需要导入模块: from charmhelpers.contrib.openstack import context [as 别名]
# 或者: from charmhelpers.contrib.openstack.context import HAProxyContext [as 别名]
def test_haproxy_context_with_missing_data(self):
'''Test haproxy context with missing relation data'''
self.relation_ids.return_value = []
haproxy = context.HAProxyContext()
self.assertEquals({}, haproxy())
示例6: test_haproxy_context_with_data
# 需要导入模块: from charmhelpers.contrib.openstack import context [as 别名]
# 或者: from charmhelpers.contrib.openstack.context import HAProxyContext [as 别名]
def test_haproxy_context_with_data(self, local_unit, unit_get):
'''Test haproxy context with all relation data'''
cluster_relation = {
'cluster:0': {
'peer/1': {
'private-address': 'cluster-peer1.localnet',
},
'peer/2': {
'private-address': 'cluster-peer2.localnet',
},
},
}
local_unit.return_value = 'peer/0'
unit_get.return_value = 'cluster-peer0.localnet'
relation = FakeRelation(cluster_relation)
self.relation_ids.side_effect = relation.relation_ids
self.relation_get.side_effect = relation.get
self.related_units.side_effect = relation.relation_units
self.get_address_in_network.return_value = None
self.get_netmask_for_address.return_value = '255.255.0.0'
self.config.return_value = False
self.maxDiff = None
self.is_ipv6_disabled.return_value = True
haproxy = context.HAProxyContext()
with patch_open() as (_open, _file):
result = haproxy()
ex = {
'frontends': {
'cluster-peer0.localnet': {
'network': 'cluster-peer0.localnet/255.255.0.0',
'backends': {
'peer-0': 'cluster-peer0.localnet',
'peer-1': 'cluster-peer1.localnet',
'peer-2': 'cluster-peer2.localnet',
}
}
},
'default_backend': 'cluster-peer0.localnet',
'local_host': '127.0.0.1',
'haproxy_host': '0.0.0.0',
'ipv6_enabled': False,
'stat_password': 'testpassword',
'stat_port': '8888',
}
# the context gets generated.
self.assertEquals(ex, result)
# and /etc/default/haproxy is updated.
self.assertEquals(_file.write.call_args_list,
[call('ENABLED=1\n')])
示例7: test_haproxy_context_with_data_timeout
# 需要导入模块: from charmhelpers.contrib.openstack import context [as 别名]
# 或者: from charmhelpers.contrib.openstack.context import HAProxyContext [as 别名]
def test_haproxy_context_with_data_timeout(self, local_unit, unit_get):
'''Test haproxy context with all relation data and timeout'''
cluster_relation = {
'cluster:0': {
'peer/1': {
'private-address': 'cluster-peer1.localnet',
},
'peer/2': {
'private-address': 'cluster-peer2.localnet',
},
},
}
local_unit.return_value = 'peer/0'
unit_get.return_value = 'cluster-peer0.localnet'
relation = FakeRelation(cluster_relation)
self.relation_ids.side_effect = relation.relation_ids
self.relation_get.side_effect = relation.get
self.related_units.side_effect = relation.relation_units
self.get_address_in_network.return_value = None
self.get_netmask_for_address.return_value = '255.255.0.0'
self.config.return_value = False
self.maxDiff = None
c = fake_config(HAPROXY_CONFIG)
c.data['prefer-ipv6'] = False
self.config.side_effect = c
self.is_ipv6_disabled.return_value = True
haproxy = context.HAProxyContext()
with patch_open() as (_open, _file):
result = haproxy()
ex = {
'frontends': {
'cluster-peer0.localnet': {
'network': 'cluster-peer0.localnet/255.255.0.0',
'backends': {
'peer-0': 'cluster-peer0.localnet',
'peer-1': 'cluster-peer1.localnet',
'peer-2': 'cluster-peer2.localnet',
}
}
},
'default_backend': 'cluster-peer0.localnet',
'local_host': '127.0.0.1',
'haproxy_host': '0.0.0.0',
'ipv6_enabled': False,
'stat_password': 'testpassword',
'stat_port': '8888',
'haproxy_client_timeout': 50000,
'haproxy_server_timeout': 50000,
}
# the context gets generated.
self.assertEquals(ex, result)
# and /etc/default/haproxy is updated.
self.assertEquals(_file.write.call_args_list,
[call('ENABLED=1\n')])
示例8: test_haproxy_context_with_data_ipv6
# 需要导入模块: from charmhelpers.contrib.openstack import context [as 别名]
# 或者: from charmhelpers.contrib.openstack.context import HAProxyContext [as 别名]
def test_haproxy_context_with_data_ipv6(self, local_unit, unit_get):
'''Test haproxy context with all relation data ipv6'''
cluster_relation = {
'cluster:0': {
'peer/1': {
'private-address': 'cluster-peer1.localnet',
},
'peer/2': {
'private-address': 'cluster-peer2.localnet',
},
},
}
local_unit.return_value = 'peer/0'
relation = FakeRelation(cluster_relation)
self.relation_ids.side_effect = relation.relation_ids
self.relation_get.side_effect = relation.get
self.related_units.side_effect = relation.relation_units
self.get_address_in_network.return_value = None
self.get_netmask_for_address.return_value = \
'FFFF:FFFF:FFFF:FFFF:0000:0000:0000:0000'
self.get_ipv6_addr.return_value = ['cluster-peer0.localnet']
c = fake_config(HAPROXY_CONFIG)
c.data['prefer-ipv6'] = True
self.config.side_effect = c
self.maxDiff = None
self.is_ipv6_disabled.return_value = False
haproxy = context.HAProxyContext()
with patch_open() as (_open, _file):
result = haproxy()
ex = {
'frontends': {
'cluster-peer0.localnet': {
'network': 'cluster-peer0.localnet/'
'FFFF:FFFF:FFFF:FFFF:0000:0000:0000:0000',
'backends': {
'peer-0': 'cluster-peer0.localnet',
'peer-1': 'cluster-peer1.localnet',
'peer-2': 'cluster-peer2.localnet',
}
}
},
'default_backend': 'cluster-peer0.localnet',
'local_host': 'ip6-localhost',
'haproxy_server_timeout': 50000,
'haproxy_client_timeout': 50000,
'haproxy_host': '::',
'ipv6_enabled': True,
'stat_password': 'testpassword',
'stat_port': '8888',
}
# the context gets generated.
self.assertEquals(ex, result)
# and /etc/default/haproxy is updated.
self.assertEquals(_file.write.call_args_list,
[call('ENABLED=1\n')])