Pass service admin auth from the Octavia driver

Some implementations of Octavia may require authenticated access
to the service. For this, pass the service admin token in a header
along with the API request.

Change-Id: I038f79de5638f1992d9f89972bcb91de331448e3
Closes-Bug: #1531640
This commit is contained in:
ptoohill1 2016-01-06 16:17:24 -06:00
parent 70fbd72541
commit b3b8f4a3ad

View File

@ -23,10 +23,11 @@ from oslo_serialization import jsonutils
from oslo_utils import excutils from oslo_utils import excutils
import requests import requests
from neutron_lbaas.common import keystone
from neutron_lbaas.drivers import driver_base from neutron_lbaas.drivers import driver_base
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
VERSION = "1.0.0" VERSION = "1.0.1"
OPTS = [ OPTS = [
cfg.StrOpt( cfg.StrOpt(
@ -115,14 +116,17 @@ def async_op(func):
class OctaviaRequest(object): class OctaviaRequest(object):
def __init__(self, base_url): def __init__(self, base_url, auth_session):
self.base_url = base_url self.base_url = base_url
self.auth_session = auth_session
def request(self, method, url, args=None, headers=None): def request(self, method, url, args=None, headers=None):
if args: if args:
if not headers: if not headers:
token = self.auth_session.get_token()
headers = { headers = {
'Content-type': 'application/json' 'Content-type': 'application/json',
'X-Auth-Token': token
} }
args = jsonutils.dumps(args) args = jsonutils.dumps(args)
LOG.debug("url = %s", '%s%s' % (self.base_url, str(url))) LOG.debug("url = %s", '%s%s' % (self.base_url, str(url)))
@ -154,8 +158,8 @@ class OctaviaDriver(driver_base.LoadBalancerBaseDriver):
def __init__(self, plugin): def __init__(self, plugin):
super(OctaviaDriver, self).__init__(plugin) super(OctaviaDriver, self).__init__(plugin)
self.req = OctaviaRequest(cfg.CONF.octavia.base_url,
self.req = OctaviaRequest(cfg.CONF.octavia.base_url) keystone.get_session())
self.load_balancer = LoadBalancerManager(self) self.load_balancer = LoadBalancerManager(self)
self.listener = ListenerManager(self) self.listener = ListenerManager(self)