Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- #
- # 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 neutron_lib.api import validators
- from neutron_lib import constants
- from neutron_lib.db import model_base
- from neutron_lib.plugins.ml2 import api
- from oslo_log import log as logging
- import sqlalchemy as sa
- from sqlalchemy import orm
- from neutron.db import models_v2
- LOG = logging.getLogger(__name__)
- class VpcExtensionDriverBase(api.ExtensionDriver):
- _supported_extension_aliases = 'fake_extension'
- @property
- def extension_alias(self):
- return self._supported_extension_aliases
- class VpcNetworkExtension(model_base.BASEV2):
- network_id = sa.Column(sa.String(36),
- sa.ForeignKey('networks.id', ondelete="CASCADE"),
- primary_key=True)
- value = sa.Column(sa.String(64))
- network = orm.relationship(
- models_v2.Network,
- backref=orm.backref('extension', cascade='delete', uselist=False,
- lazy='joined'))
- class VpcDbExtensionDriver(VpcExtensionDriverBase):
- def initialize(self):
- LOG.info("VpcDbExtensionDriver initialization complete")
- def _get_value(self, data, key):
- value = data[key]
- if not validators.is_attr_set(value):
- value = ''
- return value
- def process_create_network(self, plugin_context, data, result):
- session = plugin_context.session
- value = self._get_value(data, 'vpc_vni')
- record = VpcNetworkExtension(network_id=result['id'], value=value)
- session.add(record)
- result['vpc_vni'] = value
- def process_update_network(self, plugin_context, data, result):
- session = plugin_context.session
- record = (session.query(VpcNetworkExtension).
- filter_by(network_id=result['id']).one())
- value = data.get('vpc_vni')
- if value and value != record.value:
- record.value = value
- result['vpc_vni'] = record.value
- def extend_network_dict(self, session, net_db, result):
- result['vpc_vni'] = net_db.extension.value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement