Allow API listening address to be specified in config
This allows users to configure a specific API listening address for the astara administrative API. This also updates devstack plugin to publish this into the keystone catalog, for easier lookup by astara-horizon. Partially-implements: blueprint astara-horizon-mitaka Partial-bug: #1516787 Change-Id: I2b96137c05b832a68ad01a11ec0cfb2371111c3c
This commit is contained in:
parent
48598653d8
commit
1d26671b3f
|
@ -33,8 +33,13 @@ from astara.common.i18n import _, _LE, _LI, _LW
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
RUG_API_OPTS = [
|
RUG_API_OPTS = [
|
||||||
cfg.IntOpt('rug_api_port', default=44250,
|
cfg.IntOpt('api_port', default=44250,
|
||||||
help='RUG API listening port')
|
help='Astara administrative API listening port',
|
||||||
|
deprecated_opts=[
|
||||||
|
cfg.DeprecatedOpt('rug_api_port',
|
||||||
|
group='DEFAULT')]),
|
||||||
|
cfg.StrOpt('api_listen', default='0.0.0.0',
|
||||||
|
help='Astara administrative API listening address')
|
||||||
]
|
]
|
||||||
cfg.CONF.register_opts(RUG_API_OPTS)
|
cfg.CONF.register_opts(RUG_API_OPTS)
|
||||||
|
|
||||||
|
@ -76,8 +81,15 @@ class RugAPIServer(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.pool = eventlet.GreenPool(1000)
|
self.pool = eventlet.GreenPool(1000)
|
||||||
|
|
||||||
def run(self, ip_address, port=cfg.CONF.rug_api_port):
|
def run(self, ip_address, port):
|
||||||
app = RugAPI()
|
app = RugAPI()
|
||||||
|
|
||||||
|
try:
|
||||||
|
socket.inet_pton(socket.AF_INET6, ip_address)
|
||||||
|
family = socket.AF_INET6
|
||||||
|
except Exception:
|
||||||
|
family = socket.AF_INET
|
||||||
|
|
||||||
for i in six.moves.range(5):
|
for i in six.moves.range(5):
|
||||||
LOG.info(_LI(
|
LOG.info(_LI(
|
||||||
'Starting the rug-api on %s:%s'),
|
'Starting the rug-api on %s:%s'),
|
||||||
|
@ -86,7 +98,7 @@ class RugAPIServer(object):
|
||||||
try:
|
try:
|
||||||
sock = eventlet.listen(
|
sock = eventlet.listen(
|
||||||
(ip_address, port),
|
(ip_address, port),
|
||||||
family=socket.AF_INET6,
|
family=family,
|
||||||
backlog=128
|
backlog=128
|
||||||
)
|
)
|
||||||
except socket.error as err:
|
except socket.error as err:
|
||||||
|
@ -109,5 +121,5 @@ class RugAPIServer(object):
|
||||||
log=loggers.WritableLogger(LOG))
|
log=loggers.WritableLogger(LOG))
|
||||||
|
|
||||||
|
|
||||||
def serve(ip_address):
|
def serve():
|
||||||
RugAPIServer().run(ip_address)
|
RugAPIServer().run(cfg.CONF.api_listen, cfg.CONF.api_port)
|
||||||
|
|
|
@ -170,7 +170,6 @@ def main(argv=sys.argv[1:]):
|
||||||
from astara.api import rug as rug_api
|
from astara.api import rug as rug_api
|
||||||
rug_api_proc = multiprocessing.Process(
|
rug_api_proc = multiprocessing.Process(
|
||||||
target=rug_api.serve,
|
target=rug_api.serve,
|
||||||
args=(mgt_ip_address,),
|
|
||||||
name='rug-api'
|
name='rug-api'
|
||||||
)
|
)
|
||||||
rug_api_proc.start()
|
rug_api_proc.start()
|
||||||
|
|
|
@ -161,12 +161,31 @@ class TestRugAPIServer(unittest.TestCase):
|
||||||
|
|
||||||
@mock.patch('eventlet.listen')
|
@mock.patch('eventlet.listen')
|
||||||
@mock.patch('eventlet.wsgi')
|
@mock.patch('eventlet.wsgi')
|
||||||
def test_bind_and_serve(self, wsgi, listen):
|
def test_bind_and_serve_ipv4(self, wsgi, listen):
|
||||||
sock = listen.return_value
|
sock = listen.return_value
|
||||||
server = rug.RugAPIServer()
|
server = rug.RugAPIServer()
|
||||||
server.run('::1/128')
|
server.run('10.0.0.250', 44250)
|
||||||
listen.assert_called_with(
|
listen.assert_called_with(
|
||||||
('::1/128', 44250),
|
('10.0.0.250', 44250),
|
||||||
|
family=socket.AF_INET,
|
||||||
|
backlog=128
|
||||||
|
)
|
||||||
|
args, kwargs = wsgi.server.call_args
|
||||||
|
assert all([
|
||||||
|
args[0] == sock,
|
||||||
|
isinstance(args[1], rug.RugAPI),
|
||||||
|
kwargs['custom_pool'] == server.pool,
|
||||||
|
isinstance(kwargs['log'], loggers.WritableLogger)
|
||||||
|
])
|
||||||
|
|
||||||
|
@mock.patch('eventlet.listen')
|
||||||
|
@mock.patch('eventlet.wsgi')
|
||||||
|
def test_bind_and_serve_ipv6(self, wsgi, listen):
|
||||||
|
sock = listen.return_value
|
||||||
|
server = rug.RugAPIServer()
|
||||||
|
server.run('fdca:3ba5:a17a:acda::1', 44250)
|
||||||
|
listen.assert_called_with(
|
||||||
|
('fdca:3ba5:a17a:acda::1', 44250),
|
||||||
family=socket.AF_INET6,
|
family=socket.AF_INET6,
|
||||||
backlog=128
|
backlog=128
|
||||||
)
|
)
|
||||||
|
@ -188,10 +207,12 @@ class TestRugAPIServer(unittest.TestCase):
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
RuntimeError,
|
RuntimeError,
|
||||||
server.run,
|
server.run,
|
||||||
'::1/128'
|
'fdca:3ba5:a17a:acda::1',
|
||||||
|
44250,
|
||||||
)
|
)
|
||||||
assert listen.call_args_list == [
|
assert listen.call_args_list == [
|
||||||
mock.call(('::1/128', 44250), family=socket.AF_INET6, backlog=128)
|
mock.call(('fdca:3ba5:a17a:acda::1', 44250),
|
||||||
|
family=socket.AF_INET6, backlog=128)
|
||||||
for i in range(5)
|
for i in range(5)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -205,9 +226,10 @@ class TestRugAPIServer(unittest.TestCase):
|
||||||
sock
|
sock
|
||||||
]
|
]
|
||||||
server = rug.RugAPIServer()
|
server = rug.RugAPIServer()
|
||||||
server.run('::1/128')
|
server.run('fdca:3ba5:a17a:acda::1', 44250)
|
||||||
assert listen.call_args_list == [
|
assert listen.call_args_list == [
|
||||||
mock.call(('::1/128', 44250), family=socket.AF_INET6, backlog=128)
|
mock.call(('fdca:3ba5:a17a:acda::1', 44250),
|
||||||
|
family=socket.AF_INET6, backlog=128)
|
||||||
for i in range(2) # fails the first time, succeeds the second
|
for i in range(2) # fails the first time, succeeds the second
|
||||||
]
|
]
|
||||||
args, kwargs = wsgi.server.call_args
|
args, kwargs = wsgi.server.call_args
|
||||||
|
|
|
@ -34,6 +34,7 @@ ROUTER_INSTANCE_FLAVOR_CPUS=${ROUTER_INSTANCE_FLAVOR_CPUS:-1}
|
||||||
PUBLIC_INTERFACE_DEFAULT='eth0'
|
PUBLIC_INTERFACE_DEFAULT='eth0'
|
||||||
ASTARA_MANAGEMENT_PREFIX=${ASTARA_MANAGEMENT_PREFIX:-"fdca:3ba5:a17a:acda::/64"}
|
ASTARA_MANAGEMENT_PREFIX=${ASTARA_MANAGEMENT_PREFIX:-"fdca:3ba5:a17a:acda::/64"}
|
||||||
ASTARA_MANAGEMENT_PORT=${ASTARA_MANAGEMENT_PORT:-5000}
|
ASTARA_MANAGEMENT_PORT=${ASTARA_MANAGEMENT_PORT:-5000}
|
||||||
|
ASTARA_API_LISTEN=${ASTARA_API_LISTEN:-$SERVICE_HOST}
|
||||||
ASTARA_API_PORT=${ASTARA_API_PORT:-44250}
|
ASTARA_API_PORT=${ASTARA_API_PORT:-44250}
|
||||||
|
|
||||||
HORIZON_LOCAL_SETTINGS=$HORIZON_DIR/openstack_dashboard/local/local_settings.py
|
HORIZON_LOCAL_SETTINGS=$HORIZON_DIR/openstack_dashboard/local/local_settings.py
|
||||||
|
@ -83,7 +84,8 @@ function configure_astara() {
|
||||||
|
|
||||||
iniset $ASTARA_CONF DEFAULT management_prefix $ASTARA_MANAGEMENT_PREFIX
|
iniset $ASTARA_CONF DEFAULT management_prefix $ASTARA_MANAGEMENT_PREFIX
|
||||||
iniset $ASTARA_CONF DEFAULT astara_mgt_service_port $ASTARA_MANAGEMENT_PORT
|
iniset $ASTARA_CONF DEFAULT astara_mgt_service_port $ASTARA_MANAGEMENT_PORT
|
||||||
iniset $ASTARA_CONF DEFAULT rug_api_port $ASTARA_API_PORT
|
iniset $ASTARA_CONF DEFAULT api_listen $ASTARA_API_LISTEN
|
||||||
|
iniset $ASTARA_CONF DEFAULT api_port $ASTARA_API_PORT
|
||||||
|
|
||||||
if [[ "$Q_AGENT" == "linuxbridge" ]]; then
|
if [[ "$Q_AGENT" == "linuxbridge" ]]; then
|
||||||
iniset $ASTARA_CONF DEFAULT interface_driver "astara.common.linux.interface.BridgeInterfaceDriver"
|
iniset $ASTARA_CONF DEFAULT interface_driver "astara.common.linux.interface.BridgeInterfaceDriver"
|
||||||
|
@ -337,6 +339,15 @@ function set_demo_tenant_sec_group_private_traffic() {
|
||||||
neutron $auth_args security-group-rule-create --direction ingress --remote-ip-prefix $FIXED_RANGE default
|
neutron $auth_args security-group-rule-create --direction ingress --remote-ip-prefix $FIXED_RANGE default
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function create_astara_endpoint() {
|
||||||
|
# Publish the API endpoint of the administrative API (used by Horizon)
|
||||||
|
get_or_create_service "astara" "astara" "Astara Network Orchestration Administrative API"
|
||||||
|
get_or_create_endpoint "astara" \
|
||||||
|
"$REGION_NAME" \
|
||||||
|
"http://$ASTARA_API_LISTEN:$ASTARA_API_PORT" \
|
||||||
|
"http://$ASTARA_API_LISTEN:$ASTARA_API_PORT" \
|
||||||
|
"http://$ASTARA_API_LISTEN:$ASTARA_API_PORT"
|
||||||
|
}
|
||||||
|
|
||||||
function check_prereqs() {
|
function check_prereqs() {
|
||||||
# Fail devstack as early as possible if system does not satisfy some known
|
# Fail devstack as early as possible if system does not satisfy some known
|
||||||
|
@ -366,6 +377,7 @@ if is_service_enabled astara; then
|
||||||
if is_service_enabled horizon; then
|
if is_service_enabled horizon; then
|
||||||
configure_astara_horizon
|
configure_astara_horizon
|
||||||
fi
|
fi
|
||||||
|
create_astara_endpoint
|
||||||
cd $old_cwd
|
cd $old_cwd
|
||||||
|
|
||||||
elif [[ "$1" == "stack" && "$2" == "extra" ]]; then
|
elif [[ "$1" == "stack" && "$2" == "extra" ]]; then
|
||||||
|
|
|
@ -55,6 +55,10 @@ provider_rules_path=/opt/stack/astara/etc/provider_rules.json
|
||||||
control_exchange = quantum
|
control_exchange = quantum
|
||||||
neutron_port_security_extension_enabled = True
|
neutron_port_security_extension_enabled = True
|
||||||
|
|
||||||
|
# api_listen address and port for the astara administrative API
|
||||||
|
api_listen = 0.0.0.0
|
||||||
|
api_port = 44250
|
||||||
|
|
||||||
[AGENT]
|
[AGENT]
|
||||||
root_helper=sudo astara-rootwrap /etc/astara/rootwrap.conf
|
root_helper=sudo astara-rootwrap /etc/astara/rootwrap.conf
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue