Merge "Move profile helper method to openstack.profile"
This commit is contained in:
@@ -74,18 +74,20 @@ try to find it and if that fails, you would create it::
|
|||||||
network = conn.network.create_network({"name": "zuul"})
|
network = conn.network.create_network({"name": "zuul"})
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
__all__ = [
|
||||||
|
'from_config',
|
||||||
|
'Connection',
|
||||||
|
]
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
import keystoneauth1.exceptions
|
import keystoneauth1.exceptions
|
||||||
import os_service_types
|
import os_service_types
|
||||||
import requestsexceptions
|
import requestsexceptions
|
||||||
import six
|
import six
|
||||||
from six.moves import urllib
|
|
||||||
|
|
||||||
from openstack import _log
|
from openstack import _log
|
||||||
import openstack.config
|
from openstack import config as _config
|
||||||
from openstack.config import cloud_region
|
|
||||||
from openstack.config import defaults as config_defaults
|
|
||||||
from openstack import exceptions
|
from openstack import exceptions
|
||||||
from openstack import service_description
|
from openstack import service_description
|
||||||
from openstack import task_manager
|
from openstack import task_manager
|
||||||
@@ -120,7 +122,7 @@ def from_config(cloud=None, config=None, options=None, **kwargs):
|
|||||||
cloud = cloud or kwargs.get('cloud_name')
|
cloud = cloud or kwargs.get('cloud_name')
|
||||||
config = config or kwargs.get('cloud_config')
|
config = config or kwargs.get('cloud_config')
|
||||||
if config is None:
|
if config is None:
|
||||||
config = openstack.config.OpenStackConfig().get_one(
|
config = _config.OpenStackConfig().get_one(
|
||||||
cloud=cloud, argparse=options)
|
cloud=cloud, argparse=options)
|
||||||
|
|
||||||
return Connection(config=config)
|
return Connection(config=config)
|
||||||
@@ -186,12 +188,13 @@ class Connection(object):
|
|||||||
|
|
||||||
if not self.config:
|
if not self.config:
|
||||||
if profile:
|
if profile:
|
||||||
|
import openstack.profile
|
||||||
# TODO(shade) Remove this once we've shifted
|
# TODO(shade) Remove this once we've shifted
|
||||||
# python-openstackclient to not use the profile interface.
|
# python-openstackclient to not use the profile interface.
|
||||||
self.config = self._get_config_from_profile(
|
self.config = openstack.profile._get_config_from_profile(
|
||||||
profile, authenticator, **kwargs)
|
profile, authenticator, **kwargs)
|
||||||
else:
|
else:
|
||||||
openstack_config = openstack.config.OpenStackConfig(
|
openstack_config = _config.OpenStackConfig(
|
||||||
app_name=app_name, app_version=app_version,
|
app_name=app_name, app_version=app_version,
|
||||||
load_yaml_config=profile is None)
|
load_yaml_config=profile is None)
|
||||||
self.config = openstack_config.get_one(
|
self.config = openstack_config.get_one(
|
||||||
@@ -218,36 +221,6 @@ class Connection(object):
|
|||||||
service_description.OpenStackServiceDescription(
|
service_description.OpenStackServiceDescription(
|
||||||
service, self.config))
|
service, self.config))
|
||||||
|
|
||||||
def _get_config_from_profile(self, 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.
|
|
||||||
|
|
||||||
# We don't have a cloud name. Make one up from the auth_url hostname
|
|
||||||
# so that log messages work.
|
|
||||||
name = urllib.parse.urlparse(authenticator.auth_url).hostname
|
|
||||||
region_name = None
|
|
||||||
for service in profile.get_services():
|
|
||||||
if service.region:
|
|
||||||
region_name = service.region
|
|
||||||
service_type = service.service_type
|
|
||||||
if service.interface:
|
|
||||||
key = cloud_region._make_key('interface', service_type)
|
|
||||||
kwargs[key] = service.interface
|
|
||||||
if service.version:
|
|
||||||
version = service.version
|
|
||||||
if version.startswith('v'):
|
|
||||||
version = version[1:]
|
|
||||||
key = cloud_region._make_key('api_version', service_type)
|
|
||||||
kwargs[key] = service.version
|
|
||||||
|
|
||||||
config_kwargs = config_defaults.get_defaults()
|
|
||||||
config_kwargs.update(kwargs)
|
|
||||||
config = cloud_region.CloudRegion(
|
|
||||||
name=name, region_name=region_name, config=config_kwargs)
|
|
||||||
config._auth = authenticator
|
|
||||||
return config
|
|
||||||
|
|
||||||
def add_service(self, service):
|
def add_service(self, service):
|
||||||
"""Add a service to the Connection.
|
"""Add a service to the Connection.
|
||||||
|
|
||||||
|
@@ -16,8 +16,11 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
from six.moves import urllib
|
||||||
|
|
||||||
from openstack import _log
|
from openstack import _log
|
||||||
|
from openstack.config import cloud_region
|
||||||
|
from openstack.config import defaults as config_defaults
|
||||||
from openstack.baremetal import baremetal_service
|
from openstack.baremetal import baremetal_service
|
||||||
from openstack.block_storage import block_storage_service
|
from openstack.block_storage import block_storage_service
|
||||||
from openstack.clustering import clustering_service
|
from openstack.clustering import clustering_service
|
||||||
@@ -38,6 +41,36 @@ from openstack.workflow import workflow_service
|
|||||||
_logger = _log.setup_logging('openstack')
|
_logger = _log.setup_logging('openstack')
|
||||||
|
|
||||||
|
|
||||||
|
def _get_config_from_profile(profile, authenticator, **kwargs):
|
||||||
|
# TODO(shade) Remove this once we've shifted python-openstackclient
|
||||||
|
# to not use the profile interface.
|
||||||
|
|
||||||
|
# We don't have a cloud name. Make one up from the auth_url hostname
|
||||||
|
# so that log messages work.
|
||||||
|
name = urllib.parse.urlparse(authenticator.auth_url).hostname
|
||||||
|
region_name = None
|
||||||
|
for service in profile.get_services():
|
||||||
|
if service.region:
|
||||||
|
region_name = service.region
|
||||||
|
service_type = service.service_type
|
||||||
|
if service.interface:
|
||||||
|
key = cloud_region._make_key('interface', service_type)
|
||||||
|
kwargs[key] = service.interface
|
||||||
|
if service.version:
|
||||||
|
version = service.version
|
||||||
|
if version.startswith('v'):
|
||||||
|
version = version[1:]
|
||||||
|
key = cloud_region._make_key('api_version', service_type)
|
||||||
|
kwargs[key] = service.version
|
||||||
|
|
||||||
|
config_kwargs = config_defaults.get_defaults()
|
||||||
|
config_kwargs.update(kwargs)
|
||||||
|
config = cloud_region.CloudRegion(
|
||||||
|
name=name, region_name=region_name, config=config_kwargs)
|
||||||
|
config._auth = authenticator
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
class Profile(object):
|
class Profile(object):
|
||||||
|
|
||||||
ALL = "*"
|
ALL = "*"
|
||||||
|
@@ -26,7 +26,7 @@ from requests_mock.contrib import fixture as rm_fixture
|
|||||||
from six.moves import urllib
|
from six.moves import urllib
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
import openstack
|
import openstack.cloud
|
||||||
import openstack.connection
|
import openstack.connection
|
||||||
from openstack.tests import base
|
from openstack.tests import base
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user