Esempio n. 1
0
    def create_a10_device_instance(self, context, a10_device_instance):
        """Attempt to create instance using neutron context"""
        LOG.debug("A10DeviceInstancePlugin.create(): a10_device_instance=%s",
                  a10_device_instance)

        config = a10_config.A10Config()
        vthunder_defaults = config.get_vthunder_config()

        imgr = instance_manager.InstanceManager.from_config(config, context)

        dev_instance = common_resources.remove_attributes_not_specified(
            a10_device_instance.get(resources.RESOURCE))

        # Create the instance with specified defaults.
        vthunder_config = vthunder_defaults.copy()
        vthunder_config.update(_convert(dev_instance, _API, _VTHUNDER_CONFIG))
        instance = imgr.create_device_instance(vthunder_config,
                                               dev_instance.get("name"))

        db_record = {}
        db_record.update(_convert(vthunder_config, _VTHUNDER_CONFIG, _DB))
        db_record.update(_convert(dev_instance, _API, _DB))
        db_record.update(_convert(instance, _INSTANCE, _DB))

        # If success, return the created DB record
        # Else, raise an exception because that's what we would do anyway
        db_instance = super(A10DeviceInstancePlugin,
                            self).create_a10_device_instance(
                                context, {resources.RESOURCE: db_record})

        return _make_api_dict(db_instance)
Esempio n. 2
0
    def delete_a10_device_instance(self, context, id):
        LOG.debug("A10DeviceInstancePlugin.delete(): id=%s", id)
        # Deleting the actual instance requires knowing the nova instance ID
        instance = super(A10DeviceInstancePlugin,
                         self).get_a10_device_instance(context, id)
        nova_instance_id = instance.get("nova_instance_id")
        config = a10_config.A10Config()
        imgr = instance_manager.InstanceManager.from_config(config, context)
        imgr.delete_instance(nova_instance_id)

        return super(A10DeviceInstancePlugin,
                     self).delete_a10_device_instance(context, id)
Esempio n. 3
0
def get_engine(url=None):
    global A10_CFG

    if url is None:
        if A10_CFG is None:
            from a10_neutron_lbaas import a10_config
            A10_CFG = a10_config.A10Config()

        if not A10_CFG.get('use_database'):
            raise ex.InternalError(
                "attempted to use database when it is disabled")
        url = A10_CFG.get('database_connection')

    return sqlalchemy.create_engine(url)
Esempio n. 4
0
    def setUp(self):
        super(TestPlugin, self).setUp()
        self.plugin = plugin.A10DeviceInstancePlugin()
        self.target = self.plugin

        self.maxDiff = None

        self.instance_manager = mock.MagicMock()
        self.instance_manager.create_device_instance.side_effect = self.fake_instance

        self.vthunder_defaults = a10_config.A10Config().get_vthunder_config()

        self._im_patcher = mock.patch(
            'a10_neutron_lbaas.vthunder.instance_manager.InstanceManager.from_config',
            return_value=self.instance_manager)
        self._im_patcher.start()
Esempio n. 5
0
    def _late_init(self, provider):
        LOG.info(
            "A10-neutron-lbaas: initializing, version=%s, acos_client=%s, provider=%s",
            version.VERSION, acos_client.VERSION, provider)

        self.provider = provider
        if self.config is None:
            self.config = a10_config.A10Config(config_dir=self.config_dir,
                                               provider=provider)

        if self.plumbing_hooks_class is not None:
            self.hooks = self.plumbing_hooks_class(self)
        else:
            self.hooks = self.config.get('plumbing_hooks_class')(self)

        if self.config.get('verify_appliances'):
            self._verify_appliances()
 def __init__(self, *args, **kwargs):
     super(A10DeviceInstanceDbMixin, self).__init__(*args, **kwargs)
     self.config = a10_config.A10Config()
Esempio n. 7
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.


import sqlalchemy
import sqlalchemy.ext.declarative
import sqlalchemy.orm

import a10_neutron_lbaas.a10_config as a10_config
import a10_neutron_lbaas.a10_exceptions as ex

Base = sqlalchemy.ext.declarative.declarative_base()
a10_cfg = a10_config.A10Config()


def get_base():
    return Base


def get_engine(url=None):
    if url is None:
        if not a10_cfg.get('use_database'):
            raise ex.InternalError("attempted to use database when it is disabled")
        url = a10_cfg.get('database_connection')

    return sqlalchemy.create_engine(url)

Esempio n. 8
0
 def __init__(self, *args, **kwargs):
     super(A10CertificateDbMixin, self).__init__(*args, **kwargs)
     self.config = a10_config.A10Config()
Esempio n. 9
0
def config(config_dict):
    config_constructor = type('config', (object,), config_dict)
    return a10_config.A10Config(config=config_constructor())
Esempio n. 10
0
def empty_config():
    return a10_config.A10Config(config=blank_config)