Make better names for Client and APIClient classes
Rename Client and APIClient classes, so new names better represent their purpose. * Rename "Client" to "APIClient" * Rename "APIClient" to "DefaultAPIClient" Change-Id: Ifa208b27ba4039e3a71830a567c9199a6ed8b7b5 Related-Bug: #1454347
This commit is contained in:
parent
05055066c1
commit
c9402da0ea
|
@ -31,7 +31,7 @@ def connect(host, port, http_proxy=None, os_username=None, os_password=None,
|
|||
"""Creates API connection."""
|
||||
from fuelclient import client
|
||||
|
||||
return client.Client(
|
||||
return client.APIClient(
|
||||
host, port, http_proxy=http_proxy, os_username=os_username,
|
||||
os_password=os_password, os_tenant_name=os_tenant_name, debug=debug)
|
||||
|
||||
|
@ -51,7 +51,7 @@ def get_client(resource, version='v1', connection=None):
|
|||
:type version: str,
|
||||
Available: v1. Default: v1.
|
||||
:param connection: API connection
|
||||
:type connection: fuelclient.client.Client
|
||||
:type connection: fuelclient.client.APIClient
|
||||
:return: Facade to the specified resource that wraps
|
||||
calls to the specified version of the API.
|
||||
|
||||
|
|
|
@ -26,6 +26,6 @@ class FuelVersionAction(argparse._VersionAction):
|
|||
"""
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
serializer = serializers.Serializer.from_params(namespace)
|
||||
version = client.APIClient.get_fuel_version()
|
||||
version = client.DefaultAPIClient.get_fuel_version()
|
||||
print(serializer.serialize(version))
|
||||
sys.exit(0)
|
||||
|
|
|
@ -21,7 +21,7 @@ import six
|
|||
from fuelclient.cli import error
|
||||
from fuelclient.cli.formatting import quote_and_join
|
||||
from fuelclient.cli.serializers import Serializer
|
||||
from fuelclient.client import APIClient
|
||||
from fuelclient.client import DefaultAPIClient
|
||||
|
||||
|
||||
class Action(object):
|
||||
|
@ -47,7 +47,7 @@ class Action(object):
|
|||
def action_func(self, params):
|
||||
"""Entry point for all actions subclasses
|
||||
"""
|
||||
APIClient.debug_mode(debug=params.debug)
|
||||
DefaultAPIClient.debug_mode(debug=params.debug)
|
||||
|
||||
self.serializer = Serializer.from_params(params)
|
||||
if self.flag_func_map is not None:
|
||||
|
|
|
@ -20,7 +20,7 @@ import yaml
|
|||
from fuelclient.cli.actions.base import Action
|
||||
import fuelclient.cli.arguments as Args
|
||||
from fuelclient.cli.formatting import download_snapshot_with_progress_bar
|
||||
from fuelclient.client import APIClient
|
||||
from fuelclient.client import DefaultAPIClient
|
||||
from fuelclient.objects.task import SnapshotTask
|
||||
|
||||
|
||||
|
@ -67,7 +67,7 @@ class SnapshotAction(Action):
|
|||
if snapshot_task.status == 'ready':
|
||||
download_snapshot_with_progress_bar(
|
||||
snapshot_task.connection.root + snapshot_task.data["message"],
|
||||
auth_token=APIClient.auth_token,
|
||||
auth_token=DefaultAPIClient.auth_token,
|
||||
directory=params.dir
|
||||
)
|
||||
elif snapshot_task.status == 'error':
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
import sys
|
||||
|
||||
from fuelclient.cli.actions.base import Action
|
||||
from fuelclient.client import APIClient
|
||||
from fuelclient.client import DefaultAPIClient
|
||||
|
||||
|
||||
class TokenAction(Action):
|
||||
|
@ -34,4 +34,4 @@ class TokenAction(Action):
|
|||
def get_token(self, params):
|
||||
"""Print out a valid Keystone auth token
|
||||
"""
|
||||
sys.stdout.write(APIClient.auth_token)
|
||||
sys.stdout.write(DefaultAPIClient.auth_token)
|
||||
|
|
|
@ -17,7 +17,7 @@ from getpass import getpass
|
|||
from fuelclient.cli.actions.base import Action
|
||||
import fuelclient.cli.arguments as Args
|
||||
from fuelclient.cli.error import ArgumentException
|
||||
from fuelclient.client import APIClient
|
||||
from fuelclient.client import DefaultAPIClient
|
||||
from fuelclient import fuelclient_settings
|
||||
|
||||
|
||||
|
@ -56,7 +56,7 @@ class UserAction(Action):
|
|||
else:
|
||||
password = self._get_password_from_prompt()
|
||||
|
||||
APIClient.update_own_password(password)
|
||||
DefaultAPIClient.update_own_password(password)
|
||||
settings = fuelclient_settings.get_settings()
|
||||
self.serializer.print_to_output(
|
||||
None, "\nPassword changed.\nPlease note that configuration "
|
||||
|
|
|
@ -19,7 +19,7 @@ import os
|
|||
from fuelclient import __version__
|
||||
from fuelclient.actions import fuel_version
|
||||
from fuelclient.cli.error import ArgumentException
|
||||
from fuelclient.client import APIClient
|
||||
from fuelclient.client import DefaultAPIClient
|
||||
|
||||
substitutions = {
|
||||
# replace from: to
|
||||
|
@ -78,7 +78,7 @@ class NodeAction(argparse.Action):
|
|||
if input_macs:
|
||||
nodes_mac_to_id_map = dict(
|
||||
(n["mac"], n["id"])
|
||||
for n in APIClient.get_request("nodes/")
|
||||
for n in DefaultAPIClient.get_request("nodes/")
|
||||
)
|
||||
for short_mac in input_macs:
|
||||
target_node = None
|
||||
|
|
|
@ -113,7 +113,7 @@ class EnvironmentException(Exception):
|
|||
|
||||
def exceptions_decorator(func):
|
||||
"""Handles HTTP errors and expected exceptions that may occur
|
||||
in methods of APIClient class
|
||||
in methods of DefaultAPIClient class
|
||||
"""
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
|
|
|
@ -196,7 +196,7 @@ class Parser(object):
|
|||
|
||||
def move_argument_before_action(self, flag, has_value=True):
|
||||
"""We need to move general argument before action, we use them
|
||||
not directly in action but in APIClient.
|
||||
not directly in action but in DefaultAPIClient.
|
||||
"""
|
||||
for arg in self.args:
|
||||
if flag in arg:
|
||||
|
|
|
@ -30,7 +30,7 @@ logger = logging.getLogger()
|
|||
logger.addHandler(NullHandler())
|
||||
|
||||
|
||||
class Client(object):
|
||||
class APIClient(object):
|
||||
"""This class handles API requests
|
||||
"""
|
||||
|
||||
|
@ -241,9 +241,9 @@ class Client(object):
|
|||
except requests.exceptions.HTTPError as e:
|
||||
raise error.HTTPError(error.get_full_error_message(e))
|
||||
|
||||
# This line is single point of instantiation for 'Client' class,
|
||||
# This line is single point of instantiation for 'APIClient' class,
|
||||
# which intended to implement Singleton design pattern.
|
||||
APIClient = Client.default_client()
|
||||
DefaultAPIClient = APIClient.default_client()
|
||||
"""
|
||||
.. deprecated:: Use fuelclient.client.Client instead
|
||||
.. deprecated:: Use fuelclient.client.APIClient instead
|
||||
"""
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# under the License.
|
||||
|
||||
from fuelclient.cli.serializers import Serializer
|
||||
from fuelclient.client import APIClient
|
||||
from fuelclient.client import DefaultAPIClient
|
||||
|
||||
|
||||
class BaseObject(object):
|
||||
|
@ -22,14 +22,14 @@ class BaseObject(object):
|
|||
'class_api_path' - url path to object handler on Nailgun server.
|
||||
'instance_api_path' - url path template which formatted with object id
|
||||
returns only one serialized object.
|
||||
'connection' - 'Client' class instance from fuelclient.client
|
||||
'connection' - 'APIClient' class instance from fuelclient.client
|
||||
"""
|
||||
class_api_path = None
|
||||
instance_api_path = None
|
||||
connection = APIClient
|
||||
connection = DefaultAPIClient
|
||||
|
||||
def __init__(self, obj_id, **kwargs):
|
||||
self.connection = APIClient
|
||||
self.connection = DefaultAPIClient
|
||||
self.serializer = Serializer.from_params(kwargs.get('params'))
|
||||
self.id = obj_id
|
||||
self._data = None
|
||||
|
|
|
@ -239,4 +239,4 @@ class TestUtils(base.UnitTestCase):
|
|||
|
||||
with self.assertRaisesRegexp(error.HTTPError,
|
||||
'403.*{}'.format(text)):
|
||||
client.APIClient.post_request('address')
|
||||
client.DefaultAPIClient.post_request('address')
|
||||
|
|
|
@ -42,7 +42,7 @@ class UnitTestCase(oslo_base.BaseTestCase):
|
|||
super(UnitTestCase, self).setUp()
|
||||
|
||||
self.auth_required_patcher = mock.patch('fuelclient.client.'
|
||||
'Client.auth_required',
|
||||
'APIClient.auth_required',
|
||||
new_callable=mock.PropertyMock)
|
||||
|
||||
self.auth_required_mock = self.auth_required_patcher.start()
|
||||
|
|
|
@ -77,7 +77,7 @@ class ClientPerfTest(base.UnitTestCase):
|
|||
def setUp(self):
|
||||
super(ClientPerfTest, self).setUp()
|
||||
|
||||
token_patcher = mock.patch.object(client.Client, 'auth_token',
|
||||
token_patcher = mock.patch.object(client.APIClient, 'auth_token',
|
||||
new_callable=mock.PropertyMock)
|
||||
self.mock_auth_token = token_patcher.start()
|
||||
self.addCleanup(self.mock_auth_token.stop)
|
||||
|
|
|
@ -37,7 +37,7 @@ class TestSnapshot(base.UnitTestCase):
|
|||
self.execute(['fuel', 'snapshot', '--conf'])
|
||||
self.assertEqual(mstdout.write.call_args_list, [call('key: value\n')])
|
||||
|
||||
@patch('fuelclient.cli.actions.snapshot.APIClient',
|
||||
@patch('fuelclient.cli.actions.snapshot.DefaultAPIClient',
|
||||
mock.Mock(auth_token='token123'))
|
||||
@patch('fuelclient.cli.actions.snapshot.SnapshotTask.start_snapshot_task')
|
||||
@patch('fuelclient.cli.actions.snapshot.'
|
||||
|
@ -61,7 +61,7 @@ class TestSnapshot(base.UnitTestCase):
|
|||
auth_token='token123',
|
||||
directory='.')
|
||||
|
||||
@patch('fuelclient.cli.actions.snapshot.APIClient',
|
||||
@patch('fuelclient.cli.actions.snapshot.DefaultAPIClient',
|
||||
mock.Mock(auth_token='token123'))
|
||||
@patch('fuelclient.cli.actions.snapshot.SnapshotTask.start_snapshot_task')
|
||||
@patch('fuelclient.cli.actions.snapshot.'
|
||||
|
|
|
@ -23,7 +23,7 @@ from fuelclient.tests.unit.v1 import base
|
|||
|
||||
class TestPluginsActions(base.UnitTestCase):
|
||||
|
||||
@mock.patch('fuelclient.cli.actions.token.APIClient')
|
||||
@mock.patch('fuelclient.cli.actions.token.DefaultAPIClient')
|
||||
def test_token_action(self, mAPIClient):
|
||||
with mock.patch('sys.stdout', new=io.StringIO()) as mstdout:
|
||||
token = u'token123'
|
||||
|
|
|
@ -43,7 +43,7 @@ class TestChangePassword(base.UnitTestCase):
|
|||
|
||||
@mock.patch('fuelclient.cli.serializers.Serializer.print_to_output')
|
||||
@mock.patch('fuelclient.cli.actions.user.fuelclient_settings')
|
||||
@mock.patch('fuelclient.cli.actions.user.APIClient')
|
||||
@mock.patch('fuelclient.cli.actions.user.DefaultAPIClient')
|
||||
def test_change_password(self, mapiclient, settings_mock, print_mock):
|
||||
user_action = UserAction()
|
||||
params = mock.Mock()
|
||||
|
@ -74,7 +74,7 @@ class TestChangePassword(base.UnitTestCase):
|
|||
None,
|
||||
msg)
|
||||
|
||||
@mock.patch('fuelclient.cli.actions.user.APIClient')
|
||||
@mock.patch('fuelclient.cli.actions.user.DefaultAPIClient')
|
||||
def test_change_password_w_newpass(self, mapiclient):
|
||||
user_action = UserAction()
|
||||
params = mock.Mock()
|
||||
|
|
|
@ -30,7 +30,7 @@ class BaseLibTest(oslo_base.BaseTestCase):
|
|||
self.m_request = rm.Mocker()
|
||||
self.m_request.start()
|
||||
|
||||
self.auth_required_patch = patch.object(client.Client,
|
||||
self.auth_required_patch = patch.object(client.APIClient,
|
||||
'auth_required',
|
||||
new_callable=mock.PropertyMock)
|
||||
self.m_auth_required = self.auth_required_patch.start()
|
||||
|
|
|
@ -28,7 +28,7 @@ class BaseV1Client(object):
|
|||
|
||||
def __init__(self, connection=None):
|
||||
if connection is None:
|
||||
connection = client.APIClient
|
||||
connection = client.DefaultAPIClient
|
||||
self.connection = connection
|
||||
|
||||
cls_wrapper = self.__class__._entity_wrapper
|
||||
|
|
Loading…
Reference in New Issue