Advertisement
fsb4000

Untitled

Aug 24th, 2022
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. #
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. # not use this file except in compliance with the License. You may obtain
  5. # a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations
  13. # under the License.
  14.  
  15. from neutron_lib.api import validators
  16. from neutron_lib import constants
  17. from neutron_lib.db import model_base
  18. from neutron_lib.plugins.ml2 import api
  19. from oslo_log import log as logging
  20. import sqlalchemy as sa
  21. from sqlalchemy import orm
  22.  
  23. from neutron.db import models_v2
  24.  
  25. LOG = logging.getLogger(__name__)
  26.  
  27. class VpcExtensionDriverBase(api.ExtensionDriver):
  28. _supported_extension_aliases = 'fake_extension'
  29.  
  30. @property
  31. def extension_alias(self):
  32. return self._supported_extension_aliases
  33.  
  34. class VpcNetworkExtension(model_base.BASEV2):
  35. network_id = sa.Column(sa.String(36),
  36. sa.ForeignKey('networks.id', ondelete="CASCADE"),
  37. primary_key=True)
  38. value = sa.Column(sa.String(64))
  39. network = orm.relationship(
  40. models_v2.Network,
  41. backref=orm.backref('extension', cascade='delete', uselist=False,
  42. lazy='joined'))
  43.  
  44. class VpcDbExtensionDriver(VpcExtensionDriverBase):
  45. def initialize(self):
  46. LOG.info("VpcDbExtensionDriver initialization complete")
  47.  
  48. def _get_value(self, data, key):
  49. value = data[key]
  50. if not validators.is_attr_set(value):
  51. value = ''
  52. return value
  53.  
  54. def process_create_network(self, plugin_context, data, result):
  55. session = plugin_context.session
  56. value = self._get_value(data, 'vpc_vni')
  57. record = VpcNetworkExtension(network_id=result['id'], value=value)
  58. session.add(record)
  59. result['vpc_vni'] = value
  60.  
  61. def process_update_network(self, plugin_context, data, result):
  62. session = plugin_context.session
  63. record = (session.query(VpcNetworkExtension).
  64. filter_by(network_id=result['id']).one())
  65. value = data.get('vpc_vni')
  66. if value and value != record.value:
  67. record.value = value
  68. result['vpc_vni'] = record.value
  69.  
  70. def extend_network_dict(self, session, net_db, result):
  71. result['vpc_vni'] = net_db.extension.value
  72.  
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement