Skip to content

Commit

Permalink
Add app creds support to OS provider for JS2 (#297)
Browse files Browse the repository at this point in the history
* Add app creds support to OS provider for JS2

Co-authored-by: Nuwan Goonasekera <2070605+nuwang@users.noreply.github.com>
  • Loading branch information
Alexandru Mahmoud and nuwang committed Aug 8, 2022
1 parent 7b1bcd1 commit b2555ff
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cloudbridge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging

# Current version of the library
__version__ = '3.0.0'
__version__ = '3.1.0'


def get_version():
Expand Down
36 changes: 23 additions & 13 deletions cloudbridge/providers/openstack/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from cloudbridge.base import BaseCloudProvider
from cloudbridge.base.helpers import get_env

from cloudbridge.interfaces.exceptions import ProviderConnectionException

from .services import OpenStackComputeService
from .services import OpenStackDnsService
from .services import OpenStackNetworkingService
Expand All @@ -34,6 +36,10 @@ def __init__(self, config):
super(OpenStackCloudProvider, self).__init__(config)

# Initialize cloud connection fields
self.app_cred_id = self._get_config_value(
'os_application_credential_id', get_env('OS_APPLICATION_CREDENTIAL_ID'))
self.app_cred_secret = self._get_config_value(
'os_application_credential_secret', get_env('OS_APPLICATION_CREDENTIAL_SECRET'))
self.username = self._get_config_value(
'os_username', get_env('OS_USERNAME'))
self.password = self._get_config_value(
Expand Down Expand Up @@ -112,13 +118,22 @@ def _keystone_session(self):

if self._keystone_version == 3:
from keystoneauth1.identity import v3
auth = v3.Password(auth_url=self.auth_url,
username=self.username,
password=self.password,
user_domain_name=self.user_domain_name,
project_domain_id=self.project_domain_id,
project_domain_name=self.project_domain_name,
project_name=self.project_name)
if self.username and self.password:
auth = v3.Password(auth_url=self.auth_url,
username=self.username,
password=self.password,
user_domain_name=self.user_domain_name,
project_domain_id=self.project_domain_id,
project_domain_name=self.project_domain_name,
project_name=self.project_name)
elif self.app_cred_id and self.app_cred_secret:
auth = v3.ApplicationCredential(auth_url=self.auth_url,
application_credential_id=self.app_cred_id,
application_credential_secret=self.app_cred_secret)
else:
raise ProviderConnectionException("""No valid credentials were found. You must supply either
'os_username' and 'os_password', or 'os_application_credential_id'
and 'os_application_credential_secret'""")
self._cached_keystone_session = session.Session(auth=auth)
else:
from keystoneauth1.identity import v2
Expand All @@ -133,12 +148,7 @@ def _connect_openstack(self):
region_name=self.region_name,
user_agent='cloudbridge',
auth_url=self.auth_url,
project_name=self.project_name,
username=self.username,
password=self.password,
user_domain_name=self.user_domain_name,
project_domain_id=self.project_domain_id,
project_domain_name=self.project_domain_name
session=self._keystone_session,
)

@property
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
]
REQS_OPENSTACK = [
'openstacksdk>=0.12.0,<1.0.0',
'python-novaclient>=7.0.0,<18.0',
'python-swiftclient>=3.2.0,<4.0',
'python-novaclient>=7.0.0,<19.0',
'python-swiftclient>=3.2.0,<5.0',
'python-neutronclient>=6.0.0,<8.0',
'python-keystoneclient>=3.13.0,<5.0'
]
Expand Down

0 comments on commit b2555ff

Please sign in to comment.