Fix nova client initialization in multi-region cloud
The current nova client initialization doesn't take regions into
consideration so that the flavor used for creating trove instance
is coming from other regions.
Change-Id: Ia5a93a220c9ec86a23d281dc3604eeaa9c2d6673
(cherry-picked from 28e02161b0
)
This commit is contained in:
parent
c3f0c85ed1
commit
a0da9cd19b
@ -13,17 +13,15 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from troveclient.v1 import client
|
|
||||||
|
|
||||||
from openstack_dashboard.api import base
|
|
||||||
from oslo_log import log as logging
|
|
||||||
|
|
||||||
from horizon.utils import functions as utils
|
from horizon.utils import functions as utils
|
||||||
from horizon.utils.memoized import memoized # noqa
|
from horizon.utils.memoized import memoized # noqa
|
||||||
|
|
||||||
from keystoneauth1 import loading
|
|
||||||
from keystoneauth1 import session
|
from keystoneauth1 import session
|
||||||
|
from keystoneclient.auth import token_endpoint
|
||||||
from novaclient import client as nova_client
|
from novaclient import client as nova_client
|
||||||
|
from openstack_auth import utils as auth_utils
|
||||||
|
from openstack_dashboard.api import base
|
||||||
|
from oslo_log import log as logging
|
||||||
|
from troveclient.v1 import client
|
||||||
|
|
||||||
# Supported compute versions
|
# Supported compute versions
|
||||||
NOVA_VERSIONS = base.APIVersionManager("compute", preferred_version=2)
|
NOVA_VERSIONS = base.APIVersionManager("compute", preferred_version=2)
|
||||||
@ -39,17 +37,21 @@ LOG = logging.getLogger(__name__)
|
|||||||
def troveclient(request):
|
def troveclient(request):
|
||||||
insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
|
insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
|
||||||
cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
|
cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
|
||||||
trove_url = base.url_for(request, 'database')
|
endpoint_type = getattr(settings, 'OPENSTACK_ENDPOINT_TYPE', 'publicURL')
|
||||||
c = client.Client(request.user.username,
|
region = request.user.services_region
|
||||||
request.user.token.id,
|
|
||||||
project_id=request.user.project_id,
|
endpoint = base.url_for(request, 'database')
|
||||||
auth_url=trove_url,
|
auth_url, _ = auth_utils.fix_auth_url_version_prefix(
|
||||||
insecure=insecure,
|
settings.OPENSTACK_KEYSTONE_URL)
|
||||||
cacert=cacert,
|
auth = token_endpoint.Token(auth_url, request.user.token.id)
|
||||||
http_log_debug=settings.DEBUG)
|
verify = not insecure and (cacert or True)
|
||||||
c.client.auth_token = request.user.token.id
|
|
||||||
c.client.management_url = trove_url
|
t_client = client.Client(session=session.Session(auth=auth, verify=verify),
|
||||||
return c
|
service_type='database',
|
||||||
|
endpoint_type=endpoint_type,
|
||||||
|
region_name=region,
|
||||||
|
endpoint_override=endpoint)
|
||||||
|
return t_client
|
||||||
|
|
||||||
|
|
||||||
def cluster_list(request, marker=None):
|
def cluster_list(request, marker=None):
|
||||||
@ -283,17 +285,23 @@ def backup_strategy_delete(request, instance_id=None, project_id=None):
|
|||||||
def nova_client_client(request):
|
def nova_client_client(request):
|
||||||
insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
|
insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
|
||||||
cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
|
cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
|
||||||
identity_url = base.url_for(request, 'identity')
|
endpoint_type = getattr(settings, 'OPENSTACK_ENDPOINT_TYPE', 'publicURL')
|
||||||
loader = loading.get_plugin_loader('token')
|
region = request.user.services_region
|
||||||
auth = loader.load_from_options(auth_url=identity_url,
|
|
||||||
token=request.user.token.id,
|
endpoint = base.url_for(request, 'compute')
|
||||||
tenant_id=request.user.project_id)
|
auth_url, _ = auth_utils.fix_auth_url_version_prefix(
|
||||||
sess = session.Session(auth=auth)
|
settings.OPENSTACK_KEYSTONE_URL)
|
||||||
nova = nova_client.Client(NOVA_VERSION,
|
auth = token_endpoint.Token(auth_url, request.user.token.id)
|
||||||
session=sess,
|
verify = not insecure and (cacert or True)
|
||||||
insecure=insecure,
|
|
||||||
cacert=cacert,
|
nova = nova_client.Client(
|
||||||
http_log_debug=settings.DEBUG)
|
NOVA_VERSION,
|
||||||
|
session=session.Session(auth=auth, verify=verify),
|
||||||
|
endpoint_type=endpoint_type,
|
||||||
|
service_type='compute',
|
||||||
|
region_name=region,
|
||||||
|
endpoint_override=endpoint)
|
||||||
|
|
||||||
return nova
|
return nova
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user