Brocade plugins/drivers for ML2 and Service Plugins
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.py 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # Copyright 2016 Brocade Communications System, Inc.
  2. # All rights reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. """Brocade specific database schema/model."""
  16. import sqlalchemy as sa
  17. from neutron.db import model_base
  18. from neutron.db import models_v2
  19. class ML2_BrocadeNetwork(model_base.BASEV2, models_v2.HasId,
  20. models_v2.HasTenant):
  21. """Schema for brocade network."""
  22. vlan = sa.Column(sa.String(10))
  23. segment_id = sa.Column(sa.String(36))
  24. network_type = sa.Column(sa.String(10))
  25. class ML2_BrocadePort(model_base.BASEV2, models_v2.HasId,
  26. models_v2.HasTenant):
  27. """Schema for brocade port."""
  28. network_id = sa.Column(sa.String(36),
  29. sa.ForeignKey("ml2_brocadenetworks.id"),
  30. nullable=False)
  31. admin_state_up = sa.Column(sa.Boolean, nullable=False)
  32. physical_interface = sa.Column(sa.String(36))
  33. vlan_id = sa.Column(sa.String(36))
  34. def create_network(context, net_id, vlan, segment_id, network_type, tenant_id):
  35. """Create a brocade specific network/port-profiles."""
  36. # only network_type of vlan is supported
  37. session = context.session
  38. with session.begin(subtransactions=True):
  39. net = get_network(context, net_id, None)
  40. if not net:
  41. net = ML2_BrocadeNetwork(id=net_id, vlan=vlan,
  42. segment_id=segment_id,
  43. network_type='vlan',
  44. tenant_id=tenant_id)
  45. session.add(net)
  46. return net
  47. def delete_network(context, net_id):
  48. """Delete a brocade specific network/port-profiles."""
  49. session = context.session
  50. with session.begin(subtransactions=True):
  51. net = get_network(context, net_id, None)
  52. if net:
  53. session.delete(net)
  54. def get_network(context, net_id, fields=None):
  55. """Get brocade specific network, with vlan extension."""
  56. session = context.session
  57. return session.query(ML2_BrocadeNetwork).filter_by(id=net_id).first()
  58. def get_networks(context, filters=None, fields=None):
  59. """Get all brocade specific networks."""
  60. session = context.session
  61. return session.query(ML2_BrocadeNetwork).all()
  62. def create_port(context, port_id, network_id, physical_interface,
  63. vlan_id, tenant_id, admin_state_up):
  64. """Create a brocade specific port, has policy like vlan."""
  65. session = context.session
  66. with session.begin(subtransactions=True):
  67. port = get_port(context, port_id)
  68. if not port:
  69. port = ML2_BrocadePort(id=port_id,
  70. network_id=network_id,
  71. physical_interface=physical_interface,
  72. vlan_id=vlan_id,
  73. admin_state_up=admin_state_up,
  74. tenant_id=tenant_id)
  75. session.add(port)
  76. return port
  77. def get_port(context, port_id):
  78. """get a brocade specific port."""
  79. session = context.session
  80. return session.query(ML2_BrocadePort).filter_by(id=port_id).first()
  81. def get_ports(context, network_id=None):
  82. """get a brocade specific port."""
  83. session = context.session
  84. return session.query(ML2_BrocadePort).filter_by(
  85. network_id=network_id).all()
  86. def delete_port(context, port_id):
  87. """delete brocade specific port."""
  88. session = context.session
  89. with session.begin(subtransactions=True):
  90. port = get_port(context, port_id)
  91. if port:
  92. session.delete(port)
  93. def update_port_state(context, port_id, admin_state_up):
  94. """Update port attributes."""
  95. session = context.session
  96. with session.begin(subtransactions=True):
  97. session.query(ML2_BrocadePort).filter_by(
  98. id=port_id).update({'admin_state_up': admin_state_up})