Add the parameter bypass_url to the cinder client
If the bypass_url is specified in the http client, there is no need to get it from Keystone. Change-Id: I891849f77ad2ba98a83c993b401121216c8cfff6 closes-bug: #1350702
This commit is contained in:
parent
5b172959c6
commit
7a50182fbe
cinderclient
@ -145,7 +145,8 @@ class HTTPClient(object):
|
||||
insecure=False, timeout=None, tenant_id=None,
|
||||
proxy_tenant_id=None, proxy_token=None, region_name=None,
|
||||
endpoint_type='publicURL', service_type=None,
|
||||
service_name=None, volume_service_name=None, retries=None,
|
||||
service_name=None, volume_service_name=None,
|
||||
bypass_url=None, retries=None,
|
||||
http_log_debug=False, cacert=None,
|
||||
auth_system='keystone', auth_plugin=None):
|
||||
self.user = user
|
||||
@ -168,10 +169,11 @@ class HTTPClient(object):
|
||||
self.service_type = service_type
|
||||
self.service_name = service_name
|
||||
self.volume_service_name = volume_service_name
|
||||
self.bypass_url = bypass_url.rstrip('/') if bypass_url else bypass_url
|
||||
self.retries = int(retries or 0)
|
||||
self.http_log_debug = http_log_debug
|
||||
|
||||
self.management_url = None
|
||||
self.management_url = self.bypass_url or None
|
||||
self.auth_token = None
|
||||
self.proxy_token = proxy_token
|
||||
self.proxy_tenant_id = proxy_tenant_id
|
||||
@ -410,7 +412,10 @@ class HTTPClient(object):
|
||||
# existing token? If so, our actual endpoints may
|
||||
# be different than that of the admin token.
|
||||
if self.proxy_token:
|
||||
self._fetch_endpoints_from_auth(admin_url)
|
||||
if self.bypass_url:
|
||||
self.set_management_url(self.bypass_url)
|
||||
else:
|
||||
self._fetch_endpoints_from_auth(admin_url)
|
||||
# Since keystone no longer returns the user token
|
||||
# with the endpoints any more, we need to replace
|
||||
# our service account token with the user token.
|
||||
@ -427,6 +432,11 @@ class HTTPClient(object):
|
||||
auth_url = auth_url + '/v2.0'
|
||||
self._v2_auth(auth_url)
|
||||
|
||||
if self.bypass_url:
|
||||
self.set_management_url(self.bypass_url)
|
||||
elif not self.management_url:
|
||||
raise exceptions.Unauthorized('Cinder Client')
|
||||
|
||||
def _v1_auth(self, url):
|
||||
if self.proxy_token:
|
||||
raise exceptions.NoTokenLookupException()
|
||||
@ -486,7 +496,7 @@ def _construct_http_client(username=None, password=None, project_id=None,
|
||||
region_name=None, endpoint_type='publicURL',
|
||||
service_type='volume',
|
||||
service_name=None, volume_service_name=None,
|
||||
retries=None,
|
||||
bypass_url=None, retries=None,
|
||||
http_log_debug=False,
|
||||
auth_system='keystone', auth_plugin=None,
|
||||
cacert=None, tenant_id=None,
|
||||
@ -519,6 +529,7 @@ def _construct_http_client(username=None, password=None, project_id=None,
|
||||
service_type=service_type,
|
||||
service_name=service_name,
|
||||
volume_service_name=volume_service_name,
|
||||
bypass_url=bypass_url,
|
||||
retries=retries,
|
||||
http_log_debug=http_log_debug,
|
||||
cacert=cacert,
|
||||
|
@ -183,6 +183,16 @@ class OpenStackCinderShell(object):
|
||||
parser.add_argument('--os_volume_api_version',
|
||||
help=argparse.SUPPRESS)
|
||||
|
||||
parser.add_argument('--bypass-url',
|
||||
metavar='<bypass-url>',
|
||||
dest='bypass_url',
|
||||
default=utils.env('CINDERCLIENT_BYPASS_URL'),
|
||||
help="Use this API endpoint instead of the "
|
||||
"Service Catalog. Defaults to "
|
||||
"env[CINDERCLIENT_BYPASS_URL]")
|
||||
parser.add_argument('--bypass_url',
|
||||
help=argparse.SUPPRESS)
|
||||
|
||||
parser.add_argument('--retries',
|
||||
metavar='<retries>',
|
||||
type=int,
|
||||
@ -545,14 +555,15 @@ class OpenStackCinderShell(object):
|
||||
|
||||
(os_username, os_password, os_tenant_name, os_auth_url,
|
||||
os_region_name, os_tenant_id, endpoint_type, insecure,
|
||||
service_type, service_name, volume_service_name,
|
||||
service_type, service_name, volume_service_name, bypass_url,
|
||||
cacert, os_auth_system) = (
|
||||
args.os_username, args.os_password,
|
||||
args.os_tenant_name, args.os_auth_url,
|
||||
args.os_region_name, args.os_tenant_id,
|
||||
args.endpoint_type, args.insecure,
|
||||
args.service_type, args.service_name,
|
||||
args.volume_service_name, args.os_cacert,
|
||||
args.volume_service_name,
|
||||
args.bypass_url, args.os_cacert,
|
||||
args.os_auth_system)
|
||||
if os_auth_system and os_auth_system != "keystone":
|
||||
auth_plugin = cinderclient.auth_plugin.load_plugin(os_auth_system)
|
||||
@ -652,6 +663,7 @@ class OpenStackCinderShell(object):
|
||||
service_type=service_type,
|
||||
service_name=service_name,
|
||||
volume_service_name=volume_service_name,
|
||||
bypass_url=bypass_url,
|
||||
retries=options.retries,
|
||||
http_log_debug=args.debug,
|
||||
cacert=cacert, auth_system=os_auth_system,
|
||||
|
@ -71,6 +71,14 @@ def get_authed_client(retries=0):
|
||||
return cl
|
||||
|
||||
|
||||
def get_authed_bypass_url(retries=0):
|
||||
cl = client.HTTPClient("username", "password",
|
||||
"project_id", "auth_test",
|
||||
bypass_url="volume/v100/", retries=retries)
|
||||
cl.auth_token = "token"
|
||||
return cl
|
||||
|
||||
|
||||
class ClientTest(utils.TestCase):
|
||||
|
||||
def test_get(self):
|
||||
@ -223,6 +231,11 @@ class ClientTest(utils.TestCase):
|
||||
|
||||
test_post_call()
|
||||
|
||||
def test_bypass_url(self):
|
||||
cl = get_authed_bypass_url()
|
||||
self.assertEqual("volume/v100", cl.bypass_url)
|
||||
self.assertEqual("volume/v100", cl.management_url)
|
||||
|
||||
def test_auth_failure(self):
|
||||
cl = get_client()
|
||||
|
||||
|
@ -49,7 +49,8 @@ class Client(object):
|
||||
proxy_tenant_id=None, proxy_token=None, region_name=None,
|
||||
endpoint_type='publicURL', extensions=None,
|
||||
service_type='volume', service_name=None,
|
||||
volume_service_name=None, retries=None, http_log_debug=False,
|
||||
volume_service_name=None, bypass_url=None,
|
||||
retries=None, http_log_debug=False,
|
||||
cacert=None, auth_system='keystone', auth_plugin=None,
|
||||
session=None, **kwargs):
|
||||
# FIXME(comstud): Rename the api_key argument above when we
|
||||
@ -95,6 +96,7 @@ class Client(object):
|
||||
service_type=service_type,
|
||||
service_name=service_name,
|
||||
volume_service_name=volume_service_name,
|
||||
bypass_url=bypass_url,
|
||||
retries=retries,
|
||||
http_log_debug=http_log_debug,
|
||||
cacert=cacert,
|
||||
|
@ -49,9 +49,9 @@ class Client(object):
|
||||
proxy_tenant_id=None, proxy_token=None, region_name=None,
|
||||
endpoint_type='publicURL', extensions=None,
|
||||
service_type='volumev2', service_name=None,
|
||||
volume_service_name=None, retries=None, http_log_debug=False,
|
||||
cacert=None, auth_system='keystone', auth_plugin=None,
|
||||
session=None, **kwargs):
|
||||
volume_service_name=None, bypass_url=None, retries=None,
|
||||
http_log_debug=False, cacert=None, auth_system='keystone',
|
||||
auth_plugin=None, session=None, **kwargs):
|
||||
# FIXME(comstud): Rename the api_key argument above when we
|
||||
# know it's not being used as keyword argument
|
||||
password = api_key
|
||||
@ -98,6 +98,7 @@ class Client(object):
|
||||
service_type=service_type,
|
||||
service_name=service_name,
|
||||
volume_service_name=volume_service_name,
|
||||
bypass_url=bypass_url,
|
||||
retries=retries,
|
||||
http_log_debug=http_log_debug,
|
||||
cacert=cacert,
|
||||
|
Loading…
x
Reference in New Issue
Block a user