Remove openstack_cloud factory function

This is mostly mechanical as these are no longer needed.

Change-Id: I632675506bef591704068d17ec3dfad963a4c4b5
This commit is contained in:
Monty Taylor 2018-01-30 19:31:47 -06:00
parent 0a6083b876
commit 958a35a5ca
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
22 changed files with 51 additions and 70 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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]')

View File

@ -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()])

View File

@ -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]')

View File

@ -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'])

View File

@ -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)

View File

@ -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',

View File

@ -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'))

View File

@ -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'))

View File

@ -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')

View File

@ -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',

View File

@ -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',

View File

@ -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()

View File

@ -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)

View File

@ -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

View File

@ -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')

View File

@ -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)

View File

@ -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',