From 7c50a8e3575d56c295b3e0d402aecc37c9d1e427 Mon Sep 17 00:00:00 2001 From: Matt Dietz Date: Fri, 1 Mar 2013 23:34:14 +0000 Subject: [PATCH] Added in the new port ip address association table but didn't remove the port_id association yet from the IP address. Deallocation needs to be reworked --- TODO | 3 +++ quark/db/models.py | 14 +++++++++++++- quark/plugin.py | 12 +++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index 2601449..1a1da56 100644 --- a/TODO +++ b/TODO @@ -9,6 +9,9 @@ CRUD IP Allocations * CRUD MacAddressRanges * AIC doesn't support creating multiple switches on the same network. i.e. if we expand past the port count per switch, undefined +We may want to override the existing sessionmaker. Things it chooses to do, like disabling expiration and autocommiting, are discouraged by the docs +Implementation of Zope Interfaces to abstract base class all the things, as well as represent pluggable all the things + Later: Maybe implement a straight passthrough driver for testing and debugging purposes diff --git a/quark/db/models.py b/quark/db/models.py index b2ab6f0..7e18180 100644 --- a/quark/db/models.py +++ b/quark/db/models.py @@ -210,6 +210,18 @@ class Port(BASEV2, HasId, HasTenant): ip_addresses = orm.relationship(IPAddress, backref=orm.backref("ports")) +class PortIPAddressAssociation(BASEV2, HasId): + __tablename__ = "quark_port_ip_address_associations" + port_id = sa.Column(sa.String(36), sa.ForeignKey("quark_ports.id"), + nullable=False) + ip_address_id = sa.Column(sa.String(36), + sa.ForeignKey("quark_ip_addresses.id"), + nullable=False) + port = orm.relationship(Port, uselist=False, backref="association") + ip_address = orm.relationship(IPAddress, uselist=False, + backref="association") + + class MacAddress(BASEV2, HasTenant): __tablename__ = "quark_mac_addresses" address = sa.Column(sa.BigInteger(), primary_key=True) @@ -218,7 +230,6 @@ class MacAddress(BASEV2, HasTenant): nullable=False) deallocated = sa.Column(sa.Boolean()) deallocated_at = sa.Column(sa.DateTime()) - orm.relationship(Port, backref="mac_address") class MacAddressRange(BASEV2, HasId): @@ -226,6 +237,7 @@ class MacAddressRange(BASEV2, HasId): cidr = sa.Column(sa.String(255), nullable=False) first_address = sa.Column(sa.BigInteger(), nullable=False) last_address = sa.Column(sa.BigInteger(), nullable=False) + mac_addresses = orm.relationship(MacAddress, backref="mac_address_range") class Network(BASEV2, HasTenant, HasId): diff --git a/quark/plugin.py b/quark/plugin.py index 46fdfc8..5087422 100644 --- a/quark/plugin.py +++ b/quark/plugin.py @@ -489,6 +489,7 @@ class Plugin(quantum_plugin_base_v2.QuantumPluginBaseV2): if k in port["port"]: port["port"].pop(k) + addresses = [] with session.begin(): port_id = uuidutils.generate_uuid() net_id = port["port"]["network_id"] @@ -520,10 +521,15 @@ class Plugin(quantum_plugin_base_v2.QuantumPluginBaseV2): new_port["addresses"] = addresses new_port["mac_address"] = mac["address"] - for a in addresses: - session.add(a) - session.add(mac) session.add(new_port) + session.add(mac) + for addr in addresses: + addr["port"] = new_port + assoc = models.PortIPAddressAssociation() + assoc["port"] = new_port + assoc["ip_address"] = addr + session.add(addr) + session.add(assoc) new_port["mac_address"] = str(netaddr.EUI(new_port["mac_address"], dialect=netaddr.mac_unix))