Merge "Add openstacksdk plugin"

This commit is contained in:
Jenkins 2017-04-19 08:40:55 +00:00 committed by Gerrit Code Review
commit 8b1d912a56
5 changed files with 81 additions and 0 deletions

View File

@ -0,0 +1,45 @@
#
# 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 openstack import connection
from openstack import exceptions
from openstack import profile
from heat.engine.clients import client_plugin
class OpenStackSDKPlugin(client_plugin.ClientPlugin):
exceptions_module = exceptions
service_types = [NETWORK] = ['network']
service_client_map = {NETWORK: 'neutron'}
api_version_map = {NETWORK: '2.0'}
def _create(self, version=None):
prof = profile.Profile()
for svc_type in self.service_types:
interface = self._get_client_option(
self.service_client_map[svc_type], 'endpoint_type')
prof.set_interface(svc_type, interface)
prof.set_region(svc_type, self._get_region_name())
prof.set_version(svc_type, self.api_version_map[svc_type])
key_session = self.context.keystone_session
return connection.Connection(authenticator=key_session.auth,
verify=key_session.verify,
cert=key_session.cert,
profile=prof)
def is_not_found(self, ex):
return isinstance(ex, exceptions.ResourceNotFound)

View File

@ -22,6 +22,7 @@ from keystoneauth1.identity import generic
from manilaclient import exceptions as manila_exc
import mock
from neutronclient.common import exceptions as neutron_exc
from openstack import exceptions
from oslo_config import cfg
from saharaclient.api import base as sahara_base
import six
@ -640,6 +641,15 @@ class TestIsNotFound(common.HeatTestCase):
plugin='nova',
exception=lambda: fakes_nova.fake_exception(409),
)),
('openstack_not_found', dict(
is_not_found=True,
is_over_limit=False,
is_client_exception=True,
is_conflict=False,
is_unprocessable_entity=False,
plugin='openstack',
exception=lambda: exceptions.ResourceNotFound,
)),
('swift_not_found', dict(
is_not_found=True,
is_over_limit=False,

View File

@ -0,0 +1,24 @@
#
# 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 heat.tests import common
from heat.tests import utils
class OpenStackSDKPluginTest(common.HeatTestCase):
def test_create(self):
context = utils.dummy_context()
plugin = context.clients.client_plugin('openstack')
client = plugin.client()
self.assertIsNotNone(client.network.segments)

View File

@ -12,6 +12,7 @@ keystoneauth1>=2.18.0 # Apache-2.0
keystonemiddleware>=4.12.0 # Apache-2.0
lxml!=3.7.0,>=2.3 # BSD
netaddr!=0.7.16,>=0.7.13 # BSD
openstacksdk>=0.9.14 # Apache-2.0
oslo.cache>=1.5.0 # Apache-2.0
oslo.config>=3.22.0 # Apache-2.0
oslo.concurrency>=3.8.0 # Apache-2.0

View File

@ -72,6 +72,7 @@ heat.clients =
monasca = heat.engine.clients.os.monasca:MonascaClientPlugin
nova = heat.engine.clients.os.nova:NovaClientPlugin
neutron = heat.engine.clients.os.neutron:NeutronClientPlugin
openstack = heat.engine.clients.os.openstacksdk:OpenStackSDKPlugin
sahara = heat.engine.clients.os.sahara:SaharaClientPlugin
senlin = heat.engine.clients.os.senlin:SenlinClientPlugin
swift = heat.engine.clients.os.swift:SwiftClientPlugin