From 1cb7abd3bee50f6161ee1139e6f36b0fbd14db63 Mon Sep 17 00:00:00 2001 From: Yohei Matsuhashi Date: Wed, 30 Oct 2013 21:54:32 +0900 Subject: [PATCH] Enable to select specific network service type Network service type is selected as 'network' statically. This will select the service_type from environment variables or CLI options. The option works like the service type option in the novaclient. Implements blueprint specify-service-type Change-Id: If21bd2b5cb35da5bcabca79aa0567870331a3a6f --- neutronclient/client.py | 3 +++ neutronclient/common/clientmanager.py | 3 +++ neutronclient/shell.py | 6 ++++++ neutronclient/tests/unit/test_ssl.py | 2 ++ neutronclient/v2_0/client.py | 2 ++ 5 files changed, 16 insertions(+) diff --git a/neutronclient/client.py b/neutronclient/client.py index 3a153b0..49db9c6 100644 --- a/neutronclient/client.py +++ b/neutronclient/client.py @@ -99,6 +99,7 @@ class HTTPClient(httplib2.Http): endpoint_url=None, insecure=False, endpoint_type='publicURL', auth_strategy='keystone', ca_cert=None, log_credentials=False, + service_type='network', **kwargs): super(HTTPClient, self).__init__(timeout=timeout, ca_certs=ca_cert) @@ -107,6 +108,7 @@ class HTTPClient(httplib2.Http): self.tenant_id = tenant_id self.password = password self.auth_url = auth_url.rstrip('/') if auth_url else None + self.service_type = service_type self.endpoint_type = endpoint_type self.region_name = region_name self.auth_token = token @@ -212,6 +214,7 @@ class HTTPClient(httplib2.Http): if not self.endpoint_url: self.endpoint_url = self.service_catalog.url_for( attr='region', filter_value=self.region_name, + service_type=self.service_type, endpoint_type=self.endpoint_type) def authenticate(self): diff --git a/neutronclient/common/clientmanager.py b/neutronclient/common/clientmanager.py index 62cc129..b36d21e 100644 --- a/neutronclient/common/clientmanager.py +++ b/neutronclient/common/clientmanager.py @@ -60,10 +60,12 @@ class ClientManager(object): insecure=False, ca_cert=None, log_credentials=False, + service_type=None, ): self._token = token self._url = url self._auth_url = auth_url + self._service_type = service_type self._endpoint_type = endpoint_type self._tenant_name = tenant_name self._tenant_id = tenant_id @@ -87,6 +89,7 @@ class ClientManager(object): password=self._password, region_name=self._region_name, auth_url=self._auth_url, + service_type=self._service_type, endpoint_type=self._endpoint_type, insecure=self._insecure, ca_cert=self._ca_cert, diff --git a/neutronclient/shell.py b/neutronclient/shell.py index 9718604..91e3e8a 100644 --- a/neutronclient/shell.py +++ b/neutronclient/shell.py @@ -414,6 +414,11 @@ class NeutronShell(app.App): '--os_token', help=argparse.SUPPRESS) + parser.add_argument( + '--service-type', metavar='', + default=env('OS_NETWORK_SERVICE_TYPE', default='network'), + help=_('Defaults to env[OS_NETWORK_SERVICE_TYPE] or network.')) + parser.add_argument( '--endpoint-type', metavar='', default=env('OS_ENDPOINT_TYPE', default='publicURL'), @@ -605,6 +610,7 @@ class NeutronShell(app.App): region_name=self.options.os_region_name, api_version=self.api_version, auth_strategy=self.options.os_auth_strategy, + service_type=self.options.service_type, endpoint_type=self.options.endpoint_type, insecure=self.options.insecure, ca_cert=self.options.os_cacert, diff --git a/neutronclient/tests/unit/test_ssl.py b/neutronclient/tests/unit/test_ssl.py index 0fefb78..9f3970d 100644 --- a/neutronclient/tests/unit/test_ssl.py +++ b/neutronclient/tests/unit/test_ssl.py @@ -51,6 +51,7 @@ class TestSSL(testtools.TestCase): api_version=mox.IgnoreArg(), auth_strategy=mox.IgnoreArg(), auth_url=mox.IgnoreArg(), + service_type=mox.IgnoreArg(), endpoint_type=mox.IgnoreArg(), insecure=mox.IgnoreArg(), password=mox.IgnoreArg(), @@ -80,6 +81,7 @@ class TestSSL(testtools.TestCase): api_version=mox.IgnoreArg(), auth_strategy=mox.IgnoreArg(), auth_url=mox.IgnoreArg(), + service_type=mox.IgnoreArg(), endpoint_type=mox.IgnoreArg(), insecure=mox.IgnoreArg(), password=mox.IgnoreArg(), diff --git a/neutronclient/v2_0/client.py b/neutronclient/v2_0/client.py index 99ff6e2..c4e888f 100644 --- a/neutronclient/v2_0/client.py +++ b/neutronclient/v2_0/client.py @@ -123,6 +123,8 @@ class Client(object): :param string tenant_name: Tenant name. (optional) :param string tenant_id: Tenant id. (optional) :param string auth_url: Keystone service endpoint for authorization. + :param string service_type: Network service type to pull from the + keystone catalog (e.g. 'network') (optional) :param string endpoint_type: Network service endpoint type to pull from the keystone catalog (e.g. 'publicURL', 'internalURL', or 'adminURL') (optional)