From 8b6d55ff01bc73df0ff8355d9db73762222c00b5 Mon Sep 17 00:00:00 2001 From: Kengo Takahara Date: Fri, 20 Apr 2018 16:39:22 +0900 Subject: [PATCH] Add --os-interface and --os-region-name options Added --os-region-name option so that operator can run masakari commands against multiple regions. By default, keystoneauth always tries to connect to the 'public' interface of endpoint so added --os-interface option as well as in most cases, operator will configure only "internal" interface. Co-Author: tpatil Change-Id: I7194ed62d3df9760af61a505a43239097549f3d2 Closes-Bug: #1764931 --- masakariclient/cliargs.py | 11 ++++++++ masakariclient/plugin.py | 7 +++--- masakariclient/shell.py | 2 ++ masakariclient/tests/unit/test_cliargs.py | 4 ++- masakariclient/tests/unit/v1/test_client.py | 10 ++++++-- masakariclient/v1/client.py | 5 +++- .../notes/bug-1764931-889d9fe4cfb80b01.yaml | 10 ++++++++ releasenotes/source/conf.py | 25 ++++++++++--------- tox.ini | 2 +- 9 files changed, 56 insertions(+), 20 deletions(-) create mode 100644 releasenotes/notes/bug-1764931-889d9fe4cfb80b01.yaml diff --git a/masakariclient/cliargs.py b/masakariclient/cliargs.py index e6666ef..9cea2cb 100644 --- a/masakariclient/cliargs.py +++ b/masakariclient/cliargs.py @@ -158,3 +158,14 @@ def add_global_identity_args(parser): '--os-access-info', dest='access_info', metavar='ACCESS_INFO', default=utils.env('OS_ACCESS_INFO'), help=_('Access info, defaults to env[OS_ACCESS_INFO]')) + + parser.add_argument( + '--os-interface', dest='interface', metavar='INTERFACE', + default=utils.env('OS_INTERFACE', default='internal'), + help=_('API Interface to use [public, internal, admin]' + ', defaults to env[OS_INTERFACE]')) + + parser.add_argument( + '--os-region-name', dest='region_name', metavar='REGION_NAME', + default=utils.env('OS_REGION_NAME'), + help=_('Region of the cloud to use, defaults to env[OS_REGION_NAME]')) diff --git a/masakariclient/plugin.py b/masakariclient/plugin.py index 2d1b06d..794ab47 100644 --- a/masakariclient/plugin.py +++ b/masakariclient/plugin.py @@ -18,12 +18,13 @@ from osc_lib import utils DEFAULT_HA_API_VERSION = '1' API_VERSION_OPTION = 'os_ha_api_version' -API_NAME = 'ha' def make_client(instance): - """Returns a ha proxy""" - conn = connection.Connection(session=instance.session) + """Returns a instance_ha proxy""" + conn = connection.Connection(session=instance.session, + interface=instance.interface, + region_name=instance.region_name) return conn.instance_ha diff --git a/masakariclient/shell.py b/masakariclient/shell.py index fef890c..f0e55c5 100644 --- a/masakariclient/shell.py +++ b/masakariclient/shell.py @@ -111,6 +111,8 @@ class MasakariShell(object): 'verify': args.verify, 'token': args.token, 'trust_id': args.trust_id, + 'interface': args.interface, + 'region_name': args.region_name, } return masakari_client.Client(api_ver, user_agent=USER_AGENT, **kwargs) diff --git a/masakariclient/tests/unit/test_cliargs.py b/masakariclient/tests/unit/test_cliargs.py index 38ff0e5..d5648e4 100644 --- a/masakariclient/tests/unit/test_cliargs.py +++ b/masakariclient/tests/unit/test_cliargs.py @@ -41,7 +41,9 @@ class TestCliArgs(testtools.TestCase): '--os-password', '--os-trust-id', '--os-token', - '--os-access-info' + '--os-access-info', + '--os-interface', + '--os-region-name' ] options = [arg[0][0] for arg in parser.add_argument.call_args_list] diff --git a/masakariclient/tests/unit/v1/test_client.py b/masakariclient/tests/unit/v1/test_client.py index 5cd5158..7d94368 100644 --- a/masakariclient/tests/unit/v1/test_client.py +++ b/masakariclient/tests/unit/v1/test_client.py @@ -59,13 +59,17 @@ class TestV1Client(base.TestCase): fake_user_domain_id = 'fake_user_domain_id' fake_project_name = 'fake_project_name' fake_project_domain_id = 'fake_project_domain_id' + fake_interface = 'fake_interface' + fake_region_name = 'fake_region_name' res = mc.Client(auth_url=fake_auth_url, username=fake_username, password=fake_password, user_domain_id=fake_user_domain_id, project_name=fake_project_name, - project_domain_id=fake_project_domain_id) + project_domain_id=fake_project_domain_id, + interface=fake_interface, + region_name=fake_region_name) self.assertEqual(self.conn.instance_ha, res.service) mock_password.assert_called_once_with( @@ -76,4 +80,6 @@ class TestV1Client(base.TestCase): project_name=fake_project_name, project_domain_id=fake_project_domain_id) mock_session.assert_called_once_with(auth=self.auth) - mock_connection.assert_called_once_with(session=self.session) + mock_connection.assert_called_once_with( + session=self.session, interface=fake_interface, + region_name=fake_region_name) diff --git a/masakariclient/v1/client.py b/masakariclient/v1/client.py index 5a36420..559893a 100644 --- a/masakariclient/v1/client.py +++ b/masakariclient/v1/client.py @@ -30,5 +30,8 @@ class Client(object): project_domain_id=kwargs.get('project_domain_id')) session = ks_session.Session(auth=auth) - self.con = connection.Connection(session=session) + self.con = connection.Connection( + session=session, + interface=kwargs.get('interface'), + region_name=kwargs.get('region_name')) self.service = self.con.instance_ha diff --git a/releasenotes/notes/bug-1764931-889d9fe4cfb80b01.yaml b/releasenotes/notes/bug-1764931-889d9fe4cfb80b01.yaml new file mode 100644 index 0000000..8afced8 --- /dev/null +++ b/releasenotes/notes/bug-1764931-889d9fe4cfb80b01.yaml @@ -0,0 +1,10 @@ +--- +features: + - | + Added ``--os-region-name`` and ``--os-interface`` options to select which + endpoint it should use to connect to the masakari service. + If masakari services are running in multiple regions of your cloud, + you can specify `--os-region-name` in order to get OpenStack service + client for the specified region. By default, keystoneauth always selects + `public` interface endpoint from the service catalog. Now you can also + specify `admin` or `internal` in the --os-interface option. diff --git a/releasenotes/source/conf.py b/releasenotes/source/conf.py index ab81cd0..775a9ba 100644 --- a/releasenotes/source/conf.py +++ b/releasenotes/source/conf.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Glance Release Notes documentation build configuration file, created by +# Masakari Release Notes documentation build configuration file, created by # sphinx-quickstart on Tue Nov 3 17:40:50 2015. # # This file is execfile()d with the current directory set to its @@ -55,7 +55,7 @@ source_suffix = '.rst' master_doc = 'index' # General information about the project. -project = u'masakariclient Release Notes' +project = u'PythonMasakariClient Release Notes' copyright = u'2016, OpenStack Foundation' # The version info for the project you're documenting, acts as replacement for @@ -189,7 +189,7 @@ html_static_path = ['_static'] # html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'GlanceReleaseNotesdoc' +htmlhelp_basename = 'MasakariClientReleaseNotesdoc' # -- Options for LaTeX output --------------------------------------------- @@ -209,8 +209,9 @@ latex_elements = { # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - ('index', 'GlanceReleaseNotes.tex', u'Glance Release Notes Documentation', - u'Glance Developers', 'manual'), + ('index', 'MasakariClientReleaseNotes.tex', + u'MasakariClient Release Notes Documentation', + u'MasakariClient Developers', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -239,8 +240,9 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'glancereleasenotes', u'Glance Release Notes Documentation', - [u'Glance Developers'], 1) + ('index', 'MasakariClientreleasenotes', + u'MasakariClient Release Notes Documentation', + [u'MasakariClient Developers'], 1) ] # If true, show URL addresses after external links. @@ -253,12 +255,11 @@ man_pages = [ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'GlanceReleaseNotes', u'Glance Release Notes Documentation', - u'Glance Developers', 'GlanceReleaseNotes', - 'One line description of project.', - 'Miscellaneous'), + ('index', 'PythonMasakariClient', + u'PythonMasakariClient Release Notes Documentation', + u'Masakari developers', 'PythonMasakariClient', + 'One line description of project.', 'Miscellaneous') ] - # Documents to append as an appendix to all manuals. # texinfo_appendices = [] diff --git a/tox.ini b/tox.ini index 2ccf99e..e7d76ed 100644 --- a/tox.ini +++ b/tox.ini @@ -34,7 +34,7 @@ commands = ostestr '{posargs}' [testenv:pep8] -basepython = python3 +#basepython = python3 commands = flake8 {posargs} [testenv:venv]