Add BlazarNeutronClient base class

Partially Implements: blueprint floatingip-reservation
Change-Id: Ie1e41123331bdbcc7c5a8f96ad6ed512d85d4963
This commit is contained in:
Masahito Muroi 2018-12-21 17:44:18 +09:00 committed by Pierre Riteau
parent 80938dfab9
commit dd3f3e30a9
4 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,36 @@
# Copyright (c) 2019 NTT.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from oslo_config import cfg
from oslo_config import fixture
from blazar import tests
from blazar.utils.openstack import neutron
CONF = cfg.CONF
class TestBlazarNeutronClient(tests.TestCase):
def setUp(self):
super(TestBlazarNeutronClient, self).setUp()
self.cfg = self.useFixture(fixture.Config(CONF))
def test_client_from_kwargs(self):
kwargs = {
'auth_url': 'http://foo:8080/identity/v3'
}
client = neutron.BlazarNeutronClient(**kwargs)
self.assertEqual("http://foo:8080/identity/v3",
client.neutron.httpclient.session.auth.auth_url)

View File

@ -0,0 +1,57 @@
# Copyright (c) 2019 NTT.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from keystoneauth1.identity import v3
from keystoneauth1 import session
from neutronclient.v2_0 import client as neutron_client
from oslo_config import cfg
from oslo_log import log as logging
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
class BlazarNeutronClient(object):
"""Client class for Neutron service."""
def __init__(self, **kwargs):
username = kwargs.pop('username',
CONF.os_admin_username)
password = kwargs.pop('password',
CONF.os_admin_password)
project_name = kwargs.pop('project_name',
CONF.os_admin_project_name)
user_domain_name = kwargs.pop('user_domain_name',
CONF.os_admin_user_domain_name)
project_domain_name = kwargs.pop('project_domain_name',
CONF.os_admin_project_domain_name)
auth_url = kwargs.pop('auth_url', None)
if auth_url is None:
auth_url = "%s://%s:%s/%s/%s" % (CONF.os_auth_protocol,
CONF.os_auth_host,
CONF.os_auth_port,
CONF.os_auth_prefix,
CONF.os_auth_version)
auth = v3.Password(auth_url=auth_url,
username=username,
password=password,
project_name=project_name,
user_domain_name=user_domain_name,
project_domain_name=project_domain_name)
sess = session.Session(auth=auth)
self.neutron = neutron_client.Client(session=sess)

View File

@ -83,6 +83,7 @@ python-dateutil==2.7.0
python-editor==1.0.3
python-keystoneclient==3.8.0
python-mimeparse==1.6.0
python-neutronclient==6.0.0
python-novaclient==9.1.0
python-subunit==1.2.0
pytz==2018.3

View File

@ -23,6 +23,7 @@ oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0
oslo.service!=1.28.1,>=1.24.0 # Apache-2.0
oslo.upgradecheck>=0.1.0 # Apache-2.0
oslo.utils>=3.33.0 # Apache-2.0
python-neutronclient>=6.0.0 # Apache-2.0
python-novaclient>=9.1.0 # Apache-2.0
netaddr>=0.7.18 # BSD
python-keystoneclient>=3.8.0 # Apache-2.0