From 958a35a5ca7607f2f59b86b9583d1538eee78b8e Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Tue, 30 Jan 2018 19:31:47 -0600 Subject: [PATCH] Remove openstack_cloud factory function This is mostly mechanical as these are no longer needed. Change-Id: I632675506bef591704068d17ec3dfad963a4c4b5 --- README.rst | 17 +++------ doc/source/user/multi-cloud-demo.rst | 38 +++++++++---------- examples/cloud/cleanup-servers.py | 2 +- examples/cloud/create-server-dict.py | 2 +- examples/cloud/create-server-name-or-id.py | 2 +- examples/cloud/debug-logging.py | 2 +- examples/cloud/find-an-image.py | 2 +- examples/cloud/http-debug-logging.py | 2 +- examples/cloud/munch-dict-object.py | 2 +- examples/cloud/normalization.py | 2 +- examples/cloud/server-information.py | 2 +- .../cloud/service-conditional-overrides.py | 2 +- examples/cloud/service-conditionals.py | 2 +- examples/cloud/strict-mode.py | 2 +- examples/cloud/upload-large-object.py | 2 +- examples/cloud/upload-object.py | 2 +- examples/cloud/user-agent.py | 2 +- openstack/cloud/__init__.py | 14 ------- openstack/cloud/inventory.py | 2 + openstack/cloud/openstackcloud.py | 10 ++--- openstack/tests/unit/cloud/test_caching.py | 6 +-- .../tests/unit/cloud/test_operator_noauth.py | 4 +- 22 files changed, 51 insertions(+), 70 deletions(-) diff --git a/README.rst b/README.rst index ab100dcdf..d453ef5a5 100644 --- a/README.rst +++ b/README.rst @@ -65,13 +65,6 @@ and provides different argument defaults where needed for compatibility. Similarly future releases of os-client-config will provide a compatibility layer shim around ``openstack.config``. -.. note:: - - The ``openstack.cloud.OpenStackCloud`` object and the - ``openstack.connection.Connection`` object are going to be merged. It is - recommended to not write any new code which consumes objects from the - ``openstack.cloud`` namespace until that merge is complete. - .. _nodepool: https://docs.openstack.org/infra/nodepool/ .. _Ansible OpenStack Modules: http://docs.ansible.com/ansible/latest/list_of_cloud_modules.html#openstack .. _Session: http://docs.python-requests.org/en/master/user/advanced/#session-objects @@ -143,20 +136,20 @@ Create a server using objects configured with the ``clouds.yaml`` file: # Initialize and turn on debug logging openstack.enable_logging(debug=True) - # Initialize cloud + # Initialize connection # Cloud configs are read with openstack.config - cloud = openstack.cloud.openstack_cloud(cloud='mordred') + conn = openstack.connect(cloud='mordred') # Upload an image to the cloud - image = cloud.create_image( + image = conn.create_image( 'ubuntu-trusty', filename='ubuntu-trusty.qcow2', wait=True) # Find a flavor with at least 512M of RAM - flavor = cloud.get_flavor_by_ram(512) + flavor = conn.get_flavor_by_ram(512) # Boot a server, wait for it to boot, and then do whatever is needed # to get a public ip for it. - cloud.create_server( + conn.create_server( 'my-server', image=image, flavor=flavor, wait=True, auto_ip=True) Links diff --git a/doc/source/user/multi-cloud-demo.rst b/doc/source/user/multi-cloud-demo.rst index 757796096..461af139b 100644 --- a/doc/source/user/multi-cloud-demo.rst +++ b/doc/source/user/multi-cloud-demo.rst @@ -72,7 +72,7 @@ Complete Example ('my-citycloud', 'Buf1'), ('my-internap', 'ams01')]: # Initialize cloud - cloud = openstack.openstack_cloud(cloud=cloud_name, region_name=region_name) + cloud = openstack.connect(cloud=cloud_name, region_name=region_name) # Upload an image to the cloud image = cloud.create_image( @@ -324,7 +324,7 @@ Complete Example Again ('my-citycloud', 'Buf1'), ('my-internap', 'ams01')]: # Initialize cloud - cloud = openstack.openstack_cloud(cloud=cloud_name, region_name=region_name) + cloud = openstack.connect(cloud=cloud_name, region_name=region_name) # Upload an image to the cloud image = cloud.create_image( @@ -376,7 +376,7 @@ Example with Debug Logging from openstack import cloud as openstack openstack.enable_logging(debug=True) - cloud = openstack.openstack_cloud( + cloud = openstack.connect( cloud='my-vexxhost', region_name='ca-ymq-1') cloud.get_image('Ubuntu 16.04.1 LTS [2017-03-03]') @@ -390,7 +390,7 @@ Example with HTTP Debug Logging from openstack import cloud as openstack openstack.enable_logging(http_debug=True) - cloud = openstack.openstack_cloud( + cloud = openstack.connect( cloud='my-vexxhost', region_name='ca-ymq-1') cloud.get_image('Ubuntu 16.04.1 LTS [2017-03-03]') @@ -398,7 +398,7 @@ Cloud Regions ============= * `cloud` constructor needs `cloud` and `region_name` -* `openstack.openstack_cloud` is a helper factory function +* `openstack.connect` is a helper factory function .. code:: python @@ -407,7 +407,7 @@ Cloud Regions ('my-citycloud', 'Buf1'), ('my-internap', 'ams01')]: # Initialize cloud - cloud = openstack.openstack_cloud(cloud=cloud_name, region_name=region_name) + cloud = openstack.connect(cloud=cloud_name, region_name=region_name) Upload an Image =============== @@ -497,7 +497,7 @@ Image and Flavor by Name or ID ('my-internap', 'ams01', 'Ubuntu 16.04 LTS (Xenial Xerus)', 'A1.4')]: # Initialize cloud - cloud = openstack.openstack_cloud(cloud=cloud_name, region_name=region_name) + cloud = openstack.connect(cloud=cloud_name, region_name=region_name) # Boot a server, wait for it to boot, and then do whatever is needed # to get a public ip for it. @@ -544,7 +544,7 @@ Image and Flavor by Dict ('my-internap', 'ams01', 'Ubuntu 16.04 LTS (Xenial Xerus)', 'A1.4')]: # Initialize cloud - cloud = openstack.openstack_cloud(cloud=cloud_name, region_name=region_name) + cloud = openstack.connect(cloud=cloud_name, region_name=region_name) # Boot a server, wait for it to boot, and then do whatever is needed # to get a public ip for it. @@ -565,7 +565,7 @@ Munch Objects from openstack import cloud as openstack openstack.enable_logging(debug=True) - cloud = openstack.openstack_cloud(cloud='zetta', region_name='no-osl1') + cloud = openstack.connect(cloud='zetta', region_name='no-osl1') image = cloud.get_image('Ubuntu 14.04 (AMD64) [Local Storage]') print(image.name) print(image['name']) @@ -604,7 +604,7 @@ Cleanup Script ('my-citycloud', 'Buf1'), ('my-internap', 'ams01')]: # Initialize cloud - cloud = openstack.openstack_cloud(cloud=cloud_name, region_name=region_name) + cloud = openstack.connect(cloud=cloud_name, region_name=region_name) for server in cloud.search_servers('my-server'): cloud.delete_server(server, wait=True, delete_ips=True) @@ -619,7 +619,7 @@ Normalization from openstack import cloud as openstack openstack.enable_logging() - cloud = openstack.openstack_cloud(cloud='fuga', region_name='cystack') + cloud = openstack.connect(cloud='fuga', region_name='cystack') image = cloud.get_image( 'Ubuntu 16.04 LTS - Xenial Xerus - 64-bit - Fuga Cloud Based Image') cloud.pprint(image) @@ -635,7 +635,7 @@ Strict Normalized Results from openstack import cloud as openstack openstack.enable_logging() - cloud = openstack.openstack_cloud( + cloud = openstack.connect( cloud='fuga', region_name='cystack', strict=True) image = cloud.get_image( 'Ubuntu 16.04 LTS - Xenial Xerus - 64-bit - Fuga Cloud Based Image') @@ -652,7 +652,7 @@ How Did I Find the Image Name for the Last Example? from openstack import cloud as openstack openstack.enable_logging() - cloud = openstack.openstack_cloud(cloud='fuga', region_name='cystack') + cloud = openstack.connect(cloud='fuga', region_name='cystack') cloud.pprint([ image for image in cloud.list_images() if 'ubuntu' in image.name.lower()]) @@ -673,7 +673,7 @@ Added / Modified Information from openstack import cloud as openstack openstack.enable_logging(debug=True) - cloud = openstack.openstack_cloud(cloud='my-citycloud', region_name='Buf1') + cloud = openstack.connect(cloud='my-citycloud', region_name='Buf1') try: server = cloud.create_server( 'my-server', image='Ubuntu 16.04 Xenial Xerus', @@ -715,7 +715,7 @@ User Agent Info from openstack import cloud as openstack openstack.enable_logging(http_debug=True) - cloud = openstack.openstack_cloud( + cloud = openstack.connect( cloud='datacentred', app_name='AmazingApp', app_version='1.0') cloud.list_networks() @@ -733,7 +733,7 @@ Uploading Large Objects from openstack import cloud as openstack openstack.enable_logging(debug=True) - cloud = openstack.openstack_cloud(cloud='ovh', region_name='SBG1') + cloud = openstack.connect(cloud='ovh', region_name='SBG1') cloud.create_object( container='my-container', name='my-object', filename='/home/mordred/briarcliff.sh3d') @@ -754,7 +754,7 @@ Uploading Large Objects from openstack import cloud as openstack openstack.enable_logging(debug=True) - cloud = openstack.openstack_cloud(cloud='ovh', region_name='SBG1') + cloud = openstack.connect(cloud='ovh', region_name='SBG1') cloud.create_object( container='my-container', name='my-object', filename='/home/mordred/briarcliff.sh3d', @@ -770,7 +770,7 @@ Service Conditionals from openstack import cloud as openstack openstack.enable_logging(debug=True) - cloud = openstack.openstack_cloud(cloud='kiss', region_name='region1') + cloud = openstack.connect(cloud='kiss', region_name='region1') print(cloud.has_service('network')) print(cloud.has_service('container-orchestration')) @@ -784,7 +784,7 @@ Service Conditional Overrides from openstack import cloud as openstack openstack.enable_logging(debug=True) - cloud = openstack.openstack_cloud(cloud='rax', region_name='DFW') + cloud = openstack.connect(cloud='rax', region_name='DFW') print(cloud.has_service('network')) .. code:: yaml diff --git a/examples/cloud/cleanup-servers.py b/examples/cloud/cleanup-servers.py index 89b7c16e4..2bf18cde5 100644 --- a/examples/cloud/cleanup-servers.py +++ b/examples/cloud/cleanup-servers.py @@ -20,7 +20,7 @@ for cloud_name, region_name in [ ('my-citycloud', 'Buf1'), ('my-internap', 'ams01')]: # Initialize cloud - cloud = openstack.openstack_cloud( + cloud = openstack.connect( cloud=cloud_name, region_name=region_name) for server in cloud.search_servers('my-server'): cloud.delete_server(server, wait=True, delete_ips=True) diff --git a/examples/cloud/create-server-dict.py b/examples/cloud/create-server-dict.py index d8d31cc34..30d1f72dc 100644 --- a/examples/cloud/create-server-dict.py +++ b/examples/cloud/create-server-dict.py @@ -23,7 +23,7 @@ for cloud_name, region_name, image, flavor_id in [ ('my-internap', 'ams01', 'Ubuntu 16.04 LTS (Xenial Xerus)', 'A1.4')]: # Initialize cloud - cloud = openstack.openstack_cloud( + cloud = openstack.connect( cloud=cloud_name, region_name=region_name) # Boot a server, wait for it to boot, and then do whatever is needed diff --git a/examples/cloud/create-server-name-or-id.py b/examples/cloud/create-server-name-or-id.py index a1fc1b95c..06b218848 100644 --- a/examples/cloud/create-server-name-or-id.py +++ b/examples/cloud/create-server-name-or-id.py @@ -23,7 +23,7 @@ for cloud_name, region_name, image, flavor in [ ('my-internap', 'ams01', 'Ubuntu 16.04 LTS (Xenial Xerus)', 'A1.4')]: # Initialize cloud - cloud = openstack.openstack_cloud( + cloud = openstack.connect( cloud=cloud_name, region_name=region_name) cloud.delete_server('my-server', wait=True, delete_ips=True) diff --git a/examples/cloud/debug-logging.py b/examples/cloud/debug-logging.py index 4c9cad328..76fce6797 100644 --- a/examples/cloud/debug-logging.py +++ b/examples/cloud/debug-logging.py @@ -13,6 +13,6 @@ from openstack import cloud as openstack openstack.enable_logging(debug=True) -cloud = openstack.openstack_cloud( +cloud = openstack.connect( cloud='my-vexxhost', region_name='ca-ymq-1') cloud.get_image('Ubuntu 16.04.1 LTS [2017-03-03]') diff --git a/examples/cloud/find-an-image.py b/examples/cloud/find-an-image.py index f15787378..297a29a87 100644 --- a/examples/cloud/find-an-image.py +++ b/examples/cloud/find-an-image.py @@ -13,7 +13,7 @@ from openstack import cloud as openstack openstack.enable_logging() -cloud = openstack.openstack_cloud(cloud='fuga', region_name='cystack') +cloud = openstack.connect(cloud='fuga', region_name='cystack') cloud.pprint([ image for image in cloud.list_images() if 'ubuntu' in image.name.lower()]) diff --git a/examples/cloud/http-debug-logging.py b/examples/cloud/http-debug-logging.py index 5e67f4a38..b047c81f0 100644 --- a/examples/cloud/http-debug-logging.py +++ b/examples/cloud/http-debug-logging.py @@ -13,6 +13,6 @@ from openstack import cloud as openstack openstack.enable_logging(http_debug=True) -cloud = openstack.openstack_cloud( +cloud = openstack.connect( cloud='my-vexxhost', region_name='ca-ymq-1') cloud.get_image('Ubuntu 16.04.1 LTS [2017-03-03]') diff --git a/examples/cloud/munch-dict-object.py b/examples/cloud/munch-dict-object.py index 65568c112..d9e7ff1a0 100644 --- a/examples/cloud/munch-dict-object.py +++ b/examples/cloud/munch-dict-object.py @@ -13,7 +13,7 @@ from openstack import cloud as openstack openstack.enable_logging(debug=True) -cloud = openstack.openstack_cloud(cloud='ovh', region_name='SBG1') +cloud = openstack.connect(cloud='ovh', region_name='SBG1') image = cloud.get_image('Ubuntu 16.10') print(image.name) print(image['name']) diff --git a/examples/cloud/normalization.py b/examples/cloud/normalization.py index 914baef70..c7830ad8c 100644 --- a/examples/cloud/normalization.py +++ b/examples/cloud/normalization.py @@ -13,7 +13,7 @@ from openstack import cloud as openstack openstack.enable_logging() -cloud = openstack.openstack_cloud(cloud='fuga', region_name='cystack') +cloud = openstack.connect(cloud='fuga', region_name='cystack') image = cloud.get_image( 'Ubuntu 16.04 LTS - Xenial Xerus - 64-bit - Fuga Cloud Based Image') cloud.pprint(image) diff --git a/examples/cloud/server-information.py b/examples/cloud/server-information.py index b851e96ad..26896e22e 100644 --- a/examples/cloud/server-information.py +++ b/examples/cloud/server-information.py @@ -13,7 +13,7 @@ import openstack openstack.enable_logging(debug=True) -cloud = openstack.openstack_cloud(cloud='my-citycloud', region_name='Buf1') +cloud = openstack.connect(cloud='my-citycloud', region_name='Buf1') try: server = cloud.create_server( 'my-server', image='Ubuntu 16.04 Xenial Xerus', diff --git a/examples/cloud/service-conditional-overrides.py b/examples/cloud/service-conditional-overrides.py index d3a2a88de..31e7840e6 100644 --- a/examples/cloud/service-conditional-overrides.py +++ b/examples/cloud/service-conditional-overrides.py @@ -13,5 +13,5 @@ import openstack openstack.enable_logging(debug=True) -cloud = openstack.openstack_cloud(cloud='rax', region_name='DFW') +cloud = openstack.connect(cloud='rax', region_name='DFW') print(cloud.has_service('network')) diff --git a/examples/cloud/service-conditionals.py b/examples/cloud/service-conditionals.py index 46b3d2e91..d17d250b6 100644 --- a/examples/cloud/service-conditionals.py +++ b/examples/cloud/service-conditionals.py @@ -13,6 +13,6 @@ import openstack openstack.enable_logging(debug=True) -cloud = openstack.openstack_cloud(cloud='kiss', region_name='region1') +cloud = openstack.connect(cloud='kiss', region_name='region1') print(cloud.has_service('network')) print(cloud.has_service('container-orchestration')) diff --git a/examples/cloud/strict-mode.py b/examples/cloud/strict-mode.py index 96eaa13b9..14877fd78 100644 --- a/examples/cloud/strict-mode.py +++ b/examples/cloud/strict-mode.py @@ -13,7 +13,7 @@ import openstack openstack.enable_logging() -cloud = openstack.openstack_cloud( +cloud = openstack.connect( cloud='fuga', region_name='cystack', strict=True) image = cloud.get_image( 'Ubuntu 16.04 LTS - Xenial Xerus - 64-bit - Fuga Cloud Based Image') diff --git a/examples/cloud/upload-large-object.py b/examples/cloud/upload-large-object.py index d89ae557d..c88c21c11 100644 --- a/examples/cloud/upload-large-object.py +++ b/examples/cloud/upload-large-object.py @@ -13,7 +13,7 @@ import openstack openstack.enable_logging(debug=True) -cloud = openstack.openstack_cloud(cloud='ovh', region_name='SBG1') +cloud = openstack.connect(cloud='ovh', region_name='SBG1') cloud.create_object( container='my-container', name='my-object', filename='/home/mordred/briarcliff.sh3d', diff --git a/examples/cloud/upload-object.py b/examples/cloud/upload-object.py index d89ae557d..c88c21c11 100644 --- a/examples/cloud/upload-object.py +++ b/examples/cloud/upload-object.py @@ -13,7 +13,7 @@ import openstack openstack.enable_logging(debug=True) -cloud = openstack.openstack_cloud(cloud='ovh', region_name='SBG1') +cloud = openstack.connect(cloud='ovh', region_name='SBG1') cloud.create_object( container='my-container', name='my-object', filename='/home/mordred/briarcliff.sh3d', diff --git a/examples/cloud/user-agent.py b/examples/cloud/user-agent.py index 578c3c2e5..52ddd4750 100644 --- a/examples/cloud/user-agent.py +++ b/examples/cloud/user-agent.py @@ -13,6 +13,6 @@ import openstack openstack.enable_logging(http_debug=True) -cloud = openstack.openstack_cloud( +cloud = openstack.connect( cloud='datacentred', app_name='AmazingApp', app_version='1.0') cloud.list_networks() diff --git a/openstack/cloud/__init__.py b/openstack/cloud/__init__.py index c3ad1f9cf..4b9999279 100644 --- a/openstack/cloud/__init__.py +++ b/openstack/cloud/__init__.py @@ -52,17 +52,3 @@ def openstack_clouds( except keystoneauth1.exceptions.auth_plugins.NoMatchingPlugin as e: raise OpenStackCloudException( "Invalid cloud configuration: {exc}".format(exc=str(e))) - - -def openstack_cloud( - config=None, strict=False, app_name=None, app_version=None, **kwargs): - # Late import while we unwind things - from openstack import connection - if not config: - config = _get_openstack_config(app_name, app_version) - try: - cloud_region = config.get_one(**kwargs) - except keystoneauth1.exceptions.auth_plugins.NoMatchingPlugin as e: - raise OpenStackCloudException( - "Invalid cloud configuration: {exc}".format(exc=str(e))) - return connection.Connection(config=cloud_region, strict=strict) diff --git a/openstack/cloud/inventory.py b/openstack/cloud/inventory.py index 9f0120c43..f1f549ba7 100644 --- a/openstack/cloud/inventory.py +++ b/openstack/cloud/inventory.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +__all__ = ['OpenStackInventory'] + import functools from openstack.config import loader diff --git a/openstack/cloud/openstackcloud.py b/openstack/cloud/openstackcloud.py index badc38271..aba2a53b8 100644 --- a/openstack/cloud/openstackcloud.py +++ b/openstack/cloud/openstackcloud.py @@ -263,12 +263,12 @@ class OpenStackCloud(_normalize.Normalizer): .. code-block:: python - cloud = openstack.cloud.openstack_cloud(cloud='example') + conn = openstack.connect(cloud='example') # Work normally - servers = cloud.list_servers() - cloud2 = cloud.connect_as(username='different-user', password='') + servers = conn.list_servers() + conn2 = conn.connect_as(username='different-user', password='') # Work as different-user - servers = cloud2.list_servers() + servers = conn2.list_servers() :param kwargs: keyword arguments can contain anything that would normally go in an auth dict. They will override the same @@ -342,7 +342,7 @@ class OpenStackCloud(_normalize.Normalizer): .. code-block:: python - cloud = openstack.cloud.openstack_cloud(cloud='example') + cloud = openstack.connect(cloud='example') # Work normally servers = cloud.list_servers() cloud2 = cloud.connect_as_project('different-project') diff --git a/openstack/tests/unit/cloud/test_caching.py b/openstack/tests/unit/cloud/test_caching.py index b1bcc38d8..975b5ba88 100644 --- a/openstack/tests/unit/cloud/test_caching.py +++ b/openstack/tests/unit/cloud/test_caching.py @@ -18,8 +18,8 @@ import testtools import openstack import openstack.cloud -from openstack.cloud import exc from openstack.cloud import meta +from openstack.config import exceptions as occ_exc from openstack.tests import fakes from openstack.tests.unit import base @@ -551,6 +551,6 @@ class TestBogusAuth(base.TestCase): cloud_config_fixture='clouds_cache.yaml') def test_get_auth_bogus(self): - with testtools.ExpectedException(exc.OpenStackCloudException): - openstack.cloud.openstack_cloud( + with testtools.ExpectedException(occ_exc.OpenStackConfigException): + openstack.connect( cloud='_bogus_test_', config=self.config) diff --git a/openstack/tests/unit/cloud/test_operator_noauth.py b/openstack/tests/unit/cloud/test_operator_noauth.py index 5b7dd3072..ab60dab90 100644 --- a/openstack/tests/unit/cloud/test_operator_noauth.py +++ b/openstack/tests/unit/cloud/test_operator_noauth.py @@ -50,7 +50,7 @@ class TestOpenStackCloudOperatorNoAuth(base.RequestsMockTestCase): # with 'v1'. As such, since we are overriding the endpoint, # we must explicitly do the same as we move away from the # client library. - self.cloud_noauth = openstack.cloud.openstack_cloud( + self.cloud_noauth = openstack.connect( auth_type='none', baremetal_endpoint_override="https://bare-metal.example.com/v1") @@ -63,7 +63,7 @@ class TestOpenStackCloudOperatorNoAuth(base.RequestsMockTestCase): The old way of doing this was to abuse admin_token. """ - self.cloud_noauth = openstack.cloud.openstack_cloud( + self.cloud_noauth = openstack.connect( auth_type='admin_token', auth=dict( endpoint='https://bare-metal.example.com/v1',