diff --git a/.zuul.yaml b/.zuul.yaml index 30a456719..1309cc7b0 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -220,6 +220,7 @@ - project: name: openstack/python-openstacksdk templates: + - openstack-pypy-jobs - openstacksdk-functional-tips - openstacksdk-tox-tips check: diff --git a/doc/source/contributor/layout.rst b/doc/source/contributor/layout.rst index c221bc793..2c9d70395 100644 --- a/doc/source/contributor/layout.rst +++ b/doc/source/contributor/layout.rst @@ -5,15 +5,6 @@ The following diagram shows how the project is laid out. .. literalinclude:: layout.txt -Session -------- - -The :class:`openstack.session.Session` manages an authenticator, -transport, and user profile. It exposes methods corresponding to -HTTP verbs, and injects your authentication token into a request, -determines any service preferences callers may have set, gets the endpoint -from the authenticator, and sends the request out through the transport. - Resource -------- @@ -26,7 +17,7 @@ service's ``https://openstack:1234/v2/servers`` resource. The base ``Resource`` contains methods to support the typical `CRUD `_ operations supported by REST APIs, and handles the construction of URLs -and calling the appropriate HTTP verb on the given ``Session``. +and calling the appropriate HTTP verb on the given ``Adapter``. Values sent to or returned from the service are implemented as attributes on the ``Resource`` subclass with type :class:`openstack.resource.prop`. @@ -63,10 +54,10 @@ Each service implements a ``Proxy`` class, within the ``openstack//vX/_proxy.py`` module. For example, the v2 compute service's ``Proxy`` exists in ``openstack/compute/v2/_proxy.py``. -This ``Proxy`` class manages a :class:`~openstack.sessions.Session` and +This ``Proxy`` class contains a :class:`~keystoneauth1.adapter.Adapter` and provides a higher-level interface for users to work with via a :class:`~openstack.connection.Connection` instance. Rather than requiring -users to maintain their own session and work with lower-level +users to maintain their own ``Adapter`` and work with lower-level :class:`~openstack.resource.Resource` objects, the ``Proxy`` interface offers a place to make things easier for the caller. @@ -77,7 +68,7 @@ Each ``Proxy`` class implements methods which act on the underlying return flavor.Flavor.list(self.session, **params) This method is operating on the ``openstack.compute.v2.flavor.Flavor.list`` -method. For the time being, it simply passes on the ``Session`` maintained +method. For the time being, it simply passes on the ``Adapter`` maintained by the ``Proxy``, and returns what the underlying ``Resource.list`` method does. @@ -88,9 +79,9 @@ way which will apply nicely across all of the services. Connection ---------- -The :class:`openstack.connection.Connection` class builds atop a ``Session`` -object, and provides a higher level interface constructed of ``Proxy`` -objects from each of the services. +The :class:`openstack.connection.Connection` class builds atop a +:class:`os_client_config.config.CloudConfig` object, and provides a higher +level interface constructed of ``Proxy`` objects from each of the services. The ``Connection`` class' primary purpose is to act as a high-level interface to this SDK, managing the lower level connecton bits and exposing the diff --git a/doc/source/contributor/layout.txt b/doc/source/contributor/layout.txt index 2dd7121d5..eeffbac87 100644 --- a/doc/source/contributor/layout.txt +++ b/doc/source/contributor/layout.txt @@ -1,7 +1,6 @@ openstack/ connection.py resource.py - session.py compute/ compute_service.py v2/ diff --git a/doc/source/enforcer.py b/doc/source/enforcer.py index 04bea4335..ff705e9f3 100644 --- a/doc/source/enforcer.py +++ b/doc/source/enforcer.py @@ -26,9 +26,9 @@ class EnforcementError(errors.SphinxError): def get_proxy_methods(): """Return a set of public names on all proxies""" - names = ["openstack.bare_metal.v1._proxy", - "openstack.block_store.v2._proxy", - "openstack.cluster.v1._proxy", + names = ["openstack.baremetal.v1._proxy", + "openstack.clustering.v1._proxy", + "openstack.block_storage.v2._proxy", "openstack.compute.v2._proxy", "openstack.database.v1._proxy", "openstack.identity.v2._proxy", @@ -43,8 +43,8 @@ def get_proxy_methods(): "openstack.network.v2._proxy", "openstack.object_store.v1._proxy", "openstack.orchestration.v1._proxy", - "openstack.telemetry.v2._proxy", - "openstack.telemetry.alarm.v2._proxy", + "openstack.meter.v2._proxy", + "openstack.meter.alarm.v2._proxy", "openstack.workflow.v2._proxy"] modules = (importlib.import_module(name) for name in names) diff --git a/doc/source/user/config/configuration.rst b/doc/source/user/config/configuration.rst index df0b26659..0282cf219 100644 --- a/doc/source/user/config/configuration.rst +++ b/doc/source/user/config/configuration.rst @@ -2,6 +2,8 @@ Configuring os-client-config Applications =========================================== +.. _config-environment-variables: + Environment Variables --------------------- @@ -22,6 +24,8 @@ for trove set export OS_DATABASE_SERVICE_TYPE=rax:database +.. _config-clouds-yaml: + Config Files ------------ diff --git a/doc/source/users/guides/bare_metal.rst b/doc/source/users/guides/baremetal.rst similarity index 70% rename from doc/source/users/guides/bare_metal.rst rename to doc/source/users/guides/baremetal.rst index 10e96561c..81421ea99 100644 --- a/doc/source/users/guides/bare_metal.rst +++ b/doc/source/users/guides/baremetal.rst @@ -1,7 +1,7 @@ -Using OpenStack Bare Metal +Using OpenStack Baremetal =========================== -Before working with the Bare Metal service, you'll need to create a +Before working with the Baremetal service, you'll need to create a connection to your OpenStack cloud by following the :doc:`connect` user guide. This will provide you with the ``conn`` variable used in the examples below. diff --git a/doc/source/users/guides/block_store.rst b/doc/source/users/guides/block_storage.rst similarity index 59% rename from doc/source/users/guides/block_store.rst rename to doc/source/users/guides/block_storage.rst index bb67a4eed..8f2661d09 100644 --- a/doc/source/users/guides/block_store.rst +++ b/doc/source/users/guides/block_storage.rst @@ -1,7 +1,7 @@ -Using OpenStack Block Store -=========================== +Using OpenStack Block Storage +============================= -Before working with the Block Store service, you'll need to create a +Before working with the Block Storage service, you'll need to create a connection to your OpenStack cloud by following the :doc:`connect` user guide. This will provide you with the ``conn`` variable used in the examples below. diff --git a/doc/source/users/guides/cluster.rst b/doc/source/users/guides/cluster.rst deleted file mode 100644 index d0a0474b8..000000000 --- a/doc/source/users/guides/cluster.rst +++ /dev/null @@ -1,36 +0,0 @@ -.. - Licensed under the Apache License, Version 2.0 (the "License"); you may - not use this file except in compliance with the License. You may obtain - a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - License for the specific language governing permissions and limitations - under the License. - - -======================= -Using OpenStack Cluster -======================= - -Before working with the Cluster service, you'll need to create a connection -to your OpenStack cloud by following the :doc:`connect` user guide. This will -provide you with the ``conn`` variable used by all examples in this guide. - -The primary abstractions/resources of the Cluster service are: - -.. toctree:: - :maxdepth: 1 - - Profile Type - Profile - Cluster - Node - Policy Type - Policy - Receiver - Action - Event diff --git a/doc/source/users/guides/clustering.rst b/doc/source/users/guides/clustering.rst new file mode 100644 index 000000000..c0543fd5b --- /dev/null +++ b/doc/source/users/guides/clustering.rst @@ -0,0 +1,37 @@ +.. + Licensed under the Apache License, Version 2.0 (the "License"); you may + not use this file except in compliance with the License. You may obtain + a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + License for the specific language governing permissions and limitations + under the License. + + +================================ +Using OpenStack Clustering +================================ + +Before working with the Clustering service, you'll need to create a +connection to your OpenStack cloud by following the :doc:`connect` user guide. +This will provide you with the ``conn`` variable used by all examples in this +guide. + +The primary abstractions/resources of the Clustering service are: + +.. toctree:: + :maxdepth: 1 + + Profile Type + Profile + Cluster + Node + Policy Type + Policy + Receiver + Action + Event diff --git a/doc/source/users/guides/cluster/action.rst b/doc/source/users/guides/clustering/action.rst similarity index 100% rename from doc/source/users/guides/cluster/action.rst rename to doc/source/users/guides/clustering/action.rst diff --git a/doc/source/users/guides/cluster/cluster.rst b/doc/source/users/guides/clustering/cluster.rst similarity index 100% rename from doc/source/users/guides/cluster/cluster.rst rename to doc/source/users/guides/clustering/cluster.rst diff --git a/doc/source/users/guides/cluster/event.rst b/doc/source/users/guides/clustering/event.rst similarity index 100% rename from doc/source/users/guides/cluster/event.rst rename to doc/source/users/guides/clustering/event.rst diff --git a/doc/source/users/guides/cluster/node.rst b/doc/source/users/guides/clustering/node.rst similarity index 100% rename from doc/source/users/guides/cluster/node.rst rename to doc/source/users/guides/clustering/node.rst diff --git a/doc/source/users/guides/cluster/policy.rst b/doc/source/users/guides/clustering/policy.rst similarity index 86% rename from doc/source/users/guides/cluster/policy.rst rename to doc/source/users/guides/clustering/policy.rst index c0995840c..07a8de9e9 100644 --- a/doc/source/users/guides/cluster/policy.rst +++ b/doc/source/users/guides/clustering/policy.rst @@ -26,7 +26,7 @@ List Policies To examine the list of policies: -.. literalinclude:: ../../examples/cluster/policy.py +.. literalinclude:: ../../examples/clustering/policy.py :pyobject: list_policies When listing policies, you can specify the sorting option using the ``sort`` @@ -42,7 +42,7 @@ Create Policy When creating a policy, you will provide a dictionary with keys and values according to the policy type referenced. -.. literalinclude:: ../../examples/cluster/policy.py +.. literalinclude:: ../../examples/clustering/policy.py :pyobject: create_policy Optionally, you can specify a ``metadata`` keyword argument that contains some @@ -56,7 +56,7 @@ Find Policy To find a policy based on its name or ID: -.. literalinclude:: ../../examples/cluster/policy.py +.. literalinclude:: ../../examples/clustering/policy.py :pyobject: find_policy Full example: `manage policy`_ @@ -67,7 +67,7 @@ Get Policy To get a policy based on its name or ID: -.. literalinclude:: ../../examples/cluster/policy.py +.. literalinclude:: ../../examples/clustering/policy.py :pyobject: get_policy Full example: `manage policy`_ @@ -79,7 +79,7 @@ Update Policy After a policy is created, most of its properties are immutable. Still, you can update a policy's ``name`` and/or ``metadata``. -.. literalinclude:: ../../examples/cluster/policy.py +.. literalinclude:: ../../examples/clustering/policy.py :pyobject: update_policy The Cluster service doesn't allow updating the ``spec`` of a policy. The only @@ -95,8 +95,8 @@ A policy can be deleted after creation, provided that it is not referenced by any active clusters or nodes. If you attempt to delete a policy that is still in use, you will get an error message. -.. literalinclude:: ../../examples/cluster/policy.py +.. literalinclude:: ../../examples/clustering/policy.py :pyobject: delete_policy -.. _manage policy: http://git.openstack.org/cgit/openstack/python-openstacksdk/tree/examples/cluster/policy.py +.. _manage policy: http://git.openstack.org/cgit/openstack/python-openstacksdk/tree/examples/clustering/policy.py diff --git a/doc/source/users/guides/cluster/policy_type.rst b/doc/source/users/guides/clustering/policy_type.rst similarity index 87% rename from doc/source/users/guides/cluster/policy_type.rst rename to doc/source/users/guides/clustering/policy_type.rst index 346ed7838..ceea4aefe 100644 --- a/doc/source/users/guides/cluster/policy_type.rst +++ b/doc/source/users/guides/clustering/policy_type.rst @@ -25,7 +25,7 @@ List Policy Types To examine the known policy types: -.. literalinclude:: ../../examples/cluster/policy_type.py +.. literalinclude:: ../../examples/clustering/policy_type.py :pyobject: list_policy_types Full example: `manage policy type`_ @@ -37,9 +37,9 @@ Get Policy Type To retrieve the details about a policy type, you need to provide the name of it. -.. literalinclude:: ../../examples/cluster/policy_type.py +.. literalinclude:: ../../examples/clustering/policy_type.py :pyobject: get_policy_type Full example: `manage policy type`_ -.. _manage policy type: http://git.openstack.org/cgit/openstack/python-openstacksdk/tree/examples/cluster/policy_type.py +.. _manage policy type: http://git.openstack.org/cgit/openstack/python-openstacksdk/tree/examples/clustering/policy_type.py diff --git a/doc/source/users/guides/cluster/profile.rst b/doc/source/users/guides/clustering/profile.rst similarity index 86% rename from doc/source/users/guides/cluster/profile.rst rename to doc/source/users/guides/clustering/profile.rst index ad3f5e5be..1c8d7f96a 100644 --- a/doc/source/users/guides/cluster/profile.rst +++ b/doc/source/users/guides/clustering/profile.rst @@ -26,7 +26,7 @@ List Profiles To examine the list of profiles: -.. literalinclude:: ../../examples/cluster/profile.py +.. literalinclude:: ../../examples/clustering/profile.py :pyobject: list_profiles When listing profiles, you can specify the sorting option using the ``sort`` @@ -42,7 +42,7 @@ Create Profile When creating a profile, you will provide a dictionary with keys and values specified according to the profile type referenced. -.. literalinclude:: ../../examples/cluster/profile.py +.. literalinclude:: ../../examples/clustering/profile.py :pyobject: create_profile Optionally, you can specify a ``metadata`` keyword argument that contains some @@ -56,7 +56,7 @@ Find Profile To find a profile based on its name or ID: -.. literalinclude:: ../../examples/cluster/profile.py +.. literalinclude:: ../../examples/clustering/profile.py :pyobject: find_profile The Cluster service doesn't allow updating the ``spec`` of a profile. The only @@ -70,7 +70,7 @@ Get Profile To get a profile based on its name or ID: -.. literalinclude:: ../../examples/cluster/profile.py +.. literalinclude:: ../../examples/clustering/profile.py :pyobject: get_profile Full example: `manage profile`_ @@ -82,7 +82,7 @@ Update Profile After a profile is created, most of its properties are immutable. Still, you can update a profile's ``name`` and/or ``metadata``. -.. literalinclude:: ../../examples/cluster/profile.py +.. literalinclude:: ../../examples/clustering/profile.py :pyobject: update_profile The Cluster service doesn't allow updating the ``spec`` of a profile. The only @@ -98,8 +98,8 @@ A profile can be deleted after creation, provided that it is not referenced by any active clusters or nodes. If you attempt to delete a profile that is still in use, you will get an error message. -.. literalinclude:: ../../examples/cluster/profile.py +.. literalinclude:: ../../examples/clustering/profile.py :pyobject: delete_profile -.. _manage profile: http://git.openstack.org/cgit/openstack/python-openstacksdk/tree/examples/cluster/profile.py +.. _manage profile: http://git.openstack.org/cgit/openstack/python-openstacksdk/tree/examples/clustering/profile.py diff --git a/doc/source/users/guides/cluster/profile_type.rst b/doc/source/users/guides/clustering/profile_type.rst similarity index 86% rename from doc/source/users/guides/cluster/profile_type.rst rename to doc/source/users/guides/clustering/profile_type.rst index 45183bf0a..b8a3fae35 100644 --- a/doc/source/users/guides/cluster/profile_type.rst +++ b/doc/source/users/guides/clustering/profile_type.rst @@ -25,7 +25,7 @@ List Profile Types To examine the known profile types: -.. literalinclude:: ../../examples/cluster/profile_type.py +.. literalinclude:: ../../examples/clustering/profile_type.py :pyobject: list_profile_types Full example: `manage profile type`_ @@ -36,9 +36,9 @@ Get Profile Type To get the details about a profile type, you need to provide the name of it. -.. literalinclude:: ../../examples/cluster/profile_type.py +.. literalinclude:: ../../examples/clustering/profile_type.py :pyobject: get_profile_type Full example: `manage profile type`_ -.. _manage profile type: http://git.openstack.org/cgit/openstack/python-openstacksdk/tree/examples/cluster/profile_type.py +.. _manage profile type: http://git.openstack.org/cgit/openstack/python-openstacksdk/tree/examples/clustering/profile_type.py diff --git a/doc/source/users/guides/cluster/receiver.rst b/doc/source/users/guides/clustering/receiver.rst similarity index 100% rename from doc/source/users/guides/cluster/receiver.rst rename to doc/source/users/guides/clustering/receiver.rst diff --git a/doc/source/users/guides/connect.rst b/doc/source/users/guides/connect.rst index 6c9937d9c..51be68bd6 100644 --- a/doc/source/users/guides/connect.rst +++ b/doc/source/users/guides/connect.rst @@ -4,29 +4,20 @@ Connect In order to work with an OpenStack cloud you first need to create a :class:`~openstack.connection.Connection` to it using your credentials. A :class:`~openstack.connection.Connection` can be -created in 3 ways, using the class itself, a file, or environment variables. -If this is your first time using the SDK, we recommend simply using the -class itself as illustrated below. +created in 3 ways, using the class itself, :ref:`config-clouds-yaml`, or +:ref:`config-environment-variables`. It is recommended to always use +:ref:`config-clouds-yaml` as the same config can be used across tools and +languages. Create Connection ----------------- -To create a connection you need a :class:`~openstack.profile.Profile` and a -:class:`~openstack.connection.Connection`. +To create a :class:`~openstack.connection.Connection` instance, use the +:func:`~openstack.connect` factory function. .. literalinclude:: ../examples/connect.py :pyobject: create_connection -The :class:`~openstack.profile.Profile` sets your preferences for each -service. You will pass it the region of the OpenStack cloud that this -connection will use. - -The :class:`~openstack.connection.Connection` is a context for a connection -to an OpenStack cloud. You will primarily use it to set the -:class:`~openstack.profile.Profile` and authentication information. You can -also set the ``user_agent`` to something that describes your application -(e.g. ``my-web-app/1.3.4``). - Full example at `connect.py `_ .. note:: To enable logging, see the :doc:`logging` user guide. @@ -37,5 +28,9 @@ Now that you can create a connection, continue with the :ref:`user_guides` to work with an OpenStack service. As an alternative to creating a :class:`~openstack.connection.Connection` -using the class itself, you can connect using a file or environment -variables. See the :doc:`connect_from_config` user guide. +using :ref:config-clouds-yaml, you can connect using +`config-environment-variables`. + +.. TODO(shade) Update the text here and consolidate with the old + os-client-config docs so that we have a single and consistent explanation + of the envvars cloud, etc. diff --git a/doc/source/users/guides/telemetry.rst b/doc/source/users/guides/meter.rst similarity index 73% rename from doc/source/users/guides/telemetry.rst rename to doc/source/users/guides/meter.rst index cf7acae04..a6850e282 100644 --- a/doc/source/users/guides/telemetry.rst +++ b/doc/source/users/guides/meter.rst @@ -1,10 +1,10 @@ -Using OpenStack Telemetry +Using OpenStack Meter ========================= .. caution:: BETA: This API is a work in progress and is subject to change. -Before working with the Telemetry service, you'll need to create a connection +Before working with the Meter service, you'll need to create a connection to your OpenStack cloud by following the :doc:`connect` user guide. This will provide you with the ``conn`` variable used in the examples below. diff --git a/doc/source/users/index.rst b/doc/source/users/index.rst index c06b98577..218d172ef 100644 --- a/doc/source/users/index.rst +++ b/doc/source/users/index.rst @@ -28,19 +28,19 @@ approach, this is where you'll want to begin. Connect to an OpenStack Cloud Connect to an OpenStack Cloud Using a Config File Logging - Bare Metal - Block Store - Cluster + Baremetal + Block Storage + Clustering Compute Database Identity Image Key Manager Message + Meter Network Object Store Orchestration - Telemetry API Documentation ----------------- @@ -54,26 +54,26 @@ interface is the layer upon which the *Connection* is built, with Connection Interface ******************** -A *Connection* instance maintains your session, authentication, transport, -and profile, providing you with a set of higher-level interfaces to work -with OpenStack services. +A *Connection* instance maintains your cloud config, session and authentication +information providing you with a set of higher-level interfaces to work with +OpenStack services. .. toctree:: :maxdepth: 1 connection - profile Once you have a *Connection* instance, the following services may be exposed -to you. Your user profile determine the full set of exposed services, -but listed below are the ones provided by this SDK by default. +to you. The combination of your ``CloudConfig`` and the catalog of the cloud +in question control which services are exposed, but listed below are the ones +provided by the SDK. .. toctree:: :maxdepth: 1 - Bare Metal - Block Store - Cluster + Baremetal + Block Storage + Clustering Compute Database Identity v2 @@ -85,10 +85,10 @@ but listed below are the ones provided by this SDK by default. Message v1 Message v2 Network + Meter Metric Object Store Orchestration - Telemetry Workflow Resource Interface @@ -106,20 +106,20 @@ The following services have exposed *Resource* classes. .. toctree:: :maxdepth: 1 - Bare Metal - Block Store - Cluster + Baremetal + Block Storage + Clustering Compute Database Identity Image Key Management Load Balancer + Meter Metric Network Orchestration Object Store - Telemetry Workflow Low-Level Classes @@ -133,7 +133,6 @@ can be customized. .. toctree:: :maxdepth: 1 - session resource resource2 service_filter diff --git a/doc/source/users/profile.rst b/doc/source/users/profile.rst deleted file mode 100644 index 195a1848c..000000000 --- a/doc/source/users/profile.rst +++ /dev/null @@ -1,9 +0,0 @@ -Profile -======= -.. automodule:: openstack.profile - -Profile Object --------------- - -.. autoclass:: openstack.profile.Profile - :members: diff --git a/doc/source/users/proxies/bare_metal.rst b/doc/source/users/proxies/bare_metal.rst deleted file mode 100644 index 8317b86be..000000000 --- a/doc/source/users/proxies/bare_metal.rst +++ /dev/null @@ -1,76 +0,0 @@ -Bare Metal API -============== - -For details on how to use bare_metal, see :doc:`/users/guides/bare_metal` - -.. automodule:: openstack.bare_metal.v1._proxy - -The BareMetal Class --------------------- - -The bare_metal high-level interface is available through the ``bare_metal`` -member of a :class:`~openstack.connection.Connection` object. -The ``bare_metal`` member will only be added if the service is detected. - -Node Operations -^^^^^^^^^^^^^^^ -.. autoclass:: openstack.bare_metal.v1._proxy.Proxy - - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.create_node - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.update_node - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.delete_node - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.get_node - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.find_node - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.nodes - -Port Operations -^^^^^^^^^^^^^^^ -.. autoclass:: openstack.bare_metal.v1._proxy.Proxy - - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.create_port - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.update_port - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.delete_port - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.get_port - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.find_port - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.ports - -Port Group Operations -^^^^^^^^^^^^^^^^^^^^^ -.. autoclass:: openstack.bare_metal.v1._proxy.Proxy - - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.create_port_group - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.update_port_group - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.delete_port_group - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.get_port_group - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.find_port_group - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.port_groups - -Driver Operations -^^^^^^^^^^^^^^^^^ -.. autoclass:: openstack.bare_metal.v1._proxy.Proxy - - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.drivers - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.get_driver - -Chassis Operations -^^^^^^^^^^^^^^^^^^ -.. autoclass:: openstack.bare_metal.v1._proxy.Proxy - - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.create_chassis - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.update_chassis - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.delete_chassis - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.get_chassis - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.find_chassis - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.chassis - -Deprecated Methods -^^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.bare_metal.v1._proxy.Proxy - - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.create_portgroup - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.update_portgroup - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.delete_portgroup - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.get_portgroup - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.find_portgroup - .. automethod:: openstack.bare_metal.v1._proxy.Proxy.portgroups diff --git a/doc/source/users/proxies/baremetal.rst b/doc/source/users/proxies/baremetal.rst new file mode 100644 index 000000000..5ca777b2a --- /dev/null +++ b/doc/source/users/proxies/baremetal.rst @@ -0,0 +1,76 @@ +Baremetal API +============== + +For details on how to use baremetal, see :doc:`/users/guides/baremetal` + +.. automodule:: openstack.baremetal.v1._proxy + +The Baremetal Class +-------------------- + +The baremetal high-level interface is available through the ``baremetal`` +member of a :class:`~openstack.connection.Connection` object. +The ``baremetal`` member will only be added if the service is detected. + +Node Operations +^^^^^^^^^^^^^^^ +.. autoclass:: openstack.baremetal.v1._proxy.Proxy + + .. automethod:: openstack.baremetal.v1._proxy.Proxy.create_node + .. automethod:: openstack.baremetal.v1._proxy.Proxy.update_node + .. automethod:: openstack.baremetal.v1._proxy.Proxy.delete_node + .. automethod:: openstack.baremetal.v1._proxy.Proxy.get_node + .. automethod:: openstack.baremetal.v1._proxy.Proxy.find_node + .. automethod:: openstack.baremetal.v1._proxy.Proxy.nodes + +Port Operations +^^^^^^^^^^^^^^^ +.. autoclass:: openstack.baremetal.v1._proxy.Proxy + + .. automethod:: openstack.baremetal.v1._proxy.Proxy.create_port + .. automethod:: openstack.baremetal.v1._proxy.Proxy.update_port + .. automethod:: openstack.baremetal.v1._proxy.Proxy.delete_port + .. automethod:: openstack.baremetal.v1._proxy.Proxy.get_port + .. automethod:: openstack.baremetal.v1._proxy.Proxy.find_port + .. automethod:: openstack.baremetal.v1._proxy.Proxy.ports + +Port Group Operations +^^^^^^^^^^^^^^^^^^^^^ +.. autoclass:: openstack.baremetal.v1._proxy.Proxy + + .. automethod:: openstack.baremetal.v1._proxy.Proxy.create_port_group + .. automethod:: openstack.baremetal.v1._proxy.Proxy.update_port_group + .. automethod:: openstack.baremetal.v1._proxy.Proxy.delete_port_group + .. automethod:: openstack.baremetal.v1._proxy.Proxy.get_port_group + .. automethod:: openstack.baremetal.v1._proxy.Proxy.find_port_group + .. automethod:: openstack.baremetal.v1._proxy.Proxy.port_groups + +Driver Operations +^^^^^^^^^^^^^^^^^ +.. autoclass:: openstack.baremetal.v1._proxy.Proxy + + .. automethod:: openstack.baremetal.v1._proxy.Proxy.drivers + .. automethod:: openstack.baremetal.v1._proxy.Proxy.get_driver + +Chassis Operations +^^^^^^^^^^^^^^^^^^ +.. autoclass:: openstack.baremetal.v1._proxy.Proxy + + .. automethod:: openstack.baremetal.v1._proxy.Proxy.create_chassis + .. automethod:: openstack.baremetal.v1._proxy.Proxy.update_chassis + .. automethod:: openstack.baremetal.v1._proxy.Proxy.delete_chassis + .. automethod:: openstack.baremetal.v1._proxy.Proxy.get_chassis + .. automethod:: openstack.baremetal.v1._proxy.Proxy.find_chassis + .. automethod:: openstack.baremetal.v1._proxy.Proxy.chassis + +Deprecated Methods +^^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.baremetal.v1._proxy.Proxy + + .. automethod:: openstack.baremetal.v1._proxy.Proxy.create_portgroup + .. automethod:: openstack.baremetal.v1._proxy.Proxy.update_portgroup + .. automethod:: openstack.baremetal.v1._proxy.Proxy.delete_portgroup + .. automethod:: openstack.baremetal.v1._proxy.Proxy.get_portgroup + .. automethod:: openstack.baremetal.v1._proxy.Proxy.find_portgroup + .. automethod:: openstack.baremetal.v1._proxy.Proxy.portgroups diff --git a/doc/source/users/proxies/block_storage.rst b/doc/source/users/proxies/block_storage.rst new file mode 100644 index 000000000..460624151 --- /dev/null +++ b/doc/source/users/proxies/block_storage.rst @@ -0,0 +1,43 @@ +Block Storage API +================= + +For details on how to use block_storage, see :doc:`/users/guides/block_storage` + +.. automodule:: openstack.block_storage.v2._proxy + +The BlockStorage Class +---------------------- + +The block_storage high-level interface is available through the +``block_storage`` member of a :class:`~openstack.connection.Connection` object. +The ``block_storage`` member will only be added if the service is detected. + +Volume Operations +^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.block_storage.v2._proxy.Proxy + + .. automethod:: openstack.block_storage.v2._proxy.Proxy.create_volume + .. automethod:: openstack.block_storage.v2._proxy.Proxy.delete_volume + .. automethod:: openstack.block_storage.v2._proxy.Proxy.get_volume + .. automethod:: openstack.block_storage.v2._proxy.Proxy.volumes + +Type Operations +^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.block_storage.v2._proxy.Proxy + + .. automethod:: openstack.block_storage.v2._proxy.Proxy.create_type + .. automethod:: openstack.block_storage.v2._proxy.Proxy.delete_type + .. automethod:: openstack.block_storage.v2._proxy.Proxy.get_type + .. automethod:: openstack.block_storage.v2._proxy.Proxy.types + +Snapshot Operations +^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.block_storage.v2._proxy.Proxy + + .. automethod:: openstack.block_storage.v2._proxy.Proxy.create_snapshot + .. automethod:: openstack.block_storage.v2._proxy.Proxy.delete_snapshot + .. automethod:: openstack.block_storage.v2._proxy.Proxy.get_snapshot + .. automethod:: openstack.block_storage.v2._proxy.Proxy.snapshots diff --git a/doc/source/users/proxies/block_store.rst b/doc/source/users/proxies/block_store.rst deleted file mode 100644 index 92c12cd15..000000000 --- a/doc/source/users/proxies/block_store.rst +++ /dev/null @@ -1,43 +0,0 @@ -Block Store API -=============== - -For details on how to use block_store, see :doc:`/users/guides/block_store` - -.. automodule:: openstack.block_store.v2._proxy - -The BlockStore Class --------------------- - -The block_store high-level interface is available through the ``block_store`` -member of a :class:`~openstack.connection.Connection` object. -The ``block_store`` member will only be added if the service is detected. - -Volume Operations -^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.block_store.v2._proxy.Proxy - - .. automethod:: openstack.block_store.v2._proxy.Proxy.create_volume - .. automethod:: openstack.block_store.v2._proxy.Proxy.delete_volume - .. automethod:: openstack.block_store.v2._proxy.Proxy.get_volume - .. automethod:: openstack.block_store.v2._proxy.Proxy.volumes - -Type Operations -^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.block_store.v2._proxy.Proxy - - .. automethod:: openstack.block_store.v2._proxy.Proxy.create_type - .. automethod:: openstack.block_store.v2._proxy.Proxy.delete_type - .. automethod:: openstack.block_store.v2._proxy.Proxy.get_type - .. automethod:: openstack.block_store.v2._proxy.Proxy.types - -Snapshot Operations -^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.block_store.v2._proxy.Proxy - - .. automethod:: openstack.block_store.v2._proxy.Proxy.create_snapshot - .. automethod:: openstack.block_store.v2._proxy.Proxy.delete_snapshot - .. automethod:: openstack.block_store.v2._proxy.Proxy.get_snapshot - .. automethod:: openstack.block_store.v2._proxy.Proxy.snapshots diff --git a/doc/source/users/proxies/cluster.rst b/doc/source/users/proxies/cluster.rst deleted file mode 100644 index db7eec004..000000000 --- a/doc/source/users/proxies/cluster.rst +++ /dev/null @@ -1,177 +0,0 @@ -Cluster API -=========== - -.. automodule:: openstack.cluster.v1._proxy - -The Cluster Class ------------------ - -The cluster high-level interface is available through the ``cluster`` -member of a :class:`~openstack.connection.Connection` object. The -``cluster`` member will only be added if the service is detected. - - -Build Info Operations -^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.cluster.v1._proxy.Proxy - - .. automethod:: openstack.cluster.v1._proxy.Proxy.get_build_info - - -Profile Type Operations -^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.cluster.v1._proxy.Proxy - - .. automethod:: openstack.cluster.v1._proxy.Proxy.profile_types - .. automethod:: openstack.cluster.v1._proxy.Proxy.get_profile_type - - -Profile Operations -^^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.cluster.v1._proxy.Proxy - - .. automethod:: openstack.cluster.v1._proxy.Proxy.create_profile - .. automethod:: openstack.cluster.v1._proxy.Proxy.update_profile - .. automethod:: openstack.cluster.v1._proxy.Proxy.delete_profile - .. automethod:: openstack.cluster.v1._proxy.Proxy.get_profile - .. automethod:: openstack.cluster.v1._proxy.Proxy.find_profile - .. automethod:: openstack.cluster.v1._proxy.Proxy.profiles - - .. automethod:: openstack.cluster.v1._proxy.Proxy.validate_profile - - -Policy Type Operations -^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.cluster.v1._proxy.Proxy - - .. automethod:: openstack.cluster.v1._proxy.Proxy.policy_types - .. automethod:: openstack.cluster.v1._proxy.Proxy.get_policy_type - - -Policy Operations -^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.cluster.v1._proxy.Proxy - - .. automethod:: openstack.cluster.v1._proxy.Proxy.create_policy - .. automethod:: openstack.cluster.v1._proxy.Proxy.update_policy - .. automethod:: openstack.cluster.v1._proxy.Proxy.delete_policy - .. automethod:: openstack.cluster.v1._proxy.Proxy.get_policy - .. automethod:: openstack.cluster.v1._proxy.Proxy.find_policy - .. automethod:: openstack.cluster.v1._proxy.Proxy.policies - - .. automethod:: openstack.cluster.v1._proxy.Proxy.validate_policy - - -Cluster Operations -^^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.cluster.v1._proxy.Proxy - - .. automethod:: openstack.cluster.v1._proxy.Proxy.create_cluster - .. automethod:: openstack.cluster.v1._proxy.Proxy.update_cluster - .. automethod:: openstack.cluster.v1._proxy.Proxy.delete_cluster - .. automethod:: openstack.cluster.v1._proxy.Proxy.get_cluster - .. automethod:: openstack.cluster.v1._proxy.Proxy.find_cluster - .. automethod:: openstack.cluster.v1._proxy.Proxy.clusters - - .. automethod:: openstack.cluster.v1._proxy.Proxy.check_cluster - .. automethod:: openstack.cluster.v1._proxy.Proxy.recover_cluster - .. automethod:: openstack.cluster.v1._proxy.Proxy.resize_cluster - .. automethod:: openstack.cluster.v1._proxy.Proxy.scale_in_cluster - .. automethod:: openstack.cluster.v1._proxy.Proxy.scale_out_cluster - .. automethod:: openstack.cluster.v1._proxy.Proxy.collect_cluster_attrs - .. automethod:: openstack.cluster.v1._proxy.Proxy.perform_operation_on_cluster - - .. automethod:: openstack.cluster.v1._proxy.Proxy.add_nodes_to_cluster - .. automethod:: openstack.cluster.v1._proxy.Proxy.remove_nodes_from_cluster - .. automethod:: openstack.cluster.v1._proxy.Proxy.replace_nodes_in_cluster - - .. automethod:: openstack.cluster.v1._proxy.Proxy.attach_policy_to_cluster - .. automethod:: openstack.cluster.v1._proxy.Proxy.update_cluster_policy - .. automethod:: openstack.cluster.v1._proxy.Proxy.detach_policy_from_cluster - .. automethod:: openstack.cluster.v1._proxy.Proxy.get_cluster_policy - .. automethod:: openstack.cluster.v1._proxy.Proxy.cluster_policies - - .. automethod:: openstack.cluster.v1._proxy.Proxy.cluster_add_nodes - .. automethod:: openstack.cluster.v1._proxy.Proxy.cluster_attach_policy - .. automethod:: openstack.cluster.v1._proxy.Proxy.cluster_del_nodes - .. automethod:: openstack.cluster.v1._proxy.Proxy.cluster_detach_policy - .. automethod:: openstack.cluster.v1._proxy.Proxy.cluster_operation - .. automethod:: openstack.cluster.v1._proxy.Proxy.cluster_replace_nodes - .. automethod:: openstack.cluster.v1._proxy.Proxy.cluster_resize - .. automethod:: openstack.cluster.v1._proxy.Proxy.cluster_scale_in - .. automethod:: openstack.cluster.v1._proxy.Proxy.cluster_scale_out - .. automethod:: openstack.cluster.v1._proxy.Proxy.cluster_update_policy - - -Node Operations -^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.cluster.v1._proxy.Proxy - - .. automethod:: openstack.cluster.v1._proxy.Proxy.create_node - .. automethod:: openstack.cluster.v1._proxy.Proxy.update_node - .. automethod:: openstack.cluster.v1._proxy.Proxy.delete_node - .. automethod:: openstack.cluster.v1._proxy.Proxy.get_node - .. automethod:: openstack.cluster.v1._proxy.Proxy.find_node - .. automethod:: openstack.cluster.v1._proxy.Proxy.nodes - - .. automethod:: openstack.cluster.v1._proxy.Proxy.check_node - .. automethod:: openstack.cluster.v1._proxy.Proxy.recover_node - .. automethod:: openstack.cluster.v1._proxy.Proxy.perform_operation_on_node - - .. automethod:: openstack.cluster.v1._proxy.Proxy.adopt_node - .. automethod:: openstack.cluster.v1._proxy.Proxy.node_operation - - -Receiver Operations -^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.cluster.v1._proxy.Proxy - - .. automethod:: openstack.cluster.v1._proxy.Proxy.create_receiver - .. automethod:: openstack.cluster.v1._proxy.Proxy.update_receiver - .. automethod:: openstack.cluster.v1._proxy.Proxy.delete_receiver - .. automethod:: openstack.cluster.v1._proxy.Proxy.get_receiver - .. automethod:: openstack.cluster.v1._proxy.Proxy.find_receiver - .. automethod:: openstack.cluster.v1._proxy.Proxy.receivers - - -Action Operations -^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.cluster.v1._proxy.Proxy - - .. automethod:: openstack.cluster.v1._proxy.Proxy.get_action - .. automethod:: openstack.cluster.v1._proxy.Proxy.actions - - -Event Operations -^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.cluster.v1._proxy.Proxy - - .. automethod:: openstack.cluster.v1._proxy.Proxy.get_event - .. automethod:: openstack.cluster.v1._proxy.Proxy.events - - -Helper Operations -^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.cluster.v1._proxy.Proxy - - .. automethod:: openstack.cluster.v1._proxy.Proxy.wait_for_delete - .. automethod:: openstack.cluster.v1._proxy.Proxy.wait_for_status - - -Service Operations -^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.cluster.v1._proxy.Proxy - - .. automethod:: openstack.cluster.v1._proxy.Proxy.services diff --git a/doc/source/users/proxies/clustering.rst b/doc/source/users/proxies/clustering.rst new file mode 100644 index 000000000..ff8b5c380 --- /dev/null +++ b/doc/source/users/proxies/clustering.rst @@ -0,0 +1,177 @@ +Cluster API +=========== + +.. automodule:: openstack.clustering.v1._proxy + +The Cluster Class +----------------- + +The cluster high-level interface is available through the ``cluster`` +member of a :class:`~openstack.connection.Connection` object. The +``cluster`` member will only be added if the service is detected. + + +Build Info Operations +^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.clustering.v1._proxy.Proxy + + .. automethod:: openstack.clustering.v1._proxy.Proxy.get_build_info + + +Profile Type Operations +^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.clustering.v1._proxy.Proxy + + .. automethod:: openstack.clustering.v1._proxy.Proxy.profile_types + .. automethod:: openstack.clustering.v1._proxy.Proxy.get_profile_type + + +Profile Operations +^^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.clustering.v1._proxy.Proxy + + .. automethod:: openstack.clustering.v1._proxy.Proxy.create_profile + .. automethod:: openstack.clustering.v1._proxy.Proxy.update_profile + .. automethod:: openstack.clustering.v1._proxy.Proxy.delete_profile + .. automethod:: openstack.clustering.v1._proxy.Proxy.get_profile + .. automethod:: openstack.clustering.v1._proxy.Proxy.find_profile + .. automethod:: openstack.clustering.v1._proxy.Proxy.profiles + + .. automethod:: openstack.clustering.v1._proxy.Proxy.validate_profile + + +Policy Type Operations +^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.clustering.v1._proxy.Proxy + + .. automethod:: openstack.clustering.v1._proxy.Proxy.policy_types + .. automethod:: openstack.clustering.v1._proxy.Proxy.get_policy_type + + +Policy Operations +^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.clustering.v1._proxy.Proxy + + .. automethod:: openstack.clustering.v1._proxy.Proxy.create_policy + .. automethod:: openstack.clustering.v1._proxy.Proxy.update_policy + .. automethod:: openstack.clustering.v1._proxy.Proxy.delete_policy + .. automethod:: openstack.clustering.v1._proxy.Proxy.get_policy + .. automethod:: openstack.clustering.v1._proxy.Proxy.find_policy + .. automethod:: openstack.clustering.v1._proxy.Proxy.policies + + .. automethod:: openstack.clustering.v1._proxy.Proxy.validate_policy + + +Cluster Operations +^^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.clustering.v1._proxy.Proxy + + .. automethod:: openstack.clustering.v1._proxy.Proxy.create_cluster + .. automethod:: openstack.clustering.v1._proxy.Proxy.update_cluster + .. automethod:: openstack.clustering.v1._proxy.Proxy.delete_cluster + .. automethod:: openstack.clustering.v1._proxy.Proxy.get_cluster + .. automethod:: openstack.clustering.v1._proxy.Proxy.find_cluster + .. automethod:: openstack.clustering.v1._proxy.Proxy.clusters + + .. automethod:: openstack.clustering.v1._proxy.Proxy.check_cluster + .. automethod:: openstack.clustering.v1._proxy.Proxy.recover_cluster + .. automethod:: openstack.clustering.v1._proxy.Proxy.resize_cluster + .. automethod:: openstack.clustering.v1._proxy.Proxy.scale_in_cluster + .. automethod:: openstack.clustering.v1._proxy.Proxy.scale_out_cluster + .. automethod:: openstack.clustering.v1._proxy.Proxy.collect_cluster_attrs + .. automethod:: openstack.clustering.v1._proxy.Proxy.perform_operation_on_cluster + + .. automethod:: openstack.clustering.v1._proxy.Proxy.add_nodes_to_cluster + .. automethod:: openstack.clustering.v1._proxy.Proxy.remove_nodes_from_cluster + .. automethod:: openstack.clustering.v1._proxy.Proxy.replace_nodes_in_cluster + + .. automethod:: openstack.clustering.v1._proxy.Proxy.attach_policy_to_cluster + .. automethod:: openstack.clustering.v1._proxy.Proxy.update_cluster_policy + .. automethod:: openstack.clustering.v1._proxy.Proxy.detach_policy_from_cluster + .. automethod:: openstack.clustering.v1._proxy.Proxy.get_cluster_policy + .. automethod:: openstack.clustering.v1._proxy.Proxy.cluster_policies + + .. automethod:: openstack.clustering.v1._proxy.Proxy.cluster_add_nodes + .. automethod:: openstack.clustering.v1._proxy.Proxy.cluster_attach_policy + .. automethod:: openstack.clustering.v1._proxy.Proxy.cluster_del_nodes + .. automethod:: openstack.clustering.v1._proxy.Proxy.cluster_detach_policy + .. automethod:: openstack.clustering.v1._proxy.Proxy.cluster_operation + .. automethod:: openstack.clustering.v1._proxy.Proxy.cluster_replace_nodes + .. automethod:: openstack.clustering.v1._proxy.Proxy.cluster_resize + .. automethod:: openstack.clustering.v1._proxy.Proxy.cluster_scale_in + .. automethod:: openstack.clustering.v1._proxy.Proxy.cluster_scale_out + .. automethod:: openstack.clustering.v1._proxy.Proxy.cluster_update_policy + + +Node Operations +^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.clustering.v1._proxy.Proxy + + .. automethod:: openstack.clustering.v1._proxy.Proxy.create_node + .. automethod:: openstack.clustering.v1._proxy.Proxy.update_node + .. automethod:: openstack.clustering.v1._proxy.Proxy.delete_node + .. automethod:: openstack.clustering.v1._proxy.Proxy.get_node + .. automethod:: openstack.clustering.v1._proxy.Proxy.find_node + .. automethod:: openstack.clustering.v1._proxy.Proxy.nodes + + .. automethod:: openstack.clustering.v1._proxy.Proxy.check_node + .. automethod:: openstack.clustering.v1._proxy.Proxy.recover_node + .. automethod:: openstack.clustering.v1._proxy.Proxy.perform_operation_on_node + + .. automethod:: openstack.clustering.v1._proxy.Proxy.adopt_node + .. automethod:: openstack.clustering.v1._proxy.Proxy.node_operation + + +Receiver Operations +^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.clustering.v1._proxy.Proxy + + .. automethod:: openstack.clustering.v1._proxy.Proxy.create_receiver + .. automethod:: openstack.clustering.v1._proxy.Proxy.update_receiver + .. automethod:: openstack.clustering.v1._proxy.Proxy.delete_receiver + .. automethod:: openstack.clustering.v1._proxy.Proxy.get_receiver + .. automethod:: openstack.clustering.v1._proxy.Proxy.find_receiver + .. automethod:: openstack.clustering.v1._proxy.Proxy.receivers + + +Action Operations +^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.clustering.v1._proxy.Proxy + + .. automethod:: openstack.clustering.v1._proxy.Proxy.get_action + .. automethod:: openstack.clustering.v1._proxy.Proxy.actions + + +Event Operations +^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.clustering.v1._proxy.Proxy + + .. automethod:: openstack.clustering.v1._proxy.Proxy.get_event + .. automethod:: openstack.clustering.v1._proxy.Proxy.events + + +Helper Operations +^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.clustering.v1._proxy.Proxy + + .. automethod:: openstack.clustering.v1._proxy.Proxy.wait_for_delete + .. automethod:: openstack.clustering.v1._proxy.Proxy.wait_for_status + + +Service Operations +^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.clustering.v1._proxy.Proxy + + .. automethod:: openstack.clustering.v1._proxy.Proxy.services diff --git a/doc/source/users/proxies/meter.rst b/doc/source/users/proxies/meter.rst new file mode 100644 index 000000000..a08e6f211 --- /dev/null +++ b/doc/source/users/proxies/meter.rst @@ -0,0 +1,85 @@ +Meter API +============= + +.. caution:: + BETA: This API is a work in progress and is subject to change. + +For details on how to use meter, see :doc:`/users/guides/meter` + +.. automodule:: openstack.meter.v2._proxy + +The Meter Class +------------------- + +The meter high-level interface is available through the ``meter`` +member of a :class:`~openstack.connection.Connection` object. The +``meter`` member will only be added if the service is detected. + +Sample Operations +^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.meter.v2._proxy.Proxy + + .. automethod:: openstack.meter.v2._proxy.Proxy.find_sample + .. automethod:: openstack.meter.v2._proxy.Proxy.samples + +Statistic Operations +^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.meter.v2._proxy.Proxy + + .. automethod:: openstack.meter.v2._proxy.Proxy.find_statistics + .. automethod:: openstack.meter.v2._proxy.Proxy.statistics + +Resource Operations +^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.meter.v2._proxy.Proxy + + .. automethod:: openstack.meter.v2._proxy.Proxy.get_resource + .. automethod:: openstack.meter.v2._proxy.Proxy.find_resource + .. automethod:: openstack.meter.v2._proxy.Proxy.resources + +Meter Operations +^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.meter.v2._proxy.Proxy + + .. automethod:: openstack.meter.v2._proxy.Proxy.find_meter + .. automethod:: openstack.meter.v2._proxy.Proxy.meters + +Capability Operations +^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.meter.v2._proxy.Proxy + + .. automethod:: openstack.meter.v2._proxy.Proxy.find_capability + .. automethod:: openstack.meter.v2._proxy.Proxy.capabilities + +The Alarm Class +--------------- + +The alarm high-level interface is available through the ``meter.alarm`` +member of a :class:`~openstack.connection.Connection` object. The +``meter.alarm`` member will only be added if the service is detected. + +Alarm Operations +^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.meter.alarm.v2._proxy.Proxy + + .. automethod:: openstack.meter.alarm.v2._proxy.Proxy.create_alarm + .. automethod:: openstack.meter.alarm.v2._proxy.Proxy.update_alarm + .. automethod:: openstack.meter.alarm.v2._proxy.Proxy.delete_alarm + .. automethod:: openstack.meter.alarm.v2._proxy.Proxy.get_alarm + .. automethod:: openstack.meter.alarm.v2._proxy.Proxy.find_alarm + .. automethod:: openstack.meter.alarm.v2._proxy.Proxy.alarms + + +Alarm Change Operations +^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.meter.alarm.v2._proxy.Proxy + + .. automethod:: openstack.meter.alarm.v2._proxy.Proxy.find_alarm_change + .. automethod:: openstack.meter.alarm.v2._proxy.Proxy.alarm_changes diff --git a/doc/source/users/proxies/telemetry.rst b/doc/source/users/proxies/telemetry.rst deleted file mode 100644 index fc29a13a4..000000000 --- a/doc/source/users/proxies/telemetry.rst +++ /dev/null @@ -1,85 +0,0 @@ -Telemetry API -============= - -.. caution:: - BETA: This API is a work in progress and is subject to change. - -For details on how to use telemetry, see :doc:`/users/guides/telemetry` - -.. automodule:: openstack.telemetry.v2._proxy - -The Telemetry Class -------------------- - -The telemetry high-level interface is available through the ``telemetry`` -member of a :class:`~openstack.connection.Connection` object. The -``telemetry`` member will only be added if the service is detected. - -Sample Operations -^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.telemetry.v2._proxy.Proxy - - .. automethod:: openstack.telemetry.v2._proxy.Proxy.find_sample - .. automethod:: openstack.telemetry.v2._proxy.Proxy.samples - -Statistic Operations -^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.telemetry.v2._proxy.Proxy - - .. automethod:: openstack.telemetry.v2._proxy.Proxy.find_statistics - .. automethod:: openstack.telemetry.v2._proxy.Proxy.statistics - -Resource Operations -^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.telemetry.v2._proxy.Proxy - - .. automethod:: openstack.telemetry.v2._proxy.Proxy.get_resource - .. automethod:: openstack.telemetry.v2._proxy.Proxy.find_resource - .. automethod:: openstack.telemetry.v2._proxy.Proxy.resources - -Meter Operations -^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.telemetry.v2._proxy.Proxy - - .. automethod:: openstack.telemetry.v2._proxy.Proxy.find_meter - .. automethod:: openstack.telemetry.v2._proxy.Proxy.meters - -Capability Operations -^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.telemetry.v2._proxy.Proxy - - .. automethod:: openstack.telemetry.v2._proxy.Proxy.find_capability - .. automethod:: openstack.telemetry.v2._proxy.Proxy.capabilities - -The Alarm Class ---------------- - -The alarm high-level interface is available through the ``telemetry.alarm`` -member of a :class:`~openstack.connection.Connection` object. The -``telemetry.alarm`` member will only be added if the service is detected. - -Alarm Operations -^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.telemetry.alarm.v2._proxy.Proxy - - .. automethod:: openstack.telemetry.alarm.v2._proxy.Proxy.create_alarm - .. automethod:: openstack.telemetry.alarm.v2._proxy.Proxy.update_alarm - .. automethod:: openstack.telemetry.alarm.v2._proxy.Proxy.delete_alarm - .. automethod:: openstack.telemetry.alarm.v2._proxy.Proxy.get_alarm - .. automethod:: openstack.telemetry.alarm.v2._proxy.Proxy.find_alarm - .. automethod:: openstack.telemetry.alarm.v2._proxy.Proxy.alarms - - -Alarm Change Operations -^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: openstack.telemetry.alarm.v2._proxy.Proxy - - .. automethod:: openstack.telemetry.alarm.v2._proxy.Proxy.find_alarm_change - .. automethod:: openstack.telemetry.alarm.v2._proxy.Proxy.alarm_changes diff --git a/doc/source/users/resources/bare_metal/index.rst b/doc/source/users/resources/baremetal/index.rst similarity index 85% rename from doc/source/users/resources/bare_metal/index.rst rename to doc/source/users/resources/baremetal/index.rst index 348a6e4f6..c8025248b 100644 --- a/doc/source/users/resources/bare_metal/index.rst +++ b/doc/source/users/resources/baremetal/index.rst @@ -1,4 +1,4 @@ -Bare Metal Resources +Baremetal Resources ===================== .. toctree:: diff --git a/doc/source/users/resources/bare_metal/v1/chassis.rst b/doc/source/users/resources/baremetal/v1/chassis.rst similarity index 54% rename from doc/source/users/resources/bare_metal/v1/chassis.rst rename to doc/source/users/resources/baremetal/v1/chassis.rst index 303896378..8db33407a 100644 --- a/doc/source/users/resources/bare_metal/v1/chassis.rst +++ b/doc/source/users/resources/baremetal/v1/chassis.rst @@ -1,12 +1,12 @@ -openstack.bare_metal.v1.chassis +openstack.baremetal.v1.chassis =============================== -.. automodule:: openstack.bare_metal.v1.chassis +.. automodule:: openstack.baremetal.v1.chassis The Chassis Class ----------------- The ``Chassis`` class inherits from :class:`~openstack.resource.Resource`. -.. autoclass:: openstack.bare_metal.v1.chassis.Chassis +.. autoclass:: openstack.baremetal.v1.chassis.Chassis :members: diff --git a/doc/source/users/resources/bare_metal/v1/driver.rst b/doc/source/users/resources/baremetal/v1/driver.rst similarity index 54% rename from doc/source/users/resources/bare_metal/v1/driver.rst rename to doc/source/users/resources/baremetal/v1/driver.rst index d45379e38..980a067bc 100644 --- a/doc/source/users/resources/bare_metal/v1/driver.rst +++ b/doc/source/users/resources/baremetal/v1/driver.rst @@ -1,12 +1,12 @@ -openstack.bare_metal.v1.driver +openstack.baremetal.v1.driver ============================== -.. automodule:: openstack.bare_metal.v1.driver +.. automodule:: openstack.baremetal.v1.driver The Driver Class ---------------- The ``Driver`` class inherits from :class:`~openstack.resource.Resource`. -.. autoclass:: openstack.bare_metal.v1.driver.Driver +.. autoclass:: openstack.baremetal.v1.driver.Driver :members: diff --git a/doc/source/users/resources/bare_metal/v1/node.rst b/doc/source/users/resources/baremetal/v1/node.rst similarity index 54% rename from doc/source/users/resources/bare_metal/v1/node.rst rename to doc/source/users/resources/baremetal/v1/node.rst index 7900c5598..323c8db6e 100644 --- a/doc/source/users/resources/bare_metal/v1/node.rst +++ b/doc/source/users/resources/baremetal/v1/node.rst @@ -1,12 +1,12 @@ -openstack.bare_metal.v1.Node +openstack.baremetal.v1.Node ============================ -.. automodule:: openstack.bare_metal.v1.node +.. automodule:: openstack.baremetal.v1.node The Node Class -------------- The ``Node`` class inherits from :class:`~openstack.resource.Resource`. -.. autoclass:: openstack.bare_metal.v1.node.Node +.. autoclass:: openstack.baremetal.v1.node.Node :members: diff --git a/doc/source/users/resources/bare_metal/v1/port.rst b/doc/source/users/resources/baremetal/v1/port.rst similarity index 54% rename from doc/source/users/resources/bare_metal/v1/port.rst rename to doc/source/users/resources/baremetal/v1/port.rst index b0ed31b47..34f1ab9a3 100644 --- a/doc/source/users/resources/bare_metal/v1/port.rst +++ b/doc/source/users/resources/baremetal/v1/port.rst @@ -1,12 +1,12 @@ -openstack.bare_metal.v1.port +openstack.baremetal.v1.port ============================ -.. automodule:: openstack.bare_metal.v1.port +.. automodule:: openstack.baremetal.v1.port The Port Class -------------- The ``Port`` class inherits from :class:`~openstack.resource.Resource`. -.. autoclass:: openstack.bare_metal.v1.port.Port +.. autoclass:: openstack.baremetal.v1.port.Port :members: diff --git a/doc/source/users/resources/bare_metal/v1/port_group.rst b/doc/source/users/resources/baremetal/v1/port_group.rst similarity index 53% rename from doc/source/users/resources/bare_metal/v1/port_group.rst rename to doc/source/users/resources/baremetal/v1/port_group.rst index 3feb4e2f4..8867dc16d 100644 --- a/doc/source/users/resources/bare_metal/v1/port_group.rst +++ b/doc/source/users/resources/baremetal/v1/port_group.rst @@ -1,12 +1,12 @@ -openstack.bare_metal.v1.port_group +openstack.baremetal.v1.port_group ================================== -.. automodule:: openstack.bare_metal.v1.port_group +.. automodule:: openstack.baremetal.v1.port_group The PortGroup Class ------------------- The ``PortGroup`` class inherits from :class:`~openstack.resource.Resource`. -.. autoclass:: openstack.bare_metal.v1.port_group.PortGroup +.. autoclass:: openstack.baremetal.v1.port_group.PortGroup :members: diff --git a/doc/source/users/resources/block_store/index.rst b/doc/source/users/resources/block_storage/index.rst similarity index 59% rename from doc/source/users/resources/block_store/index.rst rename to doc/source/users/resources/block_storage/index.rst index ba0be3c1f..e4a249416 100644 --- a/doc/source/users/resources/block_store/index.rst +++ b/doc/source/users/resources/block_storage/index.rst @@ -1,5 +1,5 @@ -Block Store Resources -===================== +Block Storage Resources +======================= .. toctree:: :maxdepth: 1 diff --git a/doc/source/users/resources/block_storage/v2/snapshot.rst b/doc/source/users/resources/block_storage/v2/snapshot.rst new file mode 100644 index 000000000..5b2eea172 --- /dev/null +++ b/doc/source/users/resources/block_storage/v2/snapshot.rst @@ -0,0 +1,21 @@ +openstack.block_storage.v2.snapshot +=================================== + +.. automodule:: openstack.block_storage.v2.snapshot + +The Snapshot Class +------------------ + +The ``Snapshot`` class inherits from :class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.block_storage.v2.snapshot.Snapshot + :members: + +The SnapshotDetail Class +------------------------ + +The ``SnapshotDetail`` class inherits from +:class:`~openstack.block_storage.v2.snapshot.Snapshot`. + +.. autoclass:: openstack.block_storage.v2.snapshot.SnapshotDetail + :members: diff --git a/doc/source/users/resources/block_storage/v2/type.rst b/doc/source/users/resources/block_storage/v2/type.rst new file mode 100644 index 000000000..963f235db --- /dev/null +++ b/doc/source/users/resources/block_storage/v2/type.rst @@ -0,0 +1,13 @@ +openstack.block_storage.v2.type +=============================== + +.. automodule:: openstack.block_storage.v2.type + +The Type Class +-------------- + +The ``Type`` class inherits from :class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.block_storage.v2.type.Type + :members: + diff --git a/doc/source/users/resources/block_storage/v2/volume.rst b/doc/source/users/resources/block_storage/v2/volume.rst new file mode 100644 index 000000000..499f585ae --- /dev/null +++ b/doc/source/users/resources/block_storage/v2/volume.rst @@ -0,0 +1,21 @@ +openstack.block_storage.v2.volume +================================= + +.. automodule:: openstack.block_storage.v2.volume + +The Volume Class +---------------- + +The ``Volume`` class inherits from :class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.block_storage.v2.volume.Volume + :members: + +The VolumeDetail Class +---------------------- + +The ``VolumeDetail`` class inherits from +:class:`~openstack.block_storage.v2.volume.Volume`. + +.. autoclass:: openstack.block_storage.v2.volume.VolumeDetail + :members: diff --git a/doc/source/users/resources/block_store/v2/snapshot.rst b/doc/source/users/resources/block_store/v2/snapshot.rst deleted file mode 100644 index e742ffcf8..000000000 --- a/doc/source/users/resources/block_store/v2/snapshot.rst +++ /dev/null @@ -1,21 +0,0 @@ -openstack.block_store.v2.snapshot -================================= - -.. automodule:: openstack.block_store.v2.snapshot - -The Snapshot Class ------------------- - -The ``Snapshot`` class inherits from :class:`~openstack.resource.Resource`. - -.. autoclass:: openstack.block_store.v2.snapshot.Snapshot - :members: - -The SnapshotDetail Class ------------------------- - -The ``SnapshotDetail`` class inherits from -:class:`~openstack.block_store.v2.snapshot.Snapshot`. - -.. autoclass:: openstack.block_store.v2.snapshot.SnapshotDetail - :members: diff --git a/doc/source/users/resources/block_store/v2/type.rst b/doc/source/users/resources/block_store/v2/type.rst deleted file mode 100644 index fcab77fe2..000000000 --- a/doc/source/users/resources/block_store/v2/type.rst +++ /dev/null @@ -1,13 +0,0 @@ -openstack.block_store.v2.type -============================= - -.. automodule:: openstack.block_store.v2.type - -The Type Class --------------- - -The ``Type`` class inherits from :class:`~openstack.resource.Resource`. - -.. autoclass:: openstack.block_store.v2.type.Type - :members: - diff --git a/doc/source/users/resources/block_store/v2/volume.rst b/doc/source/users/resources/block_store/v2/volume.rst deleted file mode 100644 index 115452535..000000000 --- a/doc/source/users/resources/block_store/v2/volume.rst +++ /dev/null @@ -1,21 +0,0 @@ -openstack.block_store.v2.volume -=============================== - -.. automodule:: openstack.block_store.v2.volume - -The Volume Class ----------------- - -The ``Volume`` class inherits from :class:`~openstack.resource.Resource`. - -.. autoclass:: openstack.block_store.v2.volume.Volume - :members: - -The VolumeDetail Class ----------------------- - -The ``VolumeDetail`` class inherits from -:class:`~openstack.block_store.v2.volume.Volume`. - -.. autoclass:: openstack.block_store.v2.volume.VolumeDetail - :members: diff --git a/doc/source/users/resources/cluster/v1/action.rst b/doc/source/users/resources/cluster/v1/action.rst deleted file mode 100644 index f75deb424..000000000 --- a/doc/source/users/resources/cluster/v1/action.rst +++ /dev/null @@ -1,12 +0,0 @@ -openstack.cluster.v1.action -=========================== - -.. automodule:: openstack.cluster.v1.action - -The Action Class ----------------- - -The ``Action`` class inherits from :class:`~openstack.resource.Resource`. - -.. autoclass:: openstack.cluster.v1.action.Action - :members: diff --git a/doc/source/users/resources/cluster/v1/build_info.rst b/doc/source/users/resources/cluster/v1/build_info.rst deleted file mode 100644 index 8534e1f7a..000000000 --- a/doc/source/users/resources/cluster/v1/build_info.rst +++ /dev/null @@ -1,12 +0,0 @@ -openstack.cluster.v1.build_info -=============================== - -.. automodule:: openstack.cluster.v1.build_info - -The BuildInfo Class -------------------- - -The ``BuildInfo`` class inherits from :class:`~openstack.resource.Resource`. - -.. autoclass:: openstack.cluster.v1.build_info.BuildInfo - :members: diff --git a/doc/source/users/resources/cluster/v1/cluster.rst b/doc/source/users/resources/cluster/v1/cluster.rst deleted file mode 100644 index a54ce6cf5..000000000 --- a/doc/source/users/resources/cluster/v1/cluster.rst +++ /dev/null @@ -1,12 +0,0 @@ -openstack.cluster.v1.Cluster -============================ - -.. automodule:: openstack.cluster.v1.cluster - -The Cluster Class ------------------ - -The ``Cluster`` class inherits from :class:`~openstack.resource.Resource`. - -.. autoclass:: openstack.cluster.v1.cluster.Cluster - :members: diff --git a/doc/source/users/resources/cluster/v1/cluster_policy.rst b/doc/source/users/resources/cluster/v1/cluster_policy.rst deleted file mode 100644 index d3a55d541..000000000 --- a/doc/source/users/resources/cluster/v1/cluster_policy.rst +++ /dev/null @@ -1,13 +0,0 @@ -openstack.cluster.v1.cluster_policy -=================================== - -.. automodule:: openstack.cluster.v1.cluster_policy - -The ClusterPolicy Class ------------------------ - -The ``ClusterPolicy`` class inherits from -:class:`~openstack.resource.Resource`. - -.. autoclass:: openstack.cluster.v1.cluster_policy.ClusterPolicy - :members: diff --git a/doc/source/users/resources/cluster/v1/event.rst b/doc/source/users/resources/cluster/v1/event.rst deleted file mode 100644 index 29678062a..000000000 --- a/doc/source/users/resources/cluster/v1/event.rst +++ /dev/null @@ -1,12 +0,0 @@ -openstack.cluster.v1.event -========================== - -.. automodule:: openstack.cluster.v1.event - -The Event Class ---------------- - -The ``Event`` class inherits from :class:`~openstack.resource.Resource`. - -.. autoclass:: openstack.cluster.v1.event.Event - :members: diff --git a/doc/source/users/resources/cluster/v1/node.rst b/doc/source/users/resources/cluster/v1/node.rst deleted file mode 100644 index 74f11f350..000000000 --- a/doc/source/users/resources/cluster/v1/node.rst +++ /dev/null @@ -1,12 +0,0 @@ -openstack.cluster.v1.Node -========================= - -.. automodule:: openstack.cluster.v1.node - -The Node Class --------------- - -The ``Node`` class inherits from :class:`~openstack.resource.Resource`. - -.. autoclass:: openstack.cluster.v1.node.Node - :members: diff --git a/doc/source/users/resources/cluster/v1/policy.rst b/doc/source/users/resources/cluster/v1/policy.rst deleted file mode 100644 index 0fe59378c..000000000 --- a/doc/source/users/resources/cluster/v1/policy.rst +++ /dev/null @@ -1,12 +0,0 @@ -openstack.cluster.v1.policy -=========================== - -.. automodule:: openstack.cluster.v1.policy - -The Policy Class ----------------- - -The ``Policy`` class inherits from :class:`~openstack.resource.Resource`. - -.. autoclass:: openstack.cluster.v1.policy.Policy - :members: diff --git a/doc/source/users/resources/cluster/v1/policy_type.rst b/doc/source/users/resources/cluster/v1/policy_type.rst deleted file mode 100644 index ee74b3101..000000000 --- a/doc/source/users/resources/cluster/v1/policy_type.rst +++ /dev/null @@ -1,12 +0,0 @@ -openstack.cluster.v1.policy_type -================================ - -.. automodule:: openstack.cluster.v1.policy_type - -The PolicyType Class --------------------- - -The ``PolicyType`` class inherits from :class:`~openstack.resource.Resource`. - -.. autoclass:: openstack.cluster.v1.policy_type.PolicyType - :members: diff --git a/doc/source/users/resources/cluster/v1/profile.rst b/doc/source/users/resources/cluster/v1/profile.rst deleted file mode 100644 index bdf782dcb..000000000 --- a/doc/source/users/resources/cluster/v1/profile.rst +++ /dev/null @@ -1,12 +0,0 @@ -openstack.cluster.v1.profile -============================ - -.. automodule:: openstack.cluster.v1.profile - -The Profile Class ------------------ - -The ``Profile`` class inherits from :class:`~openstack.resource.Resource`. - -.. autoclass:: openstack.cluster.v1.profile.Profile - :members: diff --git a/doc/source/users/resources/cluster/v1/profile_type.rst b/doc/source/users/resources/cluster/v1/profile_type.rst deleted file mode 100644 index 48c007f0f..000000000 --- a/doc/source/users/resources/cluster/v1/profile_type.rst +++ /dev/null @@ -1,12 +0,0 @@ -openstack.cluster.v1.profile_type -================================= - -.. automodule:: openstack.cluster.v1.profile_type - -The ProfileType Class ---------------------- - -The ``ProfileType`` class inherits from :class:`~openstack.resource.Resource`. - -.. autoclass:: openstack.cluster.v1.profile_type.ProfileType - :members: diff --git a/doc/source/users/resources/cluster/v1/receiver.rst b/doc/source/users/resources/cluster/v1/receiver.rst deleted file mode 100644 index dc23eb5c8..000000000 --- a/doc/source/users/resources/cluster/v1/receiver.rst +++ /dev/null @@ -1,12 +0,0 @@ -openstack.cluster.v1.receiver -============================= - -.. automodule:: openstack.cluster.v1.receiver - -The Receiver Class ------------------- - -The ``Receiver`` class inherits from :class:`~openstack.resource.Resource`. - -.. autoclass:: openstack.cluster.v1.receiver.Receiver - :members: diff --git a/doc/source/users/resources/cluster/index.rst b/doc/source/users/resources/clustering/index.rst similarity index 100% rename from doc/source/users/resources/cluster/index.rst rename to doc/source/users/resources/clustering/index.rst diff --git a/doc/source/users/resources/clustering/v1/action.rst b/doc/source/users/resources/clustering/v1/action.rst new file mode 100644 index 000000000..a12aa284b --- /dev/null +++ b/doc/source/users/resources/clustering/v1/action.rst @@ -0,0 +1,12 @@ +openstack.clustering.v1.action +============================== + +.. automodule:: openstack.clustering.v1.action + +The Action Class +---------------- + +The ``Action`` class inherits from :class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.clustering.v1.action.Action + :members: diff --git a/doc/source/users/resources/clustering/v1/build_info.rst b/doc/source/users/resources/clustering/v1/build_info.rst new file mode 100644 index 000000000..d84754f27 --- /dev/null +++ b/doc/source/users/resources/clustering/v1/build_info.rst @@ -0,0 +1,12 @@ +openstack.clustering.v1.build_info +================================== + +.. automodule:: openstack.clustering.v1.build_info + +The BuildInfo Class +------------------- + +The ``BuildInfo`` class inherits from :class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.clustering.v1.build_info.BuildInfo + :members: diff --git a/doc/source/users/resources/clustering/v1/cluster.rst b/doc/source/users/resources/clustering/v1/cluster.rst new file mode 100644 index 000000000..43e8a6d51 --- /dev/null +++ b/doc/source/users/resources/clustering/v1/cluster.rst @@ -0,0 +1,12 @@ +openstack.clustering.v1.Cluster +===================================== + +.. automodule:: openstack.clustering.v1.cluster + +The Cluster Class +----------------- + +The ``Cluster`` class inherits from :class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.clustering.v1.cluster.Cluster + :members: diff --git a/doc/source/users/resources/clustering/v1/cluster_policy.rst b/doc/source/users/resources/clustering/v1/cluster_policy.rst new file mode 100644 index 000000000..58ae94374 --- /dev/null +++ b/doc/source/users/resources/clustering/v1/cluster_policy.rst @@ -0,0 +1,13 @@ +openstack.clustering.v1.cluster_policy +====================================== + +.. automodule:: openstack.clustering.v1.cluster_policy + +The ClusterPolicy Class +----------------------- + +The ``ClusterPolicy`` class inherits from +:class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.clustering.v1.cluster_policy.ClusterPolicy + :members: diff --git a/doc/source/users/resources/clustering/v1/event.rst b/doc/source/users/resources/clustering/v1/event.rst new file mode 100644 index 000000000..decc992e2 --- /dev/null +++ b/doc/source/users/resources/clustering/v1/event.rst @@ -0,0 +1,12 @@ +openstack.clustering.v1.event +============================= + +.. automodule:: openstack.clustering.v1.event + +The Event Class +--------------- + +The ``Event`` class inherits from :class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.clustering.v1.event.Event + :members: diff --git a/doc/source/users/resources/clustering/v1/node.rst b/doc/source/users/resources/clustering/v1/node.rst new file mode 100644 index 000000000..3cab1ec47 --- /dev/null +++ b/doc/source/users/resources/clustering/v1/node.rst @@ -0,0 +1,12 @@ +openstack.clustering.v1.Node +============================ + +.. automodule:: openstack.clustering.v1.node + +The Node Class +-------------- + +The ``Node`` class inherits from :class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.clustering.v1.node.Node + :members: diff --git a/doc/source/users/resources/clustering/v1/policy.rst b/doc/source/users/resources/clustering/v1/policy.rst new file mode 100644 index 000000000..00b832ed0 --- /dev/null +++ b/doc/source/users/resources/clustering/v1/policy.rst @@ -0,0 +1,12 @@ +openstack.clustering.v1.policy +============================== + +.. automodule:: openstack.clustering.v1.policy + +The Policy Class +---------------- + +The ``Policy`` class inherits from :class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.clustering.v1.policy.Policy + :members: diff --git a/doc/source/users/resources/clustering/v1/policy_type.rst b/doc/source/users/resources/clustering/v1/policy_type.rst new file mode 100644 index 000000000..ad665f9ed --- /dev/null +++ b/doc/source/users/resources/clustering/v1/policy_type.rst @@ -0,0 +1,12 @@ +openstack.clustering.v1.policy_type +=================================== + +.. automodule:: openstack.clustering.v1.policy_type + +The PolicyType Class +-------------------- + +The ``PolicyType`` class inherits from :class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.clustering.v1.policy_type.PolicyType + :members: diff --git a/doc/source/users/resources/clustering/v1/profile.rst b/doc/source/users/resources/clustering/v1/profile.rst new file mode 100644 index 000000000..c114e0c36 --- /dev/null +++ b/doc/source/users/resources/clustering/v1/profile.rst @@ -0,0 +1,12 @@ +openstack.clustering.v1.profile +=============================== + +.. automodule:: openstack.clustering.v1.profile + +The Profile Class +----------------- + +The ``Profile`` class inherits from :class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.clustering.v1.profile.Profile + :members: diff --git a/doc/source/users/resources/clustering/v1/profile_type.rst b/doc/source/users/resources/clustering/v1/profile_type.rst new file mode 100644 index 000000000..d8534c0d9 --- /dev/null +++ b/doc/source/users/resources/clustering/v1/profile_type.rst @@ -0,0 +1,12 @@ +openstack.clustering.v1.profile_type +==================================== + +.. automodule:: openstack.clustering.v1.profile_type + +The ProfileType Class +--------------------- + +The ``ProfileType`` class inherits from :class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.clustering.v1.profile_type.ProfileType + :members: diff --git a/doc/source/users/resources/clustering/v1/receiver.rst b/doc/source/users/resources/clustering/v1/receiver.rst new file mode 100644 index 000000000..9cdd4e5d7 --- /dev/null +++ b/doc/source/users/resources/clustering/v1/receiver.rst @@ -0,0 +1,12 @@ +openstack.clustering.v1.receiver +================================ + +.. automodule:: openstack.clustering.v1.receiver + +The Receiver Class +------------------ + +The ``Receiver`` class inherits from :class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.clustering.v1.receiver.Receiver + :members: diff --git a/doc/source/users/resources/telemetry/index.rst b/doc/source/users/resources/meter/index.rst similarity index 86% rename from doc/source/users/resources/telemetry/index.rst rename to doc/source/users/resources/meter/index.rst index b429949d6..9efbaf68b 100644 --- a/doc/source/users/resources/telemetry/index.rst +++ b/doc/source/users/resources/meter/index.rst @@ -1,4 +1,4 @@ -Telemetry Resources +Meter Resources =================== .. toctree:: diff --git a/doc/source/users/resources/telemetry/v2/capability.rst b/doc/source/users/resources/meter/v2/capability.rst similarity index 54% rename from doc/source/users/resources/telemetry/v2/capability.rst rename to doc/source/users/resources/meter/v2/capability.rst index c17edd501..b710e907a 100644 --- a/doc/source/users/resources/telemetry/v2/capability.rst +++ b/doc/source/users/resources/meter/v2/capability.rst @@ -1,12 +1,12 @@ -openstack.telemetry.v2.capability +openstack.meter.v2.capability ================================= -.. automodule:: openstack.telemetry.v2.capability +.. automodule:: openstack.meter.v2.capability The Capability Class -------------------- The ``Capability`` class inherits from :class:`~openstack.resource.Resource`. -.. autoclass:: openstack.telemetry.v2.capability.Capability +.. autoclass:: openstack.meter.v2.capability.Capability :members: diff --git a/doc/source/users/resources/telemetry/v2/meter.rst b/doc/source/users/resources/meter/v2/meter.rst similarity index 55% rename from doc/source/users/resources/telemetry/v2/meter.rst rename to doc/source/users/resources/meter/v2/meter.rst index b38bc5b6b..4953ecdaa 100644 --- a/doc/source/users/resources/telemetry/v2/meter.rst +++ b/doc/source/users/resources/meter/v2/meter.rst @@ -1,12 +1,12 @@ -openstack.telemetry.v2.meter +openstack.meter.v2.meter ============================ -.. automodule:: openstack.telemetry.v2.meter +.. automodule:: openstack.meter.v2.meter The Meter Class ---------------- The ``Meter`` class inherits from :class:`~openstack.resource.Resource`. -.. autoclass:: openstack.telemetry.v2.meter.Meter +.. autoclass:: openstack.meter.v2.meter.Meter :members: diff --git a/doc/source/users/resources/telemetry/v2/resource.rst b/doc/source/users/resources/meter/v2/resource.rst similarity index 54% rename from doc/source/users/resources/telemetry/v2/resource.rst rename to doc/source/users/resources/meter/v2/resource.rst index f3b33887d..c2d8c0fdb 100644 --- a/doc/source/users/resources/telemetry/v2/resource.rst +++ b/doc/source/users/resources/meter/v2/resource.rst @@ -1,12 +1,12 @@ -openstack.telemetry.v2.resource +openstack.meter.v2.resource =============================== -.. automodule:: openstack.telemetry.v2.resource +.. automodule:: openstack.meter.v2.resource The Resource Class ------------------ The ``Resource`` class inherits from :class:`~openstack.resource.Resource`. -.. autoclass:: openstack.telemetry.v2.resource.Resource +.. autoclass:: openstack.meter.v2.resource.Resource :members: diff --git a/doc/source/users/resources/telemetry/v2/sample.rst b/doc/source/users/resources/meter/v2/sample.rst similarity index 54% rename from doc/source/users/resources/telemetry/v2/sample.rst rename to doc/source/users/resources/meter/v2/sample.rst index f2430df27..d5573dca6 100644 --- a/doc/source/users/resources/telemetry/v2/sample.rst +++ b/doc/source/users/resources/meter/v2/sample.rst @@ -1,12 +1,12 @@ -openstack.telemetry.v2.sample +openstack.meter.v2.sample ============================= -.. automodule:: openstack.telemetry.v2.sample +.. automodule:: openstack.meter.v2.sample The Sample Class ---------------- The ``Sample`` class inherits from :class:`~openstack.resource.Resource`. -.. autoclass:: openstack.telemetry.v2.sample.Sample +.. autoclass:: openstack.meter.v2.sample.Sample :members: diff --git a/doc/source/users/resources/telemetry/v2/statistics.rst b/doc/source/users/resources/meter/v2/statistics.rst similarity index 54% rename from doc/source/users/resources/telemetry/v2/statistics.rst rename to doc/source/users/resources/meter/v2/statistics.rst index 7e1e6b8a5..14661beb9 100644 --- a/doc/source/users/resources/telemetry/v2/statistics.rst +++ b/doc/source/users/resources/meter/v2/statistics.rst @@ -1,12 +1,12 @@ -openstack.telemetry.v2.statistics +openstack.meter.v2.statistics ================================= -.. automodule:: openstack.telemetry.v2.statistics +.. automodule:: openstack.meter.v2.statistics The Statistics Class -------------------- The ``Statistics`` class inherits from :class:`~openstack.resource.Resource`. -.. autoclass:: openstack.telemetry.v2.statistics.Statistics +.. autoclass:: openstack.meter.v2.statistics.Statistics :members: diff --git a/doc/source/users/session.rst b/doc/source/users/session.rst deleted file mode 100644 index 44ac576b2..000000000 --- a/doc/source/users/session.rst +++ /dev/null @@ -1,10 +0,0 @@ -Session -======= - -.. automodule:: openstack.session - -Session Object --------------- - -.. autoclass:: openstack.session.Session - :members: diff --git a/examples/cluster/__init__.py b/examples/clustering/__init__.py similarity index 100% rename from examples/cluster/__init__.py rename to examples/clustering/__init__.py diff --git a/examples/cluster/policy.py b/examples/clustering/policy.py similarity index 100% rename from examples/cluster/policy.py rename to examples/clustering/policy.py diff --git a/examples/cluster/policy_type.py b/examples/clustering/policy_type.py similarity index 100% rename from examples/cluster/policy_type.py rename to examples/clustering/policy_type.py diff --git a/examples/cluster/profile.py b/examples/clustering/profile.py similarity index 100% rename from examples/cluster/profile.py rename to examples/clustering/profile.py diff --git a/examples/cluster/profile_type.py b/examples/clustering/profile_type.py similarity index 97% rename from examples/cluster/profile_type.py rename to examples/clustering/profile_type.py index 8a3e99550..2856e4e0f 100644 --- a/examples/cluster/profile_type.py +++ b/examples/clustering/profile_type.py @@ -14,7 +14,7 @@ Managing profile types in the Cluster service. For a full guide see -https://developer.openstack.org/sdks/python/openstacksdk/users/guides/cluster.html +https://developer.openstack.org/sdks/python/openstacksdk/users/guides/clustering.html """ diff --git a/examples/connect.py b/examples/connect.py index 7db375ca5..cb819a7a4 100644 --- a/examples/connect.py +++ b/examples/connect.py @@ -19,9 +19,8 @@ For a full guide see TODO(etoews):link to docs on developer.openstack.org import argparse import os +import openstack from openstack import config as occ -from openstack import connection -from openstack import profile from openstack import utils import sys @@ -49,7 +48,7 @@ def _get_resource_value(resource_key, default): return default config = occ.OpenStackConfig() -cloud = config.get_one_cloud(TEST_CLOUD) +cloud = openstack.connect(cloud=TEST_CLOUD) SERVER_NAME = 'openstacksdk-example' IMAGE_NAME = _get_resource_value('image_name', 'cirros-0.3.5-x86_64-disk') @@ -66,10 +65,7 @@ EXAMPLE_IMAGE_NAME = 'openstacksdk-example-public-image' def create_connection_from_config(): - opts = Opts(cloud_name=TEST_CLOUD) - config = occ.OpenStackConfig() - cloud = config.get_one_cloud(opts.cloud) - return connection.from_config(cloud_config=cloud, options=opts) + return openstack.connect(cloud=TEST_CLOUD) def create_connection_from_args(): @@ -77,18 +73,17 @@ def create_connection_from_args(): config = occ.OpenStackConfig() config.register_argparse_arguments(parser, sys.argv[1:]) args = parser.parse_args() - return connection.from_config(options=args) + return openstack.connect(config=config.get_one_cloud(argparse=args)) def create_connection(auth_url, region, project_name, username, password): - prof = profile.Profile() - prof.set_region(profile.Profile.ALL, region) - return connection.Connection( - profile=prof, - user_agent='examples', + return openstack.connect( auth_url=auth_url, project_name=project_name, username=username, - password=password + password=password, + region_name=region, + app_name='examples', + app_version='1.0', ) diff --git a/openstack/__init__.py b/openstack/__init__.py index a03c06908..a34937014 100644 --- a/openstack/__init__.py +++ b/openstack/__init__.py @@ -23,6 +23,7 @@ from openstack import _log from openstack.cloud.exc import * # noqa from openstack.cloud.openstackcloud import OpenStackCloud from openstack.cloud.operatorcloud import OperatorCloud +import openstack.connection __version__ = pbr.version.VersionInfo('openstacksdk').version_string() @@ -130,3 +131,8 @@ def operator_cloud( raise OpenStackCloudException( "Invalid cloud configuration: {exc}".format(exc=str(e))) return OperatorCloud(cloud_config=cloud_config, strict=strict) + + +def connect(self, *args, **kwargs): + """Create a `openstack.connection.Connection`.""" + return openstack.connection.Connection(*args, **kwargs) diff --git a/openstack/bare_metal/__init__.py b/openstack/baremetal/__init__.py similarity index 100% rename from openstack/bare_metal/__init__.py rename to openstack/baremetal/__init__.py diff --git a/openstack/bare_metal/bare_metal_service.py b/openstack/baremetal/baremetal_service.py similarity index 87% rename from openstack/bare_metal/bare_metal_service.py rename to openstack/baremetal/baremetal_service.py index 71c3bca59..9853be081 100644 --- a/openstack/bare_metal/bare_metal_service.py +++ b/openstack/baremetal/baremetal_service.py @@ -13,12 +13,12 @@ from openstack import service_filter -class BareMetalService(service_filter.ServiceFilter): +class BaremetalService(service_filter.ServiceFilter): """The bare metal service.""" valid_versions = [service_filter.ValidVersion('v1')] def __init__(self, version=None): """Create a bare metal service.""" - super(BareMetalService, self).__init__(service_type='baremetal', + super(BaremetalService, self).__init__(service_type='baremetal', version=version) diff --git a/openstack/bare_metal/v1/__init__.py b/openstack/baremetal/v1/__init__.py similarity index 100% rename from openstack/bare_metal/v1/__init__.py rename to openstack/baremetal/v1/__init__.py diff --git a/openstack/bare_metal/v1/_proxy.py b/openstack/baremetal/v1/_proxy.py similarity index 88% rename from openstack/bare_metal/v1/_proxy.py rename to openstack/baremetal/v1/_proxy.py index 0c3cccfb0..0e68cf357 100644 --- a/openstack/bare_metal/v1/_proxy.py +++ b/openstack/baremetal/v1/_proxy.py @@ -10,11 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.bare_metal.v1 import chassis as _chassis -from openstack.bare_metal.v1 import driver as _driver -from openstack.bare_metal.v1 import node as _node -from openstack.bare_metal.v1 import port as _port -from openstack.bare_metal.v1 import port_group as _portgroup +from openstack.baremetal.v1 import chassis as _chassis +from openstack.baremetal.v1 import driver as _driver +from openstack.baremetal.v1 import node as _node +from openstack.baremetal.v1 import port as _port +from openstack.baremetal.v1 import port_group as _portgroup from openstack import proxy2 from openstack import utils @@ -61,11 +61,11 @@ class Proxy(proxy2.BaseProxy): """Create a new chassis from attributes. :param dict attrs: Keyword arguments that will be used to create a - :class:`~openstack.bare_metal.v1.chassis.Chassis`, it comprised + :class:`~openstack.baremetal.v1.chassis.Chassis`, it comprised of the properties on the ``Chassis`` class. :returns: The results of chassis creation. - :rtype: :class:`~openstack.bare_metal.v1.chassis.Chassis`. + :rtype: :class:`~openstack.baremetal.v1.chassis.Chassis`. """ return self._create(_chassis.Chassis, **attrs) @@ -77,7 +77,7 @@ class Proxy(proxy2.BaseProxy): :class:`~openstack.exceptions.ResourceNotFound` will be raised when the chassis does not exist. When set to `True``, None will be returned when attempting to find a nonexistent chassis. - :returns: One :class:`~openstack.bare_metal.v1.chassis.Chassis` object + :returns: One :class:`~openstack.baremetal.v1.chassis.Chassis` object or None. """ return self._find(_chassis.Chassis, name_or_id, @@ -87,9 +87,9 @@ class Proxy(proxy2.BaseProxy): """Get a specific chassis. :param chassis: The value can be the name or ID of a chassis or a - :class:`~openstack.bare_metal.v1.chassis.Chassis` instance. + :class:`~openstack.baremetal.v1.chassis.Chassis` instance. - :returns: One :class:`~openstack.bare_metal.v1.chassis.Chassis` + :returns: One :class:`~openstack.baremetal.v1.chassis.Chassis` :raises: :class:`~openstack.exceptions.ResourceNotFound` when no chassis matching the name or ID could be found. """ @@ -99,12 +99,12 @@ class Proxy(proxy2.BaseProxy): """Update a chassis. :param chassis: Either the name or the ID of a chassis, or an instance - of :class:`~openstack.bare_metal.v1.chassis.Chassis`. + of :class:`~openstack.baremetal.v1.chassis.Chassis`. :param dict attrs: The attributes to update on the chassis represented by the ``chassis`` parameter. :returns: The updated chassis. - :rtype: :class:`~openstack.bare_metal.v1.chassis.Chassis` + :rtype: :class:`~openstack.baremetal.v1.chassis.Chassis` """ return self._update(_chassis.Chassis, chassis, **attrs) @@ -112,7 +112,7 @@ class Proxy(proxy2.BaseProxy): """Delete a chassis. :param chassis: The value can be either the name or ID of a chassis or - a :class:`~openstack.bare_metal.v1.chassis.Chassis` instance. + a :class:`~openstack.baremetal.v1.chassis.Chassis` instance. :param bool ignore_missing: When set to ``False``, an exception :class:`~openstack.exceptions.ResourceNotFound` will be raised when the chassis could not be found. When set to ``True``, no @@ -120,7 +120,7 @@ class Proxy(proxy2.BaseProxy): chassis. :returns: The instance of the chassis which was deleted. - :rtype: :class:`~openstack.bare_metal.v1.chassis.Chassis`. + :rtype: :class:`~openstack.baremetal.v1.chassis.Chassis`. """ return self._delete(_chassis.Chassis, chassis, ignore_missing=ignore_missing) @@ -136,9 +136,9 @@ class Proxy(proxy2.BaseProxy): """Get a specific driver. :param driver: The value can be the name of a driver or a - :class:`~openstack.bare_metal.v1.driver.Driver` instance. + :class:`~openstack.baremetal.v1.driver.Driver` instance. - :returns: One :class:`~openstack.bare_metal.v1.driver.Driver` + :returns: One :class:`~openstack.baremetal.v1.driver.Driver` :raises: :class:`~openstack.exceptions.ResourceNotFound` when no driver matching the name could be found. """ @@ -193,11 +193,11 @@ class Proxy(proxy2.BaseProxy): """Create a new node from attributes. :param dict attrs: Keyword arguments that will be used to create a - :class:`~openstack.bare_metal.v1.node.Node`, it comprised + :class:`~openstack.baremetal.v1.node.Node`, it comprised of the properties on the ``Node`` class. :returns: The results of node creation. - :rtype: :class:`~openstack.bare_metal.v1.node.Node`. + :rtype: :class:`~openstack.baremetal.v1.node.Node`. """ return self._create(_node.Node, **attrs) @@ -209,7 +209,7 @@ class Proxy(proxy2.BaseProxy): :class:`~openstack.exceptions.ResourceNotFound` will be raised when the node does not exist. When set to `True``, None will be returned when attempting to find a nonexistent node. - :returns: One :class:`~openstack.bare_metal.v1.node.Node` object + :returns: One :class:`~openstack.baremetal.v1.node.Node` object or None. """ return self._find(_node.Node, name_or_id, @@ -219,9 +219,9 @@ class Proxy(proxy2.BaseProxy): """Get a specific node. :param node: The value can be the name or ID of a chassis or a - :class:`~openstack.bare_metal.v1.node.Node` instance. + :class:`~openstack.baremetal.v1.node.Node` instance. - :returns: One :class:`~openstack.bare_metal.v1.node.Node` + :returns: One :class:`~openstack.baremetal.v1.node.Node` :raises: :class:`~openstack.exceptions.ResourceNotFound` when no node matching the name or ID could be found. """ @@ -231,12 +231,12 @@ class Proxy(proxy2.BaseProxy): """Update a node. :param chassis: Either the name or the ID of a node or an instance - of :class:`~openstack.bare_metal.v1.node.Node`. + of :class:`~openstack.baremetal.v1.node.Node`. :param dict attrs: The attributes to update on the node represented by the ``node`` parameter. :returns: The updated node. - :rtype: :class:`~openstack.bare_metal.v1.node.Node` + :rtype: :class:`~openstack.baremetal.v1.node.Node` """ return self._update(_node.Node, node, **attrs) @@ -244,7 +244,7 @@ class Proxy(proxy2.BaseProxy): """Delete a node. :param node: The value can be either the name or ID of a node or - a :class:`~openstack.bare_metal.v1.node.Node` instance. + a :class:`~openstack.baremetal.v1.node.Node` instance. :param bool ignore_missing: When set to ``False``, an exception :class:`~openstack.exceptions.ResourceNotFound` will be raised when the node could not be found. When set to ``True``, no @@ -252,7 +252,7 @@ class Proxy(proxy2.BaseProxy): node. :returns: The instance of the node which was deleted. - :rtype: :class:`~openstack.bare_metal.v1.node.Node`. + :rtype: :class:`~openstack.baremetal.v1.node.Node`. """ return self._delete(_node.Node, node, ignore_missing=ignore_missing) @@ -306,11 +306,11 @@ class Proxy(proxy2.BaseProxy): """Create a new port from attributes. :param dict attrs: Keyword arguments that will be used to create a - :class:`~openstack.bare_metal.v1.port.Port`, it comprises of the + :class:`~openstack.baremetal.v1.port.Port`, it comprises of the properties on the ``Port`` class. :returns: The results of port creation. - :rtype: :class:`~openstack.bare_metal.v1.port.Port`. + :rtype: :class:`~openstack.baremetal.v1.port.Port`. """ return self._create(_port.Port, **attrs) @@ -322,7 +322,7 @@ class Proxy(proxy2.BaseProxy): :class:`~openstack.exceptions.ResourceNotFound` will be raised when the port does not exist. When set to `True``, None will be returned when attempting to find a nonexistent port. - :returns: One :class:`~openstack.bare_metal.v1.port.Port` object + :returns: One :class:`~openstack.baremetal.v1.port.Port` object or None. """ return self._find(_port.Port, name_or_id, @@ -332,7 +332,7 @@ class Proxy(proxy2.BaseProxy): """Get a specific port. :param port: The value can be the name or ID of a chassis or a - :class:`~openstack.bare_metal.v1.port.Port` instance. + :class:`~openstack.baremetal.v1.port.Port` instance. :param dict query: Optional query parameters to be sent to restrict the port properties returned. Available parameters include: @@ -340,7 +340,7 @@ class Proxy(proxy2.BaseProxy): in the response. This may lead to some performance gain because other fields of the resource are not refreshed. - :returns: One :class:`~openstack.bare_metal.v1.port.Port` + :returns: One :class:`~openstack.baremetal.v1.port.Port` :raises: :class:`~openstack.exceptions.ResourceNotFound` when no port matching the name or ID could be found. """ @@ -350,12 +350,12 @@ class Proxy(proxy2.BaseProxy): """Update a port. :param chassis: Either the name or the ID of a port or an instance - of :class:`~openstack.bare_metal.v1.port.Port`. + of :class:`~openstack.baremetal.v1.port.Port`. :param dict attrs: The attributes to update on the port represented by the ``port`` parameter. :returns: The updated port. - :rtype: :class:`~openstack.bare_metal.v1.port.Port` + :rtype: :class:`~openstack.baremetal.v1.port.Port` """ return self._update(_port.Port, port, **attrs) @@ -363,7 +363,7 @@ class Proxy(proxy2.BaseProxy): """Delete a port. :param port: The value can be either the name or ID of a port or - a :class:`~openstack.bare_metal.v1.port.Port` instance. + a :class:`~openstack.baremetal.v1.port.Port` instance. :param bool ignore_missing: When set to ``False``, an exception :class:`~openstack.exceptions.ResourceNotFound` will be raised when the port could not be found. When set to ``True``, no @@ -371,7 +371,7 @@ class Proxy(proxy2.BaseProxy): port. :returns: The instance of the port which was deleted. - :rtype: :class:`~openstack.bare_metal.v1.port.Port`. + :rtype: :class:`~openstack.baremetal.v1.port.Port`. """ return self._delete(_port.Port, port, ignore_missing=ignore_missing) @@ -462,11 +462,11 @@ class Proxy(proxy2.BaseProxy): """Create a new port group from attributes. :param dict attrs: Keyword arguments that will be used to create a - :class:`~openstack.bare_metal.v1.port_group.PortGroup`, it + :class:`~openstack.baremetal.v1.port_group.PortGroup`, it comprises of the properties on the ``PortGroup`` class. :returns: The results of portgroup creation. - :rtype: :class:`~openstack.bare_metal.v1.port_group.PortGroup`. + :rtype: :class:`~openstack.baremetal.v1.port_group.PortGroup`. """ return self.create_port_group(**attrs) @@ -474,11 +474,11 @@ class Proxy(proxy2.BaseProxy): """Create a new portgroup from attributes. :param dict attrs: Keyword arguments that will be used to create a - :class:`~openstack.bare_metal.v1.port_group.PortGroup`, it + :class:`~openstack.baremetal.v1.port_group.PortGroup`, it comprises of the properties on the ``PortGroup`` class. :returns: The results of portgroup creation. - :rtype: :class:`~openstack.bare_metal.v1.port_group.PortGroup`. + :rtype: :class:`~openstack.baremetal.v1.port_group.PortGroup`. """ return self._create(_portgroup.PortGroup, **attrs) @@ -492,7 +492,7 @@ class Proxy(proxy2.BaseProxy): :class:`~openstack.exceptions.ResourceNotFound` will be raised when the port group does not exist. When set to `True``, None will be returned when attempting to find a nonexistent port group. - :returns: One :class:`~openstack.bare_metal.v1.port_group.PortGroup` + :returns: One :class:`~openstack.baremetal.v1.port_group.PortGroup` object or None. """ return self.find_port_group(name_or_id, ignore_missing=ignore_missing) @@ -505,7 +505,7 @@ class Proxy(proxy2.BaseProxy): :class:`~openstack.exceptions.ResourceNotFound` will be raised when the port group does not exist. When set to `True``, None will be returned when attempting to find a nonexistent port group. - :returns: One :class:`~openstack.bare_metal.v1.port_group.PortGroup` + :returns: One :class:`~openstack.baremetal.v1.port_group.PortGroup` object or None. """ return self._find(_portgroup.PortGroup, name_or_id, @@ -517,7 +517,7 @@ class Proxy(proxy2.BaseProxy): """Get a specific port group. :param portgroup: The value can be the name or ID of a chassis or a - :class:`~openstack.bare_metal.v1.port_group.PortGroup` instance. + :class:`~openstack.baremetal.v1.port_group.PortGroup` instance. :param dict query: Optional query parameters to be sent to restrict the portgroup properties returned. Available parameters include: @@ -525,7 +525,7 @@ class Proxy(proxy2.BaseProxy): in the response. This may lead to some performance gain because other fields of the resource are not refreshed. - :returns: One :class:`~openstack.bare_metal.v1.port_group.PortGroup` + :returns: One :class:`~openstack.baremetal.v1.port_group.PortGroup` :raises: :class:`~openstack.exceptions.ResourceNotFound` when no port group matching the name or ID could be found. """ @@ -535,7 +535,7 @@ class Proxy(proxy2.BaseProxy): """Get a specific port group. :param port_group: The value can be the name or ID of a chassis or a - :class:`~openstack.bare_metal.v1.port_group.PortGroup` instance. + :class:`~openstack.baremetal.v1.port_group.PortGroup` instance. :param dict query: Optional query parameters to be sent to restrict the port group properties returned. Available parameters include: @@ -543,7 +543,7 @@ class Proxy(proxy2.BaseProxy): in the response. This may lead to some performance gain because other fields of the resource are not refreshed. - :returns: One :class:`~openstack.bare_metal.v1.port_group.PortGroup` + :returns: One :class:`~openstack.baremetal.v1.port_group.PortGroup` :raises: :class:`~openstack.exceptions.ResourceNotFound` when no port group matching the name or ID could be found. """ @@ -556,12 +556,12 @@ class Proxy(proxy2.BaseProxy): :param chassis: Either the name or the ID of a port group or an instance of - :class:`~openstack.bare_metal.v1.port_group.PortGroup`. + :class:`~openstack.baremetal.v1.port_group.PortGroup`. :param dict attrs: The attributes to update on the port group represented by the ``portgroup`` parameter. :returns: The updated port group. - :rtype: :class:`~openstack.bare_metal.v1.port_group.PortGroup` + :rtype: :class:`~openstack.baremetal.v1.port_group.PortGroup` """ return self.update_port_group(portgroup, **attrs) @@ -570,12 +570,12 @@ class Proxy(proxy2.BaseProxy): :param chassis: Either the name or the ID of a port group or an instance of - :class:`~openstack.bare_metal.v1.port_group.PortGroup`. + :class:`~openstack.baremetal.v1.port_group.PortGroup`. :param dict attrs: The attributes to update on the port group represented by the ``port_group`` parameter. :returns: The updated port group. - :rtype: :class:`~openstack.bare_metal.v1.port_group.PortGroup` + :rtype: :class:`~openstack.baremetal.v1.port_group.PortGroup` """ return self._update(_portgroup.PortGroup, port_group, **attrs) @@ -586,7 +586,7 @@ class Proxy(proxy2.BaseProxy): :param portgroup: The value can be either the name or ID of a port group or a - :class:`~openstack.bare_metal.v1.port_group.PortGroup` + :class:`~openstack.baremetal.v1.port_group.PortGroup` instance. :param bool ignore_missing: When set to ``False``, an exception :class:`~openstack.exceptions.ResourceNotFound` will be raised @@ -595,7 +595,7 @@ class Proxy(proxy2.BaseProxy): port group. :returns: The instance of the port group which was deleted. - :rtype: :class:`~openstack.bare_metal.v1.port_group.PortGroup`. + :rtype: :class:`~openstack.baremetal.v1.port_group.PortGroup`. """ return self.delete_port_group(portgroup, ignore_missing=ignore_missing) @@ -604,7 +604,7 @@ class Proxy(proxy2.BaseProxy): :param port_group: The value can be either the name or ID of a port group or a - :class:`~openstack.bare_metal.v1.port_group.PortGroup` + :class:`~openstack.baremetal.v1.port_group.PortGroup` instance. :param bool ignore_missing: When set to ``False``, an exception :class:`~openstack.exceptions.ResourceNotFound` will be raised @@ -613,7 +613,7 @@ class Proxy(proxy2.BaseProxy): port group. :returns: The instance of the port group which was deleted. - :rtype: :class:`~openstack.bare_metal.v1.port_group.PortGroup`. + :rtype: :class:`~openstack.baremetal.v1.port_group.PortGroup`. """ return self._delete(_portgroup.PortGroup, port_group, ignore_missing=ignore_missing) diff --git a/openstack/bare_metal/v1/chassis.py b/openstack/baremetal/v1/chassis.py similarity index 94% rename from openstack/bare_metal/v1/chassis.py rename to openstack/baremetal/v1/chassis.py index 7440e2f46..a8ba9746a 100644 --- a/openstack/bare_metal/v1/chassis.py +++ b/openstack/baremetal/v1/chassis.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.bare_metal import bare_metal_service +from openstack.baremetal import baremetal_service from openstack import resource2 as resource @@ -18,7 +18,7 @@ class Chassis(resource.Resource): resources_key = 'chassis' base_path = '/chassis' - service = bare_metal_service.BareMetalService() + service = baremetal_service.BaremetalService() # capabilities allow_create = True diff --git a/openstack/bare_metal/v1/driver.py b/openstack/baremetal/v1/driver.py similarity index 92% rename from openstack/bare_metal/v1/driver.py rename to openstack/baremetal/v1/driver.py index fcf6229b3..8421bdb54 100644 --- a/openstack/bare_metal/v1/driver.py +++ b/openstack/baremetal/v1/driver.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.bare_metal import bare_metal_service +from openstack.baremetal import baremetal_service from openstack import resource2 as resource @@ -18,7 +18,7 @@ class Driver(resource.Resource): resources_key = 'drivers' base_path = '/drivers' - service = bare_metal_service.BareMetalService() + service = baremetal_service.BaremetalService() # capabilities allow_create = False diff --git a/openstack/bare_metal/v1/node.py b/openstack/baremetal/v1/node.py similarity index 97% rename from openstack/bare_metal/v1/node.py rename to openstack/baremetal/v1/node.py index 8d920e66f..c1b6266ed 100644 --- a/openstack/bare_metal/v1/node.py +++ b/openstack/baremetal/v1/node.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.bare_metal import bare_metal_service +from openstack.baremetal import baremetal_service from openstack import resource2 as resource @@ -18,7 +18,7 @@ class Node(resource.Resource): resources_key = 'nodes' base_path = '/nodes' - service = bare_metal_service.BareMetalService() + service = baremetal_service.BaremetalService() # capabilities allow_create = True @@ -45,7 +45,7 @@ class Node(resource.Resource): driver = resource.Body("driver") #: All the metadata required by the driver to manage this node. List of #: fields varies between drivers, and can be retrieved from the - #: :class:`openstack.bare_metal.v1.driver.Driver` resource. + #: :class:`openstack.baremetal.v1.driver.Driver` resource. driver_info = resource.Body("driver_info", type=dict) #: Internal metadata set and stored by node's driver. This is read-only. driver_internal_info = resource.Body("driver_internal_info", type=dict) diff --git a/openstack/bare_metal/v1/port.py b/openstack/baremetal/v1/port.py similarity index 96% rename from openstack/bare_metal/v1/port.py rename to openstack/baremetal/v1/port.py index 99aa0ffe1..a3f86594c 100644 --- a/openstack/bare_metal/v1/port.py +++ b/openstack/baremetal/v1/port.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.bare_metal import bare_metal_service +from openstack.baremetal import baremetal_service from openstack import resource2 as resource @@ -18,7 +18,7 @@ class Port(resource.Resource): resources_key = 'ports' base_path = '/ports' - service = bare_metal_service.BareMetalService() + service = baremetal_service.BaremetalService() # capabilities allow_create = True diff --git a/openstack/bare_metal/v1/port_group.py b/openstack/baremetal/v1/port_group.py similarity index 96% rename from openstack/bare_metal/v1/port_group.py rename to openstack/baremetal/v1/port_group.py index 7cec820e9..b2db7467f 100644 --- a/openstack/bare_metal/v1/port_group.py +++ b/openstack/baremetal/v1/port_group.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.bare_metal import bare_metal_service +from openstack.baremetal import baremetal_service from openstack import resource2 as resource @@ -18,7 +18,7 @@ class PortGroup(resource.Resource): resources_key = 'portgroups' base_path = '/portgroups' - service = bare_metal_service.BareMetalService() + service = baremetal_service.BaremetalService() # capabilities allow_create = True diff --git a/openstack/bare_metal/version.py b/openstack/baremetal/version.py similarity index 83% rename from openstack/bare_metal/version.py rename to openstack/baremetal/version.py index f98f3b1f4..51d0e85bf 100644 --- a/openstack/bare_metal/version.py +++ b/openstack/baremetal/version.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.bare_metal import bare_metal_service +from openstack.baremetal import baremetal_service from openstack import resource2 @@ -18,8 +18,8 @@ class Version(resource2.Resource): resource_key = 'version' resources_key = 'versions' base_path = '/' - service = bare_metal_service.BareMetalService( - version=bare_metal_service.BareMetalService.UNVERSIONED + service = baremetal_service.BaremetalService( + version=baremetal_service.BaremetalService.UNVERSIONED ) # Capabilities diff --git a/openstack/block_store/__init__.py b/openstack/block_storage/__init__.py similarity index 100% rename from openstack/block_store/__init__.py rename to openstack/block_storage/__init__.py diff --git a/openstack/block_store/block_store_service.py b/openstack/block_storage/block_storage_service.py similarity index 66% rename from openstack/block_store/block_store_service.py rename to openstack/block_storage/block_storage_service.py index fa133a6a7..7192544ff 100644 --- a/openstack/block_store/block_store_service.py +++ b/openstack/block_storage/block_storage_service.py @@ -13,13 +13,12 @@ from openstack import service_filter -class BlockStoreService(service_filter.ServiceFilter): - """The block store service.""" +class BlockStorageService(service_filter.ServiceFilter): + """The block storage service.""" valid_versions = [service_filter.ValidVersion('v2')] def __init__(self, version=None): - """Create a block store service.""" - super(BlockStoreService, self).__init__(service_type='volume', - version=version, - requires_project_id=True) + """Create a block storage service.""" + super(BlockStorageService, self).__init__( + service_type='volume', version=version, requires_project_id=True) diff --git a/openstack/block_store/v2/__init__.py b/openstack/block_storage/v2/__init__.py similarity index 100% rename from openstack/block_store/v2/__init__.py rename to openstack/block_storage/v2/__init__.py diff --git a/openstack/block_store/v2/_proxy.py b/openstack/block_storage/v2/_proxy.py similarity index 93% rename from openstack/block_store/v2/_proxy.py rename to openstack/block_storage/v2/_proxy.py index 1d82eae3a..202a2d8a0 100644 --- a/openstack/block_store/v2/_proxy.py +++ b/openstack/block_storage/v2/_proxy.py @@ -10,9 +10,9 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.block_store.v2 import snapshot as _snapshot -from openstack.block_store.v2 import type as _type -from openstack.block_store.v2 import volume as _volume +from openstack.block_storage.v2 import snapshot as _snapshot +from openstack.block_storage.v2 import type as _type +from openstack.block_storage.v2 import volume as _volume from openstack import proxy2 @@ -35,9 +35,9 @@ class Proxy(proxy2.BaseProxy): """Retrieve a generator of snapshots :param bool details: When set to ``False`` - :class:`~openstack.block_store.v2.snapshot.Snapshot` + :class:`~openstack.block_storage.v2.snapshot.Snapshot` objects will be returned. The default, ``True``, will cause - :class:`~openstack.block_store.v2.snapshot.SnapshotDetail` + :class:`~openstack.block_storage.v2.snapshot.SnapshotDetail` objects to be returned. :param kwargs \*\*query: Optional query parameters to be sent to limit the snapshots being returned. Available parameters include: @@ -144,9 +144,9 @@ class Proxy(proxy2.BaseProxy): """Retrieve a generator of volumes :param bool details: When set to ``False`` - :class:`~openstack.block_store.v2.volume.Volume` objects + :class:`~openstack.block_storage.v2.volume.Volume` objects will be returned. The default, ``True``, will cause - :class:`~openstack.block_store.v2.volume.VolumeDetail` + :class:`~openstack.block_storage.v2.volume.VolumeDetail` objects to be returned. :param kwargs \*\*query: Optional query parameters to be sent to limit the volumes being returned. Available parameters include: diff --git a/openstack/block_store/v2/snapshot.py b/openstack/block_storage/v2/snapshot.py similarity index 95% rename from openstack/block_store/v2/snapshot.py rename to openstack/block_storage/v2/snapshot.py index ae2755c26..9d5b3dae6 100644 --- a/openstack/block_store/v2/snapshot.py +++ b/openstack/block_storage/v2/snapshot.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.block_store import block_store_service +from openstack.block_storage import block_storage_service from openstack import format from openstack import resource2 @@ -19,7 +19,7 @@ class Snapshot(resource2.Resource): resource_key = "snapshot" resources_key = "snapshots" base_path = "/snapshots" - service = block_store_service.BlockStoreService() + service = block_storage_service.BlockStorageService() _query_mapping = resource2.QueryParameters('all_tenants', 'name', 'status', 'volume_id') diff --git a/openstack/block_store/v2/type.py b/openstack/block_storage/v2/type.py similarity index 90% rename from openstack/block_store/v2/type.py rename to openstack/block_storage/v2/type.py index a39466a5a..7b477aee4 100644 --- a/openstack/block_store/v2/type.py +++ b/openstack/block_storage/v2/type.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.block_store import block_store_service +from openstack.block_storage import block_storage_service from openstack import resource2 @@ -18,7 +18,7 @@ class Type(resource2.Resource): resource_key = "volume_type" resources_key = "volume_types" base_path = "/types" - service = block_store_service.BlockStoreService() + service = block_storage_service.BlockStorageService() # capabilities allow_get = True diff --git a/openstack/block_store/v2/volume.py b/openstack/block_storage/v2/volume.py similarity index 97% rename from openstack/block_store/v2/volume.py rename to openstack/block_storage/v2/volume.py index a20ddd621..82ef84071 100644 --- a/openstack/block_store/v2/volume.py +++ b/openstack/block_storage/v2/volume.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.block_store import block_store_service +from openstack.block_storage import block_storage_service from openstack import format from openstack import resource2 @@ -19,7 +19,7 @@ class Volume(resource2.Resource): resource_key = "volume" resources_key = "volumes" base_path = "/volumes" - service = block_store_service.BlockStoreService() + service = block_storage_service.BlockStorageService() _query_mapping = resource2.QueryParameters('all_tenants', 'name', 'status', 'project_id') diff --git a/openstack/cloud/_adapter.py b/openstack/cloud/_adapter.py index 2929a195b..8807329f3 100644 --- a/openstack/cloud/_adapter.py +++ b/openstack/cloud/_adapter.py @@ -12,18 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -''' Wrapper around keystoneauth Session to wrap calls in TaskManager ''' +''' Wrapper around keystoneauth Adapter to wrap calls in TaskManager ''' import functools -from keystoneauth1 import adapter from six.moves import urllib -from openstack import _log -from openstack.cloud import exc -from openstack.cloud import task_manager +from keystoneauth1 import adapter + +from openstack.cloud import task_manager as _task_manager +from openstack import exceptions -def extract_name(url): +def _extract_name(url): '''Produce a key name to use in logging/metrics from the URL path. We want to be able to logic/metric sane general things, so we pull @@ -81,86 +81,67 @@ def extract_name(url): return [part for part in name_parts if part] -# TODO(shade) This adapter should go away in favor of the work merging -# adapter with openstack.proxy. -class ShadeAdapter(adapter.Adapter): +class OpenStackSDKAdapter(adapter.Adapter): + """Wrapper around keystoneauth1.adapter.Adapter. - def __init__(self, shade_logger, manager, *args, **kwargs): - super(ShadeAdapter, self).__init__(*args, **kwargs) - self.shade_logger = shade_logger - self.manager = manager - self.request_log = _log.setup_logging('openstack.cloud.request_ids') + Uses task_manager to run tasks rather than executing them directly. + This allows using the nodepool MultiThreaded Rate Limiting TaskManager. + """ - def _log_request_id(self, response, obj=None): - # Log the request id and object id in a specific logger. This way - # someone can turn it on if they're interested in this kind of tracing. - request_id = response.headers.get('x-openstack-request-id') - if not request_id: - return response - tmpl = "{meth} call to {service} for {url} used request id {req}" - kwargs = dict( - meth=response.request.method, - service=self.service_type, - url=response.request.url, - req=request_id) + def __init__(self, session=None, task_manager=None, *args, **kwargs): + super(OpenStackSDKAdapter, self).__init__( + session=session, *args, **kwargs) + if not task_manager: + task_manager = _task_manager.TaskManager(name=self.service_type) - if isinstance(obj, dict): - obj_id = obj.get('id', obj.get('uuid')) - if obj_id: - kwargs['obj_id'] = obj_id - tmpl += " returning object {obj_id}" - self.request_log.debug(tmpl.format(**kwargs)) - return response - - def _munch_response(self, response, result_key=None, error_message=None): - exc.raise_from_response(response, error_message=error_message) - - if not response.content: - # This doens't have any content - return self._log_request_id(response) - - # Some REST calls do not return json content. Don't decode it. - if 'application/json' not in response.headers.get('Content-Type'): - return self._log_request_id(response) - - try: - result_json = response.json() - self._log_request_id(response, result_json) - except Exception: - return self._log_request_id(response) - return result_json + self.task_manager = task_manager def request( self, url, method, run_async=False, error_message=None, - *args, **kwargs): - name_parts = extract_name(url) + raise_exc=False, connect_retries=1, *args, **kwargs): + name_parts = _extract_name(url) name = '.'.join([self.service_type, method] + name_parts) - class_name = "".join([ - part.lower().capitalize() for part in name.split('.')]) request_method = functools.partial( - super(ShadeAdapter, self).request, url, method) + super(OpenStackSDKAdapter, self).request, url, method) - class RequestTask(task_manager.BaseTask): - - def __init__(self, **kw): - super(RequestTask, self).__init__(**kw) - self.name = name - self.__class__.__name__ = str(class_name) - self.run_async = run_async - - def main(self, client): - self.args.setdefault('raise_exc', False) - return request_method(**self.args) - - response = self.manager.submit_task(RequestTask(**kwargs)) - if run_async: - return response - else: - return self._munch_response(response, error_message=error_message) + return self.task_manager.submit_function( + request_method, run_async=run_async, name=name, + connect_retries=connect_retries, raise_exc=raise_exc, + **kwargs) def _version_matches(self, version): api_version = self.get_api_major_version() if api_version: return api_version[0] == version return False + + +class ShadeAdapter(OpenStackSDKAdapter): + """Wrapper for shade methods that expect json unpacking.""" + + def request(self, url, method, + run_async=False, error_message=None, **kwargs): + response = super(ShadeAdapter, self).request( + url, method, run_async=run_async, **kwargs) + if run_async: + return response + else: + return self._munch_response(response, error_message=error_message) + + def _munch_response(self, response, result_key=None, error_message=None): + exceptions.raise_from_response(response, error_message=error_message) + + if not response.content: + # This doens't have any content + return response + + # Some REST calls do not return json content. Don't decode it. + if 'application/json' not in response.headers.get('Content-Type'): + return response + + try: + result_json = response.json() + except Exception: + return response + return result_json diff --git a/openstack/cloud/exc.py b/openstack/cloud/exc.py index 7635c2bfc..c02de2d77 100644 --- a/openstack/cloud/exc.py +++ b/openstack/cloud/exc.py @@ -12,46 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys +from openstack import exceptions -import munch -from requests import exceptions as _rex - -from openstack import _log - - -class OpenStackCloudException(Exception): - - log_inner_exceptions = False - - def __init__(self, message, extra_data=None, **kwargs): - args = [message] - if extra_data: - if isinstance(extra_data, munch.Munch): - extra_data = extra_data.toDict() - args.append("Extra: {0}".format(str(extra_data))) - super(OpenStackCloudException, self).__init__(*args, **kwargs) - self.extra_data = extra_data - self.inner_exception = sys.exc_info() - self.orig_message = message - - def log_error(self, logger=None): - if not logger: - logger = _log.setup_logging('openstack.cloud.exc') - if self.inner_exception and self.inner_exception[1]: - logger.error(self.orig_message, exc_info=self.inner_exception) - - def __str__(self): - message = Exception.__str__(self) - if (self.inner_exception and self.inner_exception[1] - and not self.orig_message.endswith( - str(self.inner_exception[1]))): - message = "%s (Inner Exception: %s)" % ( - message, - str(self.inner_exception[1])) - if self.log_inner_exceptions: - self.log_error() - return message +OpenStackCloudException = exceptions.SDKException class OpenStackCloudCreateException(OpenStackCloudException): @@ -76,98 +39,8 @@ class OpenStackCloudUnavailableFeature(OpenStackCloudException): pass -class OpenStackCloudHTTPError(OpenStackCloudException, _rex.HTTPError): - - def __init__(self, *args, **kwargs): - OpenStackCloudException.__init__(self, *args, **kwargs) - _rex.HTTPError.__init__(self, *args, **kwargs) - - -class OpenStackCloudBadRequest(OpenStackCloudHTTPError): - """There is something wrong with the request payload. - - Possible reasons can include malformed json or invalid values to parameters - such as flavorRef to a server create. - """ - - -class OpenStackCloudURINotFound(OpenStackCloudHTTPError): - pass - # Backwards compat +OpenStackCloudHTTPError = exceptions.HttpException +OpenStackCloudBadRequest = exceptions.BadRequestException +OpenStackCloudURINotFound = exceptions.NotFoundException OpenStackCloudResourceNotFound = OpenStackCloudURINotFound - - -def _log_response_extras(response): - # Sometimes we get weird HTML errors. This is usually from load balancers - # or other things. Log them to a special logger so that they can be - # toggled indepdently - and at debug level so that a person logging - # openstack.cloud.* only gets them at debug. - if response.headers.get('content-type') != 'text/html': - return - try: - if int(response.headers.get('content-length', 0)) == 0: - return - except Exception: - return - logger = _log.setup_logging('openstack.cloud.http') - if response.reason: - logger.debug( - "Non-standard error '{reason}' returned from {url}:".format( - reason=response.reason, - url=response.url)) - else: - logger.debug( - "Non-standard error returned from {url}:".format( - url=response.url)) - for response_line in response.text.split('\n'): - logger.debug(response_line) - - -# Logic shamelessly stolen from requests -def raise_from_response(response, error_message=None): - msg = '' - if 400 <= response.status_code < 500: - source = "Client" - elif 500 <= response.status_code < 600: - source = "Server" - else: - return - - remote_error = "Error for url: {url}".format(url=response.url) - try: - details = response.json() - # Nova returns documents that look like - # {statusname: 'message': message, 'code': code} - detail_keys = list(details.keys()) - if len(detail_keys) == 1: - detail_key = detail_keys[0] - detail_message = details[detail_key].get('message') - if detail_message: - remote_error += " {message}".format(message=detail_message) - except ValueError: - if response.reason: - remote_error += " {reason}".format(reason=response.reason) - - _log_response_extras(response) - - if error_message: - msg = '{error_message}. ({code}) {source} {remote_error}'.format( - error_message=error_message, - source=source, - code=response.status_code, - remote_error=remote_error) - else: - msg = '({code}) {source} {remote_error}'.format( - code=response.status_code, - source=source, - remote_error=remote_error) - - # Special case 404 since we raised a specific one for neutron exceptions - # before - if response.status_code == 404: - raise OpenStackCloudURINotFound(msg, response=response) - elif response.status_code == 400: - raise OpenStackCloudBadRequest(msg, response=response) - if msg: - raise OpenStackCloudHTTPError(msg, response=response) diff --git a/openstack/cloud/openstackcloud.py b/openstack/cloud/openstackcloud.py index 829db766d..a2e3dff7f 100644 --- a/openstack/cloud/openstackcloud.py +++ b/openstack/cloud/openstackcloud.py @@ -175,7 +175,7 @@ class OpenStackCloud(_normalize.Normalizer): self.manager = manager else: self.manager = task_manager.TaskManager( - name=':'.join([self.name, self.region_name]), client=self) + name=':'.join([self.name, self.region_name])) self._external_ipv4_names = cloud_config.get_external_ipv4_networks() self._internal_ipv4_names = cloud_config.get_internal_ipv4_networks() @@ -402,29 +402,27 @@ class OpenStackCloud(_normalize.Normalizer): version=config_major) adapter = _adapter.ShadeAdapter( session=self.keystone_session, - manager=self.manager, + task_manager=self.manager, service_type=self.cloud_config.get_service_type(service_type), service_name=self.cloud_config.get_service_name(service_type), interface=self.cloud_config.get_interface(service_type), endpoint_override=self.cloud_config.get_endpoint(service_type), region_name=self.cloud_config.region, min_version=request_min_version, - max_version=request_max_version, - shade_logger=self.log) + max_version=request_max_version) if adapter.get_endpoint(): return adapter adapter = _adapter.ShadeAdapter( session=self.keystone_session, - manager=self.manager, + task_manager=self.manager, service_type=self.cloud_config.get_service_type(service_type), service_name=self.cloud_config.get_service_name(service_type), interface=self.cloud_config.get_interface(service_type), endpoint_override=self.cloud_config.get_endpoint(service_type), region_name=self.cloud_config.region, min_version=min_version, - max_version=max_version, - shade_logger=self.log) + max_version=max_version) # data.api_version can be None if no version was detected, such # as with neutron @@ -456,14 +454,13 @@ class OpenStackCloud(_normalize.Normalizer): self, service_type, api_version=None, endpoint_override=None): return _adapter.ShadeAdapter( session=self.keystone_session, - manager=self.manager, + task_manager=self.manager, service_type=self.cloud_config.get_service_type(service_type), service_name=self.cloud_config.get_service_name(service_type), interface=self.cloud_config.get_interface(service_type), endpoint_override=self.cloud_config.get_endpoint( service_type) or endpoint_override, - region_name=self.cloud_config.region, - shade_logger=self.log) + region_name=self.cloud_config.region) def _is_client_version(self, client, version): client_name = '_{client}_client'.format(client=client) diff --git a/openstack/cloud/task_manager.py b/openstack/cloud/task_manager.py index 358e9eed2..b015ac85f 100644 --- a/openstack/cloud/task_manager.py +++ b/openstack/cloud/task_manager.py @@ -14,44 +14,22 @@ # See the License for the specific language governing permissions and # limitations under the License. -import abc import concurrent.futures import sys import threading import time -import types import keystoneauth1.exceptions import six -from openstack import _log -from openstack.cloud import exc -from openstack.cloud import meta +from openstack import exceptions +from openstack import utils + +_log = utils.setup_logging(__name__) -def _is_listlike(obj): - # NOTE(Shrews): Since the client API might decide to subclass one - # of these result types, we use isinstance() here instead of type(). - return ( - isinstance(obj, list) or - isinstance(obj, types.GeneratorType)) - - -def _is_objlike(obj): - # NOTE(Shrews): Since the client API might decide to subclass one - # of these result types, we use isinstance() here instead of type(). - return ( - not isinstance(obj, bool) and - not isinstance(obj, int) and - not isinstance(obj, float) and - not isinstance(obj, six.string_types) and - not isinstance(obj, set) and - not isinstance(obj, tuple)) - - -@six.add_metaclass(abc.ABCMeta) -class BaseTask(object): - """Represent a task to be performed on an OpenStack Cloud. +class Task(object): + """Represent a remote task to be performed on an OpenStack Cloud. Some consumers need to inject things like rate-limiting or auditing around each external REST interaction. Task provides an interface @@ -67,19 +45,24 @@ class BaseTask(object): the main payload at execution time. """ - def __init__(self, **kw): + def __init__(self, main=None, name=None, run_async=False, *args, **kwargs): self._exception = None self._traceback = None self._result = None self._response = None self._finished = threading.Event() - self.run_async = False - self.args = kw - self.name = type(self).__name__ + self._main = main + self._run_async = run_async + self.args = args + self.kwargs = kwargs + self.name = name or type(self).__name__ - @abc.abstractmethod - def main(self, client): - """ Override this method with the actual workload to be performed """ + def main(self): + return self._main(*self.args, **self.kwargs) + + @property + def run_async(self): + return self._run_async def done(self, result): self._result = result @@ -99,212 +82,104 @@ class BaseTask(object): return self._result - def run(self, client): - self._client = client + def run(self): try: # Retry one time if we get a retriable connection failure try: - # Keep time for connection retrying logging - start = time.time() - self.done(self.main(client)) + self.done(self.main()) except keystoneauth1.exceptions.RetriableConnectionFailure as e: - end = time.time() - dt = end - start - if client.region_name: - client.log.debug(str(e)) - client.log.debug( - "Connection failure on %(cloud)s:%(region)s" - " for %(name)s after %(secs)s seconds, retrying", - {'cloud': client.name, - 'region': client.region_name, - 'secs': dt, - 'name': self.name}) - else: - client.log.debug( - "Connection failure on %(cloud)s for %(name)s after" - " %(secs)s seconds, retrying", - {'cloud': client.name, 'name': self.name, 'secs': dt}) - self.done(self.main(client)) - except Exception: - raise + self.done(self.main()) except Exception as e: self.exception(e, sys.exc_info()[2]) -class Task(BaseTask): - """ Shade specific additions to the BaseTask Interface. """ - - def wait(self, raw=False): - super(Task, self).wait() - - if raw: - # Do NOT convert the result. - return self._result - - if _is_listlike(self._result): - return meta.obj_list_to_munch(self._result) - elif _is_objlike(self._result): - return meta.obj_to_munch(self._result) - else: - return self._result - - -class RequestTask(BaseTask): - """ Extensions to the Shade Tasks to handle raw requests """ - - # It's totally legit for calls to not return things - result_key = None - - # keystoneauth1 throws keystoneauth1.exceptions.http.HttpError on !200 - def done(self, result): - self._response = result - - try: - result_json = self._response.json() - except ValueError as e: - result_json = self._response.text - self._client.log.debug( - 'Could not decode json in response: %(e)s', {'e': str(e)}) - self._client.log.debug(result_json) - - if self.result_key: - self._result = result_json[self.result_key] - else: - self._result = result_json - - self._request_id = self._response.headers.get('x-openstack-request-id') - self._finished.set() - - def wait(self, raw=False): - super(RequestTask, self).wait() - - if raw: - # Do NOT convert the result. - return self._result - - if _is_listlike(self._result): - return meta.obj_list_to_munch( - self._result, request_id=self._request_id) - elif _is_objlike(self._result): - return meta.obj_to_munch(self._result, request_id=self._request_id) - return self._result - - -def _result_filter_cb(result): - return result - - -def generate_task_class(method, name, result_filter_cb): - if name is None: - if callable(method): - name = method.__name__ - else: - name = method - - class RunTask(Task): - def __init__(self, **kw): - super(RunTask, self).__init__(**kw) - self.name = name - self._method = method - - def wait(self, raw=False): - super(RunTask, self).wait() - - if raw: - # Do NOT convert the result. - return self._result - return result_filter_cb(self._result) - - def main(self, client): - if callable(self._method): - return method(**self.args) - else: - meth = getattr(client, self._method) - return meth(**self.args) - return RunTask - - class TaskManager(object): - log = _log.setup_logging('openstack.cloud.task_manager') - def __init__( - self, client, name, result_filter_cb=None, workers=5, **kwargs): + def __init__(self, name, log=_log, workers=5, **kwargs): self.name = name - self._client = client - self._executor = concurrent.futures.ThreadPoolExecutor( - max_workers=workers) - if not result_filter_cb: - self._result_filter_cb = _result_filter_cb - else: - self._result_filter_cb = result_filter_cb + self._executor = None + self._log = log + self._workers = workers - def set_client(self, client): - self._client = client + @property + def executor(self): + if not self._executor: + self._executor = concurrent.futures.ThreadPoolExecutor( + max_workers=self._workers) + return self._executor def stop(self): """ This is a direct action passthrough TaskManager """ - self._executor.shutdown(wait=True) + if self._executor: + self._executor.shutdown() def run(self): """ This is a direct action passthrough TaskManager """ pass - def submit_task(self, task, raw=False): + def submit_task(self, task): """Submit and execute the given task. :param task: The task to execute. :param bool raw: If True, return the raw result as received from the underlying client call. """ - return self.run_task(task=task, raw=raw) + return self.run_task(task=task) - def _run_task_async(self, task, raw=False): - self.log.debug( - "Manager %s submitting task %s", self.name, task.name) - return self._executor.submit(self._run_task, task, raw=raw) - - def run_task(self, task, raw=False): - if hasattr(task, 'run_async') and task.run_async: - return self._run_task_async(task, raw=raw) - else: - return self._run_task(task, raw=raw) - - def _run_task(self, task, raw=False): - self.log.debug( - "Manager %s running task %s", self.name, task.name) - start = time.time() - task.run(self._client) - end = time.time() - dt = end - start - self.log.debug( - "Manager %s ran task %s in %ss", self.name, task.name, dt) - - self.post_run_task(dt, task) - - return task.wait(raw) - - def post_run_task(self, elasped_time, task): - pass - - # Backwards compatibility - submitTask = submit_task - - def submit_function( - self, method, name=None, result_filter_cb=None, **kwargs): + def submit_function(self, method, name=None, *args, **kwargs): """ Allows submitting an arbitrary method for work. - :param method: Method to run in the TaskManager. Can be either the - name of a method to find on self.client, or a callable. + :param method: Callable to run in the TaskManager. + :param str name: Name to use for the generated Task object. + :param args: positional arguments to pass to the method when it runs. + :param kwargs: keyword arguments to pass to the method when it runs. """ - if not result_filter_cb: - result_filter_cb = self._result_filter_cb + task = Task(main=method, name=name, *args, **kwargs) + return self.submit_task(task) - task_class = generate_task_class(method, name, result_filter_cb) + def submit_function_async(self, method, name=None, *args, **kwargs): + """ Allows submitting an arbitrary method for async work scheduling. - return self._executor.submit_task(task_class(**kwargs)) + :param method: Callable to run in the TaskManager. + :param str name: Name to use for the generated Task object. + :param args: positional arguments to pass to the method when it runs. + :param kwargs: keyword arguments to pass to the method when it runs. + """ + task = Task(method=method, name=name, run_async=True, **kwargs) + return self.submit_task(task) + + def pre_run_task(self, task): + self._log.debug( + "Manager %s running task %s", self.name, task.name) + + def run_task(self, task): + if task.run_async: + return self._run_task_async(task) + else: + return self._run_task(task) + + def post_run_task(self, elapsed_time, task): + self._log.debug( + "Manager %s ran task %s in %ss", + self.name, task.name, elapsed_time) + + def _run_task_async(self, task): + self._log.debug( + "Manager %s submitting task %s", self.name, task.name) + return self.executor.submit(self._run_task, task) + + def _run_task(self, task): + self.pre_run_task(task) + start = time.time() + task.run() + end = time.time() + dt = end - start + self.post_run_task(dt, task) + + return task.wait() -def wait_for_futures(futures, raise_on_error=True, log=None): +def wait_for_futures(futures, raise_on_error=True, log=_log): '''Collect results or failures from a list of running future tasks.''' results = [] @@ -314,21 +189,15 @@ def wait_for_futures(futures, raise_on_error=True, log=None): for completed in concurrent.futures.as_completed(futures): try: result = completed.result() - # We have to do this here because munch_response doesn't - # get called on async job results - exc.raise_from_response(result) + exceptions.raise_from_response(result) results.append(result) except (keystoneauth1.exceptions.RetriableConnectionFailure, - exc.OpenStackCloudException) as e: - if log: - log.debug( - "Exception processing async task: {e}".format( - e=str(e)), - exc_info=True) - # If we get an exception, put the result into a list so we - # can try again + exceptions.HttpException) as e: + log.exception( + "Exception processing async task: {e}".format(e=str(e))) if raise_on_error: raise - else: - retries.append(result) + # If we get an exception, put the result into a list so we + # can try again + retries.append(result) return results, retries diff --git a/openstack/cluster/__init__.py b/openstack/clustering/__init__.py similarity index 100% rename from openstack/cluster/__init__.py rename to openstack/clustering/__init__.py diff --git a/openstack/cluster/cluster_service.py b/openstack/clustering/clustering_service.py similarity index 81% rename from openstack/cluster/cluster_service.py rename to openstack/clustering/clustering_service.py index 7b6eb5d1b..0d5e57e4a 100644 --- a/openstack/cluster/cluster_service.py +++ b/openstack/clustering/clustering_service.py @@ -13,15 +13,15 @@ from openstack import service_filter -class ClusterService(service_filter.ServiceFilter): - """The cluster service.""" +class ClusteringService(service_filter.ServiceFilter): + """The clustering service.""" valid_versions = [service_filter.ValidVersion('v1')] UNVERSIONED = None def __init__(self, version=None): - """Create a cluster service.""" - super(ClusterService, self).__init__( + """Create a clustering service.""" + super(ClusteringService, self).__init__( service_type='clustering', version=version ) diff --git a/openstack/cluster/v1/__init__.py b/openstack/clustering/v1/__init__.py similarity index 100% rename from openstack/cluster/v1/__init__.py rename to openstack/clustering/v1/__init__.py diff --git a/openstack/cluster/v1/_proxy.py b/openstack/clustering/v1/_proxy.py similarity index 84% rename from openstack/cluster/v1/_proxy.py rename to openstack/clustering/v1/_proxy.py index 7bcff9f7e..01602607d 100644 --- a/openstack/cluster/v1/_proxy.py +++ b/openstack/clustering/v1/_proxy.py @@ -10,19 +10,19 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.cluster.v1 import action as _action -from openstack.cluster.v1 import build_info -from openstack.cluster.v1 import cluster as _cluster -from openstack.cluster.v1 import cluster_attr as _cluster_attr -from openstack.cluster.v1 import cluster_policy as _cluster_policy -from openstack.cluster.v1 import event as _event -from openstack.cluster.v1 import node as _node -from openstack.cluster.v1 import policy as _policy -from openstack.cluster.v1 import policy_type as _policy_type -from openstack.cluster.v1 import profile as _profile -from openstack.cluster.v1 import profile_type as _profile_type -from openstack.cluster.v1 import receiver as _receiver -from openstack.cluster.v1 import service as _service +from openstack.clustering.v1 import action as _action +from openstack.clustering.v1 import build_info +from openstack.clustering.v1 import cluster as _cluster +from openstack.clustering.v1 import cluster_attr as _cluster_attr +from openstack.clustering.v1 import cluster_policy as _cluster_policy +from openstack.clustering.v1 import event as _event +from openstack.clustering.v1 import node as _node +from openstack.clustering.v1 import policy as _policy +from openstack.clustering.v1 import policy_type as _policy_type +from openstack.clustering.v1 import profile as _profile +from openstack.clustering.v1 import profile_type as _profile_type +from openstack.clustering.v1 import receiver as _receiver +from openstack.clustering.v1 import service as _service from openstack import proxy2 from openstack import resource2 from openstack import utils @@ -41,7 +41,7 @@ class Proxy(proxy2.BaseProxy): """Get a generator of profile types. :returns: A generator of objects that are of type - :class:`~openstack.cluster.v1.profile_type.ProfileType` + :class:`~openstack.clustering.v1.profile_type.ProfileType` """ return self._list(_profile_type.ProfileType, paginated=False, **query) @@ -49,9 +49,9 @@ class Proxy(proxy2.BaseProxy): """Get the details about a profile_type. :param name: The name of the profile_type to retrieve or an object of - :class:`~openstack.cluster.v1.profile_type.ProfileType`. + :class:`~openstack.clustering.v1.profile_type.ProfileType`. - :returns: A :class:`~openstack.cluster.v1.profile_type.ProfileType` + :returns: A :class:`~openstack.clustering.v1.profile_type.ProfileType` object. :raises: :class:`~openstack.exceptions.ResourceNotFound` when no profile_type matching the name could be found. @@ -62,7 +62,7 @@ class Proxy(proxy2.BaseProxy): """Get a generator of policy types. :returns: A generator of objects that are of type - :class:`~openstack.cluster.v1.policy_type.PolicyType` + :class:`~openstack.clustering.v1.policy_type.PolicyType` """ return self._list(_policy_type.PolicyType, paginated=False, **query) @@ -70,9 +70,9 @@ class Proxy(proxy2.BaseProxy): """Get the details about a policy_type. :param policy_type: The name of a poicy_type or an object of - :class:`~openstack.cluster.v1.policy_type.PolicyType`. + :class:`~openstack.clustering.v1.policy_type.PolicyType`. - :returns: A :class:`~openstack.cluster.v1.policy_type.PolicyType` + :returns: A :class:`~openstack.clustering.v1.policy_type.PolicyType` object. :raises: :class:`~openstack.exceptions.ResourceNotFound` when no policy_type matching the name could be found. @@ -83,11 +83,11 @@ class Proxy(proxy2.BaseProxy): """Create a new profile from attributes. :param dict attrs: Keyword arguments that will be used to create a - :class:`~openstack.cluster.v1.profile.Profile`, it is comprised + :class:`~openstack.clustering.v1.profile.Profile`, it is comprised of the properties on the Profile class. :returns: The results of profile creation. - :rtype: :class:`~openstack.cluster.v1.profile.Profile`. + :rtype: :class:`~openstack.clustering.v1.profile.Profile`. """ return self._create(_profile.Profile, **attrs) @@ -95,7 +95,7 @@ class Proxy(proxy2.BaseProxy): """Delete a profile. :param profile: The value can be either the name or ID of a profile or - a :class:`~openstack.cluster.v1.profile.Profile` instance. + a :class:`~openstack.clustering.v1.profile.Profile` instance. :param bool ignore_missing: When set to ``False``, an exception :class:`~openstack.exceptions.ResourceNotFound` will be raised when the profile could not be found. When set to ``True``, no exception @@ -114,7 +114,7 @@ class Proxy(proxy2.BaseProxy): raised when the resource does not exist. When set to ``True``, None will be returned when attempting to find a nonexistent resource. - :returns: One :class:`~openstack.cluster.v1.profile.Profile` object + :returns: One :class:`~openstack.clustering.v1.profile.Profile` object or None """ return self._find(_profile.Profile, name_or_id, @@ -124,9 +124,9 @@ class Proxy(proxy2.BaseProxy): """Get a single profile. :param profile: The value can be the name or ID of a profile or a - :class:`~openstack.cluster.v1.profile.Profile` instance. + :class:`~openstack.clustering.v1.profile.Profile` instance. - :returns: One :class:`~openstack.cluster.v1.profile.Profile` + :returns: One :class:`~openstack.clustering.v1.profile.Profile` :raises: :class:`~openstack.exceptions.ResourceNotFound` when no profile matching the criteria could be found. """ @@ -163,12 +163,12 @@ class Proxy(proxy2.BaseProxy): """Update a profile. :param profile: Either the name or the ID of the profile, or an - instance of :class:`~openstack.cluster.v1.profile.Profile`. + instance of :class:`~openstack.clustering.v1.profile.Profile`. :param attrs: The attributes to update on the profile represented by the ``value`` parameter. :returns: The updated profile. - :rtype: :class:`~openstack.cluster.v1.profile.Profile` + :rtype: :class:`~openstack.clustering.v1.profile.Profile` """ return self._update(_profile.Profile, profile, **attrs) @@ -176,11 +176,11 @@ class Proxy(proxy2.BaseProxy): """Validate a profile spec. :param dict attrs: Keyword arguments that will be used to create a - :class:`~openstack.cluster.v1.profile.ProfileValidate`, it is + :class:`~openstack.clustering.v1.profile.ProfileValidate`, it is comprised of the properties on the Profile class. :returns: The results of profile validation. - :rtype: :class:`~openstack.cluster.v1.profile.ProfileValidate`. + :rtype: :class:`~openstack.clustering.v1.profile.ProfileValidate`. """ return self._create(_profile.ProfileValidate, **attrs) @@ -188,11 +188,11 @@ class Proxy(proxy2.BaseProxy): """Create a new cluster from attributes. :param dict attrs: Keyword arguments that will be used to create a - :class:`~openstack.cluster.v1.cluster.Cluster`, it is comprised + :class:`~openstack.clustering.v1.cluster.Cluster`, it is comprised of the properties on the Cluster class. :returns: The results of cluster creation. - :rtype: :class:`~openstack.cluster.v1.cluster.Cluster`. + :rtype: :class:`~openstack.clustering.v1.cluster.Cluster`. """ return self._create(_cluster.Cluster, **attrs) @@ -200,14 +200,14 @@ class Proxy(proxy2.BaseProxy): """Delete a cluster. :param cluster: The value can be either the name or ID of a cluster or - a :class:`~openstack.cluster.v1.cluster.Cluster` instance. + a :class:`~openstack.clustering.v1.cluster.Cluster` instance. :param bool ignore_missing: When set to ``False``, an exception :class:`~openstack.exceptions.ResourceNotFound` will be raised when the cluster could not be found. When set to ``True``, no exception will be raised when attempting to delete a non-existent cluster. :returns: The instance of the Cluster which was deleted. - :rtype: :class:`~openstack.cluster.v1.cluster.Cluster`. + :rtype: :class:`~openstack.clustering.v1.cluster.Cluster`. """ return self._delete(_cluster.Cluster, cluster, ignore_missing=ignore_missing) @@ -221,7 +221,7 @@ class Proxy(proxy2.BaseProxy): raised when the resource does not exist. When set to ``True``, None will be returned when attempting to find a nonexistent resource. - :returns: One :class:`~openstack.cluster.v1.cluster.Cluster` object + :returns: One :class:`~openstack.clustering.v1.cluster.Cluster` object or None """ return self._find(_cluster.Cluster, name_or_id, @@ -231,9 +231,9 @@ class Proxy(proxy2.BaseProxy): """Get a single cluster. :param cluster: The value can be the name or ID of a cluster or a - :class:`~openstack.cluster.v1.cluster.Cluster` instance. + :class:`~openstack.clustering.v1.cluster.Cluster` instance. - :returns: One :class:`~openstack.cluster.v1.cluster.Cluster` + :returns: One :class:`~openstack.clustering.v1.cluster.Cluster` :raises: :class:`~openstack.exceptions.ResourceNotFound` when no cluster matching the criteria could be found. """ @@ -268,12 +268,12 @@ class Proxy(proxy2.BaseProxy): """Update a cluster. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param attrs: The attributes to update on the cluster represented by the ``cluster`` parameter. :returns: The updated cluster. - :rtype: :class:`~openstack.cluster.v1.cluster.Cluster` + :rtype: :class:`~openstack.clustering.v1.cluster.Cluster` """ return self._update(_cluster.Cluster, cluster, **attrs) @@ -283,7 +283,7 @@ class Proxy(proxy2.BaseProxy): """Add nodes to a cluster. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param nodes: List of nodes to be added to the cluster. :returns: A dict containing the action initiated by this operation. """ @@ -293,7 +293,7 @@ class Proxy(proxy2.BaseProxy): """Add nodes to a cluster. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param nodes: List of nodes to be added to the cluster. :returns: A dict containing the action initiated by this operation. """ @@ -301,7 +301,7 @@ class Proxy(proxy2.BaseProxy): obj = cluster else: obj = self._find(_cluster.Cluster, cluster, ignore_missing=False) - return obj.add_nodes(self._session, nodes) + return obj.add_nodes(self, nodes) @utils.deprecated(deprecated_in="0.9.14", removed_in="1.0", details="Use remove_nodes_from_cluster instead") @@ -309,7 +309,7 @@ class Proxy(proxy2.BaseProxy): """Remove nodes from a cluster. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param nodes: List of nodes to be removed from the cluster. :param kwargs \*\*params: Optional query parameters to be sent to restrict the nodes to be returned. Available parameters include: @@ -324,7 +324,7 @@ class Proxy(proxy2.BaseProxy): """Remove nodes from a cluster. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param nodes: List of nodes to be removed from the cluster. :param kwargs \*\*params: Optional query parameters to be sent to restrict the nodes to be returned. Available parameters include: @@ -337,7 +337,7 @@ class Proxy(proxy2.BaseProxy): obj = cluster else: obj = self._find(_cluster.Cluster, cluster, ignore_missing=False) - return obj.del_nodes(self._session, nodes, **params) + return obj.del_nodes(self, nodes, **params) @utils.deprecated(deprecated_in="0.9.14", removed_in="1.0", details="Use replace_nodes_in_cluster instead") @@ -345,7 +345,7 @@ class Proxy(proxy2.BaseProxy): """Replace the nodes in a cluster with specified nodes. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param nodes: List of nodes to be deleted/added to the cluster. :returns: A dict containing the action initiated by this operation. """ @@ -355,7 +355,7 @@ class Proxy(proxy2.BaseProxy): """Replace the nodes in a cluster with specified nodes. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param nodes: List of nodes to be deleted/added to the cluster. :returns: A dict containing the action initiated by this operation. """ @@ -363,7 +363,7 @@ class Proxy(proxy2.BaseProxy): obj = cluster else: obj = self._find(_cluster.Cluster, cluster, ignore_missing=False) - return obj.replace_nodes(self._session, nodes) + return obj.replace_nodes(self, nodes) @utils.deprecated(deprecated_in="0.9.14", removed_in="1.0", details="Use scale_out_cluster instead") @@ -371,7 +371,7 @@ class Proxy(proxy2.BaseProxy): """Inflate the size of a cluster. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param count: Optional parameter specifying the number of nodes to be added. :returns: A dict containing the action initiated by this operation. @@ -382,7 +382,7 @@ class Proxy(proxy2.BaseProxy): """Inflate the size of a cluster. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param count: Optional parameter specifying the number of nodes to be added. :returns: A dict containing the action initiated by this operation. @@ -391,7 +391,7 @@ class Proxy(proxy2.BaseProxy): obj = cluster else: obj = self._find(_cluster.Cluster, cluster, ignore_missing=False) - return obj.scale_out(self._session, count) + return obj.scale_out(self, count) @utils.deprecated(deprecated_in="0.9.14", removed_in="1.0", details="Use scale_in_cluster instead") @@ -399,7 +399,7 @@ class Proxy(proxy2.BaseProxy): """Shrink the size of a cluster. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param count: Optional parameter specifying the number of nodes to be removed. :returns: A dict containing the action initiated by this operation. @@ -410,7 +410,7 @@ class Proxy(proxy2.BaseProxy): """Shrink the size of a cluster. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param count: Optional parameter specifying the number of nodes to be removed. :returns: A dict containing the action initiated by this operation. @@ -419,7 +419,7 @@ class Proxy(proxy2.BaseProxy): obj = cluster else: obj = self._find(_cluster.Cluster, cluster, ignore_missing=False) - return obj.scale_in(self._session, count) + return obj.scale_in(self, count) @utils.deprecated(deprecated_in="0.9.14", removed_in="1.0", details="Use resize_cluster instead") @@ -427,7 +427,7 @@ class Proxy(proxy2.BaseProxy): """Resize of cluster. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param dict \*\*params: A dictionary providing the parameters for the resize action. :returns: A dict containing the action initiated by this operation. @@ -438,7 +438,7 @@ class Proxy(proxy2.BaseProxy): """Resize of cluster. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param dict \*\*params: A dictionary providing the parameters for the resize action. :returns: A dict containing the action initiated by this operation. @@ -447,7 +447,7 @@ class Proxy(proxy2.BaseProxy): obj = cluster else: obj = self._find(_cluster.Cluster, cluster, ignore_missing=False) - return obj.resize(self._session, **params) + return obj.resize(self, **params) @utils.deprecated(deprecated_in="0.9.14", removed_in="1.0", details="Use attach_policy_to_cluster instead") @@ -455,7 +455,7 @@ class Proxy(proxy2.BaseProxy): """Attach a policy to a cluster. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param policy: Either the name or the ID of a policy. :param dict \*\*params: A dictionary containing the properties for the policy to be attached. @@ -467,7 +467,7 @@ class Proxy(proxy2.BaseProxy): """Attach a policy to a cluster. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param policy: Either the name or the ID of a policy. :param dict \*\*params: A dictionary containing the properties for the policy to be attached. @@ -477,7 +477,7 @@ class Proxy(proxy2.BaseProxy): obj = cluster else: obj = self._find(_cluster.Cluster, cluster, ignore_missing=False) - return obj.policy_attach(self._session, policy, **params) + return obj.policy_attach(self, policy, **params) @utils.deprecated(deprecated_in="0.9.14", removed_in="1.0", details="Use detach_policy_from_cluster instead") @@ -485,7 +485,7 @@ class Proxy(proxy2.BaseProxy): """Attach a policy to a cluster. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param policy: Either the name or the ID of a policy. :returns: A dict containing the action initiated by this operation. """ @@ -495,7 +495,7 @@ class Proxy(proxy2.BaseProxy): """Detach a policy from a cluster. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param policy: Either the name or the ID of a policy. :returns: A dict containing the action initiated by this operation. """ @@ -503,7 +503,7 @@ class Proxy(proxy2.BaseProxy): obj = cluster else: obj = self._find(_cluster.Cluster, cluster, ignore_missing=False) - return obj.policy_detach(self._session, policy) + return obj.policy_detach(self, policy) @utils.deprecated(deprecated_in="0.9.14", removed_in="1.0", details="Use update_cluster_policy instead") @@ -511,7 +511,7 @@ class Proxy(proxy2.BaseProxy): """Change properties of a policy which is bound to the cluster. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param policy: Either the name or the ID of a policy. :param dict \*\*params: A dictionary containing the new properties for the policy. @@ -523,7 +523,7 @@ class Proxy(proxy2.BaseProxy): """Change properties of a policy which is bound to the cluster. :param cluster: Either the name or the ID of the cluster, or an - instance of :class:`~openstack.cluster.v1.cluster.Cluster`. + instance of :class:`~openstack.clustering.v1.cluster.Cluster`. :param policy: Either the name or the ID of a policy. :param dict \*\*params: A dictionary containing the new properties for the policy. @@ -533,13 +533,13 @@ class Proxy(proxy2.BaseProxy): obj = cluster else: obj = self._find(_cluster.Cluster, cluster, ignore_missing=False) - return obj.policy_update(self._session, policy, **params) + return obj.policy_update(self, policy, **params) def collect_cluster_attrs(self, cluster, path): """Collect attribute values across a cluster. :param cluster: The value can be either the ID of a cluster or a - :class:`~openstack.cluster.v1.cluster.Cluster` instance. + :class:`~openstack.clustering.v1.cluster.Cluster` instance. :param path: A Json path string specifying the attribute to collect. :returns: A dictionary containing the list of attribute values. @@ -551,27 +551,27 @@ class Proxy(proxy2.BaseProxy): """Check a cluster. :param cluster: The value can be either the ID of a cluster or a - :class:`~openstack.cluster.v1.cluster.Cluster` instance. + :class:`~openstack.clustering.v1.cluster.Cluster` instance. :param dict params: A dictionary providing the parameters for the check action. :returns: A dictionary containing the action ID. """ obj = self._get_resource(_cluster.Cluster, cluster) - return obj.check(self._session, **params) + return obj.check(self, **params) def recover_cluster(self, cluster, **params): """recover a cluster. :param cluster: The value can be either the ID of a cluster or a - :class:`~openstack.cluster.v1.cluster.Cluster` instance. + :class:`~openstack.clustering.v1.cluster.Cluster` instance. :param dict params: A dictionary providing the parameters for the recover action. :returns: A dictionary containing the action ID. """ obj = self._get_resource(_cluster.Cluster, cluster) - return obj.recover(self._session, **params) + return obj.recover(self, **params) @utils.deprecated(deprecated_in="0.9.14", removed_in="1.0", details="Use perform_operation_on_cluster instead") @@ -579,7 +579,7 @@ class Proxy(proxy2.BaseProxy): """Perform an operation on the specified cluster. :param cluster: The value can be either the ID of a cluster or a - :class:`~openstack.cluster.v1.cluster.Cluster` instance. + :class:`~openstack.clustering.v1.cluster.Cluster` instance. :param operation: A string specifying the operation to be performed. :param dict params: A dictionary providing the parameters for the operation. @@ -592,7 +592,7 @@ class Proxy(proxy2.BaseProxy): """Perform an operation on the specified cluster. :param cluster: The value can be either the ID of a cluster or a - :class:`~openstack.cluster.v1.cluster.Cluster` instance. + :class:`~openstack.clustering.v1.cluster.Cluster` instance. :param operation: A string specifying the operation to be performed. :param dict params: A dictionary providing the parameters for the operation. @@ -600,17 +600,17 @@ class Proxy(proxy2.BaseProxy): :returns: A dictionary containing the action ID. """ obj = self._get_resource(_cluster.Cluster, cluster) - return obj.op(self._session, operation, **params) + return obj.op(self, operation, **params) def create_node(self, **attrs): """Create a new node from attributes. :param dict attrs: Keyword arguments that will be used to create a - :class:`~openstack.cluster.v1.node.Node`, it is comprised + :class:`~openstack.clustering.v1.node.Node`, it is comprised of the properties on the ``Node`` class. :returns: The results of node creation. - :rtype: :class:`~openstack.cluster.v1.node.Node`. + :rtype: :class:`~openstack.clustering.v1.node.Node`. """ return self._create(_node.Node, **attrs) @@ -618,14 +618,14 @@ class Proxy(proxy2.BaseProxy): """Delete a node. :param node: The value can be either the name or ID of a node or a - :class:`~openstack.cluster.v1.node.Node` instance. + :class:`~openstack.clustering.v1.node.Node` instance. :param bool ignore_missing: When set to ``False``, an exception :class:`~openstack.exceptions.ResourceNotFound` will be raised when the node could not be found. When set to ``True``, no exception will be raised when attempting to delete a non-existent node. :returns: The instance of the Node which was deleted. - :rtype: :class:`~openstack.cluster.v1.node.Node`. + :rtype: :class:`~openstack.clustering.v1.node.Node`. """ return self._delete(_node.Node, node, ignore_missing=ignore_missing) @@ -633,7 +633,8 @@ class Proxy(proxy2.BaseProxy): """Find a single node. :param str name_or_id: The name or ID of a node. - :returns: One :class:`~openstack.cluster.v1.node.Node` object or None. + :returns: One :class:`~openstack.clustering.v1.node.Node` object + or None. """ return self._find(_node.Node, name_or_id, ignore_missing=ignore_missing) @@ -642,11 +643,11 @@ class Proxy(proxy2.BaseProxy): """Get a single node. :param node: The value can be the name or ID of a node or a - :class:`~openstack.cluster.v1.node.Node` instance. + :class:`~openstack.clustering.v1.node.Node` instance. :param details: An optional argument that indicates whether the server should return more details when retrieving the node data. - :returns: One :class:`~openstack.cluster.v1.node.Node` + :returns: One :class:`~openstack.clustering.v1.node.Node` :raises: :class:`~openstack.exceptions.ResourceNotFound` when no node matching the name or ID could be found. """ @@ -688,12 +689,12 @@ class Proxy(proxy2.BaseProxy): """Update a node. :param node: Either the name or the ID of the node, or an instance - of :class:`~openstack.cluster.v1.node.Node`. + of :class:`~openstack.clustering.v1.node.Node`. :param attrs: The attributes to update on the node represented by the ``node`` parameter. :returns: The updated node. - :rtype: :class:`~openstack.cluster.v1.node.Node` + :rtype: :class:`~openstack.clustering.v1.node.Node` """ return self._update(_node.Node, node, **attrs) @@ -701,26 +702,26 @@ class Proxy(proxy2.BaseProxy): """Check the health of the specified node. :param node: The value can be either the ID of a node or a - :class:`~openstack.cluster.v1.node.Node` instance. + :class:`~openstack.clustering.v1.node.Node` instance. :param dict params: A dictionary providing the parametes to the check action. :returns: A dictionary containing the action ID. """ obj = self._get_resource(_node.Node, node) - return obj.check(self._session, **params) + return obj.check(self, **params) def recover_node(self, node, **params): """Recover the specified node into healthy status. :param node: The value can be either the ID of a node or a - :class:`~openstack.cluster.v1.node.Node` instance. + :class:`~openstack.clustering.v1.node.Node` instance. :param dict params: A dict supplying parameters to the recover action. :returns: A dictionary containing the action ID. """ obj = self._get_resource(_node.Node, node) - return obj.recover(self._session, **params) + return obj.recover(self, **params) def adopt_node(self, preview=False, **attrs): """Adopting an existing resource as a node. @@ -747,12 +748,12 @@ class Proxy(proxy2.BaseProxy): to override attributes derived from the target resource. :returns: The result of node adoption. If `preview` is set to False - (default), returns a :class:`~openstack.cluster.v1.node.Node` + (default), returns a :class:`~openstack.clustering.v1.node.Node` object, otherwise a Dict is returned containing the profile to be used for the new node. """ node = self._get_resource(_node.Node, None) - return node.adopt(self._session, preview=preview, **attrs) + return node.adopt(self, preview=preview, **attrs) @utils.deprecated(deprecated_in="0.9.14", removed_in="1.0", details="Use perform_operation_on_node instead") @@ -760,7 +761,7 @@ class Proxy(proxy2.BaseProxy): """Perform an operation on the specified node. :param cluster: The value can be either the ID of a node or a - :class:`~openstack.cluster.v1.node.Node` instance. + :class:`~openstack.clustering.v1.node.Node` instance. :param operation: A string specifying the operation to be performed. :param dict params: A dictionary providing the parameters for the operation. @@ -773,7 +774,7 @@ class Proxy(proxy2.BaseProxy): """Perform an operation on the specified node. :param cluster: The value can be either the ID of a node or a - :class:`~openstack.cluster.v1.node.Node` instance. + :class:`~openstack.clustering.v1.node.Node` instance. :param operation: A string specifying the operation to be performed. :param dict params: A dictionary providing the parameters for the operation. @@ -781,17 +782,17 @@ class Proxy(proxy2.BaseProxy): :returns: A dictionary containing the action ID. """ obj = self._get_resource(_node.Node, node) - return obj.op(self._session, operation, **params) + return obj.op(self, operation, **params) def create_policy(self, **attrs): """Create a new policy from attributes. :param dict attrs: Keyword arguments that will be used to create a - :class:`~openstack.cluster.v1.policy.Policy`, it is comprised + :class:`~openstack.clustering.v1.policy.Policy`, it is comprised of the properties on the ``Policy`` class. :returns: The results of policy creation. - :rtype: :class:`~openstack.cluster.v1.policy.Policy`. + :rtype: :class:`~openstack.clustering.v1.policy.Policy`. """ return self._create(_policy.Policy, **attrs) @@ -799,7 +800,7 @@ class Proxy(proxy2.BaseProxy): """Delete a policy. :param policy: The value can be either the name or ID of a policy or a - :class:`~openstack.cluster.v1.policy.Policy` instance. + :class:`~openstack.clustering.v1.policy.Policy` instance. :param bool ignore_missing: When set to ``False``, an exception :class:`~openstack.exceptions.ResourceNotFound` will be raised when the policy could not be found. When set to ``True``, no exception @@ -819,7 +820,7 @@ class Proxy(proxy2.BaseProxy): When set to ``True``, None will be returned when attempting to find a nonexistent policy. :returns: A policy object or None. - :rtype: :class:`~openstack.cluster.v1.policy.Policy` + :rtype: :class:`~openstack.clustering.v1.policy.Policy` """ return self._find(_policy.Policy, name_or_id, ignore_missing=ignore_missing) @@ -828,10 +829,10 @@ class Proxy(proxy2.BaseProxy): """Get a single policy. :param policy: The value can be the name or ID of a policy or a - :class:`~openstack.cluster.v1.policy.Policy` instance. + :class:`~openstack.clustering.v1.policy.Policy` instance. :returns: A policy object. - :rtype: :class:`~openstack.cluster.v1.policy.Policy` + :rtype: :class:`~openstack.clustering.v1.policy.Policy` :raises: :class:`~openstack.exceptions.ResourceNotFound` when no policy matching the criteria could be found. """ @@ -866,12 +867,12 @@ class Proxy(proxy2.BaseProxy): """Update a policy. :param policy: Either the name or the ID of a policy, or an instance - of :class:`~openstack.cluster.v1.policy.Policy`. + of :class:`~openstack.clustering.v1.policy.Policy`. :param attrs: The attributes to update on the policy represented by the ``value`` parameter. :returns: The updated policy. - :rtype: :class:`~openstack.cluster.v1.policy.Policy` + :rtype: :class:`~openstack.clustering.v1.policy.Policy` """ return self._update(_policy.Policy, policy, **attrs) @@ -879,11 +880,11 @@ class Proxy(proxy2.BaseProxy): """Validate a policy spec. :param dict attrs: Keyword arguments that will be used to create a - :class:`~openstack.cluster.v1.policy.PolicyValidate`, it is + :class:`~openstack.clustering.v1.policy.PolicyValidate`, it is comprised of the properties on the Policy class. :returns: The results of Policy validation. - :rtype: :class:`~openstack.cluster.v1.policy.PolicyValidate`. + :rtype: :class:`~openstack.clustering.v1.policy.PolicyValidate`. """ return self._create(_policy.PolicyValidate, **attrs) @@ -891,7 +892,7 @@ class Proxy(proxy2.BaseProxy): """Retrieve a generator of cluster-policy bindings. :param cluster: The value can be the name or ID of a cluster or a - :class:`~openstack.cluster.v1.cluster.Cluster` instance. + :class:`~openstack.clustering.v1.cluster.Cluster` instance. :param kwargs \*\*query: Optional query parameters to be sent to restrict the policies to be returned. Available parameters include: @@ -908,12 +909,12 @@ class Proxy(proxy2.BaseProxy): :param cluster_policy: The value can be the name or ID of a policy or a - :class:`~openstack.cluster.v1.policy.Policy` instance. + :class:`~openstack.clustering.v1.policy.Policy` instance. :param cluster: The value can be the name or ID of a cluster or a - :class:`~openstack.cluster.v1.cluster.Cluster` instance. + :class:`~openstack.clustering.v1.cluster.Cluster` instance. :returns: a cluster-policy binding object. - :rtype: :class:`~openstack.cluster.v1.cluster_policy.CLusterPolicy` + :rtype: :class:`~openstack.clustering.v1.cluster_policy.CLusterPolicy` :raises: :class:`~openstack.exceptions.ResourceNotFound` when no cluster-policy binding matching the criteria could be found. """ @@ -924,11 +925,11 @@ class Proxy(proxy2.BaseProxy): """Create a new receiver from attributes. :param dict attrs: Keyword arguments that will be used to create a - :class:`~openstack.cluster.v1.receiver.Receiver`, it is comprised - of the properties on the Receiver class. + :class:`~openstack.clustering.v1.receiver.Receiver`, it is + comprised of the properties on the Receiver class. :returns: The results of receiver creation. - :rtype: :class:`~openstack.cluster.v1.receiver.Receiver`. + :rtype: :class:`~openstack.clustering.v1.receiver.Receiver`. """ return self._create(_receiver.Receiver, **attrs) @@ -936,11 +937,11 @@ class Proxy(proxy2.BaseProxy): """Update a receiver. :param receiver: The value can be either the name or ID of a receiver - or a :class:`~openstack.cluster.v1.receiver.Receiver` instance. + or a :class:`~openstack.clustering.v1.receiver.Receiver` instance. :param attrs: The attributes to update on the receiver parameter. Valid attribute names include ``name``, ``action`` and ``params``. :returns: The updated receiver. - :rtype: :class:`~openstack.cluster.v1.receiver.Receiver` + :rtype: :class:`~openstack.clustering.v1.receiver.Receiver` """ return self._update(_receiver.Receiver, receiver, **attrs) @@ -948,7 +949,7 @@ class Proxy(proxy2.BaseProxy): """Delete a receiver. :param receiver: The value can be either the name or ID of a receiver - or a :class:`~openstack.cluster.v1.receiver.Receiver` instance. + or a :class:`~openstack.clustering.v1.receiver.Receiver` instance. :param bool ignore_missing: When set to ``False``, an exception :class:`~openstack.exceptions.ResourceNotFound` will be raised when the receiver could not be found. When set to ``True``, no exception @@ -969,7 +970,7 @@ class Proxy(proxy2.BaseProxy): set to ``True``, None will be returned when attempting to find a nonexistent receiver. :returns: A receiver object or None. - :rtype: :class:`~openstack.cluster.v1.receiver.Receiver` + :rtype: :class:`~openstack.clustering.v1.receiver.Receiver` """ return self._find(_receiver.Receiver, name_or_id, ignore_missing=ignore_missing) @@ -978,10 +979,10 @@ class Proxy(proxy2.BaseProxy): """Get a single receiver. :param receiver: The value can be the name or ID of a receiver or a - :class:`~openstack.cluster.v1.receiver.Receiver` instance. + :class:`~openstack.clustering.v1.receiver.Receiver` instance. :returns: A receiver object. - :rtype: :class:`~openstack.cluster.v1.receiver.Receiver` + :rtype: :class:`~openstack.clustering.v1.receiver.Receiver` :raises: :class:`~openstack.exceptions.ResourceNotFound` when no receiver matching the criteria could be found. """ @@ -1011,10 +1012,10 @@ class Proxy(proxy2.BaseProxy): """Get a single action. :param action: The value can be the name or ID of an action or a - :class:`~openstack.cluster.v1.action.Action` instance. + :class:`~openstack.clustering.v1.action.Action` instance. :returns: an action object. - :rtype: :class:`~openstack.cluster.v1.action.Action` + :rtype: :class:`~openstack.clustering.v1.action.Action` :raises: :class:`~openstack.exceptions.ResourceNotFound` when no action matching the criteria could be found. """ @@ -1049,10 +1050,10 @@ class Proxy(proxy2.BaseProxy): """Get a single event. :param event: The value can be the name or ID of an event or a - :class:`~openstack.cluster.v1.event.Event` instance. + :class:`~openstack.clustering.v1.event.Event` instance. :returns: an event object. - :rtype: :class:`~openstack.cluster.v1.event.Event` + :rtype: :class:`~openstack.clustering.v1.event.Event` :raises: :class:`~openstack.exceptions.ResourceNotFound` when no event matching the criteria could be found. """ @@ -1110,7 +1111,7 @@ class Proxy(proxy2.BaseProxy): :raises: :class:`~AttributeError` if the resource does not have a ``status`` attribute. """ - return resource2.wait_for_status(self._session, resource, status, + return resource2.wait_for_status(self, resource, status, failures, interval, wait) def wait_for_delete(self, resource, interval=2, wait=120): @@ -1126,13 +1127,13 @@ class Proxy(proxy2.BaseProxy): :raises: :class:`~openstack.exceptions.ResourceTimeout` if transition to delete failed to occur in the specified seconds. """ - return resource2.wait_for_delete(self._session, resource, interval, + return resource2.wait_for_delete(self, resource, interval, wait) def services(self, **query): """Get a generator of services. :returns: A generator of objects that are of type - :class:`~openstack.cluster.v1.service.Service` + :class:`~openstack.clustering.v1.service.Service` """ return self._list(_service.Service, paginated=False, **query) diff --git a/openstack/cluster/v1/action.py b/openstack/clustering/v1/action.py similarity index 96% rename from openstack/cluster/v1/action.py rename to openstack/clustering/v1/action.py index a7db8aa90..46609f8a9 100644 --- a/openstack/cluster/v1/action.py +++ b/openstack/clustering/v1/action.py @@ -11,7 +11,7 @@ # under the License. -from openstack.cluster import cluster_service +from openstack.clustering import clustering_service from openstack import resource2 as resource @@ -19,7 +19,7 @@ class Action(resource.Resource): resource_key = 'action' resources_key = 'actions' base_path = '/actions' - service = cluster_service.ClusterService() + service = clustering_service.ClusteringService() # Capabilities allow_list = True diff --git a/openstack/cluster/v1/build_info.py b/openstack/clustering/v1/build_info.py similarity index 89% rename from openstack/cluster/v1/build_info.py rename to openstack/clustering/v1/build_info.py index 78ac642a1..e666050eb 100644 --- a/openstack/cluster/v1/build_info.py +++ b/openstack/clustering/v1/build_info.py @@ -10,14 +10,14 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.cluster import cluster_service +from openstack.clustering import clustering_service from openstack import resource2 as resource class BuildInfo(resource.Resource): base_path = '/build-info' resource_key = 'build_info' - service = cluster_service.ClusterService() + service = clustering_service.ClusteringService() # Capabilities allow_get = True diff --git a/openstack/cluster/v1/cluster.py b/openstack/clustering/v1/cluster.py similarity index 96% rename from openstack/cluster/v1/cluster.py rename to openstack/clustering/v1/cluster.py index a1d44ac7d..7563d0a07 100644 --- a/openstack/cluster/v1/cluster.py +++ b/openstack/clustering/v1/cluster.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.cluster import cluster_service +from openstack.clustering import clustering_service from openstack import resource2 as resource from openstack import utils @@ -19,7 +19,7 @@ class Cluster(resource.Resource): resource_key = 'cluster' resources_key = 'clusters' base_path = '/clusters' - service = cluster_service.ClusterService() + service = clustering_service.ClusteringService() # capabilities allow_create = True @@ -83,7 +83,7 @@ class Cluster(resource.Resource): def action(self, session, body): url = utils.urljoin(self.base_path, self._get_id(self), 'actions') - resp = session.post(url, endpoint_filter=self.service, json=body) + resp = session.post(url, json=body) return resp.json() def add_nodes(self, session, nodes): @@ -178,6 +178,6 @@ class Cluster(resource.Resource): :returns: A dictionary containing the action ID. """ url = utils.urljoin(self.base_path, self.id, 'ops') - resp = session.post(url, endpoint_filter=self.service, + resp = session.post(url, json={operation: params}) return resp.json() diff --git a/openstack/cluster/v1/cluster_attr.py b/openstack/clustering/v1/cluster_attr.py similarity index 91% rename from openstack/cluster/v1/cluster_attr.py rename to openstack/clustering/v1/cluster_attr.py index 1755b100f..353728503 100644 --- a/openstack/cluster/v1/cluster_attr.py +++ b/openstack/clustering/v1/cluster_attr.py @@ -10,14 +10,14 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.cluster import cluster_service +from openstack.clustering import clustering_service from openstack import resource2 as resource class ClusterAttr(resource.Resource): resources_key = 'cluster_attributes' base_path = '/clusters/%(cluster_id)s/attrs/%(path)s' - service = cluster_service.ClusterService() + service = clustering_service.ClusteringService() # capabilities allow_list = True diff --git a/openstack/cluster/v1/cluster_policy.py b/openstack/clustering/v1/cluster_policy.py similarity index 93% rename from openstack/cluster/v1/cluster_policy.py rename to openstack/clustering/v1/cluster_policy.py index 377e3d46b..6d48ece91 100644 --- a/openstack/cluster/v1/cluster_policy.py +++ b/openstack/clustering/v1/cluster_policy.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.cluster import cluster_service +from openstack.clustering import clustering_service from openstack import resource2 as resource @@ -18,7 +18,7 @@ class ClusterPolicy(resource.Resource): resource_key = 'cluster_policy' resources_key = 'cluster_policies' base_path = '/clusters/%(cluster_id)s/policies' - service = cluster_service.ClusterService() + service = clustering_service.ClusteringService() # Capabilities allow_list = True diff --git a/openstack/cluster/v1/event.py b/openstack/clustering/v1/event.py similarity index 95% rename from openstack/cluster/v1/event.py rename to openstack/clustering/v1/event.py index d9b51fbb3..c248a5179 100644 --- a/openstack/cluster/v1/event.py +++ b/openstack/clustering/v1/event.py @@ -11,7 +11,7 @@ # under the License. -from openstack.cluster import cluster_service +from openstack.clustering import clustering_service from openstack import resource2 as resource @@ -19,7 +19,7 @@ class Event(resource.Resource): resource_key = 'event' resources_key = 'events' base_path = '/events' - service = cluster_service.ClusterService() + service = clustering_service.ClusteringService() # Capabilities allow_list = True diff --git a/openstack/cluster/v1/node.py b/openstack/clustering/v1/node.py similarity index 95% rename from openstack/cluster/v1/node.py rename to openstack/clustering/v1/node.py index a0305a82c..1e3208ad8 100644 --- a/openstack/cluster/v1/node.py +++ b/openstack/clustering/v1/node.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.cluster import cluster_service +from openstack.clustering import clustering_service from openstack import resource2 as resource from openstack import utils @@ -19,7 +19,7 @@ class Node(resource.Resource): resource_key = 'node' resources_key = 'nodes' base_path = '/nodes' - service = cluster_service.ClusterService() + service = clustering_service.ClusteringService() # capabilities allow_create = True @@ -88,7 +88,7 @@ class Node(resource.Resource): :param body: The body of action to be sent. """ url = utils.urljoin(self.base_path, self.id, 'actions') - resp = session.post(url, endpoint_filter=self.service, json=body) + resp = session.post(url, json=body) return resp.json() def check(self, session, **params): @@ -123,7 +123,7 @@ class Node(resource.Resource): :returns: A dictionary containing the action ID. """ url = utils.urljoin(self.base_path, self.id, 'ops') - resp = session.post(url, endpoint_filter=self.service, + resp = session.post(url, json={operation: params}) return resp.json() @@ -149,7 +149,7 @@ class Node(resource.Resource): attrs = params url = utils.urljoin(self.base_path, path) - resp = session.post(url, endpoint_filter=self.service, json=attrs) + resp = session.post(url, json=attrs) if preview: return resp.json() diff --git a/openstack/cluster/v1/policy.py b/openstack/clustering/v1/policy.py similarity index 95% rename from openstack/cluster/v1/policy.py rename to openstack/clustering/v1/policy.py index 0137220b3..a547c7f61 100644 --- a/openstack/cluster/v1/policy.py +++ b/openstack/clustering/v1/policy.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.cluster import cluster_service +from openstack.clustering import clustering_service from openstack import resource2 as resource @@ -18,7 +18,7 @@ class Policy(resource.Resource): resource_key = 'policy' resources_key = 'policies' base_path = '/policies' - service = cluster_service.ClusterService() + service = clustering_service.ClusteringService() # Capabilities allow_list = True diff --git a/openstack/cluster/v1/policy_type.py b/openstack/clustering/v1/policy_type.py similarity index 91% rename from openstack/cluster/v1/policy_type.py rename to openstack/clustering/v1/policy_type.py index aefcffec6..e63edf007 100644 --- a/openstack/cluster/v1/policy_type.py +++ b/openstack/clustering/v1/policy_type.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.cluster import cluster_service +from openstack.clustering import clustering_service from openstack import resource2 as resource @@ -18,7 +18,7 @@ class PolicyType(resource.Resource): resource_key = 'policy_type' resources_key = 'policy_types' base_path = '/policy-types' - service = cluster_service.ClusterService() + service = clustering_service.ClusteringService() # Capabilities allow_list = True diff --git a/openstack/cluster/v1/profile.py b/openstack/clustering/v1/profile.py similarity index 95% rename from openstack/cluster/v1/profile.py rename to openstack/clustering/v1/profile.py index 711b302f2..6420d8615 100644 --- a/openstack/cluster/v1/profile.py +++ b/openstack/clustering/v1/profile.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.cluster import cluster_service +from openstack.clustering import clustering_service from openstack import resource2 as resource @@ -18,7 +18,7 @@ class Profile(resource.Resource): resource_key = 'profile' resources_key = 'profiles' base_path = '/profiles' - service = cluster_service.ClusterService() + service = clustering_service.ClusteringService() # capabilities allow_create = True diff --git a/openstack/cluster/v1/profile_type.py b/openstack/clustering/v1/profile_type.py similarity index 91% rename from openstack/cluster/v1/profile_type.py rename to openstack/clustering/v1/profile_type.py index 3b79297aa..be04686ea 100644 --- a/openstack/cluster/v1/profile_type.py +++ b/openstack/clustering/v1/profile_type.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.cluster import cluster_service +from openstack.clustering import clustering_service from openstack import resource2 as resource @@ -18,7 +18,7 @@ class ProfileType(resource.Resource): resource_key = 'profile_type' resources_key = 'profile_types' base_path = '/profile-types' - service = cluster_service.ClusterService() + service = clustering_service.ClusteringService() # Capabilities allow_list = True diff --git a/openstack/cluster/v1/receiver.py b/openstack/clustering/v1/receiver.py similarity index 95% rename from openstack/cluster/v1/receiver.py rename to openstack/clustering/v1/receiver.py index d69400489..1437fce35 100644 --- a/openstack/cluster/v1/receiver.py +++ b/openstack/clustering/v1/receiver.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.cluster import cluster_service +from openstack.clustering import clustering_service from openstack import resource2 as resource @@ -18,7 +18,7 @@ class Receiver(resource.Resource): resource_key = 'receiver' resources_key = 'receivers' base_path = '/receivers' - service = cluster_service.ClusterService() + service = clustering_service.ClusteringService() # Capabilities allow_list = True diff --git a/openstack/cluster/v1/service.py b/openstack/clustering/v1/service.py similarity index 92% rename from openstack/cluster/v1/service.py rename to openstack/clustering/v1/service.py index 0bdfaa024..dde009087 100644 --- a/openstack/cluster/v1/service.py +++ b/openstack/clustering/v1/service.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.cluster import cluster_service +from openstack.clustering import clustering_service from openstack import resource2 as resource @@ -18,7 +18,7 @@ class Service(resource.Resource): resource_key = 'service' resources_key = 'services' base_path = '/services' - service = cluster_service.ClusterService() + service = clustering_service.ClusteringService() # Capabilities allow_list = True diff --git a/openstack/cluster/version.py b/openstack/clustering/version.py similarity index 83% rename from openstack/cluster/version.py rename to openstack/clustering/version.py index 44549b60f..c08894012 100644 --- a/openstack/cluster/version.py +++ b/openstack/clustering/version.py @@ -11,7 +11,7 @@ # under the License. -from openstack.cluster import cluster_service +from openstack.clustering import clustering_service from openstack import resource2 as resource @@ -19,8 +19,8 @@ class Version(resource.Resource): resource_key = 'version' resources_key = 'versions' base_path = '/' - service = cluster_service.ClusterService( - version=cluster_service.ClusterService.UNVERSIONED + service = clustering_service.ClusteringService( + version=clustering_service.ClusteringService.UNVERSIONED ) # capabilities diff --git a/openstack/compute/v2/_proxy.py b/openstack/compute/v2/_proxy.py index a6bd829ef..9ba0ef6e4 100644 --- a/openstack/compute/v2/_proxy.py +++ b/openstack/compute/v2/_proxy.py @@ -198,7 +198,7 @@ class Proxy(proxy2.BaseProxy): :rtype: :class:`~openstack.compute.v2.image.Image` """ res = self._get_base_resource(image, _image.Image) - metadata = res.get_metadata(self._session) + metadata = res.get_metadata(self) result = _image.Image.existing(id=res.id, metadata=metadata) return result @@ -219,7 +219,7 @@ class Proxy(proxy2.BaseProxy): :rtype: :class:`~openstack.compute.v2.image.Image` """ res = self._get_base_resource(image, _image.Image) - metadata = res.set_metadata(self._session, **metadata) + metadata = res.set_metadata(self, **metadata) result = _image.Image.existing(id=res.id, metadata=metadata) return result @@ -237,7 +237,7 @@ class Proxy(proxy2.BaseProxy): :rtype: ``None`` """ res = self._get_base_resource(image, _image.Image) - return res.delete_metadata(self._session, keys) + return res.delete_metadata(self, keys) def create_keypair(self, **attrs): """Create a new keypair from attributes @@ -341,7 +341,7 @@ class Proxy(proxy2.BaseProxy): """ if force: server = self._get_resource(_server.Server, server) - server.force_delete(self._session) + server.force_delete(self) else: self._delete(_server.Server, server, ignore_missing=ignore_missing) @@ -434,7 +434,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.change_password(self._session, new_password) + server.change_password(self, new_password) def reset_server_state(self, server, state): """Reset the state of server @@ -447,7 +447,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ res = self._get_base_resource(server, _server.Server) - res.reset_state(self._session, state) + res.reset_state(self, state) def reboot_server(self, server, reboot_type): """Reboot a server @@ -460,7 +460,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.reboot(self._session, reboot_type) + server.reboot(self, reboot_type) def rebuild_server(self, server, name, admin_password, **attrs): """Rebuild a server @@ -488,7 +488,7 @@ class Proxy(proxy2.BaseProxy): instance. """ server = self._get_resource(_server.Server, server) - return server.rebuild(self._session, name, admin_password, **attrs) + return server.rebuild(self, name, admin_password, **attrs) def resize_server(self, server, flavor): """Resize a server @@ -502,7 +502,7 @@ class Proxy(proxy2.BaseProxy): """ server = self._get_resource(_server.Server, server) flavor_id = resource2.Resource._get_id(flavor) - server.resize(self._session, flavor_id) + server.resize(self, flavor_id) def confirm_server_resize(self, server): """Confirm a server resize @@ -513,7 +513,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.confirm_resize(self._session) + server.confirm_resize(self) def revert_server_resize(self, server): """Revert a server resize @@ -524,7 +524,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.revert_resize(self._session) + server.revert_resize(self) def create_server_image(self, server, name, metadata=None): """Create an image from a server @@ -537,7 +537,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.create_image(self._session, name, metadata) + server.create_image(self, name, metadata) def add_security_group_to_server(self, server, security_group): """Add a security group to a server @@ -552,7 +552,7 @@ class Proxy(proxy2.BaseProxy): """ server = self._get_resource(_server.Server, server) security_group_id = resource2.Resource._get_id(security_group) - server.add_security_group(self._session, security_group_id) + server.add_security_group(self, security_group_id) def remove_security_group_from_server(self, server, security_group): """Remove a security group from a server @@ -567,7 +567,7 @@ class Proxy(proxy2.BaseProxy): """ server = self._get_resource(_server.Server, server) security_group_id = resource2.Resource._get_id(security_group) - server.remove_security_group(self._session, security_group_id) + server.remove_security_group(self, security_group_id) def add_fixed_ip_to_server(self, server, network_id): """Adds a fixed IP address to a server instance. @@ -579,7 +579,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.add_fixed_ip(self._session, network_id) + server.add_fixed_ip(self, network_id) def remove_fixed_ip_from_server(self, server, address): """Removes a fixed IP address from a server instance. @@ -591,7 +591,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.remove_fixed_ip(self._session, address) + server.remove_fixed_ip(self, address) def add_floating_ip_to_server(self, server, address, fixed_address=None): """Adds a floating IP address to a server instance. @@ -605,7 +605,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.add_floating_ip(self._session, address, + server.add_floating_ip(self, address, fixed_address=fixed_address) def remove_floating_ip_from_server(self, server, address): @@ -618,7 +618,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.remove_floating_ip(self._session, address) + server.remove_floating_ip(self, address) def backup_server(self, server, name, backup_type, rotation): """Backup a server @@ -634,7 +634,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.backup(self._session, name, backup_type, rotation) + server.backup(self, name, backup_type, rotation) def pause_server(self, server): """Pauses a server and changes its status to ``PAUSED``. @@ -644,7 +644,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.pause(self._session) + server.pause(self) def unpause_server(self, server): """Unpauses a paused server and changes its status to ``ACTIVE``. @@ -654,7 +654,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.unpause(self._session) + server.unpause(self) def suspend_server(self, server): """Suspends a server and changes its status to ``SUSPENDED``. @@ -664,7 +664,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.suspend(self._session) + server.suspend(self) def resume_server(self, server): """Resumes a suspended server and changes its status to ``ACTIVE``. @@ -674,7 +674,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.resume(self._session) + server.resume(self) def lock_server(self, server): """Locks a server. @@ -684,7 +684,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.lock(self._session) + server.lock(self) def unlock_server(self, server): """Unlocks a locked server. @@ -694,7 +694,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.unlock(self._session) + server.unlock(self) def rescue_server(self, server, admin_pass=None, image_ref=None): """Puts a server in rescue mode and changes it status to ``RESCUE``. @@ -711,7 +711,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.rescue(self._session, admin_pass=admin_pass, + server.rescue(self, admin_pass=admin_pass, image_ref=image_ref) def unrescue_server(self, server): @@ -722,7 +722,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.unrescue(self._session) + server.unrescue(self) def evacuate_server(self, server, host=None, admin_pass=None, force=None): """Evacuates a server from a failed host to a new host. @@ -739,7 +739,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.evacuate(self._session, host=host, admin_pass=admin_pass, + server.evacuate(self, host=host, admin_pass=admin_pass, force=force) def start_server(self, server): @@ -750,7 +750,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.start(self._session) + server.start(self) def stop_server(self, server): """Stops a running server and changes its state to ``SHUTOFF``. @@ -760,7 +760,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.stop(self._session) + server.stop(self) def shelve_server(self, server): """Shelves a server. @@ -775,7 +775,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.shelve(self._session) + server.shelve(self) def unshelve_server(self, server): """Unselves or restores a shelved server. @@ -789,7 +789,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.unshelve(self._session) + server.unshelve(self) def get_server_console_output(self, server, length=None): """Return the console output for a server. @@ -802,11 +802,11 @@ class Proxy(proxy2.BaseProxy): escaped to create a valid JSON string. """ server = self._get_resource(_server.Server, server) - return server.get_console_output(self._session, length=length) + return server.get_console_output(self, length=length) def wait_for_server(self, server, status='ACTIVE', failures=['ERROR'], interval=2, wait=120): - return resource2.wait_for_status(self._session, server, status, + return resource2.wait_for_status(self, server, status, failures, interval, wait) def create_server_interface(self, server, **attrs): @@ -938,7 +938,7 @@ class Proxy(proxy2.BaseProxy): :rtype: :class:`~openstack.compute.v2.server.Server` """ res = self._get_base_resource(server, _server.Server) - metadata = res.get_metadata(self._session) + metadata = res.get_metadata(self) result = _server.Server.existing(id=res.id, metadata=metadata) return result @@ -959,7 +959,7 @@ class Proxy(proxy2.BaseProxy): :rtype: :class:`~openstack.compute.v2.server.Server` """ res = self._get_base_resource(server, _server.Server) - metadata = res.set_metadata(self._session, **metadata) + metadata = res.set_metadata(self, **metadata) result = _server.Server.existing(id=res.id, metadata=metadata) return result @@ -977,7 +977,7 @@ class Proxy(proxy2.BaseProxy): :rtype: ``None`` """ res = self._get_base_resource(server, _server.Server) - return res.delete_metadata(self._session, keys) + return res.delete_metadata(self, keys) def create_server_group(self, **attrs): """Create a new server group from attributes @@ -1096,7 +1096,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ service = self._get_resource(_service.Service, service) - service.force_down(self._session, host, binary) + service.force_down(self, host, binary) def disable_service(self, service, host, binary, disabled_reason=None): """Disable a service @@ -1110,7 +1110,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ service = self._get_resource(_service.Service, service) - service.disable(self._session, + service.disable(self, host, binary, disabled_reason) @@ -1126,7 +1126,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ service = self._get_resource(_service.Service, service) - service.enable(self._session, host, binary) + service.enable(self, host, binary) def services(self): """Return a generator of service @@ -1268,7 +1268,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.migrate(self._session) + server.migrate(self) def live_migrate_server(self, server, host=None, force=False): """Migrate a server from one host to target host @@ -1281,4 +1281,4 @@ class Proxy(proxy2.BaseProxy): :returns: None """ server = self._get_resource(_server.Server, server) - server.live_migrate(self._session, host, force) + server.live_migrate(self, host, force) diff --git a/openstack/compute/v2/keypair.py b/openstack/compute/v2/keypair.py index 26580068e..b1fd2e4cb 100644 --- a/openstack/compute/v2/keypair.py +++ b/openstack/compute/v2/keypair.py @@ -47,7 +47,7 @@ class Keypair(resource2.Resource): @classmethod def list(cls, session, paginated=False): - resp = session.get(cls.base_path, endpoint_filter=cls.service, + resp = session.get(cls.base_path, headers={"Accept": "application/json"}) resp = resp.json() resp = resp[cls.resources_key] diff --git a/openstack/compute/v2/limits.py b/openstack/compute/v2/limits.py index 113e2e85e..1e04f4d89 100644 --- a/openstack/compute/v2/limits.py +++ b/openstack/compute/v2/limits.py @@ -76,18 +76,18 @@ class Limits(resource2.Resource): absolute = resource2.Body("absolute", type=AbsoluteLimits) rate = resource2.Body("rate", type=list) - def get(self, session, requires_id=False): + def get(self, session, requires_id=False, error_message=None): """Get the Limits resource. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :returns: A Limits instance :rtype: :class:`~openstack.compute.v2.limits.Limits` """ request = self._prepare_request(requires_id=False, prepend_key=False) - response = session.get(request.uri, endpoint_filter=self.service) + response = session.get(request.url, error_message=error_message) body = response.json() body = body[self.resource_key] diff --git a/openstack/compute/v2/metadata.py b/openstack/compute/v2/metadata.py index e611fd98b..5fbb7e2c5 100644 --- a/openstack/compute/v2/metadata.py +++ b/openstack/compute/v2/metadata.py @@ -37,7 +37,7 @@ class MetadataMixin(object): else: url = utils.urljoin(base, self.id, "metadata") - kwargs = {"endpoint_filter": self.service} + kwargs = {} if metadata or clear: # 'meta' is the key for singular modifications. # 'metadata' is the key for mass modifications. diff --git a/openstack/compute/v2/server.py b/openstack/compute/v2/server.py index 574b72021..01ef2ba65 100644 --- a/openstack/compute/v2/server.py +++ b/openstack/compute/v2/server.py @@ -178,7 +178,7 @@ class Server(resource2.Resource, metadata.MetadataMixin): url = utils.urljoin(Server.base_path, self.id, 'action') headers = {'Accept': ''} return session.post( - url, endpoint_filter=self.service, json=body, headers=headers) + url, json=body, headers=headers) def change_password(self, session, new_password): """Change the administrator password to the given password.""" diff --git a/openstack/compute/v2/server_ip.py b/openstack/compute/v2/server_ip.py index bc90d645d..2f4ed9542 100644 --- a/openstack/compute/v2/server_ip.py +++ b/openstack/compute/v2/server_ip.py @@ -41,7 +41,7 @@ class ServerIP(resource2.Resource): if network_label is not None: url = utils.urljoin(url, network_label) - resp = session.get(url, endpoint_filter=cls.service) + resp = session.get(url,) resp = resp.json() if network_label is None: diff --git a/openstack/compute/v2/service.py b/openstack/compute/v2/service.py index a36f67dff..ece512703 100644 --- a/openstack/compute/v2/service.py +++ b/openstack/compute/v2/service.py @@ -44,7 +44,7 @@ class Service(resource2.Resource): def _action(self, session, action, body): url = utils.urljoin(Service.base_path, action) - return session.put(url, endpoint_filter=self.service, json=body) + return session.put(url, json=body) def force_down(self, session, host, binary): """Force a service down.""" diff --git a/openstack/config/cloud_config.py b/openstack/config/cloud_config.py index 404769f69..7f655a396 100644 --- a/openstack/config/cloud_config.py +++ b/openstack/config/cloud_config.py @@ -166,10 +166,12 @@ class CloudConfig(object): # still work. # What's even more amazing is that they did it AGAIN with cinder v3 # And then I learned that mistral copied it. - if service_type == 'volume': - if self.get_api_version(service_type).startswith('2'): + # TODO(shade) This should get removed when we have os-service-types + # alias support landed in keystoneauth. + if service_type in ('volume', 'block-storage'): + if self.get_api_version('volume').startswith('2'): service_type = 'volumev2' - elif self.get_api_version(service_type).startswith('3'): + elif self.get_api_version('volume').startswith('3'): service_type = 'volumev3' elif service_type == 'workflow': if self.get_api_version(service_type).startswith('2'): @@ -255,7 +257,7 @@ class CloudConfig(object): service_type=self.get_service_type(service_key), service_name=self.get_service_name(service_key), interface=self.get_interface(service_key), - region_name=self.region) + region_name=self.get_region_name(service_key)) def _get_highest_endpoint(self, service_types, kwargs): session = self.get_session() diff --git a/openstack/connection.py b/openstack/connection.py index d83b77daa..beb071f2e 100644 --- a/openstack/connection.py +++ b/openstack/connection.py @@ -13,22 +13,37 @@ """ The :class:`~openstack.connection.Connection` class is the primary interface to the Python SDK it maintains a context for a connection to a cloud provider. -The connection has an attribute to access each supported service. The service -attributes are created dynamically based on user profiles and the service -catalog. +The connection has an attribute to access each supported service. Examples -------- At a minimum, the :class:`~openstack.connection.Connection` class needs to be -created with an authenticator or the parameters to build one. +created with a config or the parameters to build one. Create a connection ~~~~~~~~~~~~~~~~~~~ -The following example constructor uses the identity authenticator using -username and password. The default settings for the transport are used -by this connection.:: +The preferred way to create a connection is to manage named configuration +settings in your clouds.yaml file and refer to them by name.:: + + from openstack import connection + + conn = connection.Connection(cloud='example', region_name='earth1') + +If you already have an :class:`~openstack.config.cloud_config.CloudConfig` +you can pass it in instead.:: + + from openstack import connection + import openstack.config + + config = openstack.config.OpenStackConfig.get_one_cloud( + cloud='example', region_name='earth') + conn = connection.Connection(config=config) + +It's also possible to pass in parameters directly if needed. The following +example constructor uses the default identity password auth +plugin and provides a username and password.:: from openstack import connection auth_args = { @@ -42,45 +57,47 @@ by this connection.:: List ~~~~ -Services are accessed through an attribute named after the service. A list -of all the projects is retrieved in this manner:: +Services are accessed through an attribute named after the service's official +service-type. A list of all the projects is retrieved in this manner:: projects = conn.identity.list_projects() Find or create ~~~~~~~~~~~~~~ -If you wanted to make sure you had a network named 'jenkins', you would first +If you wanted to make sure you had a network named 'zuul', you would first try to find it and if that fails, you would create it:: - network = conn.network.find_network("jenkins") + network = conn.network.find_network("zuul") if network is None: - network = conn.network.create_network({"name": "jenkins"}) + network = conn.network.create_network({"name": "zuul"}) """ +import importlib import logging import sys -from keystoneauth1.loading import base as ksa_loader -import openstack.config +import keystoneauth1.exceptions +import os_service_types +from openstack.cloud import task_manager +import openstack.config +from openstack.config import cloud_config from openstack import exceptions -from openstack import profile as _profile from openstack import proxy from openstack import proxy2 -from openstack import session as _session from openstack import utils _logger = logging.getLogger(__name__) def from_config(cloud_name=None, cloud_config=None, options=None): - """Create a Connection using os-client-config + """Create a Connection using openstack.config :param str cloud_name: Use the `cloud_name` configuration details when creating the Connection instance. :param cloud_config: An instance of `openstack.config.loader.OpenStackConfig` - as returned from the os-client-config library. + as returned from openstack.config. If no `config` is provided, `openstack.config.OpenStackConfig` will be called, and the provided `cloud_name` will be used in @@ -95,177 +112,205 @@ def from_config(cloud_name=None, cloud_config=None, options=None): :rtype: :class:`~openstack.connection.Connection` """ - # TODO(thowe): I proposed that service name defaults to None in OCC - defaults = {} - prof = _profile.Profile() - services = [service.service_type for service in prof.get_services()] - for service in services: - defaults[service + '_service_name'] = None - # TODO(thowe): default is 2 which turns into v2 which doesn't work - # this stuff needs to be fixed where we keep version and path separated. - defaults['network_api_version'] = 'v2.0' if cloud_config is None: - occ = openstack.config.OpenStackConfig(override_defaults=defaults) + occ = openstack.config.OpenStackConfig() cloud_config = occ.get_one_cloud(cloud=cloud_name, argparse=options) if cloud_config.debug: utils.enable_logging(True, stream=sys.stdout) - # TODO(mordred) we need to add service_type setting to openstacksdk. - # Some clouds have type overridden as well as name. - services = [service.service_type for service in prof.get_services()] - for service in cloud_config.get_services(): - if service in services: - version = cloud_config.get_api_version(service) - if version: - version = str(version) - if not version.startswith("v"): - version = "v" + version - prof.set_version(service, version) - name = cloud_config.get_service_name(service) - if name: - prof.set_name(service, name) - interface = cloud_config.get_interface(service) - if interface: - prof.set_interface(service, interface) - - region = cloud_config.get_region_name(service) - if region: - for service in services: - prof.set_region(service, region) - - # Auth - auth = cloud_config.config['auth'] - # TODO(thowe) We should be using auth_type - auth['auth_plugin'] = cloud_config.config['auth_type'] - if 'cacert' in auth: - auth['verify'] = auth.pop('cacert') - if 'cacert' in cloud_config.config: - auth['verify'] = cloud_config.config['cacert'] - insecure = cloud_config.config.get('insecure', False) - if insecure: - auth['verify'] = False - - cert = cloud_config.config.get('cert') - if cert: - key = cloud_config.config.get('key') - auth['cert'] = (cert, key) if key else cert - - return Connection(profile=prof, **auth) + return Connection(config=cloud_config) class Connection(object): - def __init__(self, session=None, authenticator=None, profile=None, - verify=True, cert=None, user_agent=None, - auth_plugin="password", - **auth_args): - """Create a context for a connection to a cloud provider. + def __init__(self, cloud=None, config=None, session=None, + app_name=None, app_version=None, + # TODO(shade) Remove these once we've shifted + # python-openstackclient to not use the profile interface. + authenticator=None, profile=None, + **kwargs): + """Create a connection to a cloud. - A connection needs a transport and an authenticator. The user may pass - in a transport and authenticator they want to use or they may pass in - the parameters to create a transport and authenticator. The connection - creates a - :class:`~openstack.session.Session` which uses the profile - and authenticator to perform HTTP requests. + A connection needs information about how to connect, how to + authenticate and how to select the appropriate services to use. + The recommended way to provide this information is by referencing + a named cloud config from an existing `clouds.yaml` file. The cloud + name ``envvars`` may be used to consume a cloud configured via ``OS_`` + environment variables. + + A pre-existing :class:`~openstack.config.cloud_config.CloudConfig` + object can be passed in lieu of a cloud name, for cases where the user + already has a fully formed CloudConfig and just wants to use it. + + Similarly, if for some reason the user already has a + :class:`~keystoneauth1.session.Session` and wants to use it, it may be + passed in. + + :param str cloud: Name of the cloud from config to use. + :param config: CloudConfig object representing the config for the + region of the cloud in question. + :type config: :class:`~openstack.config.cloud_config.CloudConfig` :param session: A session object compatible with - :class:`~openstack.session.Session`. - :type session: :class:`~openstack.session.Session` - :param authenticator: An authenticator derived from the base - authenticator plugin that was previously created. Two common - authentication identity plugins are - :class:`identity_v2 ` and - :class:`identity_v3 `. - If this parameter is not passed in, the connection will create an - authenticator. - :type authenticator: :class:`~openstack.auth.base.BaseAuthPlugin` - :param profile: If the user has any special profiles such as the - service name, region, version or interface, they may be provided - in the profile object. If no profiles are provided, the - services that appear first in the service catalog will be used. - :type profile: :class:`~openstack.profile.Profile` - :param bool verify: If a transport is not provided to the connection, - this parameter will be used to create a transport. If ``verify`` - is set to true, which is the default, the SSL cert will be - verified. It can also be set to a CA_BUNDLE path. - :param cert: If a transport is not provided to the connection then this - parameter will be used to create a transport. `cert` allows to - provide a client certificate file path or a tuple with client - certificate and key paths. - :type cert: str or tuple - :param str user_agent: If a transport is not provided to the - connection, this parameter will be used when creating a transport. - The value given here will be prepended to the default, which is - specified in :attr:`~openstack.transport.USER_AGENT`. - The resulting ``user_agent`` value is used for the ``User-Agent`` - HTTP header. - :param str auth_plugin: The name of authentication plugin to use. - The default value is ``password``. - :param auth_args: The rest of the parameters provided are assumed to be - authentication arguments that are used by the authentication - plugin. + :class:`~keystoneauth1.session.Session`. + :type session: :class:`~keystoneauth1.session.Session` + :param str app_name: Name of the application to be added to User Agent. + :param str app_version: Version of the application to be added to + User Agent. + :param authenticator: DEPRECATED. Only exists for short-term backwards + compatibility for python-openstackclient while we + transition. + :param profile: DEPRECATED. Only exists for short-term backwards + compatibility for python-openstackclient while we + transition. + :param kwargs: If a config is not provided, the rest of the parameters + provided are assumed to be arguments to be passed to the + CloudConfig contructor. """ - self.profile = profile if profile else _profile.Profile() + self.config = config + self.service_type_manager = os_service_types.ServiceTypes() + + if not self.config: + openstack_config = openstack.config.OpenStackConfig( + app_name=app_name, app_version=app_version, + load_yaml_config=profile is None) + if profile: + # TODO(shade) Remove this once we've shifted + # python-openstackclient to not use the profile interface. + self.config = self._get_config_from_profile( + openstack_config, profile, authenticator, **kwargs) + else: + self.config = openstack_config.get_one_cloud( + cloud=cloud, validate=session is None, **kwargs) + + self.task_manager = task_manager.TaskManager( + name=':'.join([self.config.name, self.config.region])) + if session: - # Make sure it is the right kind of session. A keystoneauth1 - # session would work in some ways but show strange errors in - # others. E.g. a Resource.find would work with an id but fail when - # given a name because it attempts to catch - # openstack.exceptions.NotFoundException to signal that a search by - # ID failed before trying a search by name, but with a - # keystoneauth1 session the lookup by ID raises - # keystoneauth1.exceptions.NotFound instead. We need to ensure our - # Session class gets used so that our implementation of various - # methods always works as we expect. - if not isinstance(session, _session.Session): - raise exceptions.SDKException( - 'Session instance is from %s but must be from %s' % - (session.__module__, _session.__name__)) - self.session = session - else: - self.authenticator = self._create_authenticator(authenticator, - auth_plugin, - **auth_args) - self.session = _session.Session( - self.profile, auth=self.authenticator, verify=verify, - cert=cert, user_agent=user_agent) + # TODO(mordred) Expose constructor option for this in OCC + self.config._keystone_session = session + + self.session = self.config.get_session() self._open() - def _create_authenticator(self, authenticator, auth_plugin, **args): - if authenticator: - return authenticator - # TODO(thowe): Jamie was suggesting we should support other - # ways of loading the plugin - loader = ksa_loader.get_plugin_loader(auth_plugin) - load_args = {} - for opt in loader.get_options(): - if args.get(opt.dest): - load_args[opt.dest] = args[opt.dest] - return loader.load_from_options(**load_args) + def _get_config_from_profile( + self, openstack_config, profile, authenticator, **kwargs): + """Get openstack.config objects from legacy profile.""" + # TODO(shade) Remove this once we've shifted python-openstackclient + # to not use the profile interface. + config = openstack_config.get_one_cloud( + cloud='defaults', validate=False, **kwargs) + config._auth = authenticator + + for service in profile.get_services(): + service_type = service.service_type + if service.interface: + key = cloud_config._make_key('interface', service_type) + config.config[key] = service.interface + if service.region: + key = cloud_config._make_key('region_name', service_type) + config.config[key] = service.region + if service.version: + version = service.version + if version.startswith('v'): + version = version[1:] + key = cloud_config._make_key('api_version', service_type) + config.config[key] = service.version + return config def _open(self): - """Open the connection. + """Open the connection. """ + for service in self.service_type_manager.services: + self._load(service['service_type']) + # TODO(mordred) openstacksdk has support for the metric service + # which is not in service-types-authority. What do we do about that? + self._load('metric') - NOTE(thowe): Have this set up some lazy loader instead. - """ - for service in self.profile.get_services(): - self._load(service) + def _load(self, service_type): + service = self._get_service(service_type) - def _load(self, service): - attr_name = service.get_service_module() - module = service.get_module() + "._proxy" - try: - __import__(module) - proxy_class = getattr(sys.modules[module], "Proxy") + if service: + module_name = service.get_module() + "._proxy" + module = importlib.import_module(module_name) + proxy_class = getattr(module, "Proxy") if not (issubclass(proxy_class, proxy.BaseProxy) or issubclass(proxy_class, proxy2.BaseProxy)): raise TypeError("%s.Proxy must inherit from BaseProxy" % proxy_class.__module__) - setattr(self, attr_name, proxy_class(self.session)) - except Exception as e: - _logger.warn("Unable to load %s: %s" % (module, e)) + else: + # If we don't have a proxy, just instantiate BaseProxy so that + # we get an adapter. + proxy_class = proxy2.BaseProxy + + proxy_object = proxy_class( + session=self.config.get_session(), + task_manager=self.task_manager, + allow_version_hack=True, + service_type=self.config.get_service_type(service_type), + service_name=self.config.get_service_name(service_type), + interface=self.config.get_interface(service_type), + region_name=self.config.region, + version=self.config.get_api_version(service_type) + ) + all_types = self.service_type_manager.get_all_types(service_type) + # Register the proxy class with every known alias + for attr_name in [name.replace('-', '_') for name in all_types]: + setattr(self, attr_name, proxy_object) + + def _get_all_types(self, service_type): + # We make connection attributes for all official real type names + # and aliases. Three services have names they were called by in + # openstacksdk that are not covered by Service Types Authority aliases. + # Include them here - but take heed, no additional values should ever + # be added to this list. + # that were only used in openstacksdk resource naming. + LOCAL_ALIASES = { + 'baremetal': 'bare_metal', + 'block_storage': 'block_store', + 'clustering': 'cluster', + } + all_types = self.service_type_manager.get_all_types(service_type) + if service_type in LOCAL_ALIASES: + all_types.append(LOCAL_ALIASES[service_type]) + return all_types + + def _get_service(self, official_service_type): + service_class = None + for service_type in self._get_all_types(official_service_type): + service_class = self._find_service_class(service_type) + if service_class: + break + if not service_class: + return None + # TODO(mordred) Replace this with proper discovery + version_string = self.config.get_api_version(official_service_type) + version = None + if version_string: + version = 'v{version}'.format(version=version_string[0]) + return service_class(version=version) + + def _find_service_class(self, service_type): + package_name = 'openstack.{service_type}'.format( + service_type=service_type).replace('-', '_') + module_name = service_type.replace('-', '_') + '_service' + class_name = ''.join( + [part.capitalize() for part in module_name.split('_')]) + try: + import_name = '.'.join([package_name, module_name]) + service_module = importlib.import_module(import_name) + except ImportError: + return None + service_class = getattr(service_module, class_name, None) + if not service_class: + _logger.warn( + 'Unable to find class {class_name} in module for service' + ' for service {service_type}'.format( + class_name=class_name, + service_type=service_type)) + return None + return service_class def authorize(self): """Authorize this Connection @@ -278,9 +323,10 @@ class Connection(object): :raises: :class:`~openstack.exceptions.HttpException` if the authorization fails due to reasons like the credentials - provided are unable to be authorized or the `auth_plugin` + provided are unable to be authorized or the `auth_type` argument is missing, etc. """ - headers = self.session.get_auth_headers() - - return headers.get('X-Auth-Token') if headers else None + try: + return self.session.get_token() + except keystoneauth1.exceptions.ClientException as e: + raise exceptions.raise_from_response(e.response) diff --git a/openstack/database/v1/instance.py b/openstack/database/v1/instance.py index 97660a981..30d03cc9a 100644 --- a/openstack/database/v1/instance.py +++ b/openstack/database/v1/instance.py @@ -60,12 +60,12 @@ class Instance(resource.Resource): and provides the user with a generated root password. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :returns: A dictionary with keys ``name`` and ``password`` specifying the login credentials. """ url = utils.urljoin(self.base_path, self.id, 'root') - resp = session.post(url, endpoint_filter=self.service) + resp = session.post(url,) return resp.json()['user'] def is_root_enabled(self, session): @@ -74,12 +74,12 @@ class Instance(resource.Resource): Determine if root is enabled on this particular instance. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :returns: ``True`` if root user is enabled for a specified database instance or ``False`` otherwise. """ url = utils.urljoin(self.base_path, self.id, 'root') - resp = session.get(url, endpoint_filter=self.service) + resp = session.get(url,) return resp.json()['rootEnabled'] def restart(self, session): @@ -89,7 +89,7 @@ class Instance(resource.Resource): """ body = {'restart': {}} url = utils.urljoin(self.base_path, self.id, 'action') - session.post(url, endpoint_filter=self.service, json=body) + session.post(url, json=body) def resize(self, session, flavor_reference): """Resize the database instance @@ -98,7 +98,7 @@ class Instance(resource.Resource): """ body = {'resize': {'flavorRef': flavor_reference}} url = utils.urljoin(self.base_path, self.id, 'action') - session.post(url, endpoint_filter=self.service, json=body) + session.post(url, json=body) def resize_volume(self, session, volume_size): """Resize the volume attached to the instance @@ -107,4 +107,4 @@ class Instance(resource.Resource): """ body = {'resize': {'volume': volume_size}} url = utils.urljoin(self.base_path, self.id, 'action') - session.post(url, endpoint_filter=self.service, json=body) + session.post(url, json=body) diff --git a/openstack/exceptions.py b/openstack/exceptions.py index 069f020d1..d56c92edc 100644 --- a/openstack/exceptions.py +++ b/openstack/exceptions.py @@ -18,15 +18,17 @@ Exception definitions. import re +from requests import exceptions as _rex import six class SDKException(Exception): """The base exception class for all exceptions this library raises.""" - def __init__(self, message=None, cause=None): + def __init__(self, message=None, extra_data=None): self.message = self.__class__.__name__ if message is None else message - self.cause = cause + self.extra_data = extra_data super(SDKException, self).__init__(self.message) +OpenStackCloudException = SDKException class EndpointNotFound(SDKException): @@ -50,24 +52,53 @@ class InvalidRequest(SDKException): super(InvalidRequest, self).__init__(message) -class HttpException(SDKException): +class HttpException(SDKException, _rex.HTTPError): - def __init__(self, message=None, details=None, response=None, - request_id=None, url=None, method=None, - http_status=None, cause=None): - super(HttpException, self).__init__(message=message, cause=cause) + def __init__(self, message='Error', response=None, + http_status=None, + details=None, request_id=None): + # TODO(shade) Remove http_status parameter and the ability for response + # to be None once we're not mocking Session everywhere. + if not message: + if response: + message = "{name}: {code}".format( + name=self.__class__.__name__, + code=response.status_code) + else: + message = "{name}: Unknown error".format( + name=self.__class__.__name__) + + # Call directly rather than via super to control parameters + SDKException.__init__(self, message=message) + _rex.HTTPError.__init__(self, message, response=response) + + if response: + self.request_id = response.headers.get('x-openstack-request-id') + self.status_code = response.status_code + else: + self.request_id = None + self.status_code = http_status self.details = details - self.response = response - self.request_id = request_id - self.url = url - self.method = method - self.http_status = http_status + self.url = self.request and self.request.url or None + self.method = self.request and self.request.method or None + self.source = "Server" + if self.status_code is not None and (400 <= self.status_code < 500): + self.source = "Client" def __unicode__(self): - msg = self.__class__.__name__ + ": " + self.message + if not self.url and not self.url: + return super(HttpException, self).__str__() + if self.url: + remote_error = "{source} Error for url: {url}".format( + source=self.source, url=self.url) + if self.details: + remote_error += ', ' if self.details: - msg += ", " + six.text_type(self.details) - return msg + remote_error += six.text_type(self.details) + + return "{message}: {remote_error}".format( + message=super(HttpException, self).__str__(), + remote_error=remote_error) def __str__(self): return self.__unicode__() @@ -78,6 +109,11 @@ class NotFoundException(HttpException): pass +class BadRequestException(HttpException): + """HTTP 400 Bad Request.""" + pass + + class MethodNotSupported(SDKException): """The resource does not support this operation type.""" def __init__(self, resource, method): @@ -112,37 +148,49 @@ class ResourceFailure(SDKException): pass -def from_exception(exc): - """Return an instance of an HTTPException based on httplib response.""" - if exc.response.status_code == 404: +def raise_from_response(response, error_message=None): + """Raise an instance of an HTTPException based on keystoneauth response.""" + if response.status_code < 400: + return + + if response.status_code == 404: cls = NotFoundException + elif response.status_code == 400: + cls = BadRequestException else: cls = HttpException - resp = exc.response - details = resp.text - resp_body = resp.content - content_type = resp.headers.get('content-type', '') - if resp_body and 'application/json' in content_type: + details = None + content_type = response.headers.get('content-type', '') + if response.content and 'application/json' in content_type: # Iterate over the nested objects to retrieve "message" attribute. - messages = [obj.get('message') for obj in resp.json().values() - if isinstance(obj, dict)] - # Join all of the messages together nicely and filter out any objects - # that don't have a "message" attr. - details = '\n'.join(msg for msg in messages if msg) + # TODO(shade) Add exception handling for times when the content type + # is lying. - elif resp_body and 'text/html' in content_type: + try: + content = response.json() + messages = [obj.get('message') for obj in content.values() + if isinstance(obj, dict)] + # Join all of the messages together nicely and filter out any + # objects that don't have a "message" attr. + details = '\n'.join(msg for msg in messages if msg) + except Exception: + details = response.text + elif response.content and 'text/html' in content_type: # Split the lines, strip whitespace and inline HTML from the response. details = [re.sub(r'<.+?>', '', i.strip()) - for i in details.splitlines()] - details = [msg for msg in details if msg] - # Remove duplicates from the list. - details_temp = [] - for detail in details: - if detail not in details_temp: - details_temp.append(detail) + for i in response.text.splitlines()] + details = list(set([msg for msg in details if msg])) # Return joined string separated by colons. - details = ': '.join(details_temp) - return cls(details=details, message=exc.message, response=exc.response, - request_id=exc.request_id, url=exc.url, method=exc.method, - http_status=exc.http_status, cause=exc) + details = ': '.join(details) + if not details and response.reason: + details = response.reason + else: + details = response.text + + raise cls(message=error_message, response=response, details=details) + + +class ArgumentDeprecationWarning(Warning): + """A deprecated argument has been provided.""" + pass diff --git a/openstack/identity/v2/extension.py b/openstack/identity/v2/extension.py index b4160aad4..e8ba4fcfd 100644 --- a/openstack/identity/v2/extension.py +++ b/openstack/identity/v2/extension.py @@ -46,7 +46,7 @@ class Extension(resource.Resource): @classmethod def list(cls, session, paginated=False, **params): - resp = session.get(cls.base_path, endpoint_filter=cls.service, + resp = session.get(cls.base_path, params=params) resp = resp.json() for data in resp[cls.resources_key]['values']: diff --git a/openstack/identity/v3/domain.py b/openstack/identity/v3/domain.py index 42e57649d..f358e4913 100644 --- a/openstack/identity/v3/domain.py +++ b/openstack/identity/v3/domain.py @@ -49,7 +49,7 @@ class Domain(resource.Resource): """Assign role to user on domain""" url = utils.urljoin(self.base_path, self.id, 'users', user.id, 'roles', role.id) - resp = session.put(url, endpoint_filter=self.service) + resp = session.put(url,) if resp.status_code == 204: return True return False @@ -58,7 +58,7 @@ class Domain(resource.Resource): """Validates that a user has a role on a domain""" url = utils.urljoin(self.base_path, self.id, 'users', user.id, 'roles', role.id) - resp = session.head(url, endpoint_filter=self.service) + resp = session.head(url,) if resp.status_code == 201: return True return False @@ -67,7 +67,7 @@ class Domain(resource.Resource): """Unassigns a role from a user on a domain""" url = utils.urljoin(self.base_path, self.id, 'users', user.id, 'roles', role.id) - resp = session.delete(url, endpoint_filter=self.service) + resp = session.delete(url,) if resp.status_code == 204: return True return False @@ -76,7 +76,7 @@ class Domain(resource.Resource): """Assign role to group on domain""" url = utils.urljoin(self.base_path, self.id, 'groups', group.id, 'roles', role.id) - resp = session.put(url, endpoint_filter=self.service) + resp = session.put(url,) if resp.status_code == 204: return True return False @@ -85,7 +85,7 @@ class Domain(resource.Resource): """Validates that a group has a role on a domain""" url = utils.urljoin(self.base_path, self.id, 'groups', group.id, 'roles', role.id) - resp = session.head(url, endpoint_filter=self.service) + resp = session.head(url,) if resp.status_code == 201: return True return False @@ -94,7 +94,7 @@ class Domain(resource.Resource): """Unassigns a role from a group on a domain""" url = utils.urljoin(self.base_path, self.id, 'groups', group.id, 'roles', role.id) - resp = session.delete(url, endpoint_filter=self.service) + resp = session.delete(url,) if resp.status_code == 204: return True return False diff --git a/openstack/identity/v3/project.py b/openstack/identity/v3/project.py index 3a1ab714c..ab28e359f 100644 --- a/openstack/identity/v3/project.py +++ b/openstack/identity/v3/project.py @@ -56,7 +56,7 @@ class Project(resource.Resource): """Assign role to user on project""" url = utils.urljoin(self.base_path, self.id, 'users', user.id, 'roles', role.id) - resp = session.put(url, endpoint_filter=self.service) + resp = session.put(url,) if resp.status_code == 204: return True return False @@ -65,7 +65,7 @@ class Project(resource.Resource): """Validates that a user has a role on a project""" url = utils.urljoin(self.base_path, self.id, 'users', user.id, 'roles', role.id) - resp = session.head(url, endpoint_filter=self.service) + resp = session.head(url,) if resp.status_code == 201: return True return False @@ -74,7 +74,7 @@ class Project(resource.Resource): """Unassigns a role from a user on a project""" url = utils.urljoin(self.base_path, self.id, 'users', user.id, 'roles', role.id) - resp = session.delete(url, endpoint_filter=self.service) + resp = session.delete(url,) if resp.status_code == 204: return True return False @@ -83,7 +83,7 @@ class Project(resource.Resource): """Assign role to group on project""" url = utils.urljoin(self.base_path, self.id, 'groups', group.id, 'roles', role.id) - resp = session.put(url, endpoint_filter=self.service) + resp = session.put(url,) if resp.status_code == 204: return True return False @@ -92,7 +92,7 @@ class Project(resource.Resource): """Validates that a group has a role on a project""" url = utils.urljoin(self.base_path, self.id, 'groups', group.id, 'roles', role.id) - resp = session.head(url, endpoint_filter=self.service) + resp = session.head(url,) if resp.status_code == 201: return True return False @@ -101,7 +101,7 @@ class Project(resource.Resource): """Unassigns a role from a group on a project""" url = utils.urljoin(self.base_path, self.id, 'groups', group.id, 'roles', role.id) - resp = session.delete(url, endpoint_filter=self.service) + resp = session.delete(url,) if resp.status_code == 204: return True return False diff --git a/openstack/identity/version.py b/openstack/identity/version.py index 4564cab9d..1f8442a68 100644 --- a/openstack/identity/version.py +++ b/openstack/identity/version.py @@ -32,7 +32,7 @@ class Version(resource.Resource): @classmethod def list(cls, session, paginated=False, **params): - resp = session.get(cls.base_path, endpoint_filter=cls.service, + resp = session.get(cls.base_path, params=params) resp = resp.json() for data in resp[cls.resources_key]['values']: diff --git a/openstack/image/v2/_proxy.py b/openstack/image/v2/_proxy.py index 9de368a7c..55d7db916 100644 --- a/openstack/image/v2/_proxy.py +++ b/openstack/image/v2/_proxy.py @@ -56,7 +56,7 @@ class Proxy(proxy2.BaseProxy): # return anything anyway. Otherwise this blocks while uploading # significant amounts of image data. img.data = data - img.upload(self._session) + img.upload(self) return img @@ -92,7 +92,7 @@ class Proxy(proxy2.BaseProxy): """ image = self._get_resource(_image.Image, image) - return image.download(self._session, stream=stream) + return image.download(self, stream=stream) def delete_image(self, image, ignore_missing=True): """Delete an image @@ -158,7 +158,7 @@ class Proxy(proxy2.BaseProxy): :rtype: :class:`~openstack.image.v2.image.Image` """ img = self._get_resource(_image.Image, image) - return img.update(self._session, **attrs) + return img.update(self, **attrs) def deactivate_image(self, image): """Deactivate an image @@ -169,7 +169,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ image = self._get_resource(_image.Image, image) - image.deactivate(self._session) + image.deactivate(self) def reactivate_image(self, image): """Deactivate an image @@ -180,7 +180,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ image = self._get_resource(_image.Image, image) - image.reactivate(self._session) + image.reactivate(self) def add_tag(self, image, tag): """Add a tag to an image @@ -193,7 +193,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ image = self._get_resource(_image.Image, image) - image.add_tag(self._session, tag) + image.add_tag(self, tag) def remove_tag(self, image, tag): """Remove a tag to an image @@ -206,7 +206,7 @@ class Proxy(proxy2.BaseProxy): :returns: None """ image = self._get_resource(_image.Image, image) - image.remove_tag(self._session, tag) + image.remove_tag(self, tag) def add_member(self, image, **attrs): """Create a new member from attributes diff --git a/openstack/image/v2/image.py b/openstack/image/v2/image.py index 61f970fad..79af09ea0 100644 --- a/openstack/image/v2/image.py +++ b/openstack/image/v2/image.py @@ -214,7 +214,7 @@ class Image(resource2.Resource): def _action(self, session, action): """Call an action on an image ID.""" url = utils.urljoin(self.base_path, self.id, 'actions', action) - return session.post(url, endpoint_filter=self.service) + return session.post(url,) def deactivate(self, session): """Deactivate an image @@ -234,17 +234,17 @@ class Image(resource2.Resource): def add_tag(self, session, tag): """Add a tag to an image""" url = utils.urljoin(self.base_path, self.id, 'tags', tag) - session.put(url, endpoint_filter=self.service) + session.put(url,) def remove_tag(self, session, tag): """Remove a tag from an image""" url = utils.urljoin(self.base_path, self.id, 'tags', tag) - session.delete(url, endpoint_filter=self.service) + session.delete(url,) def upload(self, session): """Upload data into an existing image""" url = utils.urljoin(self.base_path, self.id, 'file') - session.put(url, endpoint_filter=self.service, data=self.data, + session.put(url, data=self.data, headers={"Content-Type": "application/octet-stream", "Accept": ""}) @@ -253,7 +253,7 @@ class Image(resource2.Resource): # TODO(briancurtin): This method should probably offload the get # operation into another thread or something of that nature. url = utils.urljoin(self.base_path, self.id, 'file') - resp = session.get(url, endpoint_filter=self.service, stream=stream) + resp = session.get(url, stream=stream) # See the following bug report for details on why the checksum # code may sometimes depend on a second GET call. @@ -294,7 +294,7 @@ class Image(resource2.Resource): } original = self.to_dict() patch_string = jsonpatch.make_patch(original, attrs).to_string() - resp = session.patch(url, endpoint_filter=self.service, + resp = session.patch(url, data=patch_string, headers=headers) self._translate_response(resp, has_body=True) diff --git a/openstack/key_manager/v1/secret.py b/openstack/key_manager/v1/secret.py index 603b09ef0..de11b28e7 100644 --- a/openstack/key_manager/v1/secret.py +++ b/openstack/key_manager/v1/secret.py @@ -81,8 +81,7 @@ class Secret(resource2.Resource): def get(self, session, requires_id=True): request = self._prepare_request(requires_id=requires_id) - response = session.get(request.uri, - endpoint_filter=self.service).json() + response = session.get(request.url).json() content_type = None if self.payload_content_type is not None: @@ -93,8 +92,7 @@ class Secret(resource2.Resource): # Only try to get the payload if a content type has been explicitly # specified or if one was found in the metadata response if content_type is not None: - payload = session.get(utils.urljoin(request.uri, "payload"), - endpoint_filter=self.service, + payload = session.get(utils.urljoin(request.url, "payload"), headers={"Accept": content_type}) response["payload"] = payload.text diff --git a/openstack/message/v1/_proxy.py b/openstack/message/v1/_proxy.py index bdd25ef04..86a3af367 100644 --- a/openstack/message/v1/_proxy.py +++ b/openstack/message/v1/_proxy.py @@ -64,7 +64,7 @@ class Proxy(proxy.BaseProxy): :class:`~openstack.message.v1.message.Message` objects that were created. """ - return message.Message.create_messages(self._session, values) + return message.Message.create_messages(self, values) @utils.deprecated(deprecated_in="0.9.16", removed_in="0.9.17", details="Message v1 is deprecated since 2014. Use v2.") @@ -78,7 +78,7 @@ class Proxy(proxy.BaseProxy): :class:`~openstack.message.v1.message.Message` objects that were claimed. """ - return claim.Claim.claim_messages(self._session, value) + return claim.Claim.claim_messages(self, value) @utils.deprecated(deprecated_in="0.9.16", removed_in="0.9.17", details="Message v1 is deprecated since 2014. Use v2.") @@ -90,4 +90,4 @@ class Proxy(proxy.BaseProxy): :returns: ``None`` """ - message.Message.delete_by_id(self._session, value) + message.Message.delete_by_id(self, value) diff --git a/openstack/message/v1/claim.py b/openstack/message/v1/claim.py index 5b8c25f61..d993a443f 100644 --- a/openstack/message/v1/claim.py +++ b/openstack/message/v1/claim.py @@ -60,7 +60,7 @@ class Claim(resource.Resource): body = [] try: - resp = session.post(url, endpoint_filter=cls.service, + resp = session.post(url, headers=headers, data=json.dumps(claim, cls=ClaimEncoder), params=params) diff --git a/openstack/message/v1/message.py b/openstack/message/v1/message.py index 4650032ee..6d6f703f0 100644 --- a/openstack/message/v1/message.py +++ b/openstack/message/v1/message.py @@ -69,7 +69,7 @@ class Message(resource.Resource): url = cls._get_url({'queue_name': messages[0].queue_name}) headers = {'Client-ID': messages[0].client_id} - resp = session.post(url, endpoint_filter=cls.service, headers=headers, + resp = session.post(url, headers=headers, data=json.dumps(messages, cls=MessageEncoder)) resp = resp.json() @@ -99,7 +99,7 @@ class Message(resource.Resource): 'Client-ID': message.client_id, 'Accept': '', } - session.delete(url, endpoint_filter=cls.service, headers=headers) + session.delete(url, headers=headers) class MessageEncoder(json.JSONEncoder): diff --git a/openstack/message/v1/queue.py b/openstack/message/v1/queue.py index dd10420fa..034ce3c2a 100644 --- a/openstack/message/v1/queue.py +++ b/openstack/message/v1/queue.py @@ -30,5 +30,5 @@ class Queue(resource.Resource): def create_by_id(cls, session, attrs, resource_id=None, path_args=None): url = cls._get_url(path_args, resource_id) headers = {'Accept': ''} - session.put(url, endpoint_filter=cls.service, headers=headers) + session.put(url, headers=headers) return {cls.id_attribute: resource_id} diff --git a/openstack/message/v2/_proxy.py b/openstack/message/v2/_proxy.py index 7652ec6c7..948277278 100644 --- a/openstack/message/v2/_proxy.py +++ b/openstack/message/v2/_proxy.py @@ -87,7 +87,7 @@ class Proxy(proxy2.BaseProxy): """ message = self._get_resource(_message.Message, None, queue_name=queue_name) - return message.post(self._session, messages) + return message.post(self, messages) def messages(self, queue_name, **query): """Retrieve a generator of messages diff --git a/openstack/message/v2/claim.py b/openstack/message/v2/claim.py index 135858726..6125418de 100644 --- a/openstack/message/v2/claim.py +++ b/openstack/message/v2/claim.py @@ -71,7 +71,7 @@ class Claim(resource2.Resource): "X-PROJECT-ID": self.project_id or session.get_project_id() } request.headers.update(headers) - response = session.post(request.uri, endpoint_filter=self.service, + response = session.post(request.url, json=request.body, headers=request.headers) # For case no message was claimed successfully, 204 No Content @@ -90,7 +90,7 @@ class Claim(resource2.Resource): } request.headers.update(headers) - response = session.get(request.uri, endpoint_filter=self.service, + response = session.get(request.url, headers=request.headers) self._translate_response(response) @@ -104,7 +104,7 @@ class Claim(resource2.Resource): } request.headers.update(headers) - session.patch(request.uri, endpoint_filter=self.service, + session.patch(request.url, json=request.body, headers=request.headers) return self @@ -117,7 +117,7 @@ class Claim(resource2.Resource): } request.headers.update(headers) - response = session.delete(request.uri, endpoint_filter=self.service, + response = session.delete(request.url, headers=request.headers) self._translate_response(response, has_body=False) diff --git a/openstack/message/v2/message.py b/openstack/message/v2/message.py index 668f69c06..a889f14d2 100644 --- a/openstack/message/v2/message.py +++ b/openstack/message/v2/message.py @@ -63,7 +63,7 @@ class Message(resource2.Resource): } request.headers.update(headers) request.body = {'messages': messages} - response = session.post(request.uri, endpoint_filter=self.service, + response = session.post(request.url, json=request.body, headers=request.headers) return response.json()['resources'] @@ -86,7 +86,7 @@ class Message(resource2.Resource): query_params = cls._query_mapping._transpose(params) while more_data: - resp = session.get(uri, endpoint_filter=cls.service, + resp = session.get(uri, headers=headers, params=query_params) resp = resp.json() resp = resp[cls.resources_key] @@ -117,7 +117,7 @@ class Message(resource2.Resource): } request.headers.update(headers) - response = session.get(request.uri, endpoint_filter=self.service, + response = session.get(request.url, headers=headers) self._translate_response(response) @@ -135,8 +135,8 @@ class Message(resource2.Resource): # parameter when deleting a message that has been claimed, we # rebuild the request URI if claim_id is not None. if self.claim_id: - request.uri += '?claim_id=%s' % self.claim_id - response = session.delete(request.uri, endpoint_filter=self.service, + request.url += '?claim_id=%s' % self.claim_id + response = session.delete(request.url, headers=headers) self._translate_response(response, has_body=False) diff --git a/openstack/message/v2/queue.py b/openstack/message/v2/queue.py index 49f79f6e1..7be063789 100644 --- a/openstack/message/v2/queue.py +++ b/openstack/message/v2/queue.py @@ -60,7 +60,7 @@ class Queue(resource2.Resource): "X-PROJECT-ID": self.project_id or session.get_project_id() } request.headers.update(headers) - response = session.put(request.uri, endpoint_filter=self.service, + response = session.put(request.url, json=request.body, headers=request.headers) self._translate_response(response, has_body=False) @@ -84,7 +84,7 @@ class Queue(resource2.Resource): } while more_data: - resp = session.get(uri, endpoint_filter=cls.service, + resp = session.get(uri, headers=headers, params=query_params) resp = resp.json() resp = resp[cls.resources_key] @@ -114,7 +114,7 @@ class Queue(resource2.Resource): "X-PROJECT-ID": self.project_id or session.get_project_id() } request.headers.update(headers) - response = session.get(request.uri, endpoint_filter=self.service, + response = session.get(request.url, headers=headers) self._translate_response(response) @@ -127,7 +127,7 @@ class Queue(resource2.Resource): "X-PROJECT-ID": self.project_id or session.get_project_id() } request.headers.update(headers) - response = session.delete(request.uri, endpoint_filter=self.service, + response = session.delete(request.url, headers=headers) self._translate_response(response, has_body=False) diff --git a/openstack/message/v2/subscription.py b/openstack/message/v2/subscription.py index d5acdb059..e95329fe2 100644 --- a/openstack/message/v2/subscription.py +++ b/openstack/message/v2/subscription.py @@ -68,7 +68,7 @@ class Subscription(resource2.Resource): "X-PROJECT-ID": self.project_id or session.get_project_id() } request.headers.update(headers) - response = session.post(request.uri, endpoint_filter=self.service, + response = session.post(request.url, json=request.body, headers=request.headers) self._translate_response(response) @@ -92,7 +92,7 @@ class Subscription(resource2.Resource): query_params = cls._query_mapping._transpose(params) while more_data: - resp = session.get(uri, endpoint_filter=cls.service, + resp = session.get(uri, headers=headers, params=query_params) resp = resp.json() resp = resp[cls.resources_key] @@ -123,7 +123,7 @@ class Subscription(resource2.Resource): } request.headers.update(headers) - response = session.get(request.uri, endpoint_filter=self.service, + response = session.get(request.url, headers=request.headers) self._translate_response(response) @@ -137,7 +137,7 @@ class Subscription(resource2.Resource): } request.headers.update(headers) - response = session.delete(request.uri, endpoint_filter=self.service, + response = session.delete(request.url, headers=request.headers) self._translate_response(response, has_body=False) diff --git a/openstack/telemetry/__init__.py b/openstack/meter/__init__.py similarity index 100% rename from openstack/telemetry/__init__.py rename to openstack/meter/__init__.py diff --git a/openstack/telemetry/alarm/__init__.py b/openstack/meter/alarm/__init__.py similarity index 100% rename from openstack/telemetry/alarm/__init__.py rename to openstack/meter/alarm/__init__.py diff --git a/openstack/telemetry/alarm/alarm_service.py b/openstack/meter/alarm/alarm_service.py similarity index 100% rename from openstack/telemetry/alarm/alarm_service.py rename to openstack/meter/alarm/alarm_service.py diff --git a/openstack/telemetry/alarm/v2/__init__.py b/openstack/meter/alarm/v2/__init__.py similarity index 100% rename from openstack/telemetry/alarm/v2/__init__.py rename to openstack/meter/alarm/v2/__init__.py diff --git a/openstack/telemetry/alarm/v2/_proxy.py b/openstack/meter/alarm/v2/_proxy.py similarity index 83% rename from openstack/telemetry/alarm/v2/_proxy.py rename to openstack/meter/alarm/v2/_proxy.py index abadcd268..32b9e5795 100644 --- a/openstack/telemetry/alarm/v2/_proxy.py +++ b/openstack/meter/alarm/v2/_proxy.py @@ -11,8 +11,8 @@ # under the License. from openstack import proxy -from openstack.telemetry.alarm.v2 import alarm as _alarm -from openstack.telemetry.alarm.v2 import alarm_change as _alarm_change +from openstack.meter.alarm.v2 import alarm as _alarm +from openstack.meter.alarm.v2 import alarm_change as _alarm_change class Proxy(proxy.BaseProxy): @@ -22,11 +22,11 @@ class Proxy(proxy.BaseProxy): """Create a new alarm from attributes :param dict attrs: Keyword arguments which will be used to create - a :class:`~openstack.telemetry.v2.alarm.Alarm`, + a :class:`~openstack.meter.v2.alarm.Alarm`, comprised of the properties on the Alarm class. :returns: The results of alarm creation - :rtype: :class:`~openstack.telemetry.v2.alarm.Alarm` + :rtype: :class:`~openstack.meter.v2.alarm.Alarm` """ return self._create(_alarm.Alarm, **attrs) @@ -34,7 +34,7 @@ class Proxy(proxy.BaseProxy): """Delete an alarm :param alarm: The value can be either the ID of an alarm or a - :class:`~openstack.telemetry.v2.alarm.Alarm` instance. + :class:`~openstack.meter.v2.alarm.Alarm` instance. :param bool ignore_missing: When set to ``False`` :class:`~openstack.exceptions.ResourceNotFound` will be raised when the alarm does not exist. @@ -54,7 +54,7 @@ class Proxy(proxy.BaseProxy): raised when the resource does not exist. When set to ``True``, None will be returned when attempting to find a nonexistent resource. - :returns: One :class:`~openstack.telemetry.v2.alarm.Alarm` or None + :returns: One :class:`~openstack.meter.v2.alarm.Alarm` or None """ return self._find(_alarm.Alarm, name_or_id, ignore_missing=ignore_missing) @@ -63,9 +63,9 @@ class Proxy(proxy.BaseProxy): """Get a single alarm :param alarm: The value can be the ID of an alarm or a - :class:`~openstack.telemetry.v2.alarm.Alarm` instance. + :class:`~openstack.meter.v2.alarm.Alarm` instance. - :returns: One :class:`~openstack.telemetry.v2.alarm.Alarm` + :returns: One :class:`~openstack.meter.v2.alarm.Alarm` :raises: :class:`~openstack.exceptions.ResourceNotFound` when no resource can be found. """ @@ -78,7 +78,7 @@ class Proxy(proxy.BaseProxy): the resources being returned. :returns: A generator of alarm objects - :rtype: :class:`~openstack.telemetry.v2.alarm.Alarm` + :rtype: :class:`~openstack.meter.v2.alarm.Alarm` """ # TODO(Qiming): Check the alarm service API docs/code to verify if # the parameters need a change. @@ -88,12 +88,12 @@ class Proxy(proxy.BaseProxy): """Update a alarm :param alarm: Either the id of a alarm or a - :class:`~openstack.telemetry.v2.alarm.Alarm` instance. + :class:`~openstack.meter.v2.alarm.Alarm` instance. :attrs kwargs: The attributes to update on the alarm represented by ``value``. :returns: The updated alarm - :rtype: :class:`~openstack.telemetry.v2.alarm.Alarm` + :rtype: :class:`~openstack.meter.v2.alarm.Alarm` """ return self._update(_alarm.Alarm, alarm, **attrs) @@ -106,7 +106,7 @@ class Proxy(proxy.BaseProxy): raised when the resource does not exist. When set to ``True``, None will be returned when attempting to find a nonexistent resource. - :returns: One :class:`~openstack.telemetry.v2.alarm_change.AlarmChange` + :returns: One :class:`~openstack.meter.v2.alarm_change.AlarmChange` or None """ return self._find(_alarm_change.AlarmChange, name_or_id, @@ -120,7 +120,7 @@ class Proxy(proxy.BaseProxy): the resources being returned. :returns: A generator of alarm change objects - :rtype: :class:`~openstack.telemetry.v2.alarm_change.AlarmChange` + :rtype: :class:`~openstack.meter.v2.alarm_change.AlarmChange` """ # TODO(Qiming): Check the alarm service API docs/code to verify if # the parameters need a change. diff --git a/openstack/telemetry/alarm/v2/alarm.py b/openstack/meter/alarm/v2/alarm.py similarity index 94% rename from openstack/telemetry/alarm/v2/alarm.py rename to openstack/meter/alarm/v2/alarm.py index 095d44aba..181a9b254 100644 --- a/openstack/telemetry/alarm/v2/alarm.py +++ b/openstack/meter/alarm/v2/alarm.py @@ -11,7 +11,7 @@ # under the License. from openstack import resource -from openstack.telemetry.alarm import alarm_service +from openstack.meter.alarm import alarm_service from openstack import utils @@ -76,7 +76,7 @@ class Alarm(resource.Resource): ``insufficient data``. """ url = utils.urljoin(self.base_path, self.id, 'state') - resp = session.put(url, endpoint_filter=self.service, json=next_state) + resp = session.put(url, json=next_state) return resp.json() def check_state(self, session): @@ -85,7 +85,7 @@ class Alarm(resource.Resource): The properties of the alarm are not modified. """ url = utils.urljoin(self.base_path, self.id, 'state') - resp = session.get(url, endpoint_filter=self.service) + resp = session.get(url,) resp = resp.json() current_state = resp.replace('\"', '') return current_state diff --git a/openstack/telemetry/alarm/v2/alarm_change.py b/openstack/meter/alarm/v2/alarm_change.py similarity index 93% rename from openstack/telemetry/alarm/v2/alarm_change.py rename to openstack/meter/alarm/v2/alarm_change.py index ecc3e42d0..a4dcdd624 100644 --- a/openstack/telemetry/alarm/v2/alarm_change.py +++ b/openstack/meter/alarm/v2/alarm_change.py @@ -11,7 +11,7 @@ # under the License. from openstack import resource -from openstack.telemetry.alarm import alarm_service +from openstack.meter.alarm import alarm_service class AlarmChange(resource.Resource): @@ -47,6 +47,6 @@ class AlarmChange(resource.Resource): def list(cls, session, limit=None, marker=None, path_args=None, paginated=False, **params): url = cls._get_url(path_args) - resp = session.get(url, endpoint_filter=cls.service, params=params) + resp = session.get(url, params=params) for item in resp.json(): yield cls.existing(**item) diff --git a/openstack/telemetry/telemetry_service.py b/openstack/meter/meter_service.py similarity index 72% rename from openstack/telemetry/telemetry_service.py rename to openstack/meter/meter_service.py index 6b0a9cc92..d84bffb67 100644 --- a/openstack/telemetry/telemetry_service.py +++ b/openstack/meter/meter_service.py @@ -13,12 +13,12 @@ from openstack import service_filter -class TelemetryService(service_filter.ServiceFilter): - """The telemetry service.""" +class MeterService(service_filter.ServiceFilter): + """The meter service.""" valid_versions = [service_filter.ValidVersion('v2')] def __init__(self, version=None): - """Create a telemetry service.""" - super(TelemetryService, self).__init__(service_type='metering', - version=version) + """Create a meter service.""" + super(MeterService, self).__init__(service_type='metering', + version=version) diff --git a/openstack/telemetry/v2/__init__.py b/openstack/meter/v2/__init__.py similarity index 100% rename from openstack/telemetry/v2/__init__.py rename to openstack/meter/v2/__init__.py diff --git a/openstack/telemetry/v2/_proxy.py b/openstack/meter/v2/_proxy.py similarity index 84% rename from openstack/telemetry/v2/_proxy.py rename to openstack/meter/v2/_proxy.py index 054becca3..dcf4b108c 100644 --- a/openstack/telemetry/v2/_proxy.py +++ b/openstack/meter/v2/_proxy.py @@ -11,11 +11,11 @@ # under the License. from openstack import proxy2 -from openstack.telemetry.v2 import capability -from openstack.telemetry.v2 import meter as _meter -from openstack.telemetry.v2 import resource as _resource -from openstack.telemetry.v2 import sample -from openstack.telemetry.v2 import statistics +from openstack.meter.v2 import capability +from openstack.meter.v2 import meter as _meter +from openstack.meter.v2 import resource as _resource +from openstack.meter.v2 import sample +from openstack.meter.v2 import statistics class Proxy(proxy2.BaseProxy): @@ -30,7 +30,7 @@ class Proxy(proxy2.BaseProxy): raised when the resource does not exist. When set to ``True``, None will be returned when attempting to find a nonexistent resource. - :returns: One :class:`~openstack.telemetry.v2.capability.Capability` + :returns: One :class:`~openstack.meter.v2.capability.Capability` or None """ return self._find(capability.Capability, name_or_id, @@ -43,7 +43,7 @@ class Proxy(proxy2.BaseProxy): the resources being returned. :returns: A generator of capability objects - :rtype: :class:`~openstack.telemetry.v2.capability.Capability` + :rtype: :class:`~openstack.meter.v2.capability.Capability` """ return self._list(capability.Capability, paginated=False, **query) @@ -56,7 +56,7 @@ class Proxy(proxy2.BaseProxy): raised when the resource does not exist. When set to ``True``, None will be returned when attempting to find a nonexistent resource. - :returns: One :class:`~openstack.telemetry.v2.meter.Meter` or None + :returns: One :class:`~openstack.meter.v2.meter.Meter` or None """ return self._find(_meter.Meter, name_or_id, ignore_missing=ignore_missing) @@ -68,7 +68,7 @@ class Proxy(proxy2.BaseProxy): the resources being returned. :returns: A generator of meter objects - :rtype: :class:`~openstack.telemetry.v2.meter.Meter` + :rtype: :class:`~openstack.meter.v2.meter.Meter` """ return self._list(_meter.Meter, paginated=False, **query) @@ -81,7 +81,7 @@ class Proxy(proxy2.BaseProxy): raised when the resource does not exist. When set to ``True``, None will be returned when attempting to find a nonexistent resource. - :returns: One :class:`~openstack.telemetry.v2.resource.Resource` or + :returns: One :class:`~openstack.meter.v2.resource.Resource` or None """ return self._find(_resource.Resource, name_or_id, @@ -91,10 +91,10 @@ class Proxy(proxy2.BaseProxy): """Get a single resource :param resource: The value can be the ID of a resource or a - :class:`~openstack.telemetry.v2.resource.Resource` + :class:`~openstack.meter.v2.resource.Resource` instance. - :returns: One :class:`~openstack.telemetry.v2.resource.Resource` + :returns: One :class:`~openstack.meter.v2.resource.Resource` :raises: :class:`~openstack.exceptions.ResourceNotFound` when no resource can be found. """ @@ -107,7 +107,7 @@ class Proxy(proxy2.BaseProxy): the resources being returned. :returns: A generator of resource objects - :rtype: :class:`~openstack.telemetry.v2.resource.Resource` + :rtype: :class:`~openstack.meter.v2.resource.Resource` """ return self._list(_resource.Resource, paginated=False, **query) @@ -120,7 +120,7 @@ class Proxy(proxy2.BaseProxy): raised when the resource does not exist. When set to ``True``, None will be returned when attempting to find a nonexistent resource. - :returns: One :class:`~openstack.telemetry.v2.sample.Sample` or None + :returns: One :class:`~openstack.meter.v2.sample.Sample` or None """ return self._find(sample.Sample, name_or_id, ignore_missing=ignore_missing) @@ -133,7 +133,7 @@ class Proxy(proxy2.BaseProxy): the resources being returned. :returns: A generator of sample objects - :rtype: :class:`~openstack.telemetry.v2.sample.Sample` + :rtype: :class:`~openstack.meter.v2.sample.Sample` """ return self._list(sample.Sample, paginated=False, counter_name=meter, **query) @@ -147,7 +147,7 @@ class Proxy(proxy2.BaseProxy): raised when the resource does not exist. When set to ``True``, None will be returned when attempting to find a nonexistent resource. - :returns: One :class:`~openstack.telemetry.v2.statistics.Statistics` + :returns: One :class:`~openstack.meter.v2.statistics.Statistics` or None """ return self._find(statistics.Statistics, name_or_id, @@ -161,7 +161,7 @@ class Proxy(proxy2.BaseProxy): the resources being returned. :returns: A generator of statistics objects - :rtype: :class:`~openstack.telemetry.v2.statistics.Statistics` + :rtype: :class:`~openstack.meter.v2.statistics.Statistics` """ return self._list(statistics.Statistics, paginated=False, meter_name=meter, **query) diff --git a/openstack/telemetry/v2/capability.py b/openstack/meter/v2/capability.py similarity index 87% rename from openstack/telemetry/v2/capability.py rename to openstack/meter/v2/capability.py index be93db841..cdef31970 100644 --- a/openstack/telemetry/v2/capability.py +++ b/openstack/meter/v2/capability.py @@ -12,7 +12,7 @@ from openstack import resource2 as resource -from openstack.telemetry import telemetry_service +from openstack.meter import meter_service class Capability(resource.Resource): @@ -20,7 +20,7 @@ class Capability(resource.Resource): resource_key = 'capability' resources_key = 'capabilities' base_path = '/capabilities' - service = telemetry_service.TelemetryService() + service = meter_service.MeterService() # Supported Operations allow_list = True @@ -30,7 +30,7 @@ class Capability(resource.Resource): @classmethod def list(cls, session, paginated=False, **params): - resp = session.get(cls.base_path, endpoint_filter=cls.service, + resp = session.get(cls.base_path, params=params) resp = resp.json() for key, value in resp['api'].items(): diff --git a/openstack/telemetry/v2/meter.py b/openstack/meter/v2/meter.py similarity index 93% rename from openstack/telemetry/v2/meter.py rename to openstack/meter/v2/meter.py index 9e7e9504e..b716252e9 100644 --- a/openstack/telemetry/v2/meter.py +++ b/openstack/meter/v2/meter.py @@ -11,14 +11,14 @@ # under the License. from openstack import resource2 as resource -from openstack.telemetry import telemetry_service +from openstack.meter import meter_service class Meter(resource.Resource): """.. caution:: This API is a work in progress and is subject to change.""" resource_key = 'meter' base_path = '/meters' - service = telemetry_service.TelemetryService() + service = meter_service.MeterService() # Supported Operations allow_list = True diff --git a/openstack/telemetry/v2/resource.py b/openstack/meter/v2/resource.py similarity index 94% rename from openstack/telemetry/v2/resource.py rename to openstack/meter/v2/resource.py index f359a391b..7e9f560ea 100644 --- a/openstack/telemetry/v2/resource.py +++ b/openstack/meter/v2/resource.py @@ -11,13 +11,13 @@ # under the License. from openstack import resource2 as resource -from openstack.telemetry import telemetry_service +from openstack.meter import meter_service class Resource(resource.Resource): """.. caution:: This API is a work in progress and is subject to change.""" base_path = '/resources' - service = telemetry_service.TelemetryService() + service = meter_service.MeterService() # Supported Operations allow_get = True diff --git a/openstack/telemetry/v2/sample.py b/openstack/meter/v2/sample.py similarity index 95% rename from openstack/telemetry/v2/sample.py rename to openstack/meter/v2/sample.py index 0ff47f287..d4838e44d 100644 --- a/openstack/telemetry/v2/sample.py +++ b/openstack/meter/v2/sample.py @@ -11,13 +11,13 @@ # under the License. from openstack import resource2 as resource -from openstack.telemetry import telemetry_service +from openstack.meter import meter_service class Sample(resource.Resource): """.. caution:: This API is a work in progress and is subject to change.""" base_path = '/meters/%(counter_name)s' - service = telemetry_service.TelemetryService() + service = meter_service.MeterService() # Supported Operations allow_get = True diff --git a/openstack/telemetry/v2/statistics.py b/openstack/meter/v2/statistics.py similarity index 93% rename from openstack/telemetry/v2/statistics.py rename to openstack/meter/v2/statistics.py index a295d5147..08a9e03b8 100644 --- a/openstack/telemetry/v2/statistics.py +++ b/openstack/meter/v2/statistics.py @@ -11,14 +11,14 @@ # under the License. from openstack import resource2 as resource -from openstack.telemetry import telemetry_service +from openstack.meter import meter_service class Statistics(resource.Resource): """.. caution:: This API is a work in progress and is subject to change.""" resource_key = 'statistics' base_path = '/meters/%(meter_name)s/statistics' - service = telemetry_service.TelemetryService() + service = meter_service.MeterService() # Supported Operations allow_list = True @@ -57,6 +57,6 @@ class Statistics(resource.Resource): @classmethod def list(cls, session, paginated=False, **params): url = cls.base_path % {'meter_name': params.pop('meter_name')} - resp = session.get(url, endpoint_filter=cls.service, params=params) + resp = session.get(url, params=params) for stat in resp.json(): yield cls.existing(**stat) diff --git a/openstack/module_loader.py b/openstack/module_loader.py deleted file mode 100644 index faf271acd..000000000 --- a/openstack/module_loader.py +++ /dev/null @@ -1,29 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -Load various modules for authorization and eventually services. -""" -from stevedore import extension - - -def load_service_plugins(namespace): - service_plugins = extension.ExtensionManager( - namespace=namespace, - invoke_on_load=True, - ) - services = {} - for service in service_plugins: - service = service.obj - service.interface = None - services[service.service_type] = service - return services diff --git a/openstack/network/v2/_proxy.py b/openstack/network/v2/_proxy.py index 3678c2b21..3f031b112 100644 --- a/openstack/network/v2/_proxy.py +++ b/openstack/network/v2/_proxy.py @@ -227,7 +227,7 @@ class Proxy(proxy2.BaseProxy): """ network = self._get_resource(_network.Network, network) agent = self._get_resource(_agent.Agent, agent) - return agent.add_agent_to_network(self._session, network.id) + return agent.add_agent_to_network(self, network.id) def remove_dhcp_agent_from_network(self, agent, network): """Remove a DHCP Agent from a network @@ -239,7 +239,7 @@ class Proxy(proxy2.BaseProxy): """ network = self._get_resource(_network.Network, network) agent = self._get_resource(_agent.Agent, agent) - return agent.remove_agent_from_network(self._session, network.id) + return agent.remove_agent_from_network(self, network.id) def network_hosting_dhcp_agents(self, network, **query): """A generator of DHCP agents hosted on a network. @@ -267,7 +267,7 @@ class Proxy(proxy2.BaseProxy): # If project option is not given, grab project id from session if project is None: - project = self._session.get_project_id() + project = self.get_project_id() return self._get(_auto_allocated_topology.AutoAllocatedTopology, project) @@ -288,7 +288,7 @@ class Proxy(proxy2.BaseProxy): # If project option is not given, grab project id from session if project is None: - project = self._session.get_project_id() + project = self.get_project_id() self._delete(_auto_allocated_topology.AutoAllocatedTopology, project, ignore_missing=ignore_missing) @@ -305,7 +305,7 @@ class Proxy(proxy2.BaseProxy): # If project option is not given, grab project id from session if project is None: - project = self._session.get_project_id() + project = self.get_project_id() return self._get(_auto_allocated_topology.ValidateTopology, project=project, requires_id=False) @@ -453,7 +453,7 @@ class Proxy(proxy2.BaseProxy): service_profile = self._get_resource( _service_profile.ServiceProfile, service_profile) return flavor.associate_flavor_with_service_profile( - self._session, service_profile.id) + self, service_profile.id) def disassociate_flavor_from_service_profile( self, flavor, service_profile): @@ -472,7 +472,7 @@ class Proxy(proxy2.BaseProxy): service_profile = self._get_resource( _service_profile.ServiceProfile, service_profile) return flavor.disassociate_flavor_from_service_profile( - self._session, service_profile.id) + self, service_profile.id) def create_ip(self, **attrs): """Create a new floating ip from attributes @@ -509,7 +509,7 @@ class Proxy(proxy2.BaseProxy): :returns: One :class:`~openstack.network.v2.floating_ip.FloatingIP` or None """ - return _floating_ip.FloatingIP.find_available(self._session) + return _floating_ip.FloatingIP.find_available(self) def find_ip(self, name_or_id, ignore_missing=True): """Find a single IP @@ -1506,11 +1506,11 @@ class Proxy(proxy2.BaseProxy): def add_ip_to_port(self, port, ip): ip['port_id'] = port.id - return ip.update(self._session) + return ip.update(self) def remove_ip_from_port(self, ip): ip['port_id'] = None - return ip.update(self._session) + return ip.update(self) def get_subnet_ports(self, subnet_id): result = [] @@ -2288,7 +2288,7 @@ class Proxy(proxy2.BaseProxy): else: body = {'subnet_id': subnet_id} router = self._get_resource(_router.Router, router) - return router.add_interface(self._session, **body) + return router.add_interface(self, **body) def remove_interface_from_router(self, router, subnet_id=None, port_id=None): @@ -2308,7 +2308,7 @@ class Proxy(proxy2.BaseProxy): else: body = {'subnet_id': subnet_id} router = self._get_resource(_router.Router, router) - return router.remove_interface(self._session, **body) + return router.remove_interface(self, **body) def add_gateway_to_router(self, router, **body): """Add Gateway to a router @@ -2320,7 +2320,7 @@ class Proxy(proxy2.BaseProxy): :rtype: :class: `~openstack.network.v2.router.Router` """ router = self._get_resource(_router.Router, router) - return router.add_gateway(self._session, **body) + return router.add_gateway(self, **body) def remove_gateway_from_router(self, router, **body): """Remove Gateway from a router @@ -2332,7 +2332,7 @@ class Proxy(proxy2.BaseProxy): :rtype: :class: `~openstack.network.v2.router.Router` """ router = self._get_resource(_router.Router, router) - return router.remove_gateway(self._session, **body) + return router.remove_gateway(self, **body) def routers_hosting_l3_agents(self, router, **query): """Return a generator of L3 agent hosting a router @@ -2375,7 +2375,7 @@ class Proxy(proxy2.BaseProxy): """ agent = self._get_resource(_agent.Agent, agent) router = self._get_resource(_router.Router, router) - return agent.add_router_to_agent(self._session, router.id) + return agent.add_router_to_agent(self, router.id) def remove_router_from_agent(self, agent, router): """Remove router from L3 agent @@ -2388,7 +2388,7 @@ class Proxy(proxy2.BaseProxy): """ agent = self._get_resource(_agent.Agent, agent) router = self._get_resource(_router.Router, router) - return agent.remove_router_from_agent(self._session, router.id) + return agent.remove_router_from_agent(self, router.id) def create_security_group(self, **attrs): """Create a new security group from attributes @@ -2988,7 +2988,7 @@ class Proxy(proxy2.BaseProxy): :rtype: :class:`~openstack.resource2.Resource` """ self._check_tag_support(resource) - return resource.set_tags(self._session, tags) + return resource.set_tags(self, tags) def create_vpn_service(self, **attrs): """Create a new vpn service from attributes diff --git a/openstack/network/v2/agent.py b/openstack/network/v2/agent.py index bb58ed415..0259d2b4e 100644 --- a/openstack/network/v2/agent.py +++ b/openstack/network/v2/agent.py @@ -70,25 +70,25 @@ class Agent(resource.Resource): def add_agent_to_network(self, session, network_id): body = {'network_id': network_id} url = utils.urljoin(self.base_path, self.id, 'dhcp-networks') - resp = session.post(url, endpoint_filter=self.service, json=body) + resp = session.post(url, json=body) return resp.json() def remove_agent_from_network(self, session, network_id): body = {'network_id': network_id} url = utils.urljoin(self.base_path, self.id, 'dhcp-networks', network_id) - session.delete(url, endpoint_filter=self.service, json=body) + session.delete(url, json=body) def add_router_to_agent(self, session, router): body = {'router_id': router} url = utils.urljoin(self.base_path, self.id, 'l3-routers') - resp = session.post(url, endpoint_filter=self.service, json=body) + resp = session.post(url, json=body) return resp.json() def remove_router_from_agent(self, session, router): body = {'router_id': router} url = utils.urljoin(self.base_path, self.id, 'l3-routers', router) - session.delete(url, endpoint_filter=self.service, json=body) + session.delete(url, json=body) class NetworkHostingDHCPAgent(Agent): diff --git a/openstack/network/v2/flavor.py b/openstack/network/v2/flavor.py index 46e9579a2..273d132f5 100644 --- a/openstack/network/v2/flavor.py +++ b/openstack/network/v2/flavor.py @@ -48,7 +48,7 @@ class Flavor(resource.Resource): flavor_id = self.id url = utils.urljoin(self.base_path, flavor_id, 'service_profiles') body = {"service_profile": {"id": service_profile_id}} - resp = session.post(url, endpoint_filter=self.service, json=body) + resp = session.post(url, json=body) return resp.json() def disassociate_flavor_from_service_profile( @@ -56,5 +56,5 @@ class Flavor(resource.Resource): flavor_id = self.id url = utils.urljoin( self.base_path, flavor_id, 'service_profiles', service_profile_id) - session.delete(url, endpoint_filter=self.service) + session.delete(url,) return None diff --git a/openstack/network/v2/router.py b/openstack/network/v2/router.py index 7fa58dbaf..2573dc62a 100644 --- a/openstack/network/v2/router.py +++ b/openstack/network/v2/router.py @@ -84,54 +84,54 @@ class Router(resource.Resource, tag.TagMixin): """Add an internal interface to a logical router. :param session: The session to communicate through. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param dict body: The body requested to be updated on the router :returns: The body of the response as a dictionary. """ url = utils.urljoin(self.base_path, self.id, 'add_router_interface') - resp = session.put(url, endpoint_filter=self.service, json=body) + resp = session.put(url, json=body) return resp.json() def remove_interface(self, session, **body): """Remove an internal interface from a logical router. :param session: The session to communicate through. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param dict body: The body requested to be updated on the router :returns: The body of the response as a dictionary. """ url = utils.urljoin(self.base_path, self.id, 'remove_router_interface') - resp = session.put(url, endpoint_filter=self.service, json=body) + resp = session.put(url, json=body) return resp.json() def add_gateway(self, session, **body): """Add an external gateway to a logical router. :param session: The session to communicate through. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param dict body: The body requested to be updated on the router :returns: The body of the response as a dictionary. """ url = utils.urljoin(self.base_path, self.id, 'add_gateway_router') - resp = session.put(url, endpoint_filter=self.service, json=body) + resp = session.put(url, json=body) return resp.json() def remove_gateway(self, session, **body): """Remove an external gateway from a logical router. :param session: The session to communicate through. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param dict body: The body requested to be updated on the router :returns: The body of the response as a dictionary. """ url = utils.urljoin(self.base_path, self.id, 'remove_gateway_router') - resp = session.put(url, endpoint_filter=self.service, json=body) + resp = session.put(url, json=body) return resp.json() diff --git a/openstack/network/v2/tag.py b/openstack/network/v2/tag.py index b216e2ebc..83ed190f3 100644 --- a/openstack/network/v2/tag.py +++ b/openstack/network/v2/tag.py @@ -24,7 +24,7 @@ class TagMixin(object): def set_tags(self, session, tags): url = utils.urljoin(self.base_path, self.id, 'tags') - session.put(url, endpoint_filter=self.service, + session.put(url, json={'tags': tags}) self._body.attributes.update({'tags': tags}) return self diff --git a/openstack/object_store/v1/_base.py b/openstack/object_store/v1/_base.py index 17df93555..cd99503fc 100644 --- a/openstack/object_store/v1/_base.py +++ b/openstack/object_store/v1/_base.py @@ -36,13 +36,13 @@ class BaseResource(resource.Resource): def set_metadata(self, session, metadata): url = self._get_url(self, self.id) - session.post(url, endpoint_filter=self.service, + session.post(url, headers=self._calculate_headers(metadata)) def delete_metadata(self, session, keys): url = self._get_url(self, self.id) headers = {key: '' for key in keys} - session.post(url, endpoint_filter=self.service, + session.post(url, headers=self._calculate_headers(headers)) def _set_metadata(self): @@ -69,7 +69,7 @@ class BaseResource(resource.Resource): """Update a Resource with the given attributes. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param resource_id: This resource's identifier, if needed by the request. The default is ``None``. :param dict attrs: The attributes to be sent in the body @@ -82,5 +82,5 @@ class BaseResource(resource.Resource): url = cls._get_url(None, resource_id) headers = attrs.get(resource.HEADERS, dict()) headers['Accept'] = '' - return session.post(url, endpoint_filter=cls.service, + return session.post(url, headers=headers).headers diff --git a/openstack/object_store/v1/_proxy.py b/openstack/object_store/v1/_proxy.py index 78a48902a..6258eab53 100644 --- a/openstack/object_store/v1/_proxy.py +++ b/openstack/object_store/v1/_proxy.py @@ -35,7 +35,7 @@ class Proxy(proxy.BaseProxy): by the user. """ account = self._get_resource(_account.Account, None) - account.set_metadata(self._session, metadata) + account.set_metadata(self, metadata) def delete_account_metadata(self, keys): """Delete metadata for this account. @@ -43,7 +43,7 @@ class Proxy(proxy.BaseProxy): :param keys: The keys of metadata to be deleted. """ account = self._get_resource(_account.Account, None) - account.delete_metadata(self._session, keys) + account.delete_metadata(self, keys) def containers(self, **query): """Obtain Container objects for this account. @@ -54,7 +54,7 @@ class Proxy(proxy.BaseProxy): :rtype: A generator of :class:`~openstack.object_store.v1.container.Container` objects. """ - return _container.Container.list(self._session, **query) + return _container.Container.list(self, **query) def create_container(self, **attrs): """Create a new container from attributes @@ -121,7 +121,7 @@ class Proxy(proxy.BaseProxy): - `sync_key` """ res = self._get_resource(_container.Container, container) - res.set_metadata(self._session, metadata) + res.set_metadata(self, metadata) def delete_container_metadata(self, container, keys): """Delete metadata for a container. @@ -132,7 +132,7 @@ class Proxy(proxy.BaseProxy): :param keys: The keys of metadata to be deleted. """ res = self._get_resource(_container.Container, container) - res.delete_metadata(self._session, keys) + res.delete_metadata(self, keys) def objects(self, container, **query): """Return a generator that yields the Container's objects. @@ -149,7 +149,7 @@ class Proxy(proxy.BaseProxy): """ container = _container.Container.from_id(container) - objs = _obj.Object.list(self._session, + objs = _obj.Object.list(self, path_args={"container": container.name}, **query) for obj in objs: @@ -300,7 +300,7 @@ class Proxy(proxy.BaseProxy): container_name = self._get_container_name(obj, container) res = self._get_resource(_obj.Object, obj, path_args={"container": container_name}) - res.set_metadata(self._session, metadata) + res.set_metadata(self, metadata) def delete_object_metadata(self, obj, container=None, keys=None): """Delete metadata for an object. @@ -315,4 +315,4 @@ class Proxy(proxy.BaseProxy): container_name = self._get_container_name(obj, container) res = self._get_resource(_obj.Object, obj, path_args={"container": container_name}) - res.delete_metadata(self._session, keys) + res.delete_metadata(self, keys) diff --git a/openstack/object_store/v1/container.py b/openstack/object_store/v1/container.py index 678846d6e..dd440b929 100644 --- a/openstack/object_store/v1/container.py +++ b/openstack/object_store/v1/container.py @@ -97,7 +97,7 @@ class Container(_base.BaseResource): """Create a Resource from its attributes. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param dict attrs: The attributes to be sent in the body of the request. :param resource_id: This resource's identifier, if needed by @@ -108,14 +108,14 @@ class Container(_base.BaseResource): url = cls._get_url(None, resource_id) headers = attrs.get(resource.HEADERS, dict()) headers['Accept'] = '' - return session.put(url, endpoint_filter=cls.service, + return session.put(url, headers=headers).headers def create(self, session): """Create a Resource from this instance. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :return: This instance. """ diff --git a/openstack/object_store/v1/obj.py b/openstack/object_store/v1/obj.py index 1be77ec16..f18ff6275 100644 --- a/openstack/object_store/v1/obj.py +++ b/openstack/object_store/v1/obj.py @@ -206,13 +206,14 @@ class Object(_base.BaseResource): del(metadata[key]) url = self._get_url(self, self.id) - session.post(url, endpoint_filter=self.service, + session.post(url, headers=self._calculate_headers(metadata)) - def get(self, session, include_headers=False, args=None): + def get(self, session, include_headers=False, args=None, + error_message=None): url = self._get_url(self, self.id) headers = {'Accept': 'bytes'} - resp = session.get(url, endpoint_filter=self.service, headers=headers) + resp = session.get(url, headers=headers, error_message=error_message) resp = resp.content self._set_metadata() return resp @@ -223,11 +224,11 @@ class Object(_base.BaseResource): headers = self.get_headers() headers['Accept'] = '' if self.data is not None: - resp = session.put(url, endpoint_filter=self.service, + resp = session.put(url, data=self.data, headers=headers).headers else: - resp = session.post(url, endpoint_filter=self.service, data=None, + resp = session.post(url, data=None, headers=headers).headers self.set_headers(resp) return self diff --git a/openstack/orchestration/v1/_proxy.py b/openstack/orchestration/v1/_proxy.py index fad49ccf5..0ce2f1ec5 100644 --- a/openstack/orchestration/v1/_proxy.py +++ b/openstack/orchestration/v1/_proxy.py @@ -125,7 +125,7 @@ class Proxy(proxy2.BaseProxy): else: stk_obj = _stack.Stack.existing(id=stack) - stk_obj.check(self._session) + stk_obj.check(self) def get_stack_template(self, stack): """Get template used by a stack @@ -184,7 +184,7 @@ class Proxy(proxy2.BaseProxy): stk = self._find(_stack.Stack, stack, ignore_missing=False) obj = _stack_files.StackFiles(stack_name=stk.name, stack_id=stk.id) - return obj.get(self._session) + return obj.get(self) def resources(self, stack, **query): """Return a generator of resources @@ -357,6 +357,6 @@ class Proxy(proxy2.BaseProxy): "'template_url' must be specified when template is None") tmpl = _template.Template.new() - return tmpl.validate(self._session, template, environment=environment, + return tmpl.validate(self, template, environment=environment, template_url=template_url, ignore_errors=ignore_errors) diff --git a/openstack/orchestration/v1/stack.py b/openstack/orchestration/v1/stack.py index 5445d11fc..9172be71e 100644 --- a/openstack/orchestration/v1/stack.py +++ b/openstack/orchestration/v1/stack.py @@ -90,7 +90,7 @@ class Stack(resource.Resource): def _action(self, session, body): """Perform stack actions""" url = utils.urljoin(self.base_path, self._get_id(self), 'actions') - resp = session.post(url, endpoint_filter=self.service, json=body) + resp = session.post(url, json=body) return resp.json() def check(self, session): diff --git a/openstack/orchestration/v1/stack_files.py b/openstack/orchestration/v1/stack_files.py index db23a4771..cb16dcd6e 100644 --- a/openstack/orchestration/v1/stack_files.py +++ b/openstack/orchestration/v1/stack_files.py @@ -36,5 +36,5 @@ class StackFiles(resource.Resource): # The stack files response contains a map of filenames and file # contents. request = self._prepare_request(requires_id=False) - resp = session.get(request.uri, endpoint_filter=self.service) + resp = session.get(request.url) return resp.json() diff --git a/openstack/orchestration/v1/template.py b/openstack/orchestration/v1/template.py index 5c8227261..7e2c5eab2 100644 --- a/openstack/orchestration/v1/template.py +++ b/openstack/orchestration/v1/template.py @@ -47,6 +47,6 @@ class Template(resource.Resource): qry = parse.urlencode({'ignore_errors': ignore_errors}) url = '?'.join([url, qry]) - resp = session.post(url, endpoint_filter=self.service, json=body) + resp = session.post(url, json=body) self._translate_response(resp) return self diff --git a/openstack/profile.py b/openstack/profile.py index 69994fafc..d70c05afa 100644 --- a/openstack/profile.py +++ b/openstack/profile.py @@ -54,9 +54,9 @@ The resulting preference print out would look something like:: import copy import logging -from openstack.bare_metal import bare_metal_service -from openstack.block_store import block_store_service -from openstack.cluster import cluster_service +from openstack.baremetal import baremetal_service +from openstack.block_storage import block_storage_service +from openstack.clustering import clustering_service from openstack.compute import compute_service from openstack.database import database_service from openstack import exceptions @@ -65,12 +65,11 @@ from openstack.image import image_service from openstack.key_manager import key_manager_service from openstack.load_balancer import load_balancer_service as lb_service from openstack.message import message_service -from openstack import module_loader +from openstack.meter.alarm import alarm_service +from openstack.meter import meter_service from openstack.network import network_service from openstack.object_store import object_store_service from openstack.orchestration import orchestration_service -from openstack.telemetry.alarm import alarm_service -from openstack.telemetry import telemetry_service from openstack.workflow import workflow_service _logger = logging.getLogger(__name__) @@ -94,9 +93,10 @@ class Profile(object): self._services = {} self._add_service(alarm_service.AlarmService(version="v2")) - self._add_service(bare_metal_service.BareMetalService(version="v1")) - self._add_service(block_store_service.BlockStoreService(version="v2")) - self._add_service(cluster_service.ClusterService(version="v1")) + self._add_service(baremetal_service.BaremetalService(version="v1")) + self._add_service( + block_storage_service.BlockStorageService(version="v2")) + self._add_service(clustering_service.ClusteringService(version="v1")) self._add_service(compute_service.ComputeService(version="v2")) self._add_service(database_service.DatabaseService(version="v1")) self._add_service(identity_service.IdentityService(version="v3")) @@ -104,17 +104,14 @@ class Profile(object): self._add_service(key_manager_service.KeyManagerService(version="v1")) self._add_service(lb_service.LoadBalancerService(version="v2")) self._add_service(message_service.MessageService(version="v1")) + self._add_service(meter_service.MeterService(version="v2")) self._add_service(network_service.NetworkService(version="v2")) self._add_service( object_store_service.ObjectStoreService(version="v1")) self._add_service( orchestration_service.OrchestrationService(version="v1")) - self._add_service(telemetry_service.TelemetryService(version="v2")) self._add_service(workflow_service.WorkflowService(version="v2")) - if plugins: - for plugin in plugins: - self._load_plugin(plugin) self.service_keys = sorted(self._services.keys()) def __repr__(self): @@ -124,18 +121,6 @@ class Profile(object): serv.interface = None self._services[serv.service_type] = serv - def _load_plugin(self, namespace): - """Load a service plugin. - - :param str namespace: Entry point namespace - """ - services = module_loader.load_service_plugins(namespace) - for service_type in services: - if service_type in self._services: - _logger.debug("Overriding %s with %s", service_type, - services[service_type]) - self._add_service(services[service_type]) - def get_filter(self, service): """Get a service preference. diff --git a/openstack/proxy.py b/openstack/proxy.py index cbe8616ee..24123f377 100644 --- a/openstack/proxy.py +++ b/openstack/proxy.py @@ -9,7 +9,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - +from openstack.cloud import _adapter from openstack import exceptions from openstack import resource @@ -38,10 +38,7 @@ def _check_resource(strict=False): return wrap -class BaseProxy(object): - - def __init__(self, session): - self._session = session +class BaseProxy(_adapter.OpenStackSDKAdapter): def _get_resource(self, resource_type, value, path_args=None): """Get a resource object to work on @@ -87,7 +84,7 @@ class BaseProxy(object): :returns: An instance of ``resource_type`` or None """ - return resource_type.find(self._session, name_or_id, + return resource_type.find(self, name_or_id, path_args=path_args, ignore_missing=ignore_missing) @@ -122,18 +119,15 @@ class BaseProxy(object): res = self._get_resource(resource_type, value, path_args) try: - rv = res.delete(self._session) - except exceptions.NotFoundException as e: + rv = res.delete( + self, + error_message="No {resource_type} found for {value}".format( + resource_type=resource_type.__name__, value=value)) + except exceptions.NotFoundException: if ignore_missing: return None else: - # Reraise with a more specific type and message - raise exceptions.ResourceNotFound( - message="No %s found for %s" % - (resource_type.__name__, value), - details=e.details, response=e.response, - request_id=e.request_id, url=e.url, method=e.method, - http_status=e.http_status, cause=e.cause) + raise return rv @@ -157,7 +151,7 @@ class BaseProxy(object): """ res = self._get_resource(resource_type, value, path_args) res.update_attrs(attrs) - return res.update(self._session) + return res.update(self) def _create(self, resource_type, path_args=None, **attrs): """Create a resource from attributes @@ -176,7 +170,7 @@ class BaseProxy(object): res = resource_type.new(**attrs) if path_args is not None: res.update_attrs(path_args) - return res.create(self._session) + return res.create(self) @_check_resource(strict=False) def _get(self, resource_type, value=None, path_args=None, args=None): @@ -197,15 +191,10 @@ class BaseProxy(object): """ res = self._get_resource(resource_type, value, path_args) - try: - return res.get(self._session, args=args) - except exceptions.NotFoundException as e: - raise exceptions.ResourceNotFound( - message="No %s found for %s" % - (resource_type.__name__, value), - details=e.details, response=e.response, - request_id=e.request_id, url=e.url, method=e.method, - http_status=e.http_status, cause=e.cause) + return res.get( + self, args=args, + error_message='No {resource} found for {value}'.format( + resource=resource_type.__name__, value=value)) def _list(self, resource_type, value=None, paginated=False, path_args=None, **query): @@ -235,7 +224,7 @@ class BaseProxy(object): res = self._get_resource(resource_type, value, path_args) query = res.convert_ids(query) - return res.list(self._session, path_args=path_args, + return res.list(self, path_args=path_args, paginated=paginated, params=query) def _head(self, resource_type, value=None, path_args=None): @@ -255,7 +244,7 @@ class BaseProxy(object): """ res = self._get_resource(resource_type, value, path_args) - return res.head(self._session) + return res.head(self) def wait_for_status(self, value, status, failures=[], interval=2, wait=120): @@ -278,7 +267,7 @@ class BaseProxy(object): :raises: :class:`~AttributeError` if the resource does not have a status attribute """ - return resource.wait_for_status(self._session, value, status, + return resource.wait_for_status(self, value, status, failures, interval, wait) def wait_for_delete(self, value, interval=2, wait=120): @@ -293,4 +282,4 @@ class BaseProxy(object): :raises: :class:`~openstack.exceptions.ResourceTimeout` transition to delete failed to occur in wait seconds. """ - return resource.wait_for_delete(self._session, value, interval, wait) + return resource.wait_for_delete(self, value, interval, wait) diff --git a/openstack/proxy2.py b/openstack/proxy2.py index 0a7fcb373..739c8510d 100644 --- a/openstack/proxy2.py +++ b/openstack/proxy2.py @@ -10,6 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. +from openstack.cloud import _adapter from openstack import exceptions from openstack import resource2 from openstack import utils @@ -39,10 +40,7 @@ def _check_resource(strict=False): return wrap -class BaseProxy(object): - - def __init__(self, session): - self._session = session +class BaseProxy(_adapter.OpenStackSDKAdapter): def _get_resource(self, resource_type, value, **attrs): """Get a resource object to work on @@ -101,7 +99,7 @@ class BaseProxy(object): :returns: An instance of ``resource_type`` or None """ - return resource_type.find(self._session, name_or_id, + return resource_type.find(self, name_or_id, ignore_missing=ignore_missing, **attrs) @@ -136,18 +134,14 @@ class BaseProxy(object): res = self._get_resource(resource_type, value, **attrs) try: - rv = res.delete(self._session) - except exceptions.NotFoundException as e: + rv = res.delete( + self, + error_message="No {resource_type} found for {value}".format( + resource_type=resource_type.__name__, value=value)) + except exceptions.NotFoundException: if ignore_missing: return None - else: - # Reraise with a more specific type and message - raise exceptions.ResourceNotFound( - message="No %s found for %s" % - (resource_type.__name__, value), - details=e.details, response=e.response, - request_id=e.request_id, url=e.url, method=e.method, - http_status=e.http_status, cause=e.cause) + raise return rv @@ -171,7 +165,7 @@ class BaseProxy(object): :rtype: :class:`~openstack.resource2.Resource` """ res = self._get_resource(resource_type, value, **attrs) - return res.update(self._session) + return res.update(self) def _create(self, resource_type, **attrs): """Create a resource from attributes @@ -191,7 +185,7 @@ class BaseProxy(object): :rtype: :class:`~openstack.resource2.Resource` """ res = resource_type.new(**attrs) - return res.create(self._session) + return res.create(self) @_check_resource(strict=False) def _get(self, resource_type, value=None, requires_id=True, **attrs): @@ -214,15 +208,10 @@ class BaseProxy(object): """ res = self._get_resource(resource_type, value, **attrs) - try: - return res.get(self._session, requires_id=requires_id) - except exceptions.NotFoundException as e: - raise exceptions.ResourceNotFound( - message="No %s found for %s" % - (resource_type.__name__, value), - details=e.details, response=e.response, - request_id=e.request_id, url=e.url, method=e.method, - http_status=e.http_status, cause=e.cause) + return res.get( + self, requires_id=requires_id, + error_message="No {resource_type} found for {value}".format( + resource_type=resource_type.__name__, value=value)) def _list(self, resource_type, value=None, paginated=False, **attrs): """List a resource @@ -248,7 +237,7 @@ class BaseProxy(object): the ``resource_type``. """ res = self._get_resource(resource_type, value, **attrs) - return res.list(self._session, paginated=paginated, **attrs) + return res.list(self, paginated=paginated, **attrs) def _head(self, resource_type, value=None, **attrs): """Retrieve a resource's header @@ -268,7 +257,7 @@ class BaseProxy(object): :rtype: :class:`~openstack.resource2.Resource` """ res = self._get_resource(resource_type, value, **attrs) - return res.head(self._session) + return res.head(self) @utils.deprecated(deprecated_in="0.9.14", removed_in="1.0", details=("This is no longer a part of the proxy base, " @@ -296,7 +285,7 @@ class BaseProxy(object): :raises: :class:`~AttributeError` if the resource does not have a status attribute """ - return resource2.wait_for_status(self._session, value, status, + return resource2.wait_for_status(self, value, status, failures, interval, wait) @utils.deprecated(deprecated_in="0.9.14", removed_in="1.0", @@ -316,4 +305,4 @@ class BaseProxy(object): :raises: :class:`~openstack.exceptions.ResourceTimeout` transition to delete failed to occur in wait seconds. """ - return resource2.wait_for_delete(self._session, value, interval, wait) + return resource2.wait_for_delete(self, value, interval, wait) diff --git a/openstack/resource.py b/openstack/resource.py index 2bc559e71..c9c0671f7 100644 --- a/openstack/resource.py +++ b/openstack/resource.py @@ -427,7 +427,8 @@ class Resource(collections.MutableMapping): def _reset_dirty(self): self._dirty = set() - def _update_attrs_from_response(self, resp, include_headers=False): + def _update_attrs_from_response(self, resp, include_headers=False, + error_message=None): resp_headers = resp.pop(HEADERS, None) self._attrs.update(resp) self.update_attrs(self._attrs) @@ -529,7 +530,7 @@ class Resource(collections.MutableMapping): """Create a remote resource from its attributes. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param dict attrs: The attributes to be sent in the body of the request. :param resource_id: This resource's identifier, if needed by @@ -556,9 +557,9 @@ class Resource(collections.MutableMapping): if headers: args[HEADERS] = headers if resource_id: - resp = session.put(url, endpoint_filter=cls.service, **args) + resp = session.put(url, **args) else: - resp = session.post(url, endpoint_filter=cls.service, **args) + resp = session.post(url, **args) resp_headers = resp.headers resp = resp.json() @@ -573,7 +574,7 @@ class Resource(collections.MutableMapping): """Create a remote resource from this instance. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :return: This :class:`Resource` instance. :raises: :exc:`~openstack.exceptions.MethodNotSupported` if @@ -590,7 +591,7 @@ class Resource(collections.MutableMapping): """Get the attributes of a remote resource from an id. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param resource_id: This resource's identifier, if needed by the request. :param dict path_args: A dictionary of arguments to construct @@ -612,7 +613,8 @@ class Resource(collections.MutableMapping): url = cls._get_url(path_args, resource_id) if args: url = '?'.join([url, url_parse.urlencode(args)]) - response = session.get(url, endpoint_filter=cls.service) + response = session.get(url,) + exceptions.raise_from_response(response) body = response.json() if cls.resource_key: @@ -629,7 +631,7 @@ class Resource(collections.MutableMapping): """Get an object representing a remote resource from an id. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param resource_id: This resource's identifier, if needed by the request. :param dict path_args: A dictionary of arguments to construct @@ -648,11 +650,12 @@ class Resource(collections.MutableMapping): include_headers=include_headers) return cls.existing(**body) - def get(self, session, include_headers=False, args=None): + def get(self, session, include_headers=False, + args=None, error_message=None): """Get the remote resource associated with this instance. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param bool include_headers: ``True`` if header data should be included in the response body, ``False`` if not. @@ -673,7 +676,7 @@ class Resource(collections.MutableMapping): """Get a dictionary representing the headers of a remote resource. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param resource_id: This resource's identifier, if needed by the request. :param dict path_args: A dictionary of arguments to construct @@ -690,7 +693,7 @@ class Resource(collections.MutableMapping): url = cls._get_url(path_args, resource_id) headers = {'Accept': ''} - resp = session.head(url, endpoint_filter=cls.service, headers=headers) + resp = session.head(url, headers=headers) return {HEADERS: resp.headers} @@ -699,7 +702,7 @@ class Resource(collections.MutableMapping): """Get an object representing the headers of a remote resource. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param resource_id: This resource's identifier, if needed by the request. :param dict path_args: A dictionary of arguments to construct @@ -717,7 +720,7 @@ class Resource(collections.MutableMapping): """Get the remote resource headers associated with this instance. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :return: This :class:`Resource` instance. :raises: :exc:`~openstack.exceptions.MethodNotSupported` if @@ -733,7 +736,7 @@ class Resource(collections.MutableMapping): """Update a remote resource with the given attributes. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param resource_id: This resource's identifier, if needed by the request. :param dict attrs: The attributes to be sent in the body @@ -762,9 +765,9 @@ class Resource(collections.MutableMapping): if headers: args[HEADERS] = headers if cls.patch_update: - resp = session.patch(url, endpoint_filter=cls.service, **args) + resp = session.patch(url, **args) else: - resp = session.put(url, endpoint_filter=cls.service, **args) + resp = session.put(url, **args) resp_headers = resp.headers resp = resp.json() @@ -779,7 +782,7 @@ class Resource(collections.MutableMapping): """Update the remote resource associated with this instance. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :return: This :class:`Resource` instance. :raises: :exc:`~openstack.exceptions.MethodNotSupported` if @@ -802,11 +805,12 @@ class Resource(collections.MutableMapping): return self @classmethod - def delete_by_id(cls, session, resource_id, path_args=None): + def delete_by_id(cls, session, resource_id, path_args=None, + error_message=None): """Delete a remote resource with the given id. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param resource_id: This resource's identifier, if needed by the request. :param dict path_args: A dictionary of arguments to construct @@ -822,19 +826,21 @@ class Resource(collections.MutableMapping): url = cls._get_url(path_args, resource_id) headers = {'Accept': ''} - session.delete(url, endpoint_filter=cls.service, headers=headers) + response = session.delete(url, headers=headers) + exceptions.raise_from_response(response, error_message=error_message) - def delete(self, session): + def delete(self, session, error_message=None): """Delete the remote resource associated with this instance. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :return: ``None`` :raises: :exc:`~openstack.exceptions.MethodNotSupported` if :data:`Resource.allow_update` is not set to ``True``. """ - self.delete_by_id(session, self.id, path_args=self) + self.delete_by_id(session, self.id, path_args=self, + error_message=error_message) @classmethod def list(cls, session, path_args=None, paginated=False, params=None): @@ -844,7 +850,7 @@ class Resource(collections.MutableMapping): params for response filtering. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param dict path_args: A dictionary of arguments to construct a compound URL. See `How path_args are used`_ for details. @@ -855,7 +861,7 @@ class Resource(collections.MutableMapping): page of data will be returned regardless of the API's support of pagination.** :param dict params: Query parameters to be passed into the underlying - :meth:`~openstack.session.Session.get` method. + :meth:`~keystoneauth1.adapter.Adapter.get` method. Values that the server may support include `limit` and `marker`. @@ -871,7 +877,7 @@ class Resource(collections.MutableMapping): url = cls._get_url(path_args) headers = {'Accept': 'application/json'} while more_data: - resp = session.get(url, endpoint_filter=cls.service, + resp = session.get(url, headers=headers, params=params) resp = resp.json() if cls.resources_key: @@ -903,7 +909,7 @@ class Resource(collections.MutableMapping): """Find a resource by its name or id. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param name_or_id: This resource's identifier, if needed by the request. The default is ``None``. :param dict path_args: A dictionary of arguments to construct @@ -969,7 +975,7 @@ def wait_for_status(session, resource, status, failures, interval, wait): """Wait for the resource to be in a particular status. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param resource: The resource to wait on to reach the status. The resource must have a status attribute. :type resource: :class:`~openstack.resource.Resource` @@ -1012,7 +1018,7 @@ def wait_for_delete(session, resource, interval, wait): """Wait for the resource to be deleted. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param resource: The resource to wait on to be deleted. :type resource: :class:`~openstack.resource.Resource` :param interval: Number of seconds to wait between checks. diff --git a/openstack/resource2.py b/openstack/resource2.py index 7d8b0403c..0f411f25b 100644 --- a/openstack/resource2.py +++ b/openstack/resource2.py @@ -172,8 +172,8 @@ class _ComponentManager(collections.MutableMapping): class _Request(object): """Prepared components that go into a KSA request""" - def __init__(self, uri, body, headers): - self.uri = uri + def __init__(self, url, body, headers): + self.url = url self.body = body self.headers = headers @@ -537,7 +537,7 @@ class Resource(object): """ return {k: v for k, v in component.items() if k in mapping.values()} - def _translate_response(self, response, has_body=True): + def _translate_response(self, response, has_body=True, error_message=None): """Given a KSA response, inflate this instance with its data DELETE operations don't return a body, so only try to work @@ -546,6 +546,7 @@ class Resource(object): This method updates attributes that correspond to headers and body on this instance and clears the dirty set. """ + exceptions.raise_from_response(response, error_message=error_message) if has_body: body = response.json() if self.resource_key and self.resource_key in body: @@ -564,7 +565,7 @@ class Resource(object): """Create a remote resource based on this instance. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param prepend_key: A boolean indicating whether the resource_key should be prepended in a resource creation request. Default to True. @@ -579,22 +580,22 @@ class Resource(object): if self.put_create: request = self._prepare_request(requires_id=True, prepend_key=prepend_key) - response = session.put(request.uri, endpoint_filter=self.service, + response = session.put(request.url, json=request.body, headers=request.headers) else: request = self._prepare_request(requires_id=False, prepend_key=prepend_key) - response = session.post(request.uri, endpoint_filter=self.service, + response = session.post(request.url, json=request.body, headers=request.headers) self._translate_response(response) return self - def get(self, session, requires_id=True): + def get(self, session, requires_id=True, error_message=None): """Get a remote resource based on this instance. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param boolean requires_id: A boolean indicating whether resource ID should be part of the requested URI. :return: This :class:`Resource` instance. @@ -605,16 +606,19 @@ class Resource(object): raise exceptions.MethodNotSupported(self, "get") request = self._prepare_request(requires_id=requires_id) - response = session.get(request.uri, endpoint_filter=self.service) + response = session.get(request.url) + kwargs = {} + if error_message: + kwargs['error_message'] = error_message - self._translate_response(response) + self._translate_response(response, **kwargs) return self def head(self, session): """Get headers from a remote resource based on this instance. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :return: This :class:`Resource` instance. :raises: :exc:`~openstack.exceptions.MethodNotSupported` if @@ -625,7 +629,7 @@ class Resource(object): request = self._prepare_request() - response = session.head(request.uri, endpoint_filter=self.service, + response = session.head(request.url, headers={"Accept": ""}) self._translate_response(response) @@ -635,7 +639,7 @@ class Resource(object): """Update the remote resource based on this instance. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param prepend_key: A boolean indicating whether the resource_key should be prepended in a resource update request. Default to True. @@ -657,21 +661,21 @@ class Resource(object): request = self._prepare_request(prepend_key=prepend_key) if self.patch_update: - response = session.patch(request.uri, endpoint_filter=self.service, + response = session.patch(request.url, json=request.body, headers=request.headers) else: - response = session.put(request.uri, endpoint_filter=self.service, + response = session.put(request.url, json=request.body, headers=request.headers) self._translate_response(response, has_body=has_body) return self - def delete(self, session): + def delete(self, session, error_message=None): """Delete the remote resource based on this instance. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :return: This :class:`Resource` instance. :raises: :exc:`~openstack.exceptions.MethodNotSupported` if @@ -682,10 +686,13 @@ class Resource(object): request = self._prepare_request() - response = session.delete(request.uri, endpoint_filter=self.service, + response = session.delete(request.url, headers={"Accept": ""}) + kwargs = {} + if error_message: + kwargs['error_message'] = error_message - self._translate_response(response, has_body=False) + self._translate_response(response, has_body=False, **kwargs) return self @classmethod @@ -696,7 +703,7 @@ class Resource(object): params for response filtering. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param bool paginated: ``True`` if a GET to this resource returns a paginated series of responses, or ``False`` if a GET returns only one page of data. @@ -707,7 +714,7 @@ class Resource(object): :meth:`~openstack.resource2.QueryParamter._transpose` method to find if any of them match expected query parameters to be sent in the *params* argument to - :meth:`~openstack.session.Session.get`. They are additionally + :meth:`~keystoneauth1.adapter.Adapter.get`. They are additionally checked against the :data:`~openstack.resource2.Resource.base_path` format string to see if any path fragments need to be filled in by the contents @@ -725,7 +732,7 @@ class Resource(object): uri = cls.base_path % params while more_data: - resp = session.get(uri, endpoint_filter=cls.service, + resp = session.get(uri, headers={"Accept": "application/json"}, params=query_params) resp = resp.json() @@ -785,7 +792,7 @@ class Resource(object): """Find a resource by its name or id. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param name_or_id: This resource's identifier, if needed by the request. The default is ``None``. :param bool ignore_missing: When set to ``False`` @@ -828,7 +835,7 @@ def wait_for_status(session, resource, status, failures, interval, wait): """Wait for the resource to be in a particular status. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param resource: The resource to wait on to reach the status. The resource must have a status attribute. :type resource: :class:`~openstack.resource.Resource` @@ -871,7 +878,7 @@ def wait_for_delete(session, resource, interval, wait): """Wait for the resource to be deleted. :param session: The session to use for making this request. - :type session: :class:`~openstack.session.Session` + :type session: :class:`~keystoneauth1.adapter.Adapter` :param resource: The resource to wait on to be deleted. :type resource: :class:`~openstack.resource.Resource` :param interval: Number of seconds to wait between checks. diff --git a/openstack/service_filter.py b/openstack/service_filter.py index 95bc2aa12..a0f60e3b6 100644 --- a/openstack/service_filter.py +++ b/openstack/service_filter.py @@ -16,8 +16,6 @@ for service identifiers and user service preferences. Each :class:`~openstack.resource.Resource` has a service identifier to associate the resource with a service. An example of a service identifier would be ``openstack.compute.compute_service.ComputeService``. -The preferences are stored in the -:class:`~openstack.profile.Profile` object. The service preference and the service identifier are joined to create a filter to match a service. diff --git a/openstack/session.py b/openstack/session.py deleted file mode 100644 index d989d1172..000000000 --- a/openstack/session.py +++ /dev/null @@ -1,352 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -The :class:`~openstack.session.Session` overrides -:class:`~keystoneauth1.session.Session` to provide end point filtering and -mapping KSA exceptions to SDK exceptions. - -""" -from collections import namedtuple -import logging - -try: - from itertools import accumulate -except ImportError: - # itertools.accumulate was added to Python 3.2, and since we have to - # support Python 2 for some reason, we include this equivalent from - # the 3.x docs. While it's stated that it's a rough equivalent, it's - # good enough for the purposes we're using it for. - # https://docs.python.org/dev/library/itertools.html#itertools.accumulate - def accumulate(iterable, func=None): - """Return running totals""" - # accumulate([1,2,3,4,5]) --> 1 3 6 10 15 - # accumulate([1,2,3,4,5], operator.mul) --> 1 2 6 24 120 - it = iter(iterable) - try: - total = next(it) - except StopIteration: - return - yield total - for element in it: - total = func(total, element) - yield total - -from keystoneauth1 import exceptions as _exceptions -from keystoneauth1 import session as _session - -from openstack import exceptions -from openstack import utils -from openstack import version as openstack_version - -from six.moves.urllib import parse - -DEFAULT_USER_AGENT = "openstacksdk/%s" % openstack_version.__version__ -API_REQUEST_HEADER = "openstack-api-version" - -Version = namedtuple("Version", ["major", "minor"]) - -_logger = logging.getLogger(__name__) - - -def map_exceptions(func): - def map_exceptions_wrapper(*args, **kwargs): - try: - return func(*args, **kwargs) - except _exceptions.HttpError as e: - raise exceptions.from_exception(e) - except _exceptions.ClientException as e: - raise exceptions.SDKException(message=e.message, cause=e) - - return map_exceptions_wrapper - - -class Session(_session.Session): - - def __init__(self, profile, user_agent=None, **kwargs): - """Create a new Keystone auth session with a profile. - - :param profile: If the user has any special profiles such as the - service name, region, version or interface, they may be provided - in the profile object. If no profiles are provided, the - services that appear first in the service catalog will be used. - :param user_agent: A User-Agent header string to use for the - request. If not provided, a default of - :attr:`~openstack.session.DEFAULT_USER_AGENT` - is used, which contains the openstacksdk version - When a non-None value is passed, it will be - prepended to the default. - :type profile: :class:`~openstack.profile.Profile` - """ - if user_agent is not None: - self.user_agent = "%s %s" % (user_agent, DEFAULT_USER_AGENT) - else: - self.user_agent = DEFAULT_USER_AGENT - - self.profile = profile - api_version_header = self._get_api_requests() - self.endpoint_cache = {} - - super(Session, self).__init__(user_agent=self.user_agent, - additional_headers=api_version_header, - **kwargs) - - def _get_api_requests(self): - """Get API micro-version requests. - - :param profile: A profile object that contains customizations about - service name, region, version, interface or - api_version. - :return: A standard header string if there is any specialization in - API microversion, or None if no such request exists. - """ - if self.profile is None: - return None - - req = [] - for svc in self.profile.get_services(): - if svc.service_type and svc.api_version: - req.append(" ".join([svc.service_type, svc.api_version])) - if req: - return {API_REQUEST_HEADER: ",".join(req)} - - return None - - class _Endpoint(object): - - def __init__(self, uri, versions, - needs_project_id=False, project_id=None): - self.uri = uri - self.versions = versions - self.needs_project_id = needs_project_id - self.project_id = project_id - - def __eq__(self, other): - return all([self.uri == other.uri, - self.versions == other.versions, - self.needs_project_id == other.needs_project_id, - self.project_id == other.project_id]) - - def _parse_versions_response(self, uri): - """Look for a "versions" JSON response at `uri` - - Return versions if we get them, otherwise return None. - """ - _logger.debug("Looking for versions at %s", uri) - - try: - response = self.get(uri) - except exceptions.HttpException: - return None - - try: - response_body = response.json() - except Exception: - # This could raise a number of things, all of which are bad. - # ValueError, JSONDecodeError, etc. Rather than pick and choose - # a bunch of things that might happen, catch 'em all. - return None - - if "versions" in response_body: - versions = response_body["versions"] - # Normalize the version response. Identity nests the versions - # a level deeper than others, inside of a "values" dictionary. - if "values" in versions: - versions = versions["values"] - return self._Endpoint(uri, versions) - - return None - - def _get_endpoint_versions(self, service_type, endpoint): - """Get available endpoints from the remote service - - Take the endpoint that the Service Catalog gives us as a base - and then work from there. In most cases, the path-less 'root' - of the URI is the base of the service which contains the versions. - In other cases, we need to discover it by trying the paths that - eminate from that root. Generally this is achieved in one roundtrip - request/response, but depending on how the service is installed, - it may require multiple requests. - """ - parts = parse.urlparse(endpoint) - - just_root = "://".join([parts.scheme, parts.netloc]) - - # If we need to try using a portion of the parts, - # the project id won't be one worth asking for so remove it. - # However, we do need to know that the project id was - # previously there, so keep it. - project_id = self.get_project_id() - # Domain scope token don't include project id - project_id_location = parts.path.find(project_id) if project_id else -1 - if project_id_location > -1: - usable_path = parts.path[slice(0, project_id_location)] - needs_project_id = True - else: - usable_path = parts.path - needs_project_id = False - - # Generate a series of paths that might contain our version - # information. This will build successively longer paths from - # the split, so /nova/v2 would return "", "/nova", - # "/nova/v2" out of it. Based on what we've normally seen, - # the match will be found early on within those. - paths = accumulate(usable_path.split("/"), - func=lambda *fragments: "/".join(fragments)) - - result = None - - # If we have paths, try them from the root outwards. - # NOTE: Both the body of the for loop and the else clause - # cover the request for `just_root`. The else clause is explicit - # in only testing it because there are no path parts. In the for - # loop, it gets requested in the first iteration. - for path in paths: - response = self._parse_versions_response(just_root + path) - if response is not None: - result = response - break - else: - # If we didn't have paths, root is all we can do anyway. - response = self._parse_versions_response(just_root) - if response is not None: - result = response - - if result is not None: - if needs_project_id: - result.needs_project_id = True - result.project_id = project_id - - return result - - raise exceptions.EndpointNotFound( - "Unable to parse endpoints for %s" % service_type) - - def _parse_version(self, version): - """Parse the version and return major and minor components - - If the version was given with a leading "v", e.g., "v3", strip - that off to just numerals. - """ - version_num = version[version.find("v") + 1:] - components = version_num.split(".") - if len(components) == 1: - # The minor version of a v2 ends up being -1 so that we can - # loop through versions taking the highest available match - # while also working around a direct match for 2.0. - rv = Version(int(components[0]), -1) - elif len(components) == 2: - rv = Version(*[int(component) for component in components]) - else: - raise ValueError("Unable to parse version string %s" % version) - - return rv - - def _get_version_match(self, endpoint, profile_version, service_type): - """Return the best matching version - - Look through each version trying to find the best match for - the version specified in this profile. - * The best match will only ever be found within the same - major version, meaning a v2 profile will never match if - only v3 is available on the server. - * The search for the best match is fuzzy if needed. - * If the profile specifies v2 and the server has - v2.0, v2.1, and v2.2, the match will be v2.2. - * When an exact major/minor is specified, e.g., v2.0, - it will only match v2.0. - """ - - match_version = None - - for version in endpoint.versions: - api_version = self._parse_version(version["id"]) - if profile_version.major != api_version.major: - continue - - if profile_version.minor <= api_version.minor: - for link in version["links"]: - if link["rel"] == "self": - resp_link = link['href'] - match_version = parse.urlsplit(resp_link).path - - # Only break out of the loop on an exact match, - # otherwise keep trying. - if profile_version.minor == api_version.minor: - break - - if match_version is None: - raise exceptions.EndpointNotFound( - "Unable to determine endpoint for %s" % service_type) - - # Make sure the root endpoint has no overlap with match_version - root_parts = parse.urlsplit(endpoint.uri) - match_version = match_version.replace(root_parts.path, "", 1) - match = utils.urljoin(endpoint.uri, match_version) - - # For services that require the project id in the request URI, - # add them in here. - if endpoint.needs_project_id: - match = utils.urljoin(match, endpoint.project_id) - - return match - - def get_endpoint(self, auth=None, interface=None, service_type=None, - **kwargs): - """Override get endpoint to automate endpoint filtering - - This method uses the service catalog to find the root URI of - each service and then gets all available versions directly - from the service, not from the service catalog. - - Endpoints are cached per service type and interface combination - so that they're only requested from the remote service once - per instance of this class. - """ - key = (service_type, interface) - if key in self.endpoint_cache: - return self.endpoint_cache[key] - - filt = self.profile.get_filter(service_type) - if filt.interface is None: - filt.interface = interface - sc_endpoint = super(Session, self).get_endpoint(auth, - **filt.get_filter()) - - # Object Storage is, of course, different. Just use what we get - # back from the service catalog as not only does it not offer - # a list of supported versions, it appends an "AUTH_" prefix to - # the project id so we'd have to special case that as well. - if service_type == "object-store": - self.endpoint_cache[key] = sc_endpoint - return sc_endpoint - - # We just want what is returned from catalog - if service_type == "load-balancer": - self.endpoint_cache[key] = sc_endpoint - return sc_endpoint - - endpoint = self._get_endpoint_versions(service_type, sc_endpoint) - - profile_version = self._parse_version(filt.version) - match = self._get_version_match(endpoint, profile_version, - service_type) - - _logger.debug("Using %s as %s %s endpoint", - match, interface, service_type) - - self.endpoint_cache[key] = match - return match - - @map_exceptions - def request(self, *args, **kwargs): - return super(Session, self).request(*args, **kwargs) diff --git a/openstack/tests/functional/block_store/__init__.py b/openstack/tests/functional/block_storage/__init__.py similarity index 100% rename from openstack/tests/functional/block_store/__init__.py rename to openstack/tests/functional/block_storage/__init__.py diff --git a/openstack/tests/functional/block_store/v2/__init__.py b/openstack/tests/functional/block_storage/v2/__init__.py similarity index 100% rename from openstack/tests/functional/block_store/v2/__init__.py rename to openstack/tests/functional/block_storage/v2/__init__.py diff --git a/openstack/tests/functional/block_store/v2/test_snapshot.py b/openstack/tests/functional/block_storage/v2/test_snapshot.py similarity index 75% rename from openstack/tests/functional/block_store/v2/test_snapshot.py rename to openstack/tests/functional/block_storage/v2/test_snapshot.py index f6b254fa5..af898488d 100644 --- a/openstack/tests/functional/block_store/v2/test_snapshot.py +++ b/openstack/tests/functional/block_storage/v2/test_snapshot.py @@ -11,8 +11,8 @@ # under the License. -from openstack.block_store.v2 import snapshot as _snapshot -from openstack.block_store.v2 import volume as _volume +from openstack.block_storage.v2 import snapshot as _snapshot +from openstack.block_storage.v2 import volume as _volume from openstack.tests.functional import base @@ -26,10 +26,10 @@ class TestSnapshot(base.BaseFunctionalTest): self.VOLUME_NAME = self.getUniqueString() self.VOLUME_ID = None - volume = self.conn.block_store.create_volume( + volume = self.conn.block_storage.create_volume( name=self.VOLUME_NAME, size=1) - self.conn.block_store.wait_for_status( + self.conn.block_storage.wait_for_status( volume, status='available', failures=['error'], @@ -38,10 +38,10 @@ class TestSnapshot(base.BaseFunctionalTest): assert isinstance(volume, _volume.Volume) self.assertEqual(self.VOLUME_NAME, volume.name) self.VOLUME_ID = volume.id - snapshot = self.conn.block_store.create_snapshot( + snapshot = self.conn.block_storage.create_snapshot( name=self.SNAPSHOT_NAME, volume_id=self.VOLUME_ID) - self.conn.block_store.wait_for_status( + self.conn.block_storage.wait_for_status( snapshot, status='available', failures=['error'], @@ -52,17 +52,17 @@ class TestSnapshot(base.BaseFunctionalTest): self.SNAPSHOT_ID = snapshot.id def tearDown(self): - snapshot = self.conn.block_store.get_snapshot(self.SNAPSHOT_ID) - sot = self.conn.block_store.delete_snapshot( + snapshot = self.conn.block_storage.get_snapshot(self.SNAPSHOT_ID) + sot = self.conn.block_storage.delete_snapshot( snapshot, ignore_missing=False) - self.conn.block_store.wait_for_delete( + self.conn.block_storage.wait_for_delete( snapshot, interval=2, wait=120) self.assertIsNone(sot) - sot = self.conn.block_store.delete_volume( + sot = self.conn.block_storage.delete_volume( self.VOLUME_ID, ignore_missing=False) self.assertIsNone(sot) super(TestSnapshot, self).tearDown() def test_get(self): - sot = self.conn.block_store.get_snapshot(self.SNAPSHOT_ID) + sot = self.conn.block_storage.get_snapshot(self.SNAPSHOT_ID) self.assertEqual(self.SNAPSHOT_NAME, sot.name) diff --git a/openstack/tests/functional/block_store/v2/test_type.py b/openstack/tests/functional/block_storage/v2/test_type.py similarity index 82% rename from openstack/tests/functional/block_store/v2/test_type.py rename to openstack/tests/functional/block_storage/v2/test_type.py index 6ae0e93ea..46d2b8720 100644 --- a/openstack/tests/functional/block_store/v2/test_type.py +++ b/openstack/tests/functional/block_storage/v2/test_type.py @@ -11,7 +11,7 @@ # under the License. -from openstack.block_store.v2 import type as _type +from openstack.block_storage.v2 import type as _type from openstack.tests.functional import base @@ -23,17 +23,17 @@ class TestType(base.BaseFunctionalTest): self.TYPE_NAME = self.getUniqueString() self.TYPE_ID = None - sot = self.conn.block_store.create_type(name=self.TYPE_NAME) + sot = self.conn.block_storage.create_type(name=self.TYPE_NAME) assert isinstance(sot, _type.Type) self.assertEqual(self.TYPE_NAME, sot.name) self.TYPE_ID = sot.id def tearDown(self): - sot = self.conn.block_store.delete_type( + sot = self.conn.block_storage.delete_type( self.TYPE_ID, ignore_missing=False) self.assertIsNone(sot) super(TestType, self).tearDown() def test_get(self): - sot = self.conn.block_store.get_type(self.TYPE_ID) + sot = self.conn.block_storage.get_type(self.TYPE_ID) self.assertEqual(self.TYPE_NAME, sot.name) diff --git a/openstack/tests/functional/block_store/v2/test_volume.py b/openstack/tests/functional/block_storage/v2/test_volume.py similarity index 82% rename from openstack/tests/functional/block_store/v2/test_volume.py rename to openstack/tests/functional/block_storage/v2/test_volume.py index 66b02880d..803d858b0 100644 --- a/openstack/tests/functional/block_store/v2/test_volume.py +++ b/openstack/tests/functional/block_storage/v2/test_volume.py @@ -11,7 +11,7 @@ # under the License. -from openstack.block_store.v2 import volume as _volume +from openstack.block_storage.v2 import volume as _volume from openstack.tests.functional import base @@ -23,10 +23,10 @@ class TestVolume(base.BaseFunctionalTest): self.VOLUME_NAME = self.getUniqueString() self.VOLUME_ID = None - volume = self.conn.block_store.create_volume( + volume = self.conn.block_storage.create_volume( name=self.VOLUME_NAME, size=1) - self.conn.block_store.wait_for_status( + self.conn.block_storage.wait_for_status( volume, status='available', failures=['error'], @@ -37,12 +37,12 @@ class TestVolume(base.BaseFunctionalTest): self.VOLUME_ID = volume.id def tearDown(self): - sot = self.conn.block_store.delete_volume( + sot = self.conn.block_storage.delete_volume( self.VOLUME_ID, ignore_missing=False) self.assertIsNone(sot) super(TestVolume, self).tearDown() def test_get(self): - sot = self.conn.block_store.get_volume(self.VOLUME_ID) + sot = self.conn.block_storage.get_volume(self.VOLUME_ID) self.assertEqual(self.VOLUME_NAME, sot.name) diff --git a/openstack/tests/functional/telemetry/__init__.py b/openstack/tests/functional/meter/__init__.py similarity index 100% rename from openstack/tests/functional/telemetry/__init__.py rename to openstack/tests/functional/meter/__init__.py diff --git a/openstack/tests/functional/telemetry/alarm/__init__.py b/openstack/tests/functional/meter/alarm/__init__.py similarity index 100% rename from openstack/tests/functional/telemetry/alarm/__init__.py rename to openstack/tests/functional/meter/alarm/__init__.py diff --git a/openstack/tests/functional/telemetry/alarm/v2/__init__.py b/openstack/tests/functional/meter/alarm/v2/__init__.py similarity index 100% rename from openstack/tests/functional/telemetry/alarm/v2/__init__.py rename to openstack/tests/functional/meter/alarm/v2/__init__.py diff --git a/openstack/tests/functional/telemetry/alarm/v2/test_alarm.py b/openstack/tests/functional/meter/alarm/v2/test_alarm.py similarity index 94% rename from openstack/tests/functional/telemetry/alarm/v2/test_alarm.py rename to openstack/tests/functional/meter/alarm/v2/test_alarm.py index 38a18ea5f..34cdf2703 100644 --- a/openstack/tests/functional/telemetry/alarm/v2/test_alarm.py +++ b/openstack/tests/functional/meter/alarm/v2/test_alarm.py @@ -12,7 +12,7 @@ import unittest -from openstack.telemetry.alarm.v2 import alarm +from openstack.meter.alarm.v2 import alarm from openstack.tests.functional import base @@ -27,7 +27,7 @@ class TestAlarm(base.BaseFunctionalTest): self.require_service('metering') self.NAME = self.getUniqueString() - meter = next(self.conn.telemetry.meters()) + meter = next(self.conn.meter.meters()) sot = self.conn.alarm.create_alarm( name=self.NAME, type='threshold', diff --git a/openstack/tests/functional/telemetry/alarm/v2/test_alarm_change.py b/openstack/tests/functional/meter/alarm/v2/test_alarm_change.py similarity index 96% rename from openstack/tests/functional/telemetry/alarm/v2/test_alarm_change.py rename to openstack/tests/functional/meter/alarm/v2/test_alarm_change.py index 311944e40..f8bd5dffe 100644 --- a/openstack/tests/functional/telemetry/alarm/v2/test_alarm_change.py +++ b/openstack/tests/functional/meter/alarm/v2/test_alarm_change.py @@ -26,7 +26,7 @@ class TestAlarmChange(base.BaseFunctionalTest): self.require_service('metering') self.NAME = self.getUniqueString() - meter = next(self.conn.telemetry.meters()) + meter = next(self.conn.meter.meters()) self.alarm = self.conn.alarm.create_alarm( name=self.NAME, type='threshold', diff --git a/openstack/tests/functional/telemetry/v2/__init__.py b/openstack/tests/functional/meter/v2/__init__.py similarity index 100% rename from openstack/tests/functional/telemetry/v2/__init__.py rename to openstack/tests/functional/meter/v2/__init__.py diff --git a/openstack/tests/functional/telemetry/v2/test_capability.py b/openstack/tests/functional/meter/v2/test_capability.py similarity index 93% rename from openstack/tests/functional/telemetry/v2/test_capability.py rename to openstack/tests/functional/meter/v2/test_capability.py index 4e4f93835..991fc3c11 100644 --- a/openstack/tests/functional/telemetry/v2/test_capability.py +++ b/openstack/tests/functional/meter/v2/test_capability.py @@ -20,7 +20,7 @@ class TestCapability(base.BaseFunctionalTest): self.require_service('metering') def test_list(self): - ids = [o.id for o in self.conn.telemetry.capabilities()] + ids = [o.id for o in self.conn.meter.capabilities()] self.assertIn('resources:query:simple', ids) self.assertIn('meters:query:simple', ids) self.assertIn('statistics:query:simple', ids) diff --git a/openstack/tests/functional/telemetry/v2/test_meter.py b/openstack/tests/functional/meter/v2/test_meter.py similarity index 94% rename from openstack/tests/functional/telemetry/v2/test_meter.py rename to openstack/tests/functional/meter/v2/test_meter.py index 26fe8a4e8..913bf4b73 100644 --- a/openstack/tests/functional/telemetry/v2/test_meter.py +++ b/openstack/tests/functional/meter/v2/test_meter.py @@ -27,5 +27,5 @@ class TestMeter(base.BaseFunctionalTest): tainer = self.conn.object_store.create_container(name=name) self.conn.object_store.delete_container(tainer) - names = set([o.name for o in self.conn.telemetry.meters()]) + names = set([o.name for o in self.conn.meter.meters()]) self.assertIn('storage.objects.incoming.bytes', names) diff --git a/openstack/tests/functional/telemetry/v2/test_resource.py b/openstack/tests/functional/meter/v2/test_resource.py similarity index 91% rename from openstack/tests/functional/telemetry/v2/test_resource.py rename to openstack/tests/functional/meter/v2/test_resource.py index 28f8a15bc..37c2bfbe7 100644 --- a/openstack/tests/functional/telemetry/v2/test_resource.py +++ b/openstack/tests/functional/meter/v2/test_resource.py @@ -20,5 +20,5 @@ class TestResource(base.BaseFunctionalTest): self.require_service('metering') def test_list(self): - ids = [o.resource_id for o in self.conn.telemetry.resources()] + ids = [o.resource_id for o in self.conn.meter.resources()] self.assertNotEqual(0, len(ids)) diff --git a/openstack/tests/functional/telemetry/v2/test_sample.py b/openstack/tests/functional/meter/v2/test_sample.py similarity index 84% rename from openstack/tests/functional/telemetry/v2/test_sample.py rename to openstack/tests/functional/meter/v2/test_sample.py index cfa3692d8..83adca7ab 100644 --- a/openstack/tests/functional/telemetry/v2/test_sample.py +++ b/openstack/tests/functional/meter/v2/test_sample.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.telemetry.v2 import sample +from openstack.meter.v2 import sample from openstack.tests.functional import base @@ -21,6 +21,6 @@ class TestSample(base.BaseFunctionalTest): self.require_service('metering') def test_list(self): - for meter in self.conn.telemetry.meters(): - for sot in self.conn.telemetry.samples(meter): + for meter in self.conn.meter.meters(): + for sot in self.conn.meter.samples(meter): assert isinstance(sot, sample.Sample) diff --git a/openstack/tests/functional/telemetry/v2/test_statistics.py b/openstack/tests/functional/meter/v2/test_statistics.py similarity index 88% rename from openstack/tests/functional/telemetry/v2/test_statistics.py rename to openstack/tests/functional/meter/v2/test_statistics.py index 349070a0f..85cd47bdd 100644 --- a/openstack/tests/functional/telemetry/v2/test_statistics.py +++ b/openstack/tests/functional/meter/v2/test_statistics.py @@ -20,7 +20,7 @@ class TestStatistics(base.BaseFunctionalTest): self.require_service('metering') def test_list(self): - for met in self.conn.telemetry.meters(): - for stat in self.conn.telemetry.statistics(met): + for met in self.conn.meter.meters(): + for stat in self.conn.meter.statistics(met): self.assertTrue(stat.period_end_at is not None) break diff --git a/openstack/tests/functional/network/v2/test_agent_add_remove_network.py b/openstack/tests/functional/network/v2/test_agent_add_remove_network.py index e1ee63d93..6cd7837fa 100644 --- a/openstack/tests/functional/network/v2/test_agent_add_remove_network.py +++ b/openstack/tests/functional/network/v2/test_agent_add_remove_network.py @@ -36,11 +36,11 @@ class TestAgentNetworks(base.BaseFunctionalTest): self.AGENT_ID = self.AGENT.id def test_add_remove_agent(self): - net = self.AGENT.add_agent_to_network(self.conn.session, + net = self.AGENT.add_agent_to_network(self.conn.network, network_id=self.NETWORK_ID) self._verify_add(net) - net = self.AGENT.remove_agent_from_network(self.conn.session, + net = self.AGENT.remove_agent_from_network(self.conn.network, network_id=self.NETWORK_ID) self._verify_remove(net) diff --git a/openstack/tests/functional/network/v2/test_floating_ip.py b/openstack/tests/functional/network/v2/test_floating_ip.py index bf8405309..8e0fb5afa 100644 --- a/openstack/tests/functional/network/v2/test_floating_ip.py +++ b/openstack/tests/functional/network/v2/test_floating_ip.py @@ -61,7 +61,7 @@ class TestFloatingIP(base.BaseFunctionalTest): self.ROT = sot # Add Router's Interface to Internal Network sot = self.ROT.add_interface( - self.conn.session, subnet_id=self.INT_SUB_ID) + self.conn.network, subnet_id=self.INT_SUB_ID) self.assertEqual(sot['subnet_id'], self.INT_SUB_ID) # Create Port in Internal Network prt = self.conn.network.create_port(network_id=self.INT_NET_ID) @@ -78,7 +78,7 @@ class TestFloatingIP(base.BaseFunctionalTest): sot = self.conn.network.delete_port(self.PORT_ID, ignore_missing=False) self.assertIsNone(sot) sot = self.ROT.remove_interface( - self.conn.session, subnet_id=self.INT_SUB_ID) + self.conn.network, subnet_id=self.INT_SUB_ID) self.assertEqual(sot['subnet_id'], self.INT_SUB_ID) sot = self.conn.network.delete_router( self.ROT_ID, ignore_missing=False) diff --git a/openstack/tests/functional/network/v2/test_router_add_remove_interface.py b/openstack/tests/functional/network/v2/test_router_add_remove_interface.py index 663400dfa..a300368a0 100644 --- a/openstack/tests/functional/network/v2/test_router_add_remove_interface.py +++ b/openstack/tests/functional/network/v2/test_router_add_remove_interface.py @@ -62,10 +62,10 @@ class TestRouterInterface(base.BaseFunctionalTest): super(TestRouterInterface, self).tearDown() def test_router_add_remove_interface(self): - iface = self.ROT.add_interface(self.conn.session, + iface = self.ROT.add_interface(self.conn.network, subnet_id=self.SUB_ID) self._verification(iface) - iface = self.ROT.remove_interface(self.conn.session, + iface = self.ROT.remove_interface(self.conn.network, subnet_id=self.SUB_ID) self._verification(iface) diff --git a/openstack/tests/unit/bare_metal/__init__.py b/openstack/tests/unit/baremetal/__init__.py similarity index 100% rename from openstack/tests/unit/bare_metal/__init__.py rename to openstack/tests/unit/baremetal/__init__.py diff --git a/openstack/tests/unit/bare_metal/test_bare_metal_service.py b/openstack/tests/unit/baremetal/test_baremetal_service.py similarity index 86% rename from openstack/tests/unit/bare_metal/test_bare_metal_service.py rename to openstack/tests/unit/baremetal/test_baremetal_service.py index 0a7f00581..e808b6ef2 100644 --- a/openstack/tests/unit/bare_metal/test_bare_metal_service.py +++ b/openstack/tests/unit/baremetal/test_baremetal_service.py @@ -12,13 +12,13 @@ import testtools -from openstack.bare_metal import bare_metal_service +from openstack.baremetal import baremetal_service -class TestBareMetalService(testtools.TestCase): +class TestBaremetalService(testtools.TestCase): def test_service(self): - sot = bare_metal_service.BareMetalService() + sot = baremetal_service.BaremetalService() self.assertEqual('baremetal', sot.service_type) self.assertEqual('public', sot.interface) self.assertIsNone(sot.region) diff --git a/openstack/tests/unit/bare_metal/test_version.py b/openstack/tests/unit/baremetal/test_version.py similarity index 97% rename from openstack/tests/unit/bare_metal/test_version.py rename to openstack/tests/unit/baremetal/test_version.py index 38aff7927..7466730a9 100644 --- a/openstack/tests/unit/bare_metal/test_version.py +++ b/openstack/tests/unit/baremetal/test_version.py @@ -12,7 +12,7 @@ import testtools -from openstack.bare_metal import version +from openstack.baremetal import version IDENTIFIER = 'IDENTIFIER' EXAMPLE = { diff --git a/openstack/tests/unit/bare_metal/v1/__init__.py b/openstack/tests/unit/baremetal/v1/__init__.py similarity index 100% rename from openstack/tests/unit/bare_metal/v1/__init__.py rename to openstack/tests/unit/baremetal/v1/__init__.py diff --git a/openstack/tests/unit/bare_metal/v1/test_chassis.py b/openstack/tests/unit/baremetal/v1/test_chassis.py similarity index 98% rename from openstack/tests/unit/bare_metal/v1/test_chassis.py rename to openstack/tests/unit/baremetal/v1/test_chassis.py index eab6c7a9a..b9dfe82a5 100644 --- a/openstack/tests/unit/bare_metal/v1/test_chassis.py +++ b/openstack/tests/unit/baremetal/v1/test_chassis.py @@ -12,7 +12,7 @@ import testtools -from openstack.bare_metal.v1 import chassis +from openstack.baremetal.v1 import chassis FAKE = { "created_at": "2016-08-18T22:28:48.165105+00:00", diff --git a/openstack/tests/unit/bare_metal/v1/test_driver.py b/openstack/tests/unit/baremetal/v1/test_driver.py similarity index 97% rename from openstack/tests/unit/bare_metal/v1/test_driver.py rename to openstack/tests/unit/baremetal/v1/test_driver.py index 36ce7dc1f..c360e0eba 100644 --- a/openstack/tests/unit/bare_metal/v1/test_driver.py +++ b/openstack/tests/unit/baremetal/v1/test_driver.py @@ -12,7 +12,7 @@ import testtools -from openstack.bare_metal.v1 import driver +from openstack.baremetal.v1 import driver FAKE = { "hosts": [ diff --git a/openstack/tests/unit/bare_metal/v1/test_node.py b/openstack/tests/unit/baremetal/v1/test_node.py similarity index 99% rename from openstack/tests/unit/bare_metal/v1/test_node.py rename to openstack/tests/unit/baremetal/v1/test_node.py index ddbf2512a..05cff3e48 100644 --- a/openstack/tests/unit/bare_metal/v1/test_node.py +++ b/openstack/tests/unit/baremetal/v1/test_node.py @@ -12,7 +12,7 @@ import testtools -from openstack.bare_metal.v1 import node +from openstack.baremetal.v1 import node # NOTE: Sample data from api-ref doc FAKE = { diff --git a/openstack/tests/unit/bare_metal/v1/test_port.py b/openstack/tests/unit/baremetal/v1/test_port.py similarity index 98% rename from openstack/tests/unit/bare_metal/v1/test_port.py rename to openstack/tests/unit/baremetal/v1/test_port.py index c58b6f93a..29d4ad4d5 100644 --- a/openstack/tests/unit/bare_metal/v1/test_port.py +++ b/openstack/tests/unit/baremetal/v1/test_port.py @@ -12,7 +12,7 @@ import testtools -from openstack.bare_metal.v1 import port +from openstack.baremetal.v1 import port FAKE = { "address": "11:11:11:11:11:11", diff --git a/openstack/tests/unit/bare_metal/v1/test_port_group.py b/openstack/tests/unit/baremetal/v1/test_port_group.py similarity index 98% rename from openstack/tests/unit/bare_metal/v1/test_port_group.py rename to openstack/tests/unit/baremetal/v1/test_port_group.py index ea1cfd06e..b2c6ed147 100644 --- a/openstack/tests/unit/bare_metal/v1/test_port_group.py +++ b/openstack/tests/unit/baremetal/v1/test_port_group.py @@ -12,7 +12,7 @@ import testtools -from openstack.bare_metal.v1 import port_group +from openstack.baremetal.v1 import port_group FAKE = { "address": "11:11:11:11:11:11", diff --git a/openstack/tests/unit/bare_metal/v1/test_proxy.py b/openstack/tests/unit/baremetal/v1/test_proxy.py similarity index 94% rename from openstack/tests/unit/bare_metal/v1/test_proxy.py rename to openstack/tests/unit/baremetal/v1/test_proxy.py index 34212a6a0..d1bb49c16 100644 --- a/openstack/tests/unit/bare_metal/v1/test_proxy.py +++ b/openstack/tests/unit/baremetal/v1/test_proxy.py @@ -12,19 +12,19 @@ import deprecation -from openstack.bare_metal.v1 import _proxy -from openstack.bare_metal.v1 import chassis -from openstack.bare_metal.v1 import driver -from openstack.bare_metal.v1 import node -from openstack.bare_metal.v1 import port -from openstack.bare_metal.v1 import port_group +from openstack.baremetal.v1 import _proxy +from openstack.baremetal.v1 import chassis +from openstack.baremetal.v1 import driver +from openstack.baremetal.v1 import node +from openstack.baremetal.v1 import port +from openstack.baremetal.v1 import port_group from openstack.tests.unit import test_proxy_base2 -class TestBareMetalProxy(test_proxy_base2.TestProxyBase): +class TestBaremetalProxy(test_proxy_base2.TestProxyBase): def setUp(self): - super(TestBareMetalProxy, self).setUp() + super(TestBaremetalProxy, self).setUp() self.proxy = _proxy.Proxy(self.session) def test_drivers(self): diff --git a/openstack/tests/unit/base.py b/openstack/tests/unit/base.py index 290910ac5..4f474e0f9 100644 --- a/openstack/tests/unit/base.py +++ b/openstack/tests/unit/base.py @@ -27,6 +27,7 @@ from six.moves import urllib import tempfile import openstack +import openstack.connection from openstack.tests import base @@ -406,6 +407,19 @@ class RequestsMockTestCase(BaseTestCase): return _RoleData(role_id, role_name, {'role': response}, {'role': request}) + def use_broken_keystone(self): + self.adapter = self.useFixture(rm_fixture.Fixture()) + self.calls = [] + self._uri_registry.clear() + self.__do_register_uris([ + dict(method='GET', uri='https://identity.example.com/', + text=open(self.discovery_json, 'r').read()), + dict(method='POST', + uri='https://identity.example.com/v3/auth/tokens', + status_code=400), + ]) + self._make_test_cloud(identity_api_version='3') + def use_keystone_v3(self, catalog='catalog-v3.json'): self.adapter = self.useFixture(rm_fixture.Fixture()) self.calls = [] @@ -444,6 +458,8 @@ class RequestsMockTestCase(BaseTestCase): test_cloud = os.environ.get('OPENSTACKSDK_OS_CLOUD', cloud_name) self.cloud_config = self.config.get_one_cloud( cloud=test_cloud, validate=True, **kwargs) + self.conn = openstack.connection.Connection( + config=self.cloud_config) self.cloud = openstack.OpenStackCloud( cloud_config=self.cloud_config, log_inner_exceptions=True) diff --git a/openstack/tests/unit/block_store/__init__.py b/openstack/tests/unit/block_storage/__init__.py similarity index 100% rename from openstack/tests/unit/block_store/__init__.py rename to openstack/tests/unit/block_storage/__init__.py diff --git a/openstack/tests/unit/block_store/test_block_store_service.py b/openstack/tests/unit/block_storage/test_block_storage_service.py similarity index 85% rename from openstack/tests/unit/block_store/test_block_store_service.py rename to openstack/tests/unit/block_storage/test_block_storage_service.py index f02d12ac5..fd4ea444e 100644 --- a/openstack/tests/unit/block_store/test_block_store_service.py +++ b/openstack/tests/unit/block_storage/test_block_storage_service.py @@ -12,13 +12,13 @@ import testtools -from openstack.block_store import block_store_service +from openstack.block_storage import block_storage_service -class TestBlockStoreService(testtools.TestCase): +class TestBlockStorageService(testtools.TestCase): def test_service(self): - sot = block_store_service.BlockStoreService() + sot = block_storage_service.BlockStorageService() self.assertEqual("volume", sot.service_type) self.assertEqual("public", sot.interface) self.assertIsNone(sot.region) diff --git a/openstack/tests/unit/block_store/v2/__init__.py b/openstack/tests/unit/block_storage/v2/__init__.py similarity index 100% rename from openstack/tests/unit/block_store/v2/__init__.py rename to openstack/tests/unit/block_storage/v2/__init__.py diff --git a/openstack/tests/unit/block_store/v2/test_proxy.py b/openstack/tests/unit/block_storage/v2/test_proxy.py similarity index 94% rename from openstack/tests/unit/block_store/v2/test_proxy.py rename to openstack/tests/unit/block_storage/v2/test_proxy.py index 4af3b4d81..431b5f48a 100644 --- a/openstack/tests/unit/block_store/v2/test_proxy.py +++ b/openstack/tests/unit/block_storage/v2/test_proxy.py @@ -10,10 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.block_store.v2 import _proxy -from openstack.block_store.v2 import snapshot -from openstack.block_store.v2 import type -from openstack.block_store.v2 import volume +from openstack.block_storage.v2 import _proxy +from openstack.block_storage.v2 import snapshot +from openstack.block_storage.v2 import type +from openstack.block_storage.v2 import volume from openstack.tests.unit import test_proxy_base2 diff --git a/openstack/tests/unit/block_store/v2/test_snapshot.py b/openstack/tests/unit/block_storage/v2/test_snapshot.py similarity index 98% rename from openstack/tests/unit/block_store/v2/test_snapshot.py rename to openstack/tests/unit/block_storage/v2/test_snapshot.py index 79388489a..6e542bd17 100644 --- a/openstack/tests/unit/block_store/v2/test_snapshot.py +++ b/openstack/tests/unit/block_storage/v2/test_snapshot.py @@ -12,7 +12,7 @@ import testtools -from openstack.block_store.v2 import snapshot +from openstack.block_storage.v2 import snapshot FAKE_ID = "ffa9bc5e-1172-4021-acaf-cdcd78a9584d" diff --git a/openstack/tests/unit/block_store/v2/test_type.py b/openstack/tests/unit/block_storage/v2/test_type.py similarity index 97% rename from openstack/tests/unit/block_store/v2/test_type.py rename to openstack/tests/unit/block_storage/v2/test_type.py index d841b35ca..b44c39dbe 100644 --- a/openstack/tests/unit/block_store/v2/test_type.py +++ b/openstack/tests/unit/block_storage/v2/test_type.py @@ -12,7 +12,7 @@ import testtools -from openstack.block_store.v2 import type +from openstack.block_storage.v2 import type FAKE_ID = "6685584b-1eac-4da6-b5c3-555430cf68ff" TYPE = { diff --git a/openstack/tests/unit/block_store/v2/test_volume.py b/openstack/tests/unit/block_storage/v2/test_volume.py similarity index 99% rename from openstack/tests/unit/block_store/v2/test_volume.py rename to openstack/tests/unit/block_storage/v2/test_volume.py index 825cb910f..70b0ce8e8 100644 --- a/openstack/tests/unit/block_store/v2/test_volume.py +++ b/openstack/tests/unit/block_storage/v2/test_volume.py @@ -14,7 +14,7 @@ import copy import testtools -from openstack.block_store.v2 import volume +from openstack.block_storage.v2 import volume FAKE_ID = "6685584b-1eac-4da6-b5c3-555430cf68ff" diff --git a/openstack/tests/unit/cloud/test__adapter.py b/openstack/tests/unit/cloud/test__adapter.py index 9722b02c8..aaca16854 100644 --- a/openstack/tests/unit/cloud/test__adapter.py +++ b/openstack/tests/unit/cloud/test__adapter.py @@ -34,5 +34,5 @@ class TestExtractName(base.TestCase): def test_extract_name(self): - results = _adapter.extract_name(self.url) + results = _adapter._extract_name(self.url) self.assertEqual(self.parts, results) diff --git a/openstack/tests/unit/cloud/test_role_assignment.py b/openstack/tests/unit/cloud/test_role_assignment.py index 5ab23d2fc..dd7fa5bfb 100644 --- a/openstack/tests/unit/cloud/test_role_assignment.py +++ b/openstack/tests/unit/cloud/test_role_assignment.py @@ -2641,6 +2641,7 @@ class TestRoleAssignment(base.RequestsMockTestCase): uri=self.get_mock_url(resource='domains', append=['baddomain']), status_code=404, + headers={'Content-Type': 'text/plain'}, text='Could not find domain: baddomain') ]) with testtools.ExpectedException( @@ -2663,6 +2664,7 @@ class TestRoleAssignment(base.RequestsMockTestCase): uri=self.get_mock_url(resource='domains', append=['baddomain']), status_code=404, + headers={'Content-Type': 'text/plain'}, text='Could not find domain: baddomain') ]) with testtools.ExpectedException( diff --git a/openstack/tests/unit/cloud/test_task_manager.py b/openstack/tests/unit/cloud/test_task_manager.py index cad3da4a7..f78d5bb4e 100644 --- a/openstack/tests/unit/cloud/test_task_manager.py +++ b/openstack/tests/unit/cloud/test_task_manager.py @@ -25,46 +25,45 @@ class TestException(Exception): class TaskTest(task_manager.Task): - def main(self, client): + def main(self): raise TestException("This is a test exception") class TaskTestGenerator(task_manager.Task): - def main(self, client): + def main(self): yield 1 class TaskTestInt(task_manager.Task): - def main(self, client): + def main(self): return int(1) class TaskTestFloat(task_manager.Task): - def main(self, client): + def main(self): return float(2.0) class TaskTestStr(task_manager.Task): - def main(self, client): + def main(self): return "test" class TaskTestBool(task_manager.Task): - def main(self, client): + def main(self): return True class TaskTestSet(task_manager.Task): - def main(self, client): + def main(self): return set([1, 2]) class TaskTestAsync(task_manager.Task): def __init__(self): - super(task_manager.Task, self).__init__() - self.run_async = True + super(TaskTestAsync, self).__init__(run_async=True) - def main(self, client): + def main(self): pass @@ -72,7 +71,7 @@ class TestTaskManager(base.TestCase): def setUp(self): super(TestTaskManager, self).setUp() - self.manager = task_manager.TaskManager(name='test', client=self) + self.manager = task_manager.TaskManager(name='test') def test_wait_re_raise(self): """Test that Exceptions thrown in a Task is reraised correctly diff --git a/openstack/tests/unit/cluster/test_cluster_service.py b/openstack/tests/unit/cluster/test_cluster_service.py index 0d7532a60..4c828bd66 100644 --- a/openstack/tests/unit/cluster/test_cluster_service.py +++ b/openstack/tests/unit/cluster/test_cluster_service.py @@ -12,13 +12,13 @@ import testtools -from openstack.cluster import cluster_service +from openstack.clustering import clustering_service -class TestClusterService(testtools.TestCase): +class TestClusteringService(testtools.TestCase): def test_service(self): - sot = cluster_service.ClusterService() + sot = clustering_service.ClusteringService() self.assertEqual('clustering', sot.service_type) self.assertEqual('public', sot.interface) self.assertIsNone(sot.region) diff --git a/openstack/tests/unit/cluster/test_version.py b/openstack/tests/unit/cluster/test_version.py index c9b0a5bd6..30646a5c7 100644 --- a/openstack/tests/unit/cluster/test_version.py +++ b/openstack/tests/unit/cluster/test_version.py @@ -12,7 +12,7 @@ import testtools -from openstack.cluster import version +from openstack.clustering import version IDENTIFIER = 'IDENTIFIER' EXAMPLE = { diff --git a/openstack/tests/unit/cluster/v1/test_action.py b/openstack/tests/unit/cluster/v1/test_action.py index 017779520..b12eaac98 100644 --- a/openstack/tests/unit/cluster/v1/test_action.py +++ b/openstack/tests/unit/cluster/v1/test_action.py @@ -12,7 +12,7 @@ import testtools -from openstack.cluster.v1 import action +from openstack.clustering.v1 import action FAKE_ID = '633bd3c6-520b-420f-8e6a-dc2a47022b53' diff --git a/openstack/tests/unit/cluster/v1/test_build_info.py b/openstack/tests/unit/cluster/v1/test_build_info.py index ab695c027..080d0b15b 100644 --- a/openstack/tests/unit/cluster/v1/test_build_info.py +++ b/openstack/tests/unit/cluster/v1/test_build_info.py @@ -12,7 +12,7 @@ import testtools -from openstack.cluster.v1 import build_info +from openstack.clustering.v1 import build_info FAKE = { diff --git a/openstack/tests/unit/cluster/v1/test_cluster.py b/openstack/tests/unit/cluster/v1/test_cluster.py index 5c1de631f..31f34cab7 100644 --- a/openstack/tests/unit/cluster/v1/test_cluster.py +++ b/openstack/tests/unit/cluster/v1/test_cluster.py @@ -13,7 +13,7 @@ import mock import testtools -from openstack.cluster.v1 import cluster +from openstack.clustering.v1 import cluster FAKE_ID = '092d0955-2645-461a-b8fa-6a44655cdb2c' @@ -122,7 +122,7 @@ class TestCluster(testtools.TestCase): self.assertEqual('', sot.scale_in(sess, 3)) url = 'clusters/%s/actions' % sot.id body = {'scale_in': {'count': 3}} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, json=body) def test_scale_out(self): @@ -135,7 +135,7 @@ class TestCluster(testtools.TestCase): self.assertEqual('', sot.scale_out(sess, 3)) url = 'clusters/%s/actions' % sot.id body = {'scale_out': {'count': 3}} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, json=body) def test_resize(self): @@ -148,7 +148,7 @@ class TestCluster(testtools.TestCase): self.assertEqual('', sot.resize(sess, foo='bar', zoo=5)) url = 'clusters/%s/actions' % sot.id body = {'resize': {'foo': 'bar', 'zoo': 5}} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, json=body) def test_add_nodes(self): @@ -161,7 +161,7 @@ class TestCluster(testtools.TestCase): self.assertEqual('', sot.add_nodes(sess, ['node-33'])) url = 'clusters/%s/actions' % sot.id body = {'add_nodes': {'nodes': ['node-33']}} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, json=body) def test_del_nodes(self): @@ -174,7 +174,7 @@ class TestCluster(testtools.TestCase): self.assertEqual('', sot.del_nodes(sess, ['node-11'])) url = 'clusters/%s/actions' % sot.id body = {'del_nodes': {'nodes': ['node-11']}} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, json=body) def test_del_nodes_with_params(self): @@ -195,7 +195,7 @@ class TestCluster(testtools.TestCase): 'destroy_after_deletion': True, } } - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, json=body) def test_replace_nodes(self): @@ -208,7 +208,7 @@ class TestCluster(testtools.TestCase): self.assertEqual('', sot.replace_nodes(sess, {'node-22': 'node-44'})) url = 'clusters/%s/actions' % sot.id body = {'replace_nodes': {'nodes': {'node-22': 'node-44'}}} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, json=body) def test_policy_attach(self): @@ -230,7 +230,7 @@ class TestCluster(testtools.TestCase): 'enabled': True, } } - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, json=body) def test_policy_detach(self): @@ -244,7 +244,7 @@ class TestCluster(testtools.TestCase): url = 'clusters/%s/actions' % sot.id body = {'policy_detach': {'policy_id': 'POLICY'}} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, json=body) def test_policy_update(self): @@ -266,7 +266,7 @@ class TestCluster(testtools.TestCase): 'enabled': False } } - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, json=body) def test_check(self): @@ -279,7 +279,7 @@ class TestCluster(testtools.TestCase): self.assertEqual('', sot.check(sess)) url = 'clusters/%s/actions' % sot.id body = {'check': {}} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, json=body) def test_recover(self): @@ -292,7 +292,7 @@ class TestCluster(testtools.TestCase): self.assertEqual('', sot.recover(sess)) url = 'clusters/%s/actions' % sot.id body = {'recover': {}} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, json=body) def test_operation(self): @@ -305,5 +305,5 @@ class TestCluster(testtools.TestCase): self.assertEqual('', sot.op(sess, 'dance', style='tango')) url = 'clusters/%s/ops' % sot.id body = {'dance': {'style': 'tango'}} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, json=body) diff --git a/openstack/tests/unit/cluster/v1/test_cluster_attr.py b/openstack/tests/unit/cluster/v1/test_cluster_attr.py index cded9ef87..3d7181682 100644 --- a/openstack/tests/unit/cluster/v1/test_cluster_attr.py +++ b/openstack/tests/unit/cluster/v1/test_cluster_attr.py @@ -12,7 +12,7 @@ import testtools -from openstack.cluster.v1 import cluster_attr as ca +from openstack.clustering.v1 import cluster_attr as ca FAKE = { diff --git a/openstack/tests/unit/cluster/v1/test_cluster_policy.py b/openstack/tests/unit/cluster/v1/test_cluster_policy.py index a4126977c..e84990e12 100644 --- a/openstack/tests/unit/cluster/v1/test_cluster_policy.py +++ b/openstack/tests/unit/cluster/v1/test_cluster_policy.py @@ -12,7 +12,7 @@ import testtools -from openstack.cluster.v1 import cluster_policy +from openstack.clustering.v1 import cluster_policy FAKE = { diff --git a/openstack/tests/unit/cluster/v1/test_event.py b/openstack/tests/unit/cluster/v1/test_event.py index 0d482b97e..82a76593a 100644 --- a/openstack/tests/unit/cluster/v1/test_event.py +++ b/openstack/tests/unit/cluster/v1/test_event.py @@ -12,7 +12,7 @@ import testtools -from openstack.cluster.v1 import event +from openstack.clustering.v1 import event FAKE = { diff --git a/openstack/tests/unit/cluster/v1/test_node.py b/openstack/tests/unit/cluster/v1/test_node.py index 4566387d4..3aa3b26ae 100644 --- a/openstack/tests/unit/cluster/v1/test_node.py +++ b/openstack/tests/unit/cluster/v1/test_node.py @@ -13,7 +13,7 @@ import mock import testtools -from openstack.cluster.v1 import node +from openstack.clustering.v1 import node FAKE_ID = '123d0955-0099-aabb-b8fa-6a44655ceeff' @@ -78,7 +78,7 @@ class TestNode(testtools.TestCase): self.assertEqual('', sot.check(sess)) url = 'nodes/%s/actions' % sot.id body = {'check': {}} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, json=body) def test_recover(self): @@ -91,7 +91,7 @@ class TestNode(testtools.TestCase): self.assertEqual('', sot.recover(sess)) url = 'nodes/%s/actions' % sot.id body = {'recover': {}} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, json=body) def test_operation(self): @@ -103,7 +103,7 @@ class TestNode(testtools.TestCase): sess.post = mock.Mock(return_value=resp) self.assertEqual('', sot.op(sess, 'dance', style='tango')) url = 'nodes/%s/ops' % sot.id - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, json={'dance': {'style': 'tango'}}) def test_adopt_preview(self): @@ -123,7 +123,6 @@ class TestNode(testtools.TestCase): res = sot.adopt(sess, True, **attrs) self.assertEqual({"foo": "bar"}, res) sess.post.assert_called_once_with("nodes/adopt-preview", - endpoint_filter=sot.service, json=attrs) def test_adopt(self): @@ -131,13 +130,13 @@ class TestNode(testtools.TestCase): resp = mock.Mock() resp.headers = {} resp.json = mock.Mock(return_value={"foo": "bar"}) + resp.status_code = 200 sess = mock.Mock() sess.post = mock.Mock(return_value=resp) res = sot.adopt(sess, False, param="value") self.assertEqual(sot, res) sess.post.assert_called_once_with("nodes/adopt", - endpoint_filter=sot.service, json={"param": "value"}) diff --git a/openstack/tests/unit/cluster/v1/test_policy.py b/openstack/tests/unit/cluster/v1/test_policy.py index 7a9b18fab..a238c08cf 100644 --- a/openstack/tests/unit/cluster/v1/test_policy.py +++ b/openstack/tests/unit/cluster/v1/test_policy.py @@ -12,7 +12,7 @@ import testtools -from openstack.cluster.v1 import policy +from openstack.clustering.v1 import policy FAKE_ID = 'ac5415bd-f522-4160-8be0-f8853e4bc332' diff --git a/openstack/tests/unit/cluster/v1/test_policy_type.py b/openstack/tests/unit/cluster/v1/test_policy_type.py index fd20733a3..7ce8f0507 100644 --- a/openstack/tests/unit/cluster/v1/test_policy_type.py +++ b/openstack/tests/unit/cluster/v1/test_policy_type.py @@ -12,7 +12,7 @@ import testtools -from openstack.cluster.v1 import policy_type +from openstack.clustering.v1 import policy_type FAKE = { diff --git a/openstack/tests/unit/cluster/v1/test_profile.py b/openstack/tests/unit/cluster/v1/test_profile.py index 7a65bf6f3..700382466 100644 --- a/openstack/tests/unit/cluster/v1/test_profile.py +++ b/openstack/tests/unit/cluster/v1/test_profile.py @@ -12,7 +12,7 @@ import testtools -from openstack.cluster.v1 import profile +from openstack.clustering.v1 import profile FAKE_ID = '9b127538-a675-4271-ab9b-f24f54cfe173' diff --git a/openstack/tests/unit/cluster/v1/test_profile_type.py b/openstack/tests/unit/cluster/v1/test_profile_type.py index d494a8e55..88816e2c6 100644 --- a/openstack/tests/unit/cluster/v1/test_profile_type.py +++ b/openstack/tests/unit/cluster/v1/test_profile_type.py @@ -12,7 +12,7 @@ import testtools -from openstack.cluster.v1 import profile_type +from openstack.clustering.v1 import profile_type FAKE = { diff --git a/openstack/tests/unit/cluster/v1/test_proxy.py b/openstack/tests/unit/cluster/v1/test_proxy.py index ec6b55c35..905a46eae 100644 --- a/openstack/tests/unit/cluster/v1/test_proxy.py +++ b/openstack/tests/unit/cluster/v1/test_proxy.py @@ -13,20 +13,20 @@ import deprecation import mock -from openstack.cluster.v1 import _proxy -from openstack.cluster.v1 import action -from openstack.cluster.v1 import build_info -from openstack.cluster.v1 import cluster -from openstack.cluster.v1 import cluster_attr -from openstack.cluster.v1 import cluster_policy -from openstack.cluster.v1 import event -from openstack.cluster.v1 import node -from openstack.cluster.v1 import policy -from openstack.cluster.v1 import policy_type -from openstack.cluster.v1 import profile -from openstack.cluster.v1 import profile_type -from openstack.cluster.v1 import receiver -from openstack.cluster.v1 import service +from openstack.clustering.v1 import _proxy +from openstack.clustering.v1 import action +from openstack.clustering.v1 import build_info +from openstack.clustering.v1 import cluster +from openstack.clustering.v1 import cluster_attr +from openstack.clustering.v1 import cluster_policy +from openstack.clustering.v1 import event +from openstack.clustering.v1 import node +from openstack.clustering.v1 import policy +from openstack.clustering.v1 import policy_type +from openstack.clustering.v1 import profile +from openstack.clustering.v1 import profile_type +from openstack.clustering.v1 import receiver +from openstack.clustering.v1 import service from openstack import proxy2 as proxy_base from openstack.tests.unit import test_proxy_base2 @@ -114,7 +114,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_cluster_add_nodes(self, mock_find): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') mock_find.return_value = mock_cluster - self._verify("openstack.cluster.v1.cluster.Cluster.add_nodes", + self._verify("openstack.clustering.v1.cluster.Cluster.add_nodes", self.proxy.cluster_add_nodes, method_args=["FAKE_CLUSTER", ["node1"]], expected_args=[["node1"]]) @@ -124,7 +124,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): @deprecation.fail_if_not_removed def test_cluster_add_nodes_with_obj(self): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') - self._verify("openstack.cluster.v1.cluster.Cluster.add_nodes", + self._verify("openstack.clustering.v1.cluster.Cluster.add_nodes", self.proxy.cluster_add_nodes, method_args=[mock_cluster, ["node1"]], expected_args=[["node1"]]) @@ -134,7 +134,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_cluster_del_nodes(self, mock_find): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') mock_find.return_value = mock_cluster - self._verify("openstack.cluster.v1.cluster.Cluster.del_nodes", + self._verify("openstack.clustering.v1.cluster.Cluster.del_nodes", self.proxy.cluster_del_nodes, method_args=["FAKE_CLUSTER", ["node1"]], expected_args=[["node1"]]) @@ -144,7 +144,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): @deprecation.fail_if_not_removed def test_cluster_del_nodes_with_obj(self): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') - self._verify("openstack.cluster.v1.cluster.Cluster.del_nodes", + self._verify("openstack.clustering.v1.cluster.Cluster.del_nodes", self.proxy.cluster_del_nodes, method_args=[mock_cluster, ["node1"]], method_kwargs={"key": "value"}, @@ -156,7 +156,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_cluster_replace_nodes(self, mock_find): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') mock_find.return_value = mock_cluster - self._verify("openstack.cluster.v1.cluster.Cluster.replace_nodes", + self._verify("openstack.clustering.v1.cluster.Cluster.replace_nodes", self.proxy.cluster_replace_nodes, method_args=["FAKE_CLUSTER", {"node1": "node2"}], expected_args=[{"node1": "node2"}]) @@ -166,7 +166,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): @deprecation.fail_if_not_removed def test_cluster_replace_nodes_with_obj(self): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') - self._verify("openstack.cluster.v1.cluster.Cluster.replace_nodes", + self._verify("openstack.clustering.v1.cluster.Cluster.replace_nodes", self.proxy.cluster_replace_nodes, method_args=[mock_cluster, {"node1": "node2"}], expected_args=[{"node1": "node2"}]) @@ -176,7 +176,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_cluster_scale_out(self, mock_find): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') mock_find.return_value = mock_cluster - self._verify("openstack.cluster.v1.cluster.Cluster.scale_out", + self._verify("openstack.clustering.v1.cluster.Cluster.scale_out", self.proxy.cluster_scale_out, method_args=["FAKE_CLUSTER", 3], expected_args=[3]) @@ -186,7 +186,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): @deprecation.fail_if_not_removed def test_cluster_scale_out_with_obj(self): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') - self._verify("openstack.cluster.v1.cluster.Cluster.scale_out", + self._verify("openstack.clustering.v1.cluster.Cluster.scale_out", self.proxy.cluster_scale_out, method_args=[mock_cluster, 5], expected_args=[5]) @@ -196,7 +196,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_cluster_scale_in(self, mock_find): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') mock_find.return_value = mock_cluster - self._verify("openstack.cluster.v1.cluster.Cluster.scale_in", + self._verify("openstack.clustering.v1.cluster.Cluster.scale_in", self.proxy.cluster_scale_in, method_args=["FAKE_CLUSTER", 3], expected_args=[3]) @@ -206,7 +206,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): @deprecation.fail_if_not_removed def test_cluster_scale_in_with_obj(self): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') - self._verify("openstack.cluster.v1.cluster.Cluster.scale_in", + self._verify("openstack.clustering.v1.cluster.Cluster.scale_in", self.proxy.cluster_scale_in, method_args=[mock_cluster, 5], expected_args=[5]) @@ -220,7 +220,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_cluster_resize(self, mock_find): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') mock_find.return_value = mock_cluster - self._verify("openstack.cluster.v1.cluster.Cluster.resize", + self._verify("openstack.clustering.v1.cluster.Cluster.resize", self.proxy.cluster_resize, method_args=["FAKE_CLUSTER"], method_kwargs={'k1': 'v1', 'k2': 'v2'}, @@ -230,7 +230,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_cluster_resize_with_obj(self): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') - self._verify("openstack.cluster.v1.cluster.Cluster.resize", + self._verify("openstack.clustering.v1.cluster.Cluster.resize", self.proxy.cluster_resize, method_args=[mock_cluster], method_kwargs={'k1': 'v1', 'k2': 'v2'}, @@ -241,7 +241,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_cluster_attach_policy(self, mock_find): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') mock_find.return_value = mock_cluster - self._verify("openstack.cluster.v1.cluster.Cluster.policy_attach", + self._verify("openstack.clustering.v1.cluster.Cluster.policy_attach", self.proxy.cluster_attach_policy, method_args=["FAKE_CLUSTER", "FAKE_POLICY"], method_kwargs={"k1": "v1", "k2": "v2"}, @@ -253,7 +253,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): @deprecation.fail_if_not_removed def test_cluster_attach_policy_with_obj(self): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') - self._verify("openstack.cluster.v1.cluster.Cluster.policy_attach", + self._verify("openstack.clustering.v1.cluster.Cluster.policy_attach", self.proxy.cluster_attach_policy, method_args=[mock_cluster, "FAKE_POLICY"], method_kwargs={"k1": "v1", "k2": "v2"}, @@ -265,7 +265,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_cluster_detach_policy(self, mock_find): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') mock_find.return_value = mock_cluster - self._verify("openstack.cluster.v1.cluster.Cluster.policy_detach", + self._verify("openstack.clustering.v1.cluster.Cluster.policy_detach", self.proxy.cluster_detach_policy, method_args=["FAKE_CLUSTER", "FAKE_POLICY"], expected_args=["FAKE_POLICY"]) @@ -275,7 +275,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): @deprecation.fail_if_not_removed def test_cluster_detach_policy_with_obj(self): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') - self._verify("openstack.cluster.v1.cluster.Cluster.policy_detach", + self._verify("openstack.clustering.v1.cluster.Cluster.policy_detach", self.proxy.cluster_detach_policy, method_args=[mock_cluster, "FAKE_POLICY"], expected_args=["FAKE_POLICY"]) @@ -285,7 +285,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_cluster_update_policy(self, mock_find): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') mock_find.return_value = mock_cluster - self._verify("openstack.cluster.v1.cluster.Cluster.policy_update", + self._verify("openstack.clustering.v1.cluster.Cluster.policy_update", self.proxy.cluster_update_policy, method_args=["FAKE_CLUSTER", "FAKE_POLICY"], method_kwargs={"k1": "v1", "k2": "v2"}, @@ -297,7 +297,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): @deprecation.fail_if_not_removed def test_cluster_update_policy_with_obj(self): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') - self._verify("openstack.cluster.v1.cluster.Cluster.policy_update", + self._verify("openstack.clustering.v1.cluster.Cluster.policy_update", self.proxy.cluster_update_policy, method_args=[mock_cluster, "FAKE_POLICY"], method_kwargs={"k1": "v1", "k2": "v2"}, @@ -315,7 +315,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_cluster_check(self, mock_get): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') mock_get.return_value = mock_cluster - self._verify("openstack.cluster.v1.cluster.Cluster.check", + self._verify("openstack.clustering.v1.cluster.Cluster.check", self.proxy.check_cluster, method_args=["FAKE_CLUSTER"]) mock_get.assert_called_once_with(cluster.Cluster, "FAKE_CLUSTER") @@ -324,7 +324,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_cluster_recover(self, mock_get): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') mock_get.return_value = mock_cluster - self._verify("openstack.cluster.v1.cluster.Cluster.recover", + self._verify("openstack.clustering.v1.cluster.Cluster.recover", self.proxy.recover_cluster, method_args=["FAKE_CLUSTER"]) mock_get.assert_called_once_with(cluster.Cluster, "FAKE_CLUSTER") @@ -334,7 +334,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_cluster_operation(self, mock_get): mock_cluster = cluster.Cluster.new(id='FAKE_CLUSTER') mock_get.return_value = mock_cluster - self._verify("openstack.cluster.v1.cluster.Cluster.op", + self._verify("openstack.clustering.v1.cluster.Cluster.op", self.proxy.cluster_operation, method_args=["FAKE_CLUSTER", "dance"], expected_args=["dance"]) @@ -377,7 +377,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_node_check(self, mock_get): mock_node = node.Node.new(id='FAKE_NODE') mock_get.return_value = mock_node - self._verify("openstack.cluster.v1.node.Node.check", + self._verify("openstack.clustering.v1.node.Node.check", self.proxy.check_node, method_args=["FAKE_NODE"]) mock_get.assert_called_once_with(node.Node, "FAKE_NODE") @@ -386,7 +386,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_node_recover(self, mock_get): mock_node = node.Node.new(id='FAKE_NODE') mock_get.return_value = mock_node - self._verify("openstack.cluster.v1.node.Node.recover", + self._verify("openstack.clustering.v1.node.Node.recover", self.proxy.recover_node, method_args=["FAKE_NODE"]) mock_get.assert_called_once_with(node.Node, "FAKE_NODE") @@ -395,7 +395,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_node_adopt(self, mock_get): mock_node = node.Node.new() mock_get.return_value = mock_node - self._verify("openstack.cluster.v1.node.Node.adopt", + self._verify("openstack.clustering.v1.node.Node.adopt", self.proxy.adopt_node, method_kwargs={"preview": False, "foo": "bar"}, expected_kwargs={"preview": False, "foo": "bar"}) @@ -406,7 +406,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_node_adopt_preview(self, mock_get): mock_node = node.Node.new() mock_get.return_value = mock_node - self._verify("openstack.cluster.v1.node.Node.adopt", + self._verify("openstack.clustering.v1.node.Node.adopt", self.proxy.adopt_node, method_kwargs={"preview": True, "foo": "bar"}, expected_kwargs={"preview": True, "foo": "bar"}) @@ -418,7 +418,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): def test_node_operation(self, mock_get): mock_node = node.Node.new(id='FAKE_CLUSTER') mock_get.return_value = mock_node - self._verify("openstack.cluster.v1.node.Node.op", + self._verify("openstack.clustering.v1.node.Node.op", self.proxy.node_operation, method_args=["FAKE_NODE", "dance"], expected_args=["dance"]) @@ -536,7 +536,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): self.proxy.wait_for_status(mock_resource, 'ACTIVE') - mock_wait.assert_called_once_with(self.session, mock_resource, + mock_wait.assert_called_once_with(self.proxy, mock_resource, 'ACTIVE', [], 2, 120) @mock.patch("openstack.resource2.wait_for_status") @@ -546,7 +546,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): self.proxy.wait_for_status(mock_resource, 'ACTIVE', ['ERROR'], 1, 2) - mock_wait.assert_called_once_with(self.session, mock_resource, + mock_wait.assert_called_once_with(self.proxy, mock_resource, 'ACTIVE', ['ERROR'], 1, 2) @mock.patch("openstack.resource2.wait_for_delete") @@ -556,7 +556,7 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): self.proxy.wait_for_delete(mock_resource) - mock_wait.assert_called_once_with(self.session, mock_resource, 2, 120) + mock_wait.assert_called_once_with(self.proxy, mock_resource, 2, 120) @mock.patch("openstack.resource2.wait_for_delete") def test_wait_for_delete_params(self, mock_wait): @@ -565,4 +565,4 @@ class TestClusterProxy(test_proxy_base2.TestProxyBase): self.proxy.wait_for_delete(mock_resource, 1, 2) - mock_wait.assert_called_once_with(self.session, mock_resource, 1, 2) + mock_wait.assert_called_once_with(self.proxy, mock_resource, 1, 2) diff --git a/openstack/tests/unit/cluster/v1/test_receiver.py b/openstack/tests/unit/cluster/v1/test_receiver.py index bac16f006..39875b4ab 100644 --- a/openstack/tests/unit/cluster/v1/test_receiver.py +++ b/openstack/tests/unit/cluster/v1/test_receiver.py @@ -12,7 +12,7 @@ import testtools -from openstack.cluster.v1 import receiver +from openstack.clustering.v1 import receiver FAKE_ID = 'ae63a10b-4a90-452c-aef1-113a0b255ee3' diff --git a/openstack/tests/unit/cluster/v1/test_service.py b/openstack/tests/unit/cluster/v1/test_service.py index 20b3b1b51..cc94f42b4 100644 --- a/openstack/tests/unit/cluster/v1/test_service.py +++ b/openstack/tests/unit/cluster/v1/test_service.py @@ -13,7 +13,7 @@ import mock import testtools -from openstack.cluster.v1 import service +from openstack.clustering.v1 import service IDENTIFIER = 'IDENTIFIER' EXAMPLE = { diff --git a/openstack/tests/unit/compute/v2/test_metadata.py b/openstack/tests/unit/compute/v2/test_metadata.py index 458f931b1..8f2c4da64 100644 --- a/openstack/tests/unit/compute/v2/test_metadata.py +++ b/openstack/tests/unit/compute/v2/test_metadata.py @@ -48,9 +48,9 @@ class TestMetadata(testtools.TestCase): result = sot.get_metadata(sess) self.assertEqual(result, self.metadata_result["metadata"]) - sess.get.assert_called_once_with("servers/IDENTIFIER/metadata", - headers={}, - endpoint_filter=sot.service) + sess.get.assert_called_once_with( + "servers/IDENTIFIER/metadata", + headers={}) def test_set_metadata(self): response = mock.Mock() @@ -66,7 +66,6 @@ class TestMetadata(testtools.TestCase): self.assertEqual(result, self.metadata_result["metadata"]) sess.post.assert_called_once_with("servers/IDENTIFIER/metadata", - endpoint_filter=sot.service, headers={}, json={"metadata": set_meta}) @@ -83,4 +82,4 @@ class TestMetadata(testtools.TestCase): sess.delete.assert_called_once_with( "servers/IDENTIFIER/metadata/" + key, headers={"Accept": ""}, - endpoint_filter=sot.service) + ) diff --git a/openstack/tests/unit/compute/v2/test_proxy.py b/openstack/tests/unit/compute/v2/test_proxy.py index a608a261d..39a971e6d 100644 --- a/openstack/tests/unit/compute/v2/test_proxy.py +++ b/openstack/tests/unit/compute/v2/test_proxy.py @@ -428,7 +428,7 @@ class TestComputeProxy(test_proxy_base2.TestProxyBase): self.proxy.get_server_metadata, method_args=["value"], method_result=server.Server(id="value", metadata={}), - expected_args=[self.session], + expected_args=[self.proxy], expected_result={}) def test_set_server_metadata(self): @@ -440,7 +440,7 @@ class TestComputeProxy(test_proxy_base2.TestProxyBase): method_kwargs=kwargs, method_result=server.Server.existing(id=id, metadata=kwargs), - expected_args=[self.session], + expected_args=[self.proxy], expected_kwargs=kwargs, expected_result=kwargs) @@ -449,7 +449,7 @@ class TestComputeProxy(test_proxy_base2.TestProxyBase): self.proxy.delete_server_metadata, expected_result=None, method_args=["value", "key"], - expected_args=[self.session, "key"]) + expected_args=[self.proxy, "key"]) def test_server_group_create(self): self.verify_create(self.proxy.create_server_group, diff --git a/openstack/tests/unit/compute/v2/test_server.py b/openstack/tests/unit/compute/v2/test_server.py index 80f5fa93e..601ec5f62 100644 --- a/openstack/tests/unit/compute/v2/test_server.py +++ b/openstack/tests/unit/compute/v2/test_server.py @@ -193,7 +193,7 @@ class TestServer(testtools.TestCase): body = {"changePassword": {"adminPass": "a"}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_reboot(self): sot = server.Server(**EXAMPLE) @@ -204,7 +204,7 @@ class TestServer(testtools.TestCase): body = {"reboot": {"type": "HARD"}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_force_delete(self): sot = server.Server(**EXAMPLE) @@ -215,7 +215,7 @@ class TestServer(testtools.TestCase): body = {'forceDelete': None} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_rebuild(self): sot = server.Server(**EXAMPLE) @@ -246,7 +246,7 @@ class TestServer(testtools.TestCase): } headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_rebuild_minimal(self): sot = server.Server(**EXAMPLE) @@ -270,7 +270,7 @@ class TestServer(testtools.TestCase): } headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_resize(self): sot = server.Server(**EXAMPLE) @@ -281,7 +281,7 @@ class TestServer(testtools.TestCase): body = {"resize": {"flavorRef": "2"}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_confirm_resize(self): sot = server.Server(**EXAMPLE) @@ -292,7 +292,7 @@ class TestServer(testtools.TestCase): body = {"confirmResize": None} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_revert_resize(self): sot = server.Server(**EXAMPLE) @@ -303,7 +303,7 @@ class TestServer(testtools.TestCase): body = {"revertResize": None} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_create_image(self): sot = server.Server(**EXAMPLE) @@ -316,7 +316,7 @@ class TestServer(testtools.TestCase): body = {"createImage": {'name': name, 'metadata': metadata}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_create_image_minimal(self): sot = server.Server(**EXAMPLE) @@ -328,7 +328,7 @@ class TestServer(testtools.TestCase): body = {"createImage": {'name': name}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=dict(sot.service), json=body, headers=headers) + url, json=body, headers=headers) def test_add_security_group(self): sot = server.Server(**EXAMPLE) @@ -339,7 +339,7 @@ class TestServer(testtools.TestCase): body = {"addSecurityGroup": {"name": "group"}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_remove_security_group(self): sot = server.Server(**EXAMPLE) @@ -350,7 +350,7 @@ class TestServer(testtools.TestCase): body = {"removeSecurityGroup": {"name": "group"}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_reset_state(self): sot = server.Server(**EXAMPLE) @@ -361,7 +361,7 @@ class TestServer(testtools.TestCase): body = {"os-resetState": {"state": 'active'}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_add_fixed_ip(self): sot = server.Server(**EXAMPLE) @@ -373,7 +373,7 @@ class TestServer(testtools.TestCase): body = {"addFixedIp": {"networkId": "NETWORK-ID"}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_remove_fixed_ip(self): sot = server.Server(**EXAMPLE) @@ -385,7 +385,7 @@ class TestServer(testtools.TestCase): body = {"removeFixedIp": {"address": "ADDRESS"}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_add_floating_ip(self): sot = server.Server(**EXAMPLE) @@ -397,7 +397,7 @@ class TestServer(testtools.TestCase): body = {"addFloatingIp": {"address": "FLOATING-IP"}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_add_floating_ip_with_fixed_addr(self): sot = server.Server(**EXAMPLE) @@ -410,7 +410,7 @@ class TestServer(testtools.TestCase): "fixed_address": "FIXED-ADDR"}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_remove_floating_ip(self): sot = server.Server(**EXAMPLE) @@ -422,7 +422,7 @@ class TestServer(testtools.TestCase): body = {"removeFloatingIp": {"address": "I-AM-FLOATING"}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_backup(self): sot = server.Server(**EXAMPLE) @@ -435,7 +435,7 @@ class TestServer(testtools.TestCase): "rotation": 1}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_pause(self): sot = server.Server(**EXAMPLE) @@ -447,7 +447,7 @@ class TestServer(testtools.TestCase): body = {"pause": None} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_unpause(self): sot = server.Server(**EXAMPLE) @@ -459,7 +459,7 @@ class TestServer(testtools.TestCase): body = {"unpause": None} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_suspend(self): sot = server.Server(**EXAMPLE) @@ -471,7 +471,7 @@ class TestServer(testtools.TestCase): body = {"suspend": None} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_resume(self): sot = server.Server(**EXAMPLE) @@ -483,7 +483,7 @@ class TestServer(testtools.TestCase): body = {"resume": None} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_lock(self): sot = server.Server(**EXAMPLE) @@ -495,7 +495,7 @@ class TestServer(testtools.TestCase): body = {"lock": None} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_unlock(self): sot = server.Server(**EXAMPLE) @@ -507,7 +507,7 @@ class TestServer(testtools.TestCase): body = {"unlock": None} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_rescue(self): sot = server.Server(**EXAMPLE) @@ -519,7 +519,7 @@ class TestServer(testtools.TestCase): body = {"rescue": {}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_rescue_with_options(self): sot = server.Server(**EXAMPLE) @@ -532,7 +532,7 @@ class TestServer(testtools.TestCase): 'rescue_image_ref': 'IMG-ID'}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_unrescue(self): sot = server.Server(**EXAMPLE) @@ -544,7 +544,7 @@ class TestServer(testtools.TestCase): body = {"unrescue": None} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_evacuate(self): sot = server.Server(**EXAMPLE) @@ -556,7 +556,7 @@ class TestServer(testtools.TestCase): body = {"evacuate": {}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_evacuate_with_options(self): sot = server.Server(**EXAMPLE) @@ -570,7 +570,7 @@ class TestServer(testtools.TestCase): 'force': True}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_start(self): sot = server.Server(**EXAMPLE) @@ -582,7 +582,7 @@ class TestServer(testtools.TestCase): body = {"os-start": None} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_stop(self): sot = server.Server(**EXAMPLE) @@ -594,7 +594,7 @@ class TestServer(testtools.TestCase): body = {"os-stop": None} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_shelve(self): sot = server.Server(**EXAMPLE) @@ -606,7 +606,7 @@ class TestServer(testtools.TestCase): body = {"shelve": None} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_unshelve(self): sot = server.Server(**EXAMPLE) @@ -618,7 +618,7 @@ class TestServer(testtools.TestCase): body = {"unshelve": None} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_migrate(self): sot = server.Server(**EXAMPLE) @@ -631,7 +631,7 @@ class TestServer(testtools.TestCase): headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_get_console_output(self): sot = server.Server(**EXAMPLE) @@ -643,7 +643,7 @@ class TestServer(testtools.TestCase): body = {'os-getConsoleOutput': {}} headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) res = sot.get_console_output(self.sess, length=1) @@ -653,7 +653,7 @@ class TestServer(testtools.TestCase): headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) def test_live_migrate(self): sot = server.Server(**EXAMPLE) @@ -672,4 +672,4 @@ class TestServer(testtools.TestCase): headers = {'Accept': ''} self.sess.post.assert_called_with( - url, endpoint_filter=sot.service, json=body, headers=headers) + url, json=body, headers=headers) diff --git a/openstack/tests/unit/compute/v2/test_service.py b/openstack/tests/unit/compute/v2/test_service.py index 0872cf08e..3a1e4ca40 100644 --- a/openstack/tests/unit/compute/v2/test_service.py +++ b/openstack/tests/unit/compute/v2/test_service.py @@ -68,7 +68,7 @@ class TestService(testtools.TestCase): 'forced_down': True, } self.sess.put.assert_called_with( - url, endpoint_filter=sot.service, json=body) + url, json=body) def test_enable(self): sot = service.Service(**EXAMPLE) @@ -82,7 +82,7 @@ class TestService(testtools.TestCase): 'host': 'host1', } self.sess.put.assert_called_with( - url, endpoint_filter=sot.service, json=body) + url, json=body) def test_disable(self): sot = service.Service(**EXAMPLE) @@ -96,7 +96,7 @@ class TestService(testtools.TestCase): 'host': 'host1', } self.sess.put.assert_called_with( - url, endpoint_filter=sot.service, json=body) + url, json=body) def test_disable_with_reason(self): sot = service.Service(**EXAMPLE) @@ -113,4 +113,4 @@ class TestService(testtools.TestCase): 'disabled_reason': reason } self.sess.put.assert_called_with( - url, endpoint_filter=sot.service, json=body) + url, json=body) diff --git a/openstack/tests/unit/database/v1/test_instance.py b/openstack/tests/unit/database/v1/test_instance.py index a13bed7b3..116f63b7c 100644 --- a/openstack/tests/unit/database/v1/test_instance.py +++ b/openstack/tests/unit/database/v1/test_instance.py @@ -70,7 +70,7 @@ class TestInstance(testtools.TestCase): self.assertEqual(response.body['user'], sot.enable_root_user(sess)) url = ("instances/%s/root" % IDENTIFIER) - sess.post.assert_called_with(url, endpoint_filter=sot.service) + sess.post.assert_called_with(url,) def test_is_root_enabled(self): sot = instance.Instance(**EXAMPLE) @@ -83,7 +83,7 @@ class TestInstance(testtools.TestCase): self.assertTrue(sot.is_root_enabled(sess)) url = ("instances/%s/root" % IDENTIFIER) - sess.get.assert_called_with(url, endpoint_filter=sot.service) + sess.get.assert_called_with(url,) def test_action_restart(self): sot = instance.Instance(**EXAMPLE) @@ -96,7 +96,7 @@ class TestInstance(testtools.TestCase): url = ("instances/%s/action" % IDENTIFIER) body = {'restart': {}} - sess.post.assert_called_with(url, endpoint_filter=sot.service, + sess.post.assert_called_with(url, json=body) def test_action_resize(self): @@ -111,7 +111,7 @@ class TestInstance(testtools.TestCase): url = ("instances/%s/action" % IDENTIFIER) body = {'resize': {'flavorRef': flavor}} - sess.post.assert_called_with(url, endpoint_filter=sot.service, + sess.post.assert_called_with(url, json=body) def test_action_resize_volume(self): @@ -126,5 +126,5 @@ class TestInstance(testtools.TestCase): url = ("instances/%s/action" % IDENTIFIER) body = {'resize': {'volume': size}} - sess.post.assert_called_with(url, endpoint_filter=sot.service, + sess.post.assert_called_with(url, json=body) diff --git a/openstack/tests/unit/image/v2/test_image.py b/openstack/tests/unit/image/v2/test_image.py index 2a3acf45f..5c0399f5b 100644 --- a/openstack/tests/unit/image/v2/test_image.py +++ b/openstack/tests/unit/image/v2/test_image.py @@ -13,6 +13,7 @@ import json import mock +import requests import testtools from openstack import exceptions @@ -79,6 +80,18 @@ EXAMPLE = { } +class FakeResponse(object): + def __init__(self, response, status_code=200, headers=None): + self.body = response + self.content = response + self.status_code = status_code + headers = headers if headers else {'content-type': 'application/json'} + self.headers = requests.structures.CaseInsensitiveDict(headers) + + def json(self): + return self.body + + class TestImage(testtools.TestCase): def setUp(self): @@ -166,14 +179,14 @@ class TestImage(testtools.TestCase): self.assertIsNone(sot.deactivate(self.sess)) self.sess.post.assert_called_with( 'images/IDENTIFIER/actions/deactivate', - endpoint_filter=sot.service) + ) def test_reactivate(self): sot = image.Image(**EXAMPLE) self.assertIsNone(sot.reactivate(self.sess)) self.sess.post.assert_called_with( 'images/IDENTIFIER/actions/reactivate', - endpoint_filter=sot.service) + ) def test_add_tag(self): sot = image.Image(**EXAMPLE) @@ -182,7 +195,7 @@ class TestImage(testtools.TestCase): self.assertIsNone(sot.add_tag(self.sess, tag)) self.sess.put.assert_called_with( 'images/IDENTIFIER/tags/%s' % tag, - endpoint_filter=sot.service) + ) def test_remove_tag(self): sot = image.Image(**EXAMPLE) @@ -191,14 +204,13 @@ class TestImage(testtools.TestCase): self.assertIsNone(sot.remove_tag(self.sess, tag)) self.sess.delete.assert_called_with( 'images/IDENTIFIER/tags/%s' % tag, - endpoint_filter=sot.service) + ) def test_upload(self): sot = image.Image(**EXAMPLE) self.assertIsNone(sot.upload(self.sess)) self.sess.put.assert_called_with('images/IDENTIFIER/file', - endpoint_filter=sot.service, data=sot.data, headers={"Content-Type": "application/octet-stream", @@ -207,14 +219,14 @@ class TestImage(testtools.TestCase): def test_download_checksum_match(self): sot = image.Image(**EXAMPLE) - resp = mock.Mock() - resp.content = b"abc" - resp.headers = {"Content-MD5": "900150983cd24fb0d6963f7d28e17f72"} + resp = FakeResponse( + b"abc", + headers={"Content-MD5": "900150983cd24fb0d6963f7d28e17f72", + "Content-Type": "application/octet-stream"}) self.sess.get.return_value = resp rv = sot.download(self.sess) self.sess.get.assert_called_with('images/IDENTIFIER/file', - endpoint_filter=sot.service, stream=False) self.assertEqual(rv, resp.content) @@ -222,9 +234,10 @@ class TestImage(testtools.TestCase): def test_download_checksum_mismatch(self): sot = image.Image(**EXAMPLE) - resp = mock.Mock() - resp.content = b"abc" - resp.headers = {"Content-MD5": "the wrong checksum"} + resp = FakeResponse( + b"abc", + headers={"Content-MD5": "the wrong checksum", + "Content-Type": "application/octet-stream"}) self.sess.get.return_value = resp self.assertRaises(exceptions.InvalidResponse, sot.download, self.sess) @@ -232,35 +245,29 @@ class TestImage(testtools.TestCase): def test_download_no_checksum_header(self): sot = image.Image(**EXAMPLE) - resp1 = mock.Mock() - resp1.content = b"abc" - resp1.headers = {"no_checksum_here": ""} + resp1 = FakeResponse( + b"abc", headers={"Content-Type": "application/octet-stream"}) - resp2 = mock.Mock() - resp2.json = mock.Mock( - return_value={"checksum": "900150983cd24fb0d6963f7d28e17f72"}) - resp2.headers = {"": ""} + resp2 = FakeResponse( + {"checksum": "900150983cd24fb0d6963f7d28e17f72"}) self.sess.get.side_effect = [resp1, resp2] rv = sot.download(self.sess) self.sess.get.assert_has_calls( - [mock.call('images/IDENTIFIER/file', endpoint_filter=sot.service, + [mock.call('images/IDENTIFIER/file', stream=False), - mock.call('images/IDENTIFIER', endpoint_filter=sot.service)]) + mock.call('images/IDENTIFIER',)]) self.assertEqual(rv, resp1.content) def test_download_no_checksum_at_all2(self): sot = image.Image(**EXAMPLE) - resp1 = mock.Mock() - resp1.content = b"abc" - resp1.headers = {"no_checksum_here": ""} + resp1 = FakeResponse( + b"abc", headers={"Content-Type": "application/octet-stream"}) - resp2 = mock.Mock() - resp2.json = mock.Mock(return_value={"checksum": None}) - resp2.headers = {"": ""} + resp2 = FakeResponse({"checksum": None}) self.sess.get.side_effect = [resp1, resp2] @@ -274,24 +281,23 @@ class TestImage(testtools.TestCase): log.records[0].msg) self.sess.get.assert_has_calls( - [mock.call('images/IDENTIFIER/file', endpoint_filter=sot.service, + [mock.call('images/IDENTIFIER/file', stream=False), - mock.call('images/IDENTIFIER', endpoint_filter=sot.service)]) + mock.call('images/IDENTIFIER',)]) self.assertEqual(rv, resp1.content) def test_download_stream(self): sot = image.Image(**EXAMPLE) - resp = mock.Mock() - resp.content = b"abc" - resp.headers = {"Content-MD5": "900150983cd24fb0d6963f7d28e17f72"} + resp = FakeResponse( + b"abc", + headers={"Content-MD5": "900150983cd24fb0d6963f7d28e17f72", + "Content-Type": "application/octet-stream"}) self.sess.get.return_value = resp rv = sot.download(self.sess, stream=True) - self.sess.get.assert_called_with('images/IDENTIFIER/file', - endpoint_filter=sot.service, - stream=True) + self.sess.get.assert_called_with('images/IDENTIFIER/file', stream=True) self.assertEqual(rv, resp) diff --git a/openstack/tests/unit/image/v2/test_proxy.py b/openstack/tests/unit/image/v2/test_proxy.py index 8bb060c77..0fafcd927 100644 --- a/openstack/tests/unit/image/v2/test_proxy.py +++ b/openstack/tests/unit/image/v2/test_proxy.py @@ -47,7 +47,7 @@ class TestImageProxy(test_proxy_base2.TestProxyBase): container_format="x", disk_format="y", name="z") - created_image.upload.assert_called_with(self.session) + created_image.upload.assert_called_with(self.proxy) self.assertEqual(rv, created_image) def test_image_delete(self): diff --git a/openstack/tests/unit/key_manager/v1/test_secret.py b/openstack/tests/unit/key_manager/v1/test_secret.py index 9e103ecbf..31814bee8 100644 --- a/openstack/tests/unit/key_manager/v1/test_secret.py +++ b/openstack/tests/unit/key_manager/v1/test_secret.py @@ -94,8 +94,7 @@ class TestSecret(testtools.TestCase): sot.get(sess) - sess.get.assert_called_once_with("secrets/id", - endpoint_filter=sot.service) + sess.get.assert_called_once_with("secrets/id") def _test_payload(self, sot, metadata, content_type): content_type = "some/type" @@ -114,8 +113,8 @@ class TestSecret(testtools.TestCase): rv = sot.get(sess) sess.get.assert_has_calls( - [mock.call("secrets/id", endpoint_filter=sot.service), - mock.call("secrets/id/payload", endpoint_filter=sot.service, + [mock.call("secrets/id",), + mock.call("secrets/id/payload", headers={"Accept": content_type})]) self.assertEqual(rv.payload, payload) diff --git a/openstack/tests/unit/message/v1/test_claim.py b/openstack/tests/unit/message/v1/test_claim.py index cbfeb9f9c..f6490a3d0 100644 --- a/openstack/tests/unit/message/v1/test_claim.py +++ b/openstack/tests/unit/message/v1/test_claim.py @@ -63,7 +63,7 @@ class TestClaim(testtools.TestCase): url = '/queues/%s/claims' % QUEUE sess.post.assert_called_with( - url, endpoint_filter=sot.service, + url, headers={'Client-ID': CLIENT}, params=None, data=json.dumps(FAKE, cls=claim.ClaimEncoder)) diff --git a/openstack/tests/unit/message/v1/test_message.py b/openstack/tests/unit/message/v1/test_message.py index 6fe5d26ad..e3cd59a7f 100644 --- a/openstack/tests/unit/message/v1/test_message.py +++ b/openstack/tests/unit/message/v1/test_message.py @@ -60,7 +60,7 @@ class TestMessage(testtools.TestCase): url = '/queues/%s/messages' % QUEUE sess.post.assert_called_with( - url, endpoint_filter=sot.service, + url, headers={'Client-ID': CLIENT}, data=mock.ANY) @@ -81,5 +81,5 @@ class TestMessage(testtools.TestCase): url = '/queues/%s/messages/1234' % QUEUE sess.delete.assert_called_with( - url, endpoint_filter=sot.service, + url, headers={'Client-ID': CLIENT, 'Accept': ''}) diff --git a/openstack/tests/unit/message/v1/test_proxy.py b/openstack/tests/unit/message/v1/test_proxy.py index 8436f024f..6f3c4a5ee 100644 --- a/openstack/tests/unit/message/v1/test_proxy.py +++ b/openstack/tests/unit/message/v1/test_proxy.py @@ -39,17 +39,17 @@ class TestMessageProxy(test_proxy_base.TestProxyBase): self.proxy.create_messages, expected_result="result", method_args=[[]], - expected_args=[self.session, []]) + expected_args=[self.proxy, []]) def test_messages_claim(self): self._verify2("openstack.message.v1.claim.Claim.claim_messages", self.proxy.claim_messages, expected_result="result", method_args=[claim.Claim], - expected_args=[self.session, claim.Claim]) + expected_args=[self.proxy, claim.Claim]) def test_message_delete(self): self._verify2("openstack.message.v1.message.Message.delete_by_id", self.proxy.delete_message, method_args=[message.Message], - expected_args=[self.session, message.Message]) + expected_args=[self.proxy, message.Message]) diff --git a/openstack/tests/unit/message/v1/test_queue.py b/openstack/tests/unit/message/v1/test_queue.py index 81b07df7f..0e62b0fec 100644 --- a/openstack/tests/unit/message/v1/test_queue.py +++ b/openstack/tests/unit/message/v1/test_queue.py @@ -49,7 +49,7 @@ class TestQueue(testtools.TestCase): url = 'queues/%s' % FAKE_NAME headers = {'Accept': ''} - sess.put.assert_called_with(url, endpoint_filter=sot.service, + sess.put.assert_called_with(url, headers=headers) self.assertEqual(FAKE_NAME, sot.id) self.assertEqual(FAKE_NAME, sot.name) diff --git a/openstack/tests/unit/message/v2/test_claim.py b/openstack/tests/unit/message/v2/test_claim.py index 945829148..649f3ca51 100644 --- a/openstack/tests/unit/message/v2/test_claim.py +++ b/openstack/tests/unit/message/v2/test_claim.py @@ -81,7 +81,7 @@ class TestClaim(testtools.TestCase): url = "/queues/%(queue)s/claims" % {"queue": FAKE.pop("queue_name")} headers = {"Client-ID": "NEW_CLIENT_ID", "X-PROJECT-ID": "NEW_PROJECT_ID"} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, headers=headers, json=FAKE) sess.get_project_id.assert_called_once_with() self.assertEqual(sot, res) @@ -103,7 +103,7 @@ class TestClaim(testtools.TestCase): url = "/queues/%(queue)s/claims" % {"queue": FAKE.pop("queue_name")} headers = {"Client-ID": "NEW_CLIENT_ID", "X-PROJECT-ID": "NEW_PROJECT_ID"} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, headers=headers, json=FAKE) sess.get_project_id.assert_called_once_with() self.assertEqual(sot, res) @@ -123,7 +123,7 @@ class TestClaim(testtools.TestCase): url = "/queues/%(queue)s/claims" % {"queue": FAKE.pop("queue_name")} headers = {"Client-ID": FAKE.pop("client_id"), "X-PROJECT-ID": FAKE.pop("project_id")} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, headers=headers, json=FAKE) self.assertEqual(sot, res) @@ -143,7 +143,7 @@ class TestClaim(testtools.TestCase): "queue": FAKE1["queue_name"], "claim": FAKE1["id"]} headers = {"Client-ID": "NEW_CLIENT_ID", "X-PROJECT-ID": "NEW_PROJECT_ID"} - sess.get.assert_called_with(url, endpoint_filter=sot.service, + sess.get.assert_called_with(url, headers=headers) sess.get_project_id.assert_called_once_with() sot._translate_response.assert_called_once_with(resp) @@ -162,7 +162,7 @@ class TestClaim(testtools.TestCase): "queue": FAKE2["queue_name"], "claim": FAKE2["id"]} headers = {"Client-ID": "OLD_CLIENT_ID", "X-PROJECT-ID": "OLD_PROJECT_ID"} - sess.get.assert_called_with(url, endpoint_filter=sot.service, + sess.get.assert_called_with(url, headers=headers) sot._translate_response.assert_called_once_with(resp) self.assertEqual(sot, res) @@ -183,7 +183,7 @@ class TestClaim(testtools.TestCase): "queue": FAKE.pop("queue_name"), "claim": FAKE["id"]} headers = {"Client-ID": "NEW_CLIENT_ID", "X-PROJECT-ID": "NEW_PROJECT_ID"} - sess.patch.assert_called_with(url, endpoint_filter=sot.service, + sess.patch.assert_called_with(url, headers=headers, json=FAKE) sess.get_project_id.assert_called_once_with() self.assertEqual(sot, res) @@ -201,7 +201,7 @@ class TestClaim(testtools.TestCase): "queue": FAKE.pop("queue_name"), "claim": FAKE["id"]} headers = {"Client-ID": FAKE.pop("client_id"), "X-PROJECT-ID": FAKE.pop("project_id")} - sess.patch.assert_called_with(url, endpoint_filter=sot.service, + sess.patch.assert_called_with(url, headers=headers, json=FAKE) self.assertEqual(sot, res) @@ -221,7 +221,7 @@ class TestClaim(testtools.TestCase): "queue": FAKE1["queue_name"], "claim": FAKE1["id"]} headers = {"Client-ID": "NEW_CLIENT_ID", "X-PROJECT-ID": "NEW_PROJECT_ID"} - sess.delete.assert_called_with(url, endpoint_filter=sot.service, + sess.delete.assert_called_with(url, headers=headers) sess.get_project_id.assert_called_once_with() sot._translate_response.assert_called_once_with(resp, has_body=False) @@ -239,6 +239,6 @@ class TestClaim(testtools.TestCase): "queue": FAKE2["queue_name"], "claim": FAKE2["id"]} headers = {"Client-ID": "OLD_CLIENT_ID", "X-PROJECT-ID": "OLD_PROJECT_ID"} - sess.delete.assert_called_with(url, endpoint_filter=sot.service, + sess.delete.assert_called_with(url, headers=headers) sot._translate_response.assert_called_once_with(resp, has_body=False) diff --git a/openstack/tests/unit/message/v2/test_message.py b/openstack/tests/unit/message/v2/test_message.py index d7541f5bc..9a095b1ef 100644 --- a/openstack/tests/unit/message/v2/test_message.py +++ b/openstack/tests/unit/message/v2/test_message.py @@ -98,7 +98,7 @@ class TestMessage(testtools.TestCase): url = '/queues/%(queue)s/messages' % {'queue': FAKE1['queue_name']} headers = {'Client-ID': 'NEW_CLIENT_ID', 'X-PROJECT-ID': 'NEW_PROJECT_ID'} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, headers=headers, json={'messages': messages}) sess.get_project_id.assert_called_once_with() @@ -131,7 +131,7 @@ class TestMessage(testtools.TestCase): url = '/queues/%(queue)s/messages' % {'queue': FAKE2['queue_name']} headers = {'Client-ID': 'OLD_CLIENT_ID', 'X-PROJECT-ID': 'OLD_PROJECT_ID'} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, headers=headers, json={'messages': messages}) resp.json.assert_called_once_with() @@ -153,7 +153,7 @@ class TestMessage(testtools.TestCase): 'queue': FAKE1['queue_name'], 'message': FAKE1['id']} headers = {'Client-ID': 'NEW_CLIENT_ID', 'X-PROJECT-ID': 'NEW_PROJECT_ID'} - sess.get.assert_called_with(url, endpoint_filter=sot.service, + sess.get.assert_called_with(url, headers=headers) sess.get_project_id.assert_called_once_with() sot._translate_response.assert_called_once_with(resp) @@ -175,7 +175,7 @@ class TestMessage(testtools.TestCase): res = sot.get(sess) headers = {'Client-ID': 'OLD_CLIENT_ID', 'X-PROJECT-ID': 'OLD_PROJECT_ID'} - sess.get.assert_called_with(url, endpoint_filter=sot.service, + sess.get.assert_called_with(url, headers=headers) sot._translate_response.assert_called_once_with(resp) self.assertEqual(sot, res) @@ -197,7 +197,7 @@ class TestMessage(testtools.TestCase): 'queue': FAKE1['queue_name'], 'message': FAKE1['id']} headers = {'Client-ID': 'NEW_CLIENT_ID', 'X-PROJECT-ID': 'NEW_PROJECT_ID'} - sess.delete.assert_called_with(url, endpoint_filter=sot.service, + sess.delete.assert_called_with(url, headers=headers) sess.get_project_id.assert_called_once_with() sot._translate_response.assert_called_once_with(resp, has_body=False) @@ -220,7 +220,7 @@ class TestMessage(testtools.TestCase): 'cid': 'CLAIM_ID'} headers = {'Client-ID': 'NEW_CLIENT_ID', 'X-PROJECT-ID': 'NEW_PROJECT_ID'} - sess.delete.assert_called_with(url, endpoint_filter=sot.service, + sess.delete.assert_called_with(url, headers=headers) sess.get_project_id.assert_called_once_with() sot._translate_response.assert_called_once_with(resp, has_body=False) @@ -239,6 +239,6 @@ class TestMessage(testtools.TestCase): 'queue': FAKE2['queue_name'], 'message': FAKE2['id']} headers = {'Client-ID': 'OLD_CLIENT_ID', 'X-PROJECT-ID': 'OLD_PROJECT_ID'} - sess.delete.assert_called_with(url, endpoint_filter=sot.service, + sess.delete.assert_called_with(url, headers=headers) sot._translate_response.assert_called_once_with(resp, has_body=False) diff --git a/openstack/tests/unit/message/v2/test_queue.py b/openstack/tests/unit/message/v2/test_queue.py index 566510c67..83acc66b4 100644 --- a/openstack/tests/unit/message/v2/test_queue.py +++ b/openstack/tests/unit/message/v2/test_queue.py @@ -73,7 +73,7 @@ class TestQueue(testtools.TestCase): url = 'queues/%s' % FAKE1['name'] headers = {'Client-ID': 'NEW_CLIENT_ID', 'X-PROJECT-ID': 'NEW_PROJECT_ID'} - sess.put.assert_called_with(url, endpoint_filter=sot.service, + sess.put.assert_called_with(url, headers=headers, json=FAKE1) sess.get_project_id.assert_called_once_with() sot._translate_response.assert_called_once_with(resp, has_body=False) @@ -91,7 +91,7 @@ class TestQueue(testtools.TestCase): url = 'queues/%s' % FAKE2['name'] headers = {'Client-ID': 'OLD_CLIENT_ID', 'X-PROJECT-ID': 'OLD_PROJECT_ID'} - sess.put.assert_called_with(url, endpoint_filter=sot.service, + sess.put.assert_called_with(url, headers=headers, json=FAKE1) sot._translate_response.assert_called_once_with(resp, has_body=False) self.assertEqual(sot, res) @@ -111,7 +111,7 @@ class TestQueue(testtools.TestCase): url = 'queues/%s' % FAKE1['name'] headers = {'Client-ID': 'NEW_CLIENT_ID', 'X-PROJECT-ID': 'NEW_PROJECT_ID'} - sess.get.assert_called_with(url, endpoint_filter=sot.service, + sess.get.assert_called_with(url, headers=headers) sess.get_project_id.assert_called_once_with() sot._translate_response.assert_called_once_with(resp) @@ -129,7 +129,7 @@ class TestQueue(testtools.TestCase): url = 'queues/%s' % FAKE2['name'] headers = {'Client-ID': 'OLD_CLIENT_ID', 'X-PROJECT-ID': 'OLD_PROJECT_ID'} - sess.get.assert_called_with(url, endpoint_filter=sot.service, + sess.get.assert_called_with(url, headers=headers) sot._translate_response.assert_called_once_with(resp) self.assertEqual(sot, res) @@ -149,7 +149,7 @@ class TestQueue(testtools.TestCase): url = 'queues/%s' % FAKE1['name'] headers = {'Client-ID': 'NEW_CLIENT_ID', 'X-PROJECT-ID': 'NEW_PROJECT_ID'} - sess.delete.assert_called_with(url, endpoint_filter=sot.service, + sess.delete.assert_called_with(url, headers=headers) sess.get_project_id.assert_called_once_with() sot._translate_response.assert_called_once_with(resp, has_body=False) @@ -166,6 +166,6 @@ class TestQueue(testtools.TestCase): url = 'queues/%s' % FAKE2['name'] headers = {'Client-ID': 'OLD_CLIENT_ID', 'X-PROJECT-ID': 'OLD_PROJECT_ID'} - sess.delete.assert_called_with(url, endpoint_filter=sot.service, + sess.delete.assert_called_with(url, headers=headers) sot._translate_response.assert_called_once_with(resp, has_body=False) diff --git a/openstack/tests/unit/message/v2/test_subscription.py b/openstack/tests/unit/message/v2/test_subscription.py index 47c165fc9..9c9c9e510 100644 --- a/openstack/tests/unit/message/v2/test_subscription.py +++ b/openstack/tests/unit/message/v2/test_subscription.py @@ -89,7 +89,7 @@ class TestSubscription(testtools.TestCase): "queue": FAKE.pop("queue_name")} headers = {"Client-ID": "NEW_CLIENT_ID", "X-PROJECT-ID": "NEW_PROJECT_ID"} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, headers=headers, json=FAKE) sess.get_project_id.assert_called_once_with() self.assertEqual(sot, res) @@ -108,7 +108,7 @@ class TestSubscription(testtools.TestCase): "queue": FAKE.pop("queue_name")} headers = {"Client-ID": FAKE.pop("client_id"), "X-PROJECT-ID": FAKE.pop("project_id")} - sess.post.assert_called_once_with(url, endpoint_filter=sot.service, + sess.post.assert_called_once_with(url, headers=headers, json=FAKE) self.assertEqual(sot, res) @@ -128,7 +128,7 @@ class TestSubscription(testtools.TestCase): "queue": FAKE1["queue_name"], "subscription": FAKE1["id"]} headers = {"Client-ID": "NEW_CLIENT_ID", "X-PROJECT-ID": "NEW_PROJECT_ID"} - sess.get.assert_called_with(url, endpoint_filter=sot.service, + sess.get.assert_called_with(url, headers=headers) sess.get_project_id.assert_called_once_with() sot._translate_response.assert_called_once_with(resp) @@ -147,7 +147,7 @@ class TestSubscription(testtools.TestCase): "queue": FAKE2["queue_name"], "subscription": FAKE2["id"]} headers = {"Client-ID": "OLD_CLIENT_ID", "X-PROJECT-ID": "OLD_PROJECT_ID"} - sess.get.assert_called_with(url, endpoint_filter=sot.service, + sess.get.assert_called_with(url, headers=headers) sot._translate_response.assert_called_once_with(resp) self.assertEqual(sot, res) @@ -168,7 +168,7 @@ class TestSubscription(testtools.TestCase): "queue": FAKE1["queue_name"], "subscription": FAKE1["id"]} headers = {"Client-ID": "NEW_CLIENT_ID", "X-PROJECT-ID": "NEW_PROJECT_ID"} - sess.delete.assert_called_with(url, endpoint_filter=sot.service, + sess.delete.assert_called_with(url, headers=headers) sess.get_project_id.assert_called_once_with() sot._translate_response.assert_called_once_with(resp, has_body=False) @@ -186,6 +186,6 @@ class TestSubscription(testtools.TestCase): "queue": FAKE2["queue_name"], "subscription": FAKE2["id"]} headers = {"Client-ID": "OLD_CLIENT_ID", "X-PROJECT-ID": "OLD_PROJECT_ID"} - sess.delete.assert_called_with(url, endpoint_filter=sot.service, + sess.delete.assert_called_with(url, headers=headers) sot._translate_response.assert_called_once_with(resp, has_body=False) diff --git a/openstack/tests/unit/telemetry/__init__.py b/openstack/tests/unit/meter/__init__.py similarity index 100% rename from openstack/tests/unit/telemetry/__init__.py rename to openstack/tests/unit/meter/__init__.py diff --git a/openstack/tests/unit/telemetry/alarm/__init__.py b/openstack/tests/unit/meter/alarm/__init__.py similarity index 100% rename from openstack/tests/unit/telemetry/alarm/__init__.py rename to openstack/tests/unit/meter/alarm/__init__.py diff --git a/openstack/tests/unit/telemetry/alarm/test_alarm_service.py b/openstack/tests/unit/meter/alarm/test_alarm_service.py similarity index 95% rename from openstack/tests/unit/telemetry/alarm/test_alarm_service.py rename to openstack/tests/unit/meter/alarm/test_alarm_service.py index 8106e961f..3f6ffea85 100644 --- a/openstack/tests/unit/telemetry/alarm/test_alarm_service.py +++ b/openstack/tests/unit/meter/alarm/test_alarm_service.py @@ -12,7 +12,7 @@ import testtools -from openstack.telemetry.alarm import alarm_service +from openstack.meter.alarm import alarm_service class TestAlarmService(testtools.TestCase): diff --git a/openstack/tests/unit/telemetry/alarm/v2/__init__.py b/openstack/tests/unit/meter/alarm/v2/__init__.py similarity index 100% rename from openstack/tests/unit/telemetry/alarm/v2/__init__.py rename to openstack/tests/unit/meter/alarm/v2/__init__.py diff --git a/openstack/tests/unit/telemetry/alarm/v2/test_alarm.py b/openstack/tests/unit/meter/alarm/v2/test_alarm.py similarity index 95% rename from openstack/tests/unit/telemetry/alarm/v2/test_alarm.py rename to openstack/tests/unit/meter/alarm/v2/test_alarm.py index cd0cb1af5..ea35e4a92 100644 --- a/openstack/tests/unit/telemetry/alarm/v2/test_alarm.py +++ b/openstack/tests/unit/meter/alarm/v2/test_alarm.py @@ -13,7 +13,7 @@ import mock import testtools -from openstack.telemetry.alarm.v2 import alarm +from openstack.meter.alarm.v2 import alarm IDENTIFIER = 'IDENTIFIER' EXAMPLE = { @@ -96,12 +96,12 @@ class TestAlarm(testtools.TestCase): sot.check_state(self.sess) url = 'alarms/IDENTIFIER/state' - self.sess.get.assert_called_with(url, endpoint_filter=sot.service) + self.sess.get.assert_called_with(url,) def test_change_status(self): sot = alarm.Alarm(EXAMPLE) self.assertEqual(self.resp.body, sot.change_state(self.sess, 'alarm')) url = 'alarms/IDENTIFIER/state' - self.sess.put.assert_called_with(url, endpoint_filter=sot.service, + self.sess.put.assert_called_with(url, json='alarm') diff --git a/openstack/tests/unit/telemetry/alarm/v2/test_alarm_change.py b/openstack/tests/unit/meter/alarm/v2/test_alarm_change.py similarity index 98% rename from openstack/tests/unit/telemetry/alarm/v2/test_alarm_change.py rename to openstack/tests/unit/meter/alarm/v2/test_alarm_change.py index bd272440e..84326f4cb 100644 --- a/openstack/tests/unit/telemetry/alarm/v2/test_alarm_change.py +++ b/openstack/tests/unit/meter/alarm/v2/test_alarm_change.py @@ -13,7 +13,7 @@ import mock import testtools -from openstack.telemetry.alarm.v2 import alarm_change +from openstack.meter.alarm.v2 import alarm_change IDENTIFIER = 'IDENTIFIER' EXAMPLE = { diff --git a/openstack/tests/unit/telemetry/alarm/v2/test_proxy.py b/openstack/tests/unit/meter/alarm/v2/test_proxy.py similarity index 92% rename from openstack/tests/unit/telemetry/alarm/v2/test_proxy.py rename to openstack/tests/unit/meter/alarm/v2/test_proxy.py index 343db8916..fc839e52e 100644 --- a/openstack/tests/unit/telemetry/alarm/v2/test_proxy.py +++ b/openstack/tests/unit/meter/alarm/v2/test_proxy.py @@ -10,9 +10,9 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.telemetry.alarm.v2 import _proxy -from openstack.telemetry.alarm.v2 import alarm -from openstack.telemetry.alarm.v2 import alarm_change +from openstack.meter.alarm.v2 import _proxy +from openstack.meter.alarm.v2 import alarm +from openstack.meter.alarm.v2 import alarm_change from openstack.tests.unit import test_proxy_base diff --git a/openstack/tests/unit/telemetry/test_telemetry_service.py b/openstack/tests/unit/meter/test_meter_service.py similarity index 86% rename from openstack/tests/unit/telemetry/test_telemetry_service.py rename to openstack/tests/unit/meter/test_meter_service.py index acc7da94c..330c6f1d0 100644 --- a/openstack/tests/unit/telemetry/test_telemetry_service.py +++ b/openstack/tests/unit/meter/test_meter_service.py @@ -12,13 +12,13 @@ import testtools -from openstack.telemetry import telemetry_service +from openstack.meter import meter_service -class TestTelemetryService(testtools.TestCase): +class TestMeterService(testtools.TestCase): def test_service(self): - sot = telemetry_service.TelemetryService() + sot = meter_service.MeterService() self.assertEqual('metering', sot.service_type) self.assertEqual('public', sot.interface) self.assertIsNone(sot.region) diff --git a/openstack/tests/unit/telemetry/v2/__init__.py b/openstack/tests/unit/meter/v2/__init__.py similarity index 100% rename from openstack/tests/unit/telemetry/v2/__init__.py rename to openstack/tests/unit/meter/v2/__init__.py diff --git a/openstack/tests/unit/telemetry/v2/test_capability.py b/openstack/tests/unit/meter/v2/test_capability.py similarity index 98% rename from openstack/tests/unit/telemetry/v2/test_capability.py rename to openstack/tests/unit/meter/v2/test_capability.py index 8d37c8ae6..0cde8b56c 100644 --- a/openstack/tests/unit/telemetry/v2/test_capability.py +++ b/openstack/tests/unit/meter/v2/test_capability.py @@ -13,7 +13,7 @@ import mock import testtools -from openstack.telemetry.v2 import capability +from openstack.meter.v2 import capability EXAMPLE = { "id": "123", diff --git a/openstack/tests/unit/telemetry/v2/test_meter.py b/openstack/tests/unit/meter/v2/test_meter.py similarity index 97% rename from openstack/tests/unit/telemetry/v2/test_meter.py rename to openstack/tests/unit/meter/v2/test_meter.py index 83cdb8943..dced7f809 100644 --- a/openstack/tests/unit/telemetry/v2/test_meter.py +++ b/openstack/tests/unit/meter/v2/test_meter.py @@ -12,7 +12,7 @@ import testtools -from openstack.telemetry.v2 import meter +from openstack.meter.v2 import meter IDENTIFIER = 'IDENTIFIER' EXAMPLE = { diff --git a/openstack/tests/unit/telemetry/v2/test_proxy.py b/openstack/tests/unit/meter/v2/test_proxy.py similarity index 85% rename from openstack/tests/unit/telemetry/v2/test_proxy.py rename to openstack/tests/unit/meter/v2/test_proxy.py index 974dd8f01..76883e973 100644 --- a/openstack/tests/unit/telemetry/v2/test_proxy.py +++ b/openstack/tests/unit/meter/v2/test_proxy.py @@ -10,18 +10,18 @@ # License for the specific language governing permissions and limitations # under the License. -from openstack.telemetry.v2 import _proxy -from openstack.telemetry.v2 import capability -from openstack.telemetry.v2 import meter -from openstack.telemetry.v2 import resource -from openstack.telemetry.v2 import sample -from openstack.telemetry.v2 import statistics +from openstack.meter.v2 import _proxy +from openstack.meter.v2 import capability +from openstack.meter.v2 import meter +from openstack.meter.v2 import resource +from openstack.meter.v2 import sample +from openstack.meter.v2 import statistics from openstack.tests.unit import test_proxy_base2 -class TestTelemetryProxy(test_proxy_base2.TestProxyBase): +class TestMeterProxy(test_proxy_base2.TestProxyBase): def setUp(self): - super(TestTelemetryProxy, self).setUp() + super(TestMeterProxy, self).setUp() self.proxy = _proxy.Proxy(self.session) def test_capability_find(self): diff --git a/openstack/tests/unit/telemetry/v2/test_resource.py b/openstack/tests/unit/meter/v2/test_resource.py similarity index 98% rename from openstack/tests/unit/telemetry/v2/test_resource.py rename to openstack/tests/unit/meter/v2/test_resource.py index 62051830c..78bb937fa 100644 --- a/openstack/tests/unit/telemetry/v2/test_resource.py +++ b/openstack/tests/unit/meter/v2/test_resource.py @@ -12,7 +12,7 @@ import testtools -from openstack.telemetry.v2 import resource +from openstack.meter.v2 import resource IDENTIFIER = 'IDENTIFIER' LINKS = [{'href': 'first_uri', 'rel': 'label 1', }, diff --git a/openstack/tests/unit/telemetry/v2/test_sample.py b/openstack/tests/unit/meter/v2/test_sample.py similarity index 98% rename from openstack/tests/unit/telemetry/v2/test_sample.py rename to openstack/tests/unit/meter/v2/test_sample.py index 9c31427d9..ee2588512 100644 --- a/openstack/tests/unit/telemetry/v2/test_sample.py +++ b/openstack/tests/unit/meter/v2/test_sample.py @@ -13,7 +13,7 @@ import mock import testtools -from openstack.telemetry.v2 import sample +from openstack.meter.v2 import sample SAMPLE = { 'sample_id': '0', diff --git a/openstack/tests/unit/telemetry/v2/test_statistics.py b/openstack/tests/unit/meter/v2/test_statistics.py similarity index 96% rename from openstack/tests/unit/telemetry/v2/test_statistics.py rename to openstack/tests/unit/meter/v2/test_statistics.py index 71ea61b3e..8fd46f573 100644 --- a/openstack/tests/unit/telemetry/v2/test_statistics.py +++ b/openstack/tests/unit/meter/v2/test_statistics.py @@ -13,7 +13,7 @@ import mock import testtools -from openstack.telemetry.v2 import statistics +from openstack.meter.v2 import statistics EXAMPLE = { 'aggregate': '1', @@ -74,7 +74,7 @@ class TestStatistics(testtools.TestCase): url = '/meters/example/statistics' stat = next(reply) - sess.get.assert_called_with(url, endpoint_filter=stat.service, + sess.get.assert_called_with(url, params={}) self.assertEqual(EXAMPLE['aggregate'], stat.aggregate) self.assertEqual(EXAMPLE['avg'], stat.avg) diff --git a/openstack/tests/unit/network/v2/test_agent.py b/openstack/tests/unit/network/v2/test_agent.py index 6eddcb27e..80bbbbd47 100644 --- a/openstack/tests/unit/network/v2/test_agent.py +++ b/openstack/tests/unit/network/v2/test_agent.py @@ -78,7 +78,7 @@ class TestAgent(testtools.TestCase): self.assertEqual(response.body, net.add_agent_to_network(sess, **body)) url = 'agents/IDENTIFIER/dhcp-networks' - sess.post.assert_called_with(url, endpoint_filter=net.service, + sess.post.assert_called_with(url, json=body) def test_remove_agent_from_network(self): @@ -90,7 +90,7 @@ class TestAgent(testtools.TestCase): body = {'network_id': {}} sess.delete.assert_called_with('agents/IDENTIFIER/dhcp-networks/', - endpoint_filter=net.service, json=body) + json=body) def test_add_router_to_agent(self): # Add router to agent @@ -105,7 +105,7 @@ class TestAgent(testtools.TestCase): sot.add_router_to_agent(sess, router_id)) body = {'router_id': router_id} url = 'agents/IDENTIFIER/l3-routers' - sess.post.assert_called_with(url, endpoint_filter=sot.service, + sess.post.assert_called_with(url, json=body) def test_remove_router_from_agent(self): @@ -117,7 +117,7 @@ class TestAgent(testtools.TestCase): body = {'router_id': {}} sess.delete.assert_called_with('agents/IDENTIFIER/l3-routers/', - endpoint_filter=sot.service, json=body) + json=body) class TestNetworkHostingDHCPAgent(testtools.TestCase): diff --git a/openstack/tests/unit/network/v2/test_flavor.py b/openstack/tests/unit/network/v2/test_flavor.py index 9bf70d5a9..236511f20 100644 --- a/openstack/tests/unit/network/v2/test_flavor.py +++ b/openstack/tests/unit/network/v2/test_flavor.py @@ -76,7 +76,7 @@ class TestFlavor(testtools.TestCase): sess, '1')) url = 'flavors/IDENTIFIER/service_profiles' - sess.post.assert_called_with(url, endpoint_filter=flav.service, + sess.post.assert_called_with(url, json=response.body) def test_disassociate_flavor_from_service_profile(self): @@ -91,4 +91,4 @@ class TestFlavor(testtools.TestCase): sess, '1')) url = 'flavors/IDENTIFIER/service_profiles/1' - sess.delete.assert_called_with(url, endpoint_filter=flav.service) + sess.delete.assert_called_with(url,) diff --git a/openstack/tests/unit/network/v2/test_floating_ip.py b/openstack/tests/unit/network/v2/test_floating_ip.py index 4673233a0..a2448ac68 100644 --- a/openstack/tests/unit/network/v2/test_floating_ip.py +++ b/openstack/tests/unit/network/v2/test_floating_ip.py @@ -77,7 +77,6 @@ class TestFloatingIP(testtools.TestCase): self.assertEqual('one', result.id) mock_session.get.assert_called_with( floating_ip.FloatingIP.base_path, - endpoint_filter=floating_ip.FloatingIP.service, headers={'Accept': 'application/json'}, params={'port_id': ''}) diff --git a/openstack/tests/unit/network/v2/test_router.py b/openstack/tests/unit/network/v2/test_router.py index 5fb87f16c..8cf9359ca 100644 --- a/openstack/tests/unit/network/v2/test_router.py +++ b/openstack/tests/unit/network/v2/test_router.py @@ -125,7 +125,7 @@ class TestRouter(testtools.TestCase): self.assertEqual(response.body, sot.add_interface(sess, **body)) url = 'routers/IDENTIFIER/add_router_interface' - sess.put.assert_called_with(url, endpoint_filter=sot.service, + sess.put.assert_called_with(url, json=body) def test_add_interface_port(self): @@ -141,7 +141,7 @@ class TestRouter(testtools.TestCase): self.assertEqual(response.body, sot.add_interface(sess, **body)) url = 'routers/IDENTIFIER/add_router_interface' - sess.put.assert_called_with(url, endpoint_filter=sot.service, + sess.put.assert_called_with(url, json=body) def test_remove_interface_subnet(self): @@ -156,7 +156,7 @@ class TestRouter(testtools.TestCase): self.assertEqual(response.body, sot.remove_interface(sess, **body)) url = 'routers/IDENTIFIER/remove_router_interface' - sess.put.assert_called_with(url, endpoint_filter=sot.service, + sess.put.assert_called_with(url, json=body) def test_remove_interface_port(self): @@ -171,7 +171,7 @@ class TestRouter(testtools.TestCase): self.assertEqual(response.body, sot.remove_interface(sess, **body)) url = 'routers/IDENTIFIER/remove_router_interface' - sess.put.assert_called_with(url, endpoint_filter=sot.service, + sess.put.assert_called_with(url, json=body) def test_add_router_gateway(self): @@ -186,7 +186,7 @@ class TestRouter(testtools.TestCase): self.assertEqual(response.body, sot.add_gateway(sess, **body)) url = 'routers/IDENTIFIER/add_gateway_router' - sess.put.assert_called_with(url, endpoint_filter=sot.service, + sess.put.assert_called_with(url, json=body) def test_remove_router_gateway(self): @@ -201,7 +201,7 @@ class TestRouter(testtools.TestCase): self.assertEqual(response.body, sot.remove_gateway(sess, **body)) url = 'routers/IDENTIFIER/remove_gateway_router' - sess.put.assert_called_with(url, endpoint_filter=sot.service, + sess.put.assert_called_with(url, json=body) diff --git a/openstack/tests/unit/network/v2/test_tag.py b/openstack/tests/unit/network/v2/test_tag.py index b22ae87dc..102247457 100644 --- a/openstack/tests/unit/network/v2/test_tag.py +++ b/openstack/tests/unit/network/v2/test_tag.py @@ -40,5 +40,5 @@ class TestTag(testtools.TestCase): # Check the passed resource is returned self.assertEqual(net, result) url = 'networks/' + ID + '/tags' - sess.put.assert_called_once_with(url, endpoint_filter=net.service, + sess.put.assert_called_once_with(url, json={'tags': ['blue', 'green']}) diff --git a/openstack/tests/unit/object_store/v1/test_container.py b/openstack/tests/unit/object_store/v1/test_container.py index 587c7e470..c18c49421 100644 --- a/openstack/tests/unit/object_store/v1/test_container.py +++ b/openstack/tests/unit/object_store/v1/test_container.py @@ -143,7 +143,7 @@ class TestContainer(testtools.TestCase): sot_call(self.sess) url = "/%s" % CONTAINER_NAME - sess_method.assert_called_with(url, endpoint_filter=sot.service, + sess_method.assert_called_with(url, headers=headers) def test_create(self): @@ -159,7 +159,7 @@ class TestContainer(testtools.TestCase): sot.create(self.sess) url = "/%s" % CONTAINER_NAME headers = {'Accept': ''} - self.sess.put.assert_called_with(url, endpoint_filter=sot.service, + self.sess.put.assert_called_with(url, headers=headers) def test_create_no_headers(self): diff --git a/openstack/tests/unit/object_store/v1/test_obj.py b/openstack/tests/unit/object_store/v1/test_obj.py index 47a3b95ad..f3dfb793f 100644 --- a/openstack/tests/unit/object_store/v1/test_obj.py +++ b/openstack/tests/unit/object_store/v1/test_obj.py @@ -113,8 +113,9 @@ class TestObject(testtools.TestCase): # "if-match": {"who": "what"} # } headers = {'Accept': 'bytes'} - self.sess.get.assert_called_with(url, endpoint_filter=sot.service, - headers=headers) + self.sess.get.assert_called_with(url, + headers=headers, + error_message=None) self.assertEqual(self.resp.content, rv) def _test_create(self, method, data, accept): @@ -126,7 +127,7 @@ class TestObject(testtools.TestCase): rv = sot.create(self.sess) url = "%s/%s" % (CONTAINER_NAME, OBJECT_NAME) - method.assert_called_with(url, endpoint_filter=sot.service, data=data, + method.assert_called_with(url, data=data, headers=headers) self.assertEqual(self.resp.headers, rv.get_headers()) diff --git a/openstack/tests/unit/orchestration/v1/test_proxy.py b/openstack/tests/unit/orchestration/v1/test_proxy.py index 9628198a7..3289f5656 100644 --- a/openstack/tests/unit/orchestration/v1/test_proxy.py +++ b/openstack/tests/unit/orchestration/v1/test_proxy.py @@ -64,7 +64,7 @@ class TestOrchestrationProxy(test_proxy_base2.TestProxyBase): res = self.proxy.check_stack(stk) self.assertIsNone(res) - mock_check.assert_called_once_with(self.proxy._session) + mock_check.assert_called_once_with(self.proxy) @mock.patch.object(stack.Stack, 'existing') def test_check_stack_with_stack_ID(self, mock_stack): @@ -75,7 +75,7 @@ class TestOrchestrationProxy(test_proxy_base2.TestProxyBase): self.assertIsNone(res) mock_stack.assert_called_once_with(id='FAKE_ID') - stk.check.assert_called_once_with(self.proxy._session) + stk.check.assert_called_once_with(self.proxy) @mock.patch.object(stack.Stack, 'find') def test_get_stack_environment_with_stack_identity(self, mock_find): @@ -121,7 +121,7 @@ class TestOrchestrationProxy(test_proxy_base2.TestProxyBase): self.assertEqual({'file': 'content'}, res) mock_find.assert_called_once_with(mock.ANY, 'IDENTITY', ignore_missing=False) - mock_get.assert_called_once_with(self.proxy._session) + mock_get.assert_called_once_with(self.proxy) @mock.patch.object(stack_files.StackFiles, 'get') def test_get_stack_files_with_stack_object(self, mock_get): @@ -133,7 +133,7 @@ class TestOrchestrationProxy(test_proxy_base2.TestProxyBase): res = self.proxy.get_stack_files(stk) self.assertEqual({'file': 'content'}, res) - mock_get.assert_called_once_with(self.proxy._session) + mock_get.assert_called_once_with(self.proxy) @mock.patch.object(stack.Stack, 'find') def test_get_stack_template_with_stack_identity(self, mock_find): @@ -202,8 +202,7 @@ class TestOrchestrationProxy(test_proxy_base2.TestProxyBase): ex = self.assertRaises(exceptions.ResourceNotFound, self.proxy.resources, stack_name) - self.assertEqual('ResourceNotFound: No stack found for test_stack', - six.text_type(ex)) + self.assertEqual('No stack found for test_stack', six.text_type(ex)) def test_create_software_config(self): self.verify_create(self.proxy.create_software_config, @@ -254,7 +253,7 @@ class TestOrchestrationProxy(test_proxy_base2.TestProxyBase): res = self.proxy.validate_template(tmpl, env, tmpl_url, ignore_errors) mock_validate.assert_called_once_with( - self.proxy._session, tmpl, environment=env, template_url=tmpl_url, + self.proxy, tmpl, environment=env, template_url=tmpl_url, ignore_errors=ignore_errors) self.assertEqual(mock_validate.return_value, res) diff --git a/openstack/tests/unit/orchestration/v1/test_stack.py b/openstack/tests/unit/orchestration/v1/test_stack.py index 4ca0d2bad..fc91d720d 100644 --- a/openstack/tests/unit/orchestration/v1/test_stack.py +++ b/openstack/tests/unit/orchestration/v1/test_stack.py @@ -132,9 +132,9 @@ class TestStack(testtools.TestCase): self.assertEqual(normal_stack, sot.get(sess)) ex = self.assertRaises(exceptions.NotFoundException, sot.get, sess) - self.assertEqual('NotFoundException: oops', six.text_type(ex)) + self.assertEqual('oops', six.text_type(ex)) ex = self.assertRaises(exceptions.NotFoundException, sot.get, sess) - self.assertEqual('NotFoundException: No stack found for %s' % FAKE_ID, + self.assertEqual('No stack found for %s' % FAKE_ID, six.text_type(ex)) diff --git a/openstack/tests/unit/orchestration/v1/test_stack_files.py b/openstack/tests/unit/orchestration/v1/test_stack_files.py index 989121a14..fe2d47c4e 100644 --- a/openstack/tests/unit/orchestration/v1/test_stack_files.py +++ b/openstack/tests/unit/orchestration/v1/test_stack_files.py @@ -50,12 +50,12 @@ class TestStackFiles(testtools.TestCase): sot.service = mock.Mock() req = mock.MagicMock() - req.uri = ('/stacks/%(stack_name)s/%(stack_id)s/files' % + req.url = ('/stacks/%(stack_name)s/%(stack_id)s/files' % {'stack_name': FAKE['stack_name'], 'stack_id': FAKE['stack_id']}) mock_prepare_request.return_value = req files = sot.get(sess) - sess.get.assert_called_once_with(req.uri, endpoint_filter=sot.service) + sess.get.assert_called_once_with(req.url) self.assertEqual({'file': 'file-content'}, files) diff --git a/openstack/tests/unit/orchestration/v1/test_template.py b/openstack/tests/unit/orchestration/v1/test_template.py index c92b0ae79..24d7a369d 100644 --- a/openstack/tests/unit/orchestration/v1/test_template.py +++ b/openstack/tests/unit/orchestration/v1/test_template.py @@ -58,7 +58,7 @@ class TestTemplate(testtools.TestCase): sot.validate(sess, tmpl) sess.post.assert_called_once_with( - '/validate', endpoint_filter=sot.service, json=body) + '/validate', json=body) mock_translate.assert_called_once_with(sess.post.return_value) @mock.patch.object(resource.Resource, '_translate_response') @@ -72,7 +72,7 @@ class TestTemplate(testtools.TestCase): sot.validate(sess, tmpl, environment=env) sess.post.assert_called_once_with( - '/validate', endpoint_filter=sot.service, json=body) + '/validate', json=body) mock_translate.assert_called_once_with(sess.post.return_value) @mock.patch.object(resource.Resource, '_translate_response') @@ -85,7 +85,7 @@ class TestTemplate(testtools.TestCase): sot.validate(sess, None, template_url=template_url) sess.post.assert_called_once_with( - '/validate', endpoint_filter=sot.service, json=body) + '/validate', json=body) mock_translate.assert_called_once_with(sess.post.return_value) @mock.patch.object(resource.Resource, '_translate_response') @@ -99,5 +99,5 @@ class TestTemplate(testtools.TestCase): sess.post.assert_called_once_with( '/validate?ignore_errors=123%2C456', - endpoint_filter=sot.service, json=body) + json=body) mock_translate.assert_called_once_with(sess.post.return_value) diff --git a/openstack/tests/unit/test_connection.py b/openstack/tests/unit/test_connection.py index 500c067a2..5a87366c2 100644 --- a/openstack/tests/unit/test_connection.py +++ b/openstack/tests/unit/test_connection.py @@ -13,14 +13,11 @@ import os import fixtures -from keystoneauth1 import session as ksa_session +from keystoneauth1 import session import mock -import openstack.config from openstack import connection -from openstack import exceptions -from openstack import profile -from openstack import session +import openstack.config from openstack.tests.unit import base @@ -46,7 +43,7 @@ clouds: password: {password} project_name: {project} cacert: {cacert} - insecure: True + verify: False cacert: auth: auth_url: {auth_url} @@ -54,109 +51,15 @@ clouds: password: {password} project_name: {project} cacert: {cacert} - insecure: False """.format(auth_url=CONFIG_AUTH_URL, username=CONFIG_USERNAME, password=CONFIG_PASSWORD, project=CONFIG_PROJECT, cacert=CONFIG_CACERT) -class TestConnection(base.TestCase): - @mock.patch("openstack.session.Session") - def test_other_parameters(self, mock_session_init): - mock_session_init.return_value = mock_session_init - mock_profile = mock.Mock() - mock_profile.get_services = mock.Mock(return_value=[]) - conn = connection.Connection(profile=mock_profile, authenticator='2', - verify=True, cert='cert', user_agent='1') - args = {'auth': '2', 'user_agent': '1', 'verify': True, 'cert': 'cert'} - mock_session_init.assert_called_with(mock_profile, **args) - self.assertEqual(mock_session_init, conn.session) +class TestConnection(base.RequestsMockTestCase): - def test_session_provided(self): - mock_session = mock.Mock(spec=session.Session) - mock_profile = mock.Mock() - mock_profile.get_services = mock.Mock(return_value=[]) - conn = connection.Connection(session=mock_session, - profile=mock_profile, - user_agent='1') - self.assertEqual(mock_session, conn.session) - - def test_ksa_session_provided(self): - mock_session = mock.Mock(spec=ksa_session.Session) - mock_profile = mock.Mock() - mock_profile.get_services = mock.Mock(return_value=[]) - self.assertRaises(exceptions.SDKException, connection.Connection, - session=mock_session, profile=mock_profile, - user_agent='1') - - @mock.patch("keystoneauth1.loading.base.get_plugin_loader") - def test_create_authenticator(self, mock_get_plugin): - mock_plugin = mock.Mock() - mock_loader = mock.Mock() - mock_options = [ - mock.Mock(dest="auth_url"), - mock.Mock(dest="password"), - mock.Mock(dest="username"), - ] - mock_loader.get_options = mock.Mock(return_value=mock_options) - mock_loader.load_from_options = mock.Mock(return_value=mock_plugin) - mock_get_plugin.return_value = mock_loader - auth_args = { - 'auth_url': '0', - 'username': '1', - 'password': '2', - } - conn = connection.Connection(auth_plugin='v2password', **auth_args) - mock_get_plugin.assert_called_with('v2password') - mock_loader.load_from_options.assert_called_with(**auth_args) - self.assertEqual(mock_plugin, conn.authenticator) - - @mock.patch("keystoneauth1.loading.base.get_plugin_loader") - def test_default_plugin(self, mock_get_plugin): - connection.Connection() - self.assertTrue(mock_get_plugin.called) - self.assertEqual(mock_get_plugin.call_args, mock.call("password")) - - @mock.patch("keystoneauth1.loading.base.get_plugin_loader") - def test_pass_authenticator(self, mock_get_plugin): - mock_plugin = mock.Mock() - mock_get_plugin.return_value = None - conn = connection.Connection(authenticator=mock_plugin) - self.assertFalse(mock_get_plugin.called) - self.assertEqual(mock_plugin, conn.authenticator) - - def test_create_session(self): - auth = mock.Mock() - prof = profile.Profile() - conn = connection.Connection(authenticator=auth, profile=prof) - self.assertEqual(auth, conn.authenticator) - self.assertEqual(prof, conn.profile) - self.assertEqual('openstack.telemetry.alarm.v2._proxy', - conn.alarm.__class__.__module__) - self.assertEqual('openstack.cluster.v1._proxy', - conn.cluster.__class__.__module__) - self.assertEqual('openstack.compute.v2._proxy', - conn.compute.__class__.__module__) - self.assertEqual('openstack.database.v1._proxy', - conn.database.__class__.__module__) - self.assertEqual('openstack.identity.v3._proxy', - conn.identity.__class__.__module__) - self.assertEqual('openstack.image.v2._proxy', - conn.image.__class__.__module__) - self.assertEqual('openstack.network.v2._proxy', - conn.network.__class__.__module__) - self.assertEqual('openstack.object_store.v1._proxy', - conn.object_store.__class__.__module__) - self.assertEqual('openstack.load_balancer.v2._proxy', - conn.load_balancer.__class__.__module__) - self.assertEqual('openstack.orchestration.v1._proxy', - conn.orchestration.__class__.__module__) - self.assertEqual('openstack.telemetry.v2._proxy', - conn.telemetry.__class__.__module__) - self.assertEqual('openstack.workflow.v2._proxy', - conn.workflow.__class__.__module__) - - def _prepare_test_config(self): + def setUp(self): + super(TestConnection, self).setUp() # Create a temporary directory where our test config will live # and insert it into the search path via OS_CLIENT_CONFIG_FILE. config_dir = self.useFixture(fixtures.TempDir()).path @@ -168,39 +71,69 @@ class TestConnection(base.TestCase): self.useFixture(fixtures.EnvironmentVariable( "OS_CLIENT_CONFIG_FILE", config_path)) - def test_from_config_given_data(self): - self._prepare_test_config() + def test_other_parameters(self): + conn = connection.Connection(cloud='sample', cert='cert') + self.assertEqual(conn.session.cert, 'cert') + def test_session_provided(self): + mock_session = mock.Mock(spec=session.Session) + conn = connection.Connection(session=mock_session, cert='cert') + self.assertEqual(mock_session, conn.session) + + def test_create_session(self): + conn = connection.Connection(cloud='sample') + self.assertEqual('openstack.proxy2', + conn.alarm.__class__.__module__) + self.assertEqual('openstack.clustering.v1._proxy', + conn.clustering.__class__.__module__) + self.assertEqual('openstack.compute.v2._proxy', + conn.compute.__class__.__module__) + self.assertEqual('openstack.database.v1._proxy', + conn.database.__class__.__module__) + self.assertEqual('openstack.identity.v2._proxy', + conn.identity.__class__.__module__) + self.assertEqual('openstack.image.v2._proxy', + conn.image.__class__.__module__) + self.assertEqual('openstack.network.v2._proxy', + conn.network.__class__.__module__) + self.assertEqual('openstack.object_store.v1._proxy', + conn.object_store.__class__.__module__) + self.assertEqual('openstack.load_balancer.v2._proxy', + conn.load_balancer.__class__.__module__) + self.assertEqual('openstack.orchestration.v1._proxy', + conn.orchestration.__class__.__module__) + self.assertEqual('openstack.meter.v2._proxy', + conn.meter.__class__.__module__) + self.assertEqual('openstack.workflow.v2._proxy', + conn.workflow.__class__.__module__) + + def test_from_config_given_data(self): data = openstack.config.OpenStackConfig().get_one_cloud("sample") sot = connection.from_config(cloud_config=data) self.assertEqual(CONFIG_USERNAME, - sot.authenticator._username) + sot.config.config['auth']['username']) self.assertEqual(CONFIG_PASSWORD, - sot.authenticator._password) + sot.config.config['auth']['password']) self.assertEqual(CONFIG_AUTH_URL, - sot.authenticator.auth_url) + sot.config.config['auth']['auth_url']) self.assertEqual(CONFIG_PROJECT, - sot.authenticator._project_name) + sot.config.config['auth']['project_name']) def test_from_config_given_name(self): - self._prepare_test_config() - sot = connection.from_config(cloud_name="sample") self.assertEqual(CONFIG_USERNAME, - sot.authenticator._username) + sot.config.config['auth']['username']) self.assertEqual(CONFIG_PASSWORD, - sot.authenticator._password) + sot.config.config['auth']['password']) self.assertEqual(CONFIG_AUTH_URL, - sot.authenticator.auth_url) + sot.config.config['auth']['auth_url']) self.assertEqual(CONFIG_PROJECT, - sot.authenticator._project_name) + sot.config.config['auth']['project_name']) def test_from_config_given_options(self): - self._prepare_test_config() - version = "100" class Opts(object): @@ -208,37 +141,24 @@ class TestConnection(base.TestCase): sot = connection.from_config(cloud_name="sample", options=Opts) - pref = sot.session.profile.get_filter("compute") - - # NOTE: Along the way, the `v` prefix gets added so we can build - # up URLs with it. - self.assertEqual("v" + version, pref.version) + self.assertEqual(version, sot.compute.version) def test_from_config_verify(self): - self._prepare_test_config() - sot = connection.from_config(cloud_name="insecure") self.assertFalse(sot.session.verify) sot = connection.from_config(cloud_name="cacert") self.assertEqual(CONFIG_CACERT, sot.session.verify) + +class TestAuthorize(base.RequestsMockTestCase): + def test_authorize_works(self): - fake_session = mock.Mock(spec=session.Session) - fake_headers = {'X-Auth-Token': 'FAKE_TOKEN'} - fake_session.get_auth_headers.return_value = fake_headers + res = self.conn.authorize() + self.assertEqual('KeystoneToken-1', res) - sot = connection.Connection(session=fake_session, - authenticator=mock.Mock()) - res = sot.authorize() - self.assertEqual('FAKE_TOKEN', res) + def test_authorize_failure(self): + self.use_broken_keystone() - def test_authorize_silent_failure(self): - fake_session = mock.Mock(spec=session.Session) - fake_session.get_auth_headers.return_value = None - fake_session.__module__ = 'openstack.session' - - sot = connection.Connection(session=fake_session, - authenticator=mock.Mock()) - res = sot.authorize() - self.assertIsNone(res) + self.assertRaises(openstack.exceptions.HttpException, + self.conn.authorize) diff --git a/openstack/tests/unit/test_exceptions.py b/openstack/tests/unit/test_exceptions.py index 54a95b1fb..9deb5bab2 100644 --- a/openstack/tests/unit/test_exceptions.py +++ b/openstack/tests/unit/test_exceptions.py @@ -54,4 +54,4 @@ class Test_HttpException(testtools.TestCase): http_status=http_status) self.assertEqual(self.message, exc.message) - self.assertEqual(http_status, exc.http_status) + self.assertEqual(http_status, exc.status_code) diff --git a/openstack/tests/unit/test_profile.py b/openstack/tests/unit/test_profile.py deleted file mode 100644 index c11d05f2a..000000000 --- a/openstack/tests/unit/test_profile.py +++ /dev/null @@ -1,106 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from openstack import exceptions -from openstack import profile -from openstack.tests.unit import base - - -class TestProfile(base.TestCase): - def test_init(self): - prof = profile.Profile() - expected = [ - 'alarming', - 'baremetal', - 'clustering', - 'compute', - 'database', - 'identity', - 'image', - 'key-manager', - 'load-balancer', - 'messaging', - 'metering', - 'network', - 'object-store', - 'orchestration', - 'volume', - 'workflowv2', - ] - self.assertEqual(expected, prof.service_keys) - - def test_default_versions(self): - prof = profile.Profile() - self.assertEqual('v1', prof.get_filter('baremetal').version) - self.assertEqual('v1', prof.get_filter('clustering').version) - self.assertEqual('v2', prof.get_filter('compute').version) - self.assertEqual('v1', prof.get_filter('database').version) - self.assertEqual('v3', prof.get_filter('identity').version) - self.assertEqual('v2', prof.get_filter('image').version) - self.assertEqual('v2', prof.get_filter('load-balancer').version) - self.assertEqual('v2', prof.get_filter('network').version) - self.assertEqual('v1', prof.get_filter('object-store').version) - self.assertEqual('v1', prof.get_filter('orchestration').version) - self.assertEqual('v1', prof.get_filter('key-manager').version) - self.assertEqual('v2', prof.get_filter('metering').version) - self.assertEqual('v2', prof.get_filter('volume').version) - self.assertEqual('v1', prof.get_filter('messaging').version) - - def test_set(self): - prof = profile.Profile() - prof.set_version('alarming', 'v2') - self.assertEqual('v2', prof.get_filter('alarming').version) - prof.set_version('baremetal', 'v1') - self.assertEqual('v1', prof.get_filter('baremetal').version) - prof.set_version('clustering', 'v1') - self.assertEqual('v1', prof.get_filter('clustering').version) - prof.set_version('compute', 'v2') - self.assertEqual('v2', prof.get_filter('compute').version) - prof.set_version('database', 'v3') - self.assertEqual('v3', prof.get_filter('database').version) - prof.set_version('identity', 'v4') - self.assertEqual('v4', prof.get_filter('identity').version) - prof.set_version('image', 'v5') - self.assertEqual('v5', prof.get_filter('image').version) - prof.set_version('metering', 'v6') - self.assertEqual('v6', prof.get_filter('metering').version) - prof.set_version('network', 'v7') - self.assertEqual('v7', prof.get_filter('network').version) - prof.set_version('object-store', 'v8') - self.assertEqual('v8', prof.get_filter('object-store').version) - prof.set_version('orchestration', 'v9') - self.assertEqual('v9', prof.get_filter('orchestration').version) - - def test_set_version_bad_service(self): - prof = profile.Profile() - self.assertRaises(exceptions.SDKException, prof.set_version, 'bogus', - 'v2') - - def test_set_api_version(self): - # This tests that api_version is effective after explicit setting, or - # else it defaults to None. - prof = profile.Profile() - prof.set_api_version('clustering', '1.2') - svc = prof.get_filter('clustering') - self.assertEqual('1.2', svc.api_version) - svc = prof.get_filter('compute') - self.assertIsNone(svc.api_version) - - def test_set_all(self): - prof = profile.Profile() - prof.set_name(prof.ALL, 'fee') - prof.set_region(prof.ALL, 'fie') - prof.set_interface(prof.ALL, 'public') - for service in prof.service_keys: - self.assertEqual('fee', prof.get_filter(service).service_name) - self.assertEqual('fie', prof.get_filter(service).region) - self.assertEqual('public', prof.get_filter(service).interface) diff --git a/openstack/tests/unit/test_proxy.py b/openstack/tests/unit/test_proxy.py index ec4f68075..6a9e9761c 100644 --- a/openstack/tests/unit/test_proxy.py +++ b/openstack/tests/unit/test_proxy.py @@ -103,11 +103,11 @@ class TestProxyDelete(testtools.TestCase): def test_delete(self): self.sot._delete(DeleteableResource, self.res) - self.res.delete.assert_called_with(self.session) + self.res.delete.assert_called_with(self.sot, error_message=mock.ANY) self.sot._delete(DeleteableResource, self.fake_id) DeleteableResource.existing.assert_called_with(id=self.fake_id) - self.res.delete.assert_called_with(self.session) + self.res.delete.assert_called_with(self.sot, error_message=mock.ANY) # Delete generally doesn't return anything, so we will normally # swallow any return from within a service's proxy, but make sure @@ -123,13 +123,12 @@ class TestProxyDelete(testtools.TestCase): rv = self.sot._delete(DeleteableResource, self.fake_id) self.assertIsNone(rv) - def test_delete_ResourceNotFound(self): + def test_delete_NotFound(self): self.res.delete.side_effect = exceptions.NotFoundException( message="test", http_status=404) self.assertRaisesRegex( - exceptions.ResourceNotFound, - "No %s found for %s" % (DeleteableResource.__name__, self.res), + exceptions.NotFoundException, "test", self.sot._delete, DeleteableResource, self.res, ignore_missing=False) @@ -166,7 +165,7 @@ class TestProxyUpdate(testtools.TestCase): self.assertEqual(rv, self.fake_result) self.res.update_attrs.assert_called_once_with(self.attrs) - self.res.update.assert_called_once_with(self.session) + self.res.update.assert_called_once_with(self.sot) def test_update_resource(self): self._test_update(self.res) @@ -196,7 +195,7 @@ class TestProxyCreate(testtools.TestCase): self.assertEqual(rv, self.fake_result) CreateableResource.new.assert_called_once_with(**attrs) - self.res.create.assert_called_once_with(self.session) + self.res.create.assert_called_once_with(self.sot) class TestProxyGet(testtools.TestCase): @@ -219,29 +218,35 @@ class TestProxyGet(testtools.TestCase): def test_get_resource(self): rv = self.sot._get(RetrieveableResource, self.res) - self.res.get.assert_called_with(self.session, args=None) + self.res.get.assert_called_with(self.sot, args=None, + error_message=mock.ANY) self.assertEqual(rv, self.fake_result) def test_get_resource_with_args(self): rv = self.sot._get(RetrieveableResource, self.res, args={'K': 'V'}) - self.res.get.assert_called_with(self.session, args={'K': 'V'}) + self.res.get.assert_called_with( + self.sot, args={'K': 'V'}, + error_message='No RetrieveableResource found for {res}'.format( + res=str(self.res))) self.assertEqual(rv, self.fake_result) def test_get_id(self): rv = self.sot._get(RetrieveableResource, self.fake_id) RetrieveableResource.existing.assert_called_with(id=self.fake_id) - self.res.get.assert_called_with(self.session, args=None) + self.res.get.assert_called_with(self.sot, args=None, + error_message=mock.ANY) self.assertEqual(rv, self.fake_result) def test_get_not_found(self): self.res.get.side_effect = exceptions.NotFoundException( message="test", http_status=404) + # TODO(shade) The mock here does not mock the right things, so we're + # not testing the actual exception mechanism. self.assertRaisesRegex( - exceptions.ResourceNotFound, - "No %s found for %s" % (RetrieveableResource.__name__, self.res), + exceptions.NotFoundException, "test", self.sot._get, RetrieveableResource, self.res) @@ -270,7 +275,7 @@ class TestProxyList(testtools.TestCase): self.assertEqual(self.fake_response, rv) ListableResource.list.assert_called_once_with( - self.session, path_args=path_args, paginated=paginated, + self.sot, path_args=path_args, paginated=paginated, params={'a': self.fake_a, 'b': self.fake_b}) def test_list_paginated(self): @@ -300,14 +305,14 @@ class TestProxyHead(testtools.TestCase): def test_head_resource(self): rv = self.sot._head(HeadableResource, self.res) - self.res.head.assert_called_with(self.session) + self.res.head.assert_called_with(self.sot) self.assertEqual(rv, self.fake_result) def test_head_id(self): rv = self.sot._head(HeadableResource, self.fake_id) HeadableResource.existing.assert_called_with(id=self.fake_id) - self.res.head.assert_called_with(self.session) + self.res.head.assert_called_with(self.sot) self.assertEqual(rv, self.fake_result) def test_head_no_value(self): @@ -318,7 +323,7 @@ class TestProxyHead(testtools.TestCase): self.sot._head(MockHeadResource) MockHeadResource.assert_called_with() - instance.head.assert_called_with(self.session) + instance.head.assert_called_with(self.sot) @mock.patch("openstack.resource.wait_for_status") def test_wait_for(self, mock_wait): @@ -326,7 +331,7 @@ class TestProxyHead(testtools.TestCase): mock_wait.return_value = mock_resource self.sot.wait_for_status(mock_resource, 'ACTIVE') mock_wait.assert_called_once_with( - self.session, mock_resource, 'ACTIVE', [], 2, 120) + self.sot, mock_resource, 'ACTIVE', [], 2, 120) @mock.patch("openstack.resource.wait_for_status") def test_wait_for_params(self, mock_wait): @@ -334,7 +339,7 @@ class TestProxyHead(testtools.TestCase): mock_wait.return_value = mock_resource self.sot.wait_for_status(mock_resource, 'ACTIVE', ['ERROR'], 1, 2) mock_wait.assert_called_once_with( - self.session, mock_resource, 'ACTIVE', ['ERROR'], 1, 2) + self.sot, mock_resource, 'ACTIVE', ['ERROR'], 1, 2) @mock.patch("openstack.resource.wait_for_delete") def test_wait_for_delete(self, mock_wait): @@ -342,7 +347,7 @@ class TestProxyHead(testtools.TestCase): mock_wait.return_value = mock_resource self.sot.wait_for_delete(mock_resource) mock_wait.assert_called_once_with( - self.session, mock_resource, 2, 120) + self.sot, mock_resource, 2, 120) @mock.patch("openstack.resource.wait_for_delete") def test_wait_for_delete_params(self, mock_wait): @@ -350,4 +355,4 @@ class TestProxyHead(testtools.TestCase): mock_wait.return_value = mock_resource self.sot.wait_for_delete(mock_resource, 1, 2) mock_wait.assert_called_once_with( - self.session, mock_resource, 1, 2) + self.sot, mock_resource, 1, 2) diff --git a/openstack/tests/unit/test_proxy2.py b/openstack/tests/unit/test_proxy2.py index 332012811..6c9832d63 100644 --- a/openstack/tests/unit/test_proxy2.py +++ b/openstack/tests/unit/test_proxy2.py @@ -175,11 +175,11 @@ class TestProxyDelete(testtools.TestCase): def test_delete(self): self.sot._delete(DeleteableResource, self.res) - self.res.delete.assert_called_with(self.session) + self.res.delete.assert_called_with(self.sot, error_message=mock.ANY) self.sot._delete(DeleteableResource, self.fake_id) DeleteableResource.new.assert_called_with(id=self.fake_id) - self.res.delete.assert_called_with(self.session) + self.res.delete.assert_called_with(self.sot, error_message=mock.ANY) # Delete generally doesn't return anything, so we will normally # swallow any return from within a service's proxy, but make sure @@ -195,13 +195,14 @@ class TestProxyDelete(testtools.TestCase): rv = self.sot._delete(DeleteableResource, self.fake_id) self.assertIsNone(rv) - def test_delete_ResourceNotFound(self): + def test_delete_NotFound(self): self.res.delete.side_effect = exceptions.NotFoundException( message="test", http_status=404) self.assertRaisesRegex( - exceptions.ResourceNotFound, - "No %s found for %s" % (DeleteableResource.__name__, self.res), + exceptions.NotFoundException, + # TODO(shade) The mocks here are hiding the thing we want to test. + "test", self.sot._delete, DeleteableResource, self.res, ignore_missing=False) @@ -237,13 +238,13 @@ class TestProxyUpdate(testtools.TestCase): self.assertEqual(rv, self.fake_result) self.res._update.assert_called_once_with(**self.attrs) - self.res.update.assert_called_once_with(self.session) + self.res.update.assert_called_once_with(self.sot) def test_update_id(self): rv = self.sot._update(UpdateableResource, self.fake_id, **self.attrs) self.assertEqual(rv, self.fake_result) - self.res.update.assert_called_once_with(self.session) + self.res.update.assert_called_once_with(self.sot) class TestProxyCreate(testtools.TestCase): @@ -267,7 +268,7 @@ class TestProxyCreate(testtools.TestCase): self.assertEqual(rv, self.fake_result) CreateableResource.new.assert_called_once_with(**attrs) - self.res.create.assert_called_once_with(self.session) + self.res.create.assert_called_once_with(self.sot) class TestProxyGet(testtools.TestCase): @@ -290,7 +291,8 @@ class TestProxyGet(testtools.TestCase): def test_get_resource(self): rv = self.sot._get(RetrieveableResource, self.res) - self.res.get.assert_called_with(self.session, requires_id=True) + self.res.get.assert_called_with(self.sot, requires_id=True, + error_message=mock.ANY) self.assertEqual(rv, self.fake_result) def test_get_resource_with_args(self): @@ -298,14 +300,16 @@ class TestProxyGet(testtools.TestCase): rv = self.sot._get(RetrieveableResource, self.res, **args) self.res._update.assert_called_once_with(**args) - self.res.get.assert_called_with(self.session, requires_id=True) + self.res.get.assert_called_with(self.sot, requires_id=True, + error_message=mock.ANY) self.assertEqual(rv, self.fake_result) def test_get_id(self): rv = self.sot._get(RetrieveableResource, self.fake_id) RetrieveableResource.new.assert_called_with(id=self.fake_id) - self.res.get.assert_called_with(self.session, requires_id=True) + self.res.get.assert_called_with(self.sot, requires_id=True, + error_message=mock.ANY) self.assertEqual(rv, self.fake_result) def test_get_not_found(self): @@ -313,9 +317,8 @@ class TestProxyGet(testtools.TestCase): message="test", http_status=404) self.assertRaisesRegex( - exceptions.ResourceNotFound, - "No %s found for %s" % (RetrieveableResource.__name__, self.res), - self.sot._get, RetrieveableResource, self.res) + exceptions.NotFoundException, + "test", self.sot._get, RetrieveableResource, self.res) class TestProxyList(testtools.TestCase): @@ -337,7 +340,7 @@ class TestProxyList(testtools.TestCase): self.assertEqual(self.fake_response, rv) ListableResource.list.assert_called_once_with( - self.session, paginated=paginated, **self.args) + self.sot, paginated=paginated, **self.args) def test_list_paginated(self): self._test_list(True) @@ -366,14 +369,14 @@ class TestProxyHead(testtools.TestCase): def test_head_resource(self): rv = self.sot._head(HeadableResource, self.res) - self.res.head.assert_called_with(self.session) + self.res.head.assert_called_with(self.sot) self.assertEqual(rv, self.fake_result) def test_head_id(self): rv = self.sot._head(HeadableResource, self.fake_id) HeadableResource.new.assert_called_with(id=self.fake_id) - self.res.head.assert_called_with(self.session) + self.res.head.assert_called_with(self.sot) self.assertEqual(rv, self.fake_result) @@ -391,7 +394,7 @@ class TestProxyWaits(testtools.TestCase): mock_wait.return_value = mock_resource self.sot.wait_for_status(mock_resource, 'ACTIVE') mock_wait.assert_called_once_with( - self.session, mock_resource, 'ACTIVE', [], 2, 120) + self.sot, mock_resource, 'ACTIVE', [], 2, 120) @mock.patch("openstack.resource2.wait_for_status") def test_wait_for_params(self, mock_wait): @@ -399,20 +402,18 @@ class TestProxyWaits(testtools.TestCase): mock_wait.return_value = mock_resource self.sot.wait_for_status(mock_resource, 'ACTIVE', ['ERROR'], 1, 2) mock_wait.assert_called_once_with( - self.session, mock_resource, 'ACTIVE', ['ERROR'], 1, 2) + self.sot, mock_resource, 'ACTIVE', ['ERROR'], 1, 2) @mock.patch("openstack.resource2.wait_for_delete") def test_wait_for_delete(self, mock_wait): mock_resource = mock.Mock() mock_wait.return_value = mock_resource self.sot.wait_for_delete(mock_resource) - mock_wait.assert_called_once_with( - self.session, mock_resource, 2, 120) + mock_wait.assert_called_once_with(self.sot, mock_resource, 2, 120) @mock.patch("openstack.resource2.wait_for_delete") def test_wait_for_delete_params(self, mock_wait): mock_resource = mock.Mock() mock_wait.return_value = mock_resource self.sot.wait_for_delete(mock_resource, 1, 2) - mock_wait.assert_called_once_with( - self.session, mock_resource, 1, 2) + mock_wait.assert_called_once_with(self.sot, mock_resource, 1, 2) diff --git a/openstack/tests/unit/test_proxy_base.py b/openstack/tests/unit/test_proxy_base.py index 348422d82..38cb1dd52 100644 --- a/openstack/tests/unit/test_proxy_base.py +++ b/openstack/tests/unit/test_proxy_base.py @@ -43,11 +43,11 @@ class TestProxyBase(base.TestCase): self.assertEqual(expected_result, test_method(*method_args, **method_kwargs)) - mocked.assert_called_with(self.session, + mocked.assert_called_with(test_method.__self__, *expected_args, **expected_kwargs) else: self.assertEqual(expected_result, test_method()) - mocked.assert_called_with(self.session) + mocked.assert_called_with(test_method.__self__) # NOTE(briancurtin): This is a duplicate version of _verify that is # temporarily here while we shift APIs. The difference is that @@ -79,7 +79,7 @@ class TestProxyBase(base.TestCase): mocked.assert_called_with(*expected_args, **expected_kwargs) else: self.assertEqual(expected_result, test_method()) - mocked.assert_called_with(self.session) + mocked.assert_called_with(test_method.__self__) def verify_create(self, test_method, resource_type, mock_method="openstack.proxy.BaseProxy._create", diff --git a/openstack/tests/unit/test_proxy_base2.py b/openstack/tests/unit/test_proxy_base2.py index f984de659..27e1c150d 100644 --- a/openstack/tests/unit/test_proxy_base2.py +++ b/openstack/tests/unit/test_proxy_base2.py @@ -43,11 +43,11 @@ class TestProxyBase(base.TestCase): self.assertEqual(expected_result, test_method(*method_args, **method_kwargs)) - mocked.assert_called_with(self.session, + mocked.assert_called_with(test_method.__self__, *expected_args, **expected_kwargs) else: self.assertEqual(expected_result, test_method()) - mocked.assert_called_with(self.session) + mocked.assert_called_with(test_method.__self__) # NOTE(briancurtin): This is a duplicate version of _verify that is # temporarily here while we shift APIs. The difference is that @@ -79,7 +79,7 @@ class TestProxyBase(base.TestCase): mocked.assert_called_with(*expected_args, **expected_kwargs) else: self.assertEqual(expected_result, test_method()) - mocked.assert_called_with(self.session) + mocked.assert_called_with(test_method.__self__) def verify_create(self, test_method, resource_type, mock_method="openstack.proxy2.BaseProxy._create", diff --git a/openstack/tests/unit/test_resource.py b/openstack/tests/unit/test_resource.py index 87f400924..2364920b2 100644 --- a/openstack/tests/unit/test_resource.py +++ b/openstack/tests/unit/test_resource.py @@ -269,7 +269,6 @@ class HeaderTests(base.TestCase): sot.create(sess) headers = {'guitar': 'johnny', 'bass': 'deedee'} sess.post.assert_called_with(HeaderTests.Test.base_path, - endpoint_filter=HeaderTests.Test.service, headers=headers, json={}) @@ -278,7 +277,6 @@ class HeaderTests(base.TestCase): headers = {'guitar': 'johnny', 'bass': 'cj'} sot.update(sess) sess.put.assert_called_with('ramones/1', - endpoint_filter=HeaderTests.Test.service, headers=headers, json={}) @@ -296,8 +294,7 @@ class ResourceTests(base.TestCase): self.assertEqual(method.call_args[0][0], url) def test_empty_id(self): - resp = mock.Mock() - resp.json = mock.Mock(return_value=fake_body) + resp = FakeResponse(fake_body) self.session.get.return_value = resp obj = FakeResource.new(**fake_arguments) @@ -372,7 +369,6 @@ class ResourceTests(base.TestCase): resp = FakeResource2.create_by_id(sess, attrs) self.assertEqual(expected_resp, resp) sess.post.assert_called_with(FakeResource2.base_path, - endpoint_filter=FakeResource2.service, json=json_body) r_id = "my_id" @@ -380,14 +376,12 @@ class ResourceTests(base.TestCase): self.assertEqual(response_value, resp) sess.put.assert_called_with( utils.urljoin(FakeResource2.base_path, r_id), - endpoint_filter=FakeResource2.service, json=json_body) path_args = {"parent_name": "my_name"} resp = FakeResource2.create_by_id(sess, attrs, path_args=path_args) self.assertEqual(response_value, resp) sess.post.assert_called_with(FakeResource2.base_path % path_args, - endpoint_filter=FakeResource2.service, json=json_body) resp = FakeResource2.create_by_id(sess, attrs, resource_id=r_id, @@ -395,7 +389,6 @@ class ResourceTests(base.TestCase): self.assertEqual(response_value, resp) sess.put.assert_called_with( utils.urljoin(FakeResource2.base_path % path_args, r_id), - endpoint_filter=FakeResource2.service, json=json_body) def test_create_without_resource_key(self): @@ -432,8 +425,7 @@ class ResourceTests(base.TestCase): resource_key = key service = "my_service" - response = mock.Mock() - response.json = mock.Mock(return_value=response_body) + response = FakeResponse(response_body) sess = mock.Mock() sess.get = mock.Mock(return_value=response) @@ -443,7 +435,7 @@ class ResourceTests(base.TestCase): self.assertEqual(response_value, resp) sess.get.assert_called_with( utils.urljoin(FakeResource2.base_path, r_id), - endpoint_filter=FakeResource2.service) + ) path_args = {"parent_name": "my_name"} resp = FakeResource2.get_data_by_id(sess, resource_id=r_id, @@ -451,7 +443,7 @@ class ResourceTests(base.TestCase): self.assertEqual(response_value, resp) sess.get.assert_called_with( utils.urljoin(FakeResource2.base_path % path_args, r_id), - endpoint_filter=FakeResource2.service) + ) def test_get_data_without_resource_key(self): key = None @@ -482,7 +474,6 @@ class ResourceTests(base.TestCase): headers = {'Accept': ''} sess.head.assert_called_with( utils.urljoin(FakeResource2.base_path, r_id), - endpoint_filter=FakeResource2.service, headers=headers) path_args = {"parent_name": "my_name"} @@ -492,7 +483,6 @@ class ResourceTests(base.TestCase): headers = {'Accept': ''} sess.head.assert_called_with( utils.urljoin(FakeResource2.base_path % path_args, r_id), - endpoint_filter=FakeResource2.service, headers=headers) def test_head_data_without_resource_key(self): @@ -528,7 +518,6 @@ class ResourceTests(base.TestCase): self.assertEqual(expected_resp, resp) sess.patch.assert_called_with( utils.urljoin(FakeResource2.base_path, r_id), - endpoint_filter=FakeResource2.service, json=json_body) path_args = {"parent_name": "my_name"} @@ -537,7 +526,6 @@ class ResourceTests(base.TestCase): self.assertEqual(expected_resp, resp) sess.patch.assert_called_with( utils.urljoin(FakeResource2.base_path % path_args, r_id), - endpoint_filter=FakeResource2.service, json=json_body) def test_update_without_resource_key(self): @@ -574,7 +562,7 @@ class ResourceTests(base.TestCase): service = "my_service" sess = mock.Mock() - sess.delete = mock.Mock(return_value=None) + sess.delete = mock.Mock(return_value=FakeResponse({})) r_id = "my_id" resp = FakeResource2.delete_by_id(sess, r_id) @@ -582,7 +570,6 @@ class ResourceTests(base.TestCase): headers = {'Accept': ''} sess.delete.assert_called_with( utils.urljoin(FakeResource2.base_path, r_id), - endpoint_filter=FakeResource2.service, headers=headers) path_args = {"parent_name": "my_name"} @@ -591,13 +578,10 @@ class ResourceTests(base.TestCase): headers = {'Accept': ''} sess.delete.assert_called_with( utils.urljoin(FakeResource2.base_path % path_args, r_id), - endpoint_filter=FakeResource2.service, headers=headers) def test_create(self): - resp = mock.Mock() - resp.json = mock.Mock(return_value=fake_body) - resp.headers = {'location': 'foo'} + resp = FakeResponse(fake_body, headers={'location': 'foo'}) self.session.post = mock.Mock(return_value=resp) # Create resource with subset of attributes in order to @@ -639,9 +623,7 @@ class ResourceTests(base.TestCase): self.assertEqual('foo', obj.location) def test_get(self): - resp = mock.Mock() - resp.json = mock.Mock(return_value=fake_body) - resp.headers = {'location': 'foo'} + resp = FakeResponse(fake_body, headers={'location': 'foo'}) self.session.get = mock.Mock(return_value=resp) # Create resource with subset of attributes in order to @@ -676,8 +658,7 @@ class ResourceTests(base.TestCase): self.assertIsNone(obj.location) def test_get_by_id(self): - resp = mock.Mock() - resp.json = mock.Mock(return_value=fake_body) + resp = FakeResponse(fake_body) self.session.get = mock.Mock(return_value=resp) obj = FakeResource.get_by_id(self.session, fake_id, @@ -703,8 +684,7 @@ class ResourceTests(base.TestCase): headers = {"header1": header1, "header2": header2} - resp = mock.Mock(headers=headers) - resp.json = mock.Mock(return_value=fake_body) + resp = FakeResponse(fake_body, headers=headers) self.session.get = mock.Mock(return_value=resp) class FakeResource2(FakeResource): @@ -737,7 +717,7 @@ class ResourceTests(base.TestCase): header1 = resource.header("header1") header2 = resource.header("header2") - resp = mock.Mock(headers={"header1": "one", "header2": "two"}) + resp = FakeResponse(None, headers={"header1": "one", "header2": "two"}) self.session.head = mock.Mock(return_value=resp) obj = FakeResource2.head_by_id(self.session, fake_id, @@ -757,9 +737,7 @@ class ResourceTests(base.TestCase): class FakeResourcePatch(FakeResource): patch_update = True - resp = mock.Mock() - resp.json = mock.Mock(return_value=fake_body) - resp.headers = {'location': 'foo'} + resp = FakeResponse(fake_body, headers={'location': 'foo'}) self.session.patch = mock.Mock(return_value=resp) # Create resource with subset of attributes in order to @@ -807,9 +785,7 @@ class ResourceTests(base.TestCase): # This is False by default, but explicit for this test. patch_update = False - resp = mock.Mock() - resp.json = mock.Mock(return_value=fake_body) - resp.headers = {'location': 'foo'} + resp = FakeResponse(fake_body, headers={'location': 'foo'}) self.session.put = mock.Mock(return_value=resp) # Create resource with subset of attributes in order to @@ -869,6 +845,7 @@ class ResourceTests(base.TestCase): def test_delete(self): obj = FakeResource({"id": fake_id, "parent_name": fake_parent}) + self.session.delete.return_value = FakeResponse({}) obj.delete(self.session) self.assertCalledURL(self.session.delete, @@ -919,8 +896,7 @@ class ResourceTests(base.TestCase): def _test_list_call_count(self, paginated): # Test that we've only made one call to receive all data results = [fake_data.copy(), fake_data.copy(), fake_data.copy()] - resp = mock.Mock() - resp.json = mock.Mock(return_value={fake_resources: results}) + resp = FakeResponse({fake_resources: results}) attrs = {"get.return_value": resp} session = mock.Mock(**attrs) @@ -1315,8 +1291,7 @@ class ResourceMapping(base.TestCase): json.dumps(attrs) except TypeError as e: self.fail("Unable to serialize _attrs: %s" % e) - resp = mock.Mock() - resp.json = mock.Mock(return_value=attrs) + resp = FakeResponse(attrs) return resp session = mock.Mock() @@ -1335,8 +1310,11 @@ class ResourceMapping(base.TestCase): class FakeResponse(object): - def __init__(self, response): + def __init__(self, response, status_code=200, headers=None): self.body = response + self.status_code = status_code + headers = headers if headers else {'content-type': 'application/json'} + self.headers = requests.structures.CaseInsensitiveDict(headers) def json(self): return self.body @@ -1378,7 +1356,7 @@ class TestFind(base.TestCase): self.assertEqual(self.PROP, result.prop) path = "fakes/" + fake_parent + "/data/" + self.ID - self.mock_get.assert_any_call(path, endpoint_filter=None) + self.mock_get.assert_any_call(path,) def test_id_no_retrieve(self): self.mock_get.side_effect = [ @@ -1423,7 +1401,7 @@ class TestFind(base.TestCase): p = {'ip_address': "127.0.0.1"} path = fake_path + "?limit=2" - self.mock_get.called_once_with(path, params=p, endpoint_filter=None) + self.mock_get.called_once_with(path, params=p,) def test_nada(self): self.mock_get.side_effect = [ @@ -1520,7 +1498,8 @@ class TestWaitForDelete(base.TestCase): sot.get = mock.Mock() sot.get.side_effect = [ sot, - exceptions.NotFoundException()] + exceptions.NotFoundException( + 'not found', FakeResponse({}, status_code=404))] self.assertEqual(sot, resource.wait_for_delete(sess, sot, 1, 2)) diff --git a/openstack/tests/unit/test_resource2.py b/openstack/tests/unit/test_resource2.py index c4055f531..8f72dbfdd 100644 --- a/openstack/tests/unit/test_resource2.py +++ b/openstack/tests/unit/test_resource2.py @@ -12,16 +12,28 @@ import itertools +from keystoneauth1 import session import mock +import requests import six from openstack import exceptions from openstack import format from openstack import resource2 -from openstack import session from openstack.tests.unit import base +class FakeResponse(object): + def __init__(self, response, status_code=200, headers=None): + self.body = response + self.status_code = status_code + headers = headers if headers else {'content-type': 'application/json'} + self.headers = requests.structures.CaseInsensitiveDict(headers) + + def json(self): + return self.body + + class TestComponent(base.TestCase): class ExampleComponent(resource2._BaseComponent): @@ -337,7 +349,7 @@ class Test_Request(base.TestCase): sot = resource2._Request(uri, body, headers) - self.assertEqual(uri, sot.uri) + self.assertEqual(uri, sot.url) self.assertEqual(body, sot.body) self.assertEqual(headers, sot.headers) @@ -791,7 +803,7 @@ class TestResource(base.TestCase): result = sot._prepare_request(requires_id=True) - self.assertEqual("something/id", result.uri) + self.assertEqual("something/id", result.url) self.assertEqual({"x": body_value, "id": the_id}, result.body) self.assertEqual({"y": header_value}, result.headers) @@ -817,7 +829,7 @@ class TestResource(base.TestCase): result = sot._prepare_request(requires_id=False, prepend_key=True) - self.assertEqual("/something", result.uri) + self.assertEqual("/something", result.url) self.assertEqual({key: {"x": body_value}}, result.body) self.assertEqual({"y": header_value}, result.headers) @@ -840,8 +852,7 @@ class TestResource(base.TestCase): class Test(resource2.Resource): attr = resource2.Header("attr") - response = mock.Mock() - response.headers = dict() + response = FakeResponse({}) sot = Test() sot._filter_component = mock.Mock(return_value={"attr": "value"}) @@ -856,9 +867,7 @@ class TestResource(base.TestCase): attr = resource2.Body("attr") body = {"attr": "value"} - response = mock.Mock() - response.headers = dict() - response.json.return_value = body + response = FakeResponse(body) sot = Test() sot._filter_component = mock.Mock(side_effect=[body, dict()]) @@ -877,9 +886,7 @@ class TestResource(base.TestCase): attr = resource2.Body("attr") body = {"attr": "value"} - response = mock.Mock() - response.headers = dict() - response.json.return_value = {key: body} + response = FakeResponse({key: body}) sot = Test() sot._filter_component = mock.Mock(side_effect=[body, dict()]) @@ -941,11 +948,11 @@ class TestResourceActions(base.TestCase): self.test_class = Test self.request = mock.Mock(spec=resource2._Request) - self.request.uri = "uri" + self.request.url = "uri" self.request.body = "body" self.request.headers = "headers" - self.response = mock.Mock() + self.response = FakeResponse({}) self.sot = Test(id="id") self.sot._prepare_request = mock.Mock(return_value=self.request) @@ -972,13 +979,11 @@ class TestResourceActions(base.TestCase): requires_id=requires_id, prepend_key=prepend_key) if requires_id: self.session.put.assert_called_once_with( - self.request.uri, - endpoint_filter=self.service_name, + self.request.url, json=self.request.body, headers=self.request.headers) else: self.session.post.assert_called_once_with( - self.request.uri, - endpoint_filter=self.service_name, + self.request.url, json=self.request.body, headers=self.request.headers) sot._translate_response.assert_called_once_with(self.response) @@ -1007,7 +1012,7 @@ class TestResourceActions(base.TestCase): self.sot._prepare_request.assert_called_once_with(requires_id=True) self.session.get.assert_called_once_with( - self.request.uri, endpoint_filter=self.service_name) + self.request.url,) self.sot._translate_response.assert_called_once_with(self.response) self.assertEqual(result, self.sot) @@ -1017,7 +1022,7 @@ class TestResourceActions(base.TestCase): self.sot._prepare_request.assert_called_once_with(requires_id=False) self.session.get.assert_called_once_with( - self.request.uri, endpoint_filter=self.service_name) + self.request.url,) self.sot._translate_response.assert_called_once_with(self.response) self.assertEqual(result, self.sot) @@ -1027,8 +1032,7 @@ class TestResourceActions(base.TestCase): self.sot._prepare_request.assert_called_once_with() self.session.head.assert_called_once_with( - self.request.uri, - endpoint_filter=self.service_name, + self.request.url, headers={"Accept": ""}) self.sot._translate_response.assert_called_once_with(self.response) @@ -1050,13 +1054,11 @@ class TestResourceActions(base.TestCase): if patch_update: self.session.patch.assert_called_once_with( - self.request.uri, - endpoint_filter=self.service_name, + self.request.url, json=self.request.body, headers=self.request.headers) else: self.session.put.assert_called_once_with( - self.request.uri, - endpoint_filter=self.service_name, + self.request.url, json=self.request.body, headers=self.request.headers) self.sot._translate_response.assert_called_once_with( @@ -1083,8 +1085,7 @@ class TestResourceActions(base.TestCase): self.sot._prepare_request.assert_called_once_with() self.session.delete.assert_called_once_with( - self.request.uri, - endpoint_filter=self.service_name, + self.request.url, headers={"Accept": ""}) self.sot._translate_response.assert_called_once_with( @@ -1095,8 +1096,7 @@ class TestResourceActions(base.TestCase): # the generator. Wrap calls to self.sot.list in a `list` # and then test the results as a list of responses. def test_list_empty_response(self): - mock_response = mock.Mock() - mock_response.json.return_value = [] + mock_response = FakeResponse([]) self.session.get.return_value = mock_response @@ -1104,7 +1104,6 @@ class TestResourceActions(base.TestCase): self.session.get.assert_called_once_with( self.base_path, - endpoint_filter=self.service_name, headers={"Accept": "application/json"}, params={}) @@ -1142,7 +1141,6 @@ class TestResourceActions(base.TestCase): self.session.get.assert_called_once_with( self.base_path, - endpoint_filter=self.service_name, headers={"Accept": "application/json"}, params={}) @@ -1168,7 +1166,6 @@ class TestResourceActions(base.TestCase): self.session.get.assert_called_once_with( self.base_path, - endpoint_filter=self.service_name, headers={"Accept": "application/json"}, params={}) @@ -1242,7 +1239,6 @@ class TestResourceActions(base.TestCase): self.assertEqual(result0.id, ids[0]) self.session.get.assert_called_with( self.base_path, - endpoint_filter=self.service_name, headers={"Accept": "application/json"}, params={}) @@ -1250,14 +1246,12 @@ class TestResourceActions(base.TestCase): self.assertEqual(result1.id, ids[1]) self.session.get.assert_called_with( self.base_path, - endpoint_filter=self.service_name, headers={"Accept": "application/json"}, params={"limit": 1, "marker": 1}) self.assertRaises(StopIteration, next, results) self.session.get.assert_called_with( self.base_path, - endpoint_filter=self.service_name, headers={"Accept": "application/json"}, params={"limit": 1, "marker": 2}) @@ -1284,7 +1278,6 @@ class TestResourceActions(base.TestCase): self.assertEqual(result1.id, ids[1]) self.session.get.assert_called_with( self.base_path, - endpoint_filter=self.service_name, headers={"Accept": "application/json"}, params={}) @@ -1293,7 +1286,6 @@ class TestResourceActions(base.TestCase): self.assertEqual(result2.id, ids[2]) self.session.get.assert_called_with( self.base_path, - endpoint_filter=self.service_name, headers={"Accept": "application/json"}, params={"limit": 2, "marker": 2}) @@ -1315,7 +1307,8 @@ class TestResourceFind(base.TestCase): @classmethod def existing(cls, **kwargs): - raise exceptions.NotFoundException + raise exceptions.NotFoundException( + 'Not Found', response=mock.Mock()) @classmethod def list(cls, session): @@ -1490,8 +1483,12 @@ class TestWaitForDelete(base.TestCase): @mock.patch("time.sleep", return_value=None) def test_success(self, mock_sleep): + response = mock.Mock() + response.headers = {} resource = mock.Mock() - resource.get.side_effect = [None, None, exceptions.NotFoundException] + resource.get.side_effect = [ + None, None, + exceptions.NotFoundException('Not Found', response)] result = resource2.wait_for_delete("session", resource, 1, 3) diff --git a/openstack/tests/unit/test_session.py b/openstack/tests/unit/test_session.py deleted file mode 100644 index 82cdeeca0..000000000 --- a/openstack/tests/unit/test_session.py +++ /dev/null @@ -1,437 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -import testtools - -from keystoneauth1 import exceptions as _exceptions - -from openstack import exceptions -from openstack import profile -from openstack import session -from openstack import utils - -HTML_MSG = """ - - 404 Entity Not Found - - -

404 Entity Not Found

- Entity could not be found -

- -""" - - -class TestSession(testtools.TestCase): - - def test_init_user_agent_none(self): - sot = session.Session(None) - self.assertTrue(sot.user_agent.startswith("openstacksdk")) - - def test_init_user_agent_set(self): - sot = session.Session(None, user_agent="testing/123") - self.assertTrue(sot.user_agent.startswith("testing/123 openstacksdk")) - - def test_init_with_single_api_request(self): - prof = profile.Profile() - prof.set_api_version('clustering', '1.2') - - sot = session.Session(prof) - - # The assertion acutally tests the property assigned in parent class - self.assertEqual({'openstack-api-version': 'clustering 1.2'}, - sot.additional_headers) - - def test_init_with_multi_api_requests(self): - prof = profile.Profile() - prof.set_api_version('clustering', '1.2') - prof.set_api_version('compute', '2.15') - - sot = session.Session(prof) - - versions = sot.additional_headers['openstack-api-version'] - requests = [req.strip() for req in versions.split(',')] - self.assertIn('clustering 1.2', requests) - self.assertIn('compute 2.15', requests) - - def test_init_with_no_api_requests(self): - prof = profile.Profile() - - sot = session.Session(prof) - - self.assertEqual({}, sot.additional_headers) - - def _assert_map_exceptions(self, expected_exc, ksa_exc, func): - os_exc = self.assertRaises( - expected_exc, session.map_exceptions(func)) - self.assertIsInstance(os_exc, expected_exc) - self.assertEqual(ksa_exc.message, os_exc.message) - self.assertEqual(ksa_exc.http_status, os_exc.http_status) - self.assertEqual(ksa_exc, os_exc.cause) - return os_exc - - def test_map_exceptions_not_found_exception(self): - response = mock.Mock() - response_body = {'NotFoundException': { - 'message': 'Resource not found'}} - response.json = mock.Mock(return_value=response_body) - response.headers = {"content-type": "application/json"} - response.status_code = 404 - ksa_exc = _exceptions.HttpError( - message="test", http_status=404, response=response) - func = mock.Mock(side_effect=ksa_exc) - os_exc = self._assert_map_exceptions( - exceptions.NotFoundException, ksa_exc, func) - self.assertEqual('Resource not found', os_exc.details) - - def test_map_exceptions_http_exception(self): - response = mock.Mock() - response_body = {'HTTPBadRequest': { - 'message': 'request is invalid'}} - response.json = mock.Mock(return_value=response_body) - response.headers = {"content-type": "application/json"} - response.status_code = 400 - ksa_exc = _exceptions.HttpError( - message="test", http_status=400, response=response) - func = mock.Mock(side_effect=ksa_exc) - - os_exc = self._assert_map_exceptions( - exceptions.HttpException, ksa_exc, func) - self.assertEqual('request is invalid', os_exc.details) - - def test_map_exceptions_http_exception_handle_json(self): - mock_resp = mock.Mock() - mock_resp.status_code = 413 - mock_resp.json.return_value = { - "overLimit": { - "message": "OverLimit413...", - "retryAt": "2017-01-03T13:33:06Z" - }, - "overLimitRetry": { - "message": "OverLimit Retry...", - "retryAt": "2017-01-03T13:33:06Z" - } - } - mock_resp.headers = { - "content-type": "application/json" - } - ksa_exc = _exceptions.HttpError( - message="test", http_status=413, response=mock_resp) - func = mock.Mock(side_effect=ksa_exc) - - os_exc = self._assert_map_exceptions( - exceptions.HttpException, ksa_exc, func) - # It's not sure that which 'message' will be first so exact checking is - # difficult here. It can be 'OverLimit413...\nOverLimit Retry...' or - # it can be 'OverLimit Retry...\nOverLimit413...'. - self.assertIn('OverLimit413...', os_exc.details) - self.assertIn('OverLimit Retry...', os_exc.details) - - def test_map_exceptions_http_exception_handle_json_1(self): - # A test for json containing non-dict values - mock_resp = mock.Mock() - mock_resp.status_code = 404 - mock_resp.json.return_value = { - "code": 404, - "error": { - "message": "resource not found", - }, - } - mock_resp.headers = { - "content-type": "application/json" - } - ksa_exc = _exceptions.HttpError(message="test", http_status=404, - response=mock_resp) - func = mock.Mock(side_effect=ksa_exc) - - os_exc = self._assert_map_exceptions( - exceptions.HttpException, ksa_exc, func) - self.assertIn('not found', os_exc.details) - - def test_map_exceptions_notfound_exception_handle_html(self): - mock_resp = mock.Mock() - mock_resp.status_code = 404 - mock_resp.text = HTML_MSG - mock_resp.headers = { - "content-type": "text/html" - } - ksa_exc = _exceptions.HttpError( - message="test", http_status=404, response=mock_resp) - func = mock.Mock(side_effect=ksa_exc) - - os_exc = self._assert_map_exceptions( - exceptions.NotFoundException, ksa_exc, func) - self.assertEqual('404 Entity Not Found: Entity could not be found', - os_exc.details) - - def test_map_exceptions_notfound_exception_handle_other_content_type(self): - mock_resp = mock.Mock() - mock_resp.status_code = 404 - fake_text = ("{'UnknownException': {'message': " - "'UnknownException occurred...'}}") - mock_resp.text = fake_text - mock_resp.headers = { - "content-type": 'application/octet-stream' - } - ksa_exc = _exceptions.HttpError( - message="test", http_status=404, response=mock_resp) - func = mock.Mock(side_effect=ksa_exc) - - os_exc = self._assert_map_exceptions( - exceptions.NotFoundException, ksa_exc, func) - self.assertEqual(fake_text, os_exc.details) - - def test_map_exceptions_sdk_exception_1(self): - ksa_exc = _exceptions.ClientException() - func = mock.Mock(side_effect=ksa_exc) - - os_exc = self.assertRaises( - exceptions.SDKException, session.map_exceptions(func)) - self.assertIsInstance(os_exc, exceptions.SDKException) - self.assertEqual(ksa_exc, os_exc.cause) - - def test_map_exceptions_sdk_exception_2(self): - ksa_exc = _exceptions.VersionNotAvailable() - func = mock.Mock(side_effect=ksa_exc) - - os_exc = self.assertRaises( - exceptions.SDKException, session.map_exceptions(func)) - self.assertIsInstance(os_exc, exceptions.SDKException) - self.assertEqual(ksa_exc, os_exc.cause) - - def test__parse_versions_response_exception(self): - uri = "http://www.openstack.org" - level = "DEBUG" - sot = session.Session(None) - sot.get = mock.Mock(side_effect=exceptions.NotFoundException) - - with self.assertLogs(logger=session.__name__, level=level) as log: - self.assertIsNone(sot._parse_versions_response(uri)) - - self.assertEqual(len(log.output), 1, - "Too many warnings were logged") - self.assertEqual( - log.output[0], - "%s:%s:Looking for versions at %s" % (level, session.__name__, - uri)) - - def test__parse_versions_response_no_json(self): - sot = session.Session(None) - retval = mock.Mock() - retval.json = mock.Mock(side_effect=ValueError) - sot.get = mock.Mock(return_value=retval) - - self.assertIsNone(sot._parse_versions_response("test")) - - def test__parse_versions_response_no_versions(self): - sot = session.Session(None) - retval = mock.Mock() - retval.json = mock.Mock(return_value={"no_versions_here": "blarga"}) - sot.get = mock.Mock(return_value=retval) - - self.assertIsNone(sot._parse_versions_response("test")) - - def test__parse_versions_response_with_versions(self): - uri = "http://openstack.org" - versions = [1, 2, 3] - - sot = session.Session(None) - retval = mock.Mock() - retval.json = mock.Mock(return_value={"versions": versions}) - sot.get = mock.Mock(return_value=retval) - - expected = session.Session._Endpoint(uri, versions) - self.assertEqual(expected, sot._parse_versions_response(uri)) - - def test__parse_versions_response_with_nested_versions(self): - uri = "http://openstack.org" - versions = [1, 2, 3] - - sot = session.Session(None) - retval = mock.Mock() - retval.json = mock.Mock(return_value={"versions": - {"values": versions}}) - sot.get = mock.Mock(return_value=retval) - - expected = session.Session._Endpoint(uri, versions) - self.assertEqual(expected, sot._parse_versions_response(uri)) - - def test__get_endpoint_versions_at_subdomain(self): - # This test covers a common case of services deployed under - # subdomains. Additionally, it covers the case of a service - # deployed at the root, which will be the first request made - # for versions. - sc_uri = "https://service.cloud.com/v1/" - versions_uri = "https://service.cloud.com" - - sot = session.Session(None) - sot.get_project_id = mock.Mock(return_value="project_id") - - responses = [session.Session._Endpoint(versions_uri, "versions")] - sot._parse_versions_response = mock.Mock(side_effect=responses) - - result = sot._get_endpoint_versions("type", sc_uri) - - sot._parse_versions_response.assert_called_once_with(versions_uri) - self.assertEqual(result, responses[0]) - self.assertFalse(result.needs_project_id) - - def test__get_endpoint_versions_at_path(self): - # This test covers a common case of services deployed under - # a path. Additionally, it covers the case of a service - # deployed at a path deeper than the root, which will mean - # more than one request will need to be made. - sc_uri = "https://cloud.com/api/service/v2/project_id" - versions_uri = "https://cloud.com/api/service" - - sot = session.Session(None) - sot.get_project_id = mock.Mock(return_value="project_id") - - responses = [None, None, - session.Session._Endpoint(versions_uri, "versions")] - sot._parse_versions_response = mock.Mock(side_effect=responses) - - result = sot._get_endpoint_versions("type", sc_uri) - - sot._parse_versions_response.assert_has_calls( - [mock.call("https://cloud.com"), - mock.call("https://cloud.com/api"), - mock.call(versions_uri)]) - self.assertEqual(result, responses[2]) - self.assertTrue(result.needs_project_id) - - def test__get_endpoint_versions_at_port(self): - # This test covers a common case of services deployed under - # a port. - sc_uri = "https://cloud.com:1234/v3" - versions_uri = "https://cloud.com:1234" - - sot = session.Session(None) - sot.get_project_id = mock.Mock(return_value="project_id") - - responses = [session.Session._Endpoint(versions_uri, "versions")] - sot._parse_versions_response = mock.Mock(side_effect=responses) - - result = sot._get_endpoint_versions("type", sc_uri) - - sot._parse_versions_response.assert_called_once_with(versions_uri) - self.assertEqual(result, responses[0]) - self.assertFalse(result.needs_project_id) - - def test__get_endpoint_versions_with_domain_scope(self): - # This test covers a common case of services deployed under - # subdomains. Additionally, it covers the case of getting endpoint - # versions with domain scope token - sc_uri = "https://service.cloud.com/identity" - versions_uri = "https://service.cloud.com" - - sot = session.Session(None) - # Project id is None when domain scope session present - sot.get_project_id = mock.Mock(return_value=None) - - responses = [session.Session._Endpoint(versions_uri, "versions")] - sot._parse_versions_response = mock.Mock(side_effect=responses) - - result = sot._get_endpoint_versions("type", sc_uri) - - sot._parse_versions_response.assert_called_once_with(versions_uri) - self.assertEqual(result, responses[0]) - self.assertFalse(result.needs_project_id) - self.assertIsNone(result.project_id) - - def test__parse_version(self): - sot = session.Session(None) - - self.assertEqual(sot._parse_version("2"), (2, -1)) - self.assertEqual(sot._parse_version("v2"), (2, -1)) - self.assertEqual(sot._parse_version("v2.1"), (2, 1)) - self.assertRaises(ValueError, sot._parse_version, "lol") - - def test__get_version_match_none(self): - sot = session.Session(None) - - endpoint = session.Session._Endpoint("root", []) - self.assertRaises( - exceptions.EndpointNotFound, - sot._get_version_match, endpoint, None, "service") - - def test__get_version_match_fuzzy(self): - match = "http://devstack/v2.1" - root_endpoint = "http://devstack" - versions = [{"id": "v2.0", - "links": [{"href": "http://devstack/v2/", - "rel": "self"}]}, - {"id": "v2.1", - "links": [{"href": match, - "rel": "self"}]}] - - sot = session.Session(None) - - endpoint = session.Session._Endpoint(root_endpoint, versions) - # Look for a v2 match, which we internally denote as a minor - # version of -1 so we can find the highest matching minor. - rv = sot._get_version_match(endpoint, session.Version(2, -1), - "service") - self.assertEqual(rv, match) - - def test__get_version_match_exact(self): - match = "http://devstack/v2" - root_endpoint = "http://devstack" - versions = [{"id": "v2.0", - "links": [{"href": match, - "rel": "self"}]}, - {"id": "v2.1", - "links": [{"href": "http://devstack/v2.1/", - "rel": "self"}]}] - - sot = session.Session(None) - endpoint = session.Session._Endpoint(root_endpoint, versions) - rv = sot._get_version_match(endpoint, session.Version(2, 0), - "service") - self.assertEqual(rv, match) - - def test__get_version_match_fragment(self): - root = "http://cloud.net" - match = "/v2" - versions = [{"id": "v2.0", "links": [{"href": match, "rel": "self"}]}] - - sot = session.Session(None) - endpoint = session.Session._Endpoint(root, versions) - rv = sot._get_version_match(endpoint, session.Version(2, 0), "service") - self.assertEqual(rv, root + match) - - def test__get_version_match_project_id(self): - match = "http://devstack/v2" - root_endpoint = "http://devstack" - project_id = "asdf123" - versions = [{"id": "v2.0", "links": [{"href": match, "rel": "self"}]}] - - sot = session.Session(None) - sot.get_project_id = mock.Mock(return_value=project_id) - endpoint = session.Session._Endpoint(root_endpoint, versions, - project_id=project_id, - needs_project_id=True) - rv = sot._get_version_match(endpoint, session.Version(2, 0), - "service") - match_endpoint = utils.urljoin(match, project_id) - self.assertEqual(rv, match_endpoint) - - def test_get_endpoint_cached(self): - sot = session.Session(None) - service_type = "compute" - interface = "public" - endpoint = "the world wide web" - - sot.endpoint_cache[(service_type, interface)] = endpoint - rv = sot.get_endpoint(service_type=service_type, interface=interface) - self.assertEqual(rv, endpoint) diff --git a/openstack/utils.py b/openstack/utils.py index 5aef9ba5f..f14c87e3b 100644 --- a/openstack/utils.py +++ b/openstack/utils.py @@ -44,6 +44,20 @@ def deprecated(deprecated_in=None, removed_in=None, details=details) +class NullHandler(logging.Handler): + def emit(self, record): + pass + + +def setup_logging(name): + '''Get a logging.Logger and make sure there is at least a NullHandler.''' + log = logging.getLogger(name) + if len(log.handlers) == 0: + h = NullHandler() + log.addHandler(h) + return log + + def enable_logging(debug=False, path=None, stream=None): """Enable logging to a file at path and/or a console stream. diff --git a/openstack/workflow/v2/execution.py b/openstack/workflow/v2/execution.py index d54160f1e..9877e2bc2 100644 --- a/openstack/workflow/v2/execution.py +++ b/openstack/workflow/v2/execution.py @@ -57,8 +57,7 @@ class Execution(resource.Resource): prepend_key=prepend_key) request_body = request.body["execution"] - response = session.post(request.uri, - endpoint_filter=self.service, + response = session.post(request.url, json=request_body, headers=request.headers) diff --git a/openstack/workflow/v2/workflow.py b/openstack/workflow/v2/workflow.py index 6624c87b3..73f04b48e 100644 --- a/openstack/workflow/v2/workflow.py +++ b/openstack/workflow/v2/workflow.py @@ -60,11 +60,10 @@ class Workflow(resource.Resource): } scope = "?scope=%s" % self.scope - uri = request.uri + scope + uri = request.url + scope request.headers.update(headers) response = session.post(uri, - endpoint_filter=self.service, json=None, headers=request.headers, **kwargs) diff --git a/releasenotes/notes/removed-profile-437f3038025b0fb3.yaml b/releasenotes/notes/removed-profile-437f3038025b0fb3.yaml new file mode 100644 index 000000000..ce8a383b3 --- /dev/null +++ b/releasenotes/notes/removed-profile-437f3038025b0fb3.yaml @@ -0,0 +1,8 @@ +--- +upgrade: + - The Profile object has been replaced with the use of + CloudConfig objects from openstack.config. + - The openstacksdk specific Session object has been removed. + - Proxy objects are now subclasses of + keystoneauth1.adapter.Adapter. + - REST interactions all go through TaskManager now. diff --git a/releasenotes/notes/renamed-bare-metal-b1cdbc52af14e042.yaml b/releasenotes/notes/renamed-bare-metal-b1cdbc52af14e042.yaml new file mode 100644 index 000000000..d39f1a1cb --- /dev/null +++ b/releasenotes/notes/renamed-bare-metal-b1cdbc52af14e042.yaml @@ -0,0 +1,4 @@ +--- +upgrade: + - Renamed bare-metal to baremetal to align with the official + service type. diff --git a/releasenotes/notes/renamed-block-store-bc5e0a7315bfeb67.yaml b/releasenotes/notes/renamed-block-store-bc5e0a7315bfeb67.yaml new file mode 100644 index 000000000..3d5a5d34c --- /dev/null +++ b/releasenotes/notes/renamed-block-store-bc5e0a7315bfeb67.yaml @@ -0,0 +1,4 @@ +--- +upgrade: + - The block_store service object has been renamed to block_storage to + align the API with the official service types. diff --git a/releasenotes/notes/renamed-cluster-743da6d321fffcba.yaml b/releasenotes/notes/renamed-cluster-743da6d321fffcba.yaml new file mode 100644 index 000000000..0796d92b8 --- /dev/null +++ b/releasenotes/notes/renamed-cluster-743da6d321fffcba.yaml @@ -0,0 +1,4 @@ +--- +upgrade: + - Renamed cluster to clustering to align with the official + service type. diff --git a/releasenotes/notes/renamed-telemetry-c08ae3e72afca24f.yaml b/releasenotes/notes/renamed-telemetry-c08ae3e72afca24f.yaml new file mode 100644 index 000000000..5929d4f55 --- /dev/null +++ b/releasenotes/notes/renamed-telemetry-c08ae3e72afca24f.yaml @@ -0,0 +1,4 @@ +--- +upgrade: + - Renamed telemetry to meter to align with the official + service type. diff --git a/requirements.txt b/requirements.txt index bb087c608..c1b23e695 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ appdirs>=1.3.0 # MIT License requestsexceptions>=1.2.0 # Apache-2.0 jsonpatch>=1.16 # BSD six>=1.9.0 # MIT -stevedore>=1.20.0 # Apache-2.0 +os-service-types>=1.1.0 # Apache-2.0 keystoneauth1>=3.2.0 # Apache-2.0 deprecation>=1.0 # Apache-2.0