summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authorJason Kölker <jason@koelker.net>2012-01-04 11:10:10 -0600
committerJason Kölker <jason@koelker.net>2012-01-16 10:52:56 -0600
commitbb867ce3948ddc23cf928ca3dda100a1a977896a (patch)
tree2931f3ea721e452bed8304fd192024394972b602 /nova/db
parent46f90f7cb79a01104376919c56e70a6324fe89af (diff)
Implement BP untie-nova-network-models
Fixes LP853979 Remove the FK references for network data. Remove unused db functions that used the FK's Update db functions to not joinload Update notification to optionally take network_info if compute has it Update EC2 Api to use the network cache, falling back to rpc.call Remove test_instance_get_project_vpn_joins which tests calls not used Change-Id: I1a01ccc5ebcf7efeafe014af62be893325bb0825
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/api.py24
-rw-r--r--nova/db/sqlalchemy/api.py154
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/070_sqlite_downgrade.sql103
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/070_sqlite_upgrade.sql99
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/070_untie_nova_network_models.py98
-rw-r--r--nova/db/sqlalchemy/models.py24
6 files changed, 350 insertions, 152 deletions
diff --git a/nova/db/api.py b/nova/db/api.py
index 81245a285..1e72747a9 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -290,11 +290,6 @@ def floating_ip_fixed_ip_associate(context, floating_address,
host)
-def floating_ip_get_all(context):
- """Get all floating ips."""
- return IMPL.floating_ip_get_all(context)
-
-
def floating_ip_get_all_by_host(context, host):
"""Get all floating ips by host."""
return IMPL.floating_ip_get_all_by_host(context, host)
@@ -315,6 +310,11 @@ def floating_ip_get_by_fixed_address(context, fixed_address):
return IMPL.floating_ip_get_by_fixed_address(context, fixed_address)
+def floating_ip_get_by_fixed_ip_id(context, fixed_ip_id):
+ """Get a floating ips by fixed address"""
+ return IMPL.floating_ip_get_by_fixed_ip_id(context, fixed_ip_id)
+
+
def floating_ip_update(context, address, values):
"""Update a floating ip by address or raise if it doesn't exist."""
return IMPL.floating_ip_update(context, address, values)
@@ -407,11 +407,6 @@ def fixed_ip_get_all(context):
return IMPL.fixed_ip_get_all(context)
-def fixed_ip_get_all_by_instance_host(context, host):
- """Get all allocated fixed ips filtered by instance host."""
- return IMPL.fixed_ip_get_all_by_instance_host(context, host)
-
-
def fixed_ip_get_by_address(context, address):
"""Get a fixed ip by address or raise if it does not exist."""
return IMPL.fixed_ip_get_by_address(context, address)
@@ -581,15 +576,6 @@ def instance_get_all_by_reservation(context, reservation_id):
return IMPL.instance_get_all_by_reservation(context, reservation_id)
-def instance_get_fixed_addresses(context, instance_id):
- """Get the fixed ip address of an instance."""
- return IMPL.instance_get_fixed_addresses(context, instance_id)
-
-
-def instance_get_fixed_addresses_v6(context, instance_id):
- return IMPL.instance_get_fixed_addresses_v6(context, instance_id)
-
-
def instance_get_floating_address(context, instance_id):
"""Get the first floating ip address of an instance."""
return IMPL.instance_get_floating_address(context, instance_id)
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 7ade110fd..13e048ba7 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -27,7 +27,6 @@ from nova import block_device
from nova import db
from nova import exception
from nova import flags
-from nova import ipv6
from nova import utils
from nova import log as logging
from nova.compute import vm_states
@@ -478,8 +477,6 @@ def certificate_update(context, certificate_id, values):
@require_context
def floating_ip_get(context, id):
result = model_query(context, models.FloatingIp, project_only=True).\
- options(joinedload('fixed_ip')).\
- options(joinedload_all('fixed_ip.instance')).\
filter_by(id=id).\
first()
@@ -548,7 +545,7 @@ def floating_ip_fixed_ip_associate(context, floating_address,
fixed_ip_ref = fixed_ip_get_by_address(context,
fixed_address,
session=session)
- floating_ip_ref.fixed_ip = fixed_ip_ref
+ floating_ip_ref.fixed_ip_id = fixed_ip_ref["id"]
floating_ip_ref.host = host
floating_ip_ref.save(session=session)
@@ -583,12 +580,13 @@ def floating_ip_disassociate(context, address):
floating_ip_ref = floating_ip_get_by_address(context,
address,
session=session)
- fixed_ip_ref = floating_ip_ref.fixed_ip
+ fixed_ip_ref = fixed_ip_get(context,
+ floating_ip_ref['fixed_ip_id'])
if fixed_ip_ref:
fixed_ip_address = fixed_ip_ref['address']
else:
fixed_ip_address = None
- floating_ip_ref.fixed_ip = None
+ floating_ip_ref.fixed_ip_id = None
floating_ip_ref.host = None
floating_ip_ref.save(session=session)
return fixed_ip_address
@@ -606,16 +604,7 @@ def floating_ip_set_auto_assigned(context, address):
def _floating_ip_get_all(context):
- return model_query(context, models.FloatingIp, read_deleted="no").\
- options(joinedload_all('fixed_ip.instance'))
-
-
-@require_admin_context
-def floating_ip_get_all(context):
- floating_ip_refs = _floating_ip_get_all(context).all()
- if not floating_ip_refs:
- raise exception.NoFloatingIpsDefined()
- return floating_ip_refs
+ return model_query(context, models.FloatingIp, read_deleted="no")
@require_admin_context
@@ -641,7 +630,6 @@ def floating_ip_get_all_by_project(context, project_id):
@require_context
def floating_ip_get_by_address(context, address, session=None):
result = model_query(context, models.FloatingIp, session=session).\
- options(joinedload_all('fixed_ip.network')).\
filter_by(address=address).\
first()
@@ -665,7 +653,6 @@ def floating_ip_get_by_fixed_address(context, fixed_address, session=None):
fixed_ip_id = fixed_ip['id']
return model_query(context, models.FloatingIp, session=session).\
- options(joinedload_all('fixed_ip.network')).\
filter_by(fixed_ip_id=fixed_ip_id).\
all()
@@ -673,6 +660,16 @@ def floating_ip_get_by_fixed_address(context, fixed_address, session=None):
@require_context
+def floating_ip_get_by_fixed_ip_id(context, fixed_ip_id, session=None):
+ if not session:
+ session = get_session()
+
+ return model_query(context, models.FloatingIp, session=session).\
+ filter_by(fixed_ip_id=fixed_ip_id).\
+ all()
+
+
+@require_context
def floating_ip_update(context, address, values):
session = get_session()
with session.begin():
@@ -732,7 +729,7 @@ def fixed_ip_associate_pool(context, network_id, instance_id=None, host=None):
read_deleted="no").\
filter(network_or_none).\
filter_by(reserved=False).\
- filter_by(instance=None).\
+ filter_by(instance_id=None).\
filter_by(host=None).\
with_lockmode('update').\
first()
@@ -740,16 +737,15 @@ def fixed_ip_associate_pool(context, network_id, instance_id=None, host=None):
# then this has concurrency issues
if not fixed_ip_ref:
raise exception.NoMoreFixedIps()
- if not fixed_ip_ref.network:
- fixed_ip_ref.network = network_get(context,
- network_id,
- session=session)
+
+ if fixed_ip_ref['network_id'] is None:
+ fixed_ip_ref['network'] = network_id
+
if instance_id:
- fixed_ip_ref.instance = instance_get(context,
- instance_id,
- session=session)
+ fixed_ip_ref['instance_id'] = instance_id
+
if host:
- fixed_ip_ref.host = host
+ fixed_ip_ref['host'] = host
session.add(fixed_ip_ref)
return fixed_ip_ref['address']
@@ -798,8 +794,6 @@ def fixed_ip_disassociate_all_by_timeout(context, host, time):
filter(models.FixedIp.updated_at < time).\
filter(models.FixedIp.instance_id != None).\
filter(models.FixedIp.allocated == False).\
- join(models.FixedIp.instance).\
- join(models.FixedIp.network).\
filter(host_filter).\
all()
result = model_query(context, models.FixedIp, session=session,
@@ -816,16 +810,15 @@ def fixed_ip_disassociate_all_by_timeout(context, host, time):
def fixed_ip_get(context, id, session=None):
result = model_query(context, models.FixedIp, session=session).\
filter_by(id=id).\
- options(joinedload('floating_ips')).\
- options(joinedload('network')).\
first()
if not result:
raise exception.FixedIpNotFound(id=id)
# FIXME(sirp): shouldn't we just use project_only here to restrict the
# results?
- if is_user_context(context):
- authorize_project_context(context, result.instance.project_id)
+ if is_user_context(context) and result['instance_id'] is not None:
+ instance = instance_get(context, result['instance_id'], session)
+ authorize_project_context(context, instance.project_id)
return result
@@ -834,7 +827,6 @@ def fixed_ip_get(context, id, session=None):
def fixed_ip_get_all(context, session=None):
result = model_query(context, models.FixedIp, session=session,
read_deleted="yes").\
- options(joinedload('floating_ips')).\
all()
if not result:
raise exception.NoFixedIpsDefined()
@@ -842,36 +834,20 @@ def fixed_ip_get_all(context, session=None):
return result
-@require_admin_context
-def fixed_ip_get_all_by_instance_host(context, host=None):
- result = model_query(context, models.FixedIp, read_deleted="yes").\
- options(joinedload('floating_ips')).\
- join(models.FixedIp.instance).\
- filter_by(host=host).\
- all()
-
- if not result:
- raise exception.FixedIpNotFoundForHost(host=host)
-
- return result
-
-
@require_context
def fixed_ip_get_by_address(context, address, session=None):
result = model_query(context, models.FixedIp, session=session,
read_deleted="yes").\
filter_by(address=address).\
- options(joinedload('floating_ips')).\
- options(joinedload('network')).\
- options(joinedload('instance')).\
first()
if not result:
raise exception.FixedIpNotFoundForAddress(address=address)
# NOTE(sirp): shouldn't we just use project_only here to restrict the
# results?
- if is_user_context(context):
- authorize_project_context(context, result.instance.project_id)
+ if is_user_context(context) and result['instance_id'] is not None:
+ instance = instance_get(context, result['instance_id'], session)
+ authorize_project_context(context, instance.project_id)
return result
@@ -879,7 +855,6 @@ def fixed_ip_get_by_address(context, address, session=None):
@require_context
def fixed_ip_get_by_instance(context, instance_id):
result = model_query(context, models.FixedIp, read_deleted="no").\
- options(joinedload('floating_ips')).\
filter_by(instance_id=instance_id).\
all()
@@ -905,7 +880,6 @@ def fixed_ip_get_by_network_host(context, network_id, host):
@require_context
def fixed_ips_by_virtual_interface(context, vif_id):
result = model_query(context, models.FixedIp, read_deleted="no").\
- options(joinedload('floating_ips')).\
filter_by(virtual_interface_id=vif_id).\
all()
@@ -966,8 +940,7 @@ def virtual_interface_update(context, vif_id, values):
@require_context
def _virtual_interface_query(context, session=None):
return model_query(context, models.VirtualInterface, session=session,
- read_deleted="yes").\
- options(joinedload_all('fixed_ips.floating_ips'))
+ read_deleted="yes")
@require_context
@@ -1202,9 +1175,6 @@ def instance_get(context, instance_id, session=None):
def _build_instance_get(context, session=None):
return model_query(context, models.Instance, session=session,
project_only=True).\
- options(joinedload_all('fixed_ips.floating_ips')).\
- options(joinedload_all('fixed_ips.network')).\
- options(joinedload_all('fixed_ips.virtual_interface')).\
options(joinedload_all('security_groups.rules')).\
options(joinedload('info_cache')).\
options(joinedload('volumes')).\
@@ -1215,10 +1185,8 @@ def _build_instance_get(context, session=None):
@require_admin_context
def instance_get_all(context):
return model_query(context, models.Instance).\
- options(joinedload_all('fixed_ips.floating_ips')).\
options(joinedload('info_cache')).\
options(joinedload('security_groups')).\
- options(joinedload_all('fixed_ips.network')).\
options(joinedload('metadata')).\
options(joinedload('instance_type')).\
all()
@@ -1266,9 +1234,6 @@ def instance_get_all_by_filters(context, filters):
session = get_session()
query_prefix = session.query(models.Instance).\
- options(joinedload_all('fixed_ips.floating_ips')).\
- options(joinedload_all('fixed_ips.network')).\
- options(joinedload_all('fixed_ips.virtual_interface')).\
options(joinedload('info_cache')).\
options(joinedload('security_groups')).\
options(joinedload('metadata')).\
@@ -1366,9 +1331,7 @@ def instance_get_active_by_window_joined(context, begin, end=None,
"""Return instances and joins that were continuously active over window."""
session = get_session()
query = session.query(models.Instance).\
- options(joinedload_all('fixed_ips.floating_ips')).\
options(joinedload('security_groups')).\
- options(joinedload_all('fixed_ips.network')).\
options(joinedload('instance_type')).\
filter(models.Instance.launched_at < begin)
if end:
@@ -1384,10 +1347,8 @@ def instance_get_active_by_window_joined(context, begin, end=None,
@require_admin_context
def _instance_get_all_query(context, project_only=False):
return model_query(context, models.Instance, project_only=project_only).\
- options(joinedload_all('fixed_ips.floating_ips')).\
options(joinedload('info_cache')).\
options(joinedload('security_groups')).\
- options(joinedload_all('fixed_ips.network')).\
options(joinedload('metadata')).\
options(joinedload('instance_type'))
@@ -1425,53 +1386,24 @@ def instance_get_project_vpn(context, project_id):
first()
-@require_context
-def instance_get_fixed_addresses(context, instance_id):
- session = get_session()
- with session.begin():
- try:
- fixed_ips = fixed_ip_get_by_instance(context, instance_id)
- except exception.NotFound:
- return []
- return [fixed_ip.address for fixed_ip in fixed_ips]
-
-
-@require_context
-def instance_get_fixed_addresses_v6(context, instance_id):
- session = get_session()
- with session.begin():
- # get instance
- instance_ref = instance_get(context, instance_id, session=session)
- # assume instance has 1 mac for each network associated with it
- # get networks associated with instance
- network_refs = network_get_all_by_instance(context, instance_id)
- # compile a list of cidr_v6 prefixes sorted by network id
- prefixes = [ref.cidr_v6 for ref in
- sorted(network_refs, key=lambda ref: ref.id)]
- # get vifs associated with instance
- vif_refs = virtual_interface_get_by_instance(context, instance_ref.id)
- # compile list of the mac_addresses for vifs sorted by network id
- macs = [vif_ref['address'] for vif_ref in
- sorted(vif_refs, key=lambda vif_ref: vif_ref['network_id'])]
- # get project id from instance
- project_id = instance_ref.project_id
- # combine prefixes, macs, and project_id into (prefix,mac,p_id) tuples
- prefix_mac_tuples = zip(prefixes, macs, [project_id for m in macs])
- # return list containing ipv6 address for each tuple
- return [ipv6.to_global(*t) for t in prefix_mac_tuples]
-
-
+# NOTE(jkoelker) This is only being left here for compat with floating
+# ips. Currently the network_api doesn't return floaters
+# in network_info. Once it starts return the model. This
+# function and it's call in compute/manager.py on 1829 can
+# go away
@require_context
def instance_get_floating_address(context, instance_id):
- fixed_ip_refs = fixed_ip_get_by_instance(context, instance_id)
- if not fixed_ip_refs:
+ fixed_ips = fixed_ip_get_by_instance(context, instance_id)
+ if not fixed_ips:
return None
# NOTE(tr3buchet): this only gets the first fixed_ip
# won't find floating ips associated with other fixed_ips
- if not fixed_ip_refs[0].floating_ips:
+ floating_ips = floating_ip_get_by_fixed_address(context,
+ fixed_ips[0]['address'])
+ if not floating_ips:
return None
# NOTE(vish): this just returns the first floating ip
- return fixed_ip_refs[0].floating_ips[0]['address']
+ return floating_ips[0]['address']
@require_admin_context
@@ -1878,7 +1810,6 @@ def network_get_associated_fixed_ips(context, network_id):
# FIXME(sirp): since this returns fixed_ips, this would be better named
# fixed_ip_get_all_by_network.
return model_query(context, models.FixedIp, read_deleted="no").\
- options(joinedload_all('instance')).\
filter_by(network_id=network_id).\
filter(models.FixedIp.instance_id != None).\
filter(models.FixedIp.virtual_interface_id != None).\
@@ -1929,7 +1860,6 @@ def network_get_by_instance(context, instance_id):
# note this uses fixed IP to get to instance
# only works for networks the instance has an IP from
result = _network_get_query(context).\
- join(models.Network.fixed_ips).\
filter_by(instance_id=instance_id).\
first()
@@ -1942,7 +1872,6 @@ def network_get_by_instance(context, instance_id):
@require_admin_context
def network_get_all_by_instance(context, instance_id):
result = _network_get_query(context).\
- join(models.Network.fixed_ips).\
filter_by(instance_id=instance_id).\
all()
@@ -1959,7 +1888,6 @@ def network_get_all_by_host(context, host):
host_filter = or_(models.Network.host == host,
models.FixedIp.host == host)
return _network_get_query(context).\
- join(models.Network.fixed_ips).\
filter(host_filter).\
all()
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/070_sqlite_downgrade.sql b/nova/db/sqlalchemy/migrate_repo/versions/070_sqlite_downgrade.sql
new file mode 100644
index 000000000..25270a686
--- /dev/null
+++ b/nova/db/sqlalchemy/migrate_repo/versions/070_sqlite_downgrade.sql
@@ -0,0 +1,103 @@
+BEGIN TRANSACTION;
+ CREATE TABLE fixed_ips_backup (
+ created_at DATETIME NOT NULL,
+ updated_at DATETIME,
+ deleted_at DATETIME,
+ deleted BOOLEAN NOT NULL,
+ id INTEGER NOT NULL,
+ address VARCHAR(255),
+ virtual_interface_id INTEGER,
+ network_id INTEGER,
+ instance_id INTEGER,
+ allocated BOOLEAN default FALSE,
+ leased BOOLEAN default FALSE,
+ reserved BOOLEAN default FALSE,
+ host VARCHAR(255),
+ PRIMARY KEY (id)
+ );
+
+ CREATE TABLE floating_ips_backup (
+ created_at DATETIME,
+ updated_at DATETIME,
+ deleted_at DATETIME,
+ deleted BOOLEAN,
+ id INTEGER NOT NULL,
+ address VARCHAR(255),
+ fixed_ip_id INTEGER,
+ project_id VARCHAR(255),
+ host VARCHAR(255),
+ auto_assigned BOOLEAN,
+ pool VARCHAR(255),
+ interface VARCHAR(255),
+ PRIMARY KEY (id)
+ );
+
+ INSERT INTO fixed_ips_backup
+ SELECT created_at, updated_at, deleted_at, deleted, id, address,
+ virtual_interface_id, network_id, instance_id, allocated,
+ leased, reserved, host
+ FROM fixed_ips;
+
+ INSERT INTO floating_ips_backup
+ SELECT created_at, updated_at, deleted_at, deleted, id, address,
+ fixed_ip_id, project_id, host, auto_assigned, pool,
+ interface
+ FROM floating_ips;
+
+ DROP TABLE fixed_ips;
+ DROP TABLE floating_ips;
+
+ CREATE TABLE fixed_ips (
+ created_at DATETIME NOT NULL,
+ updated_at DATETIME,
+ deleted_at DATETIME,
+ deleted BOOLEAN NOT NULL,
+ id INTEGER NOT NULL,
+ address VARCHAR(255),
+ virtual_interface_id INTEGER,
+ network_id INTEGER,
+ instance_id INTEGER,
+ allocated BOOLEAN default FALSE,
+ leased BOOLEAN default FALSE,
+ reserved BOOLEAN default FALSE,
+ host VARCHAR(255),
+ PRIMARY KEY (id),
+ FOREIGN KEY(virtual_interface_id) REFERENCES virtual_interfaces (id),
+ FOREIGN KEY(network_id) REFERENCES networks (id),
+ FOREIGN KEY(instance_id) REFERENCES instanced (id)
+ );
+
+ CREATE TABLE floating_ips (
+ created_at DATETIME,
+ updated_at DATETIME,
+ deleted_at DATETIME,
+ deleted BOOLEAN,
+ id INTEGER NOT NULL,
+ address VARCHAR(255),
+ fixed_ip_id INTEGER,
+ project_id VARCHAR(255),
+ host VARCHAR(255),
+ auto_assigned BOOLEAN,
+ pool VARCHAR(255),
+ interface VARCHAR(255),
+ PRIMARY KEY (id),
+ CHECK (deleted IN (0, 1)),
+ FOREIGN KEY(fixed_ip_id) REFERENCES fixed_ips (id)
+ );
+
+ INSERT INTO fixed_ips
+ SELECT created_at, updated_at, deleted_at, deleted, id, address,
+ virtual_interface_id, network_id, instance_id, allocated,
+ leased, reserved, host
+ FROM fixed_ips_backup;
+
+ INSERT INTO floating_ips
+ SELECT created_at, updated_at, deleted_at, deleted, id, address,
+ fixed_ip_id, project_id, host, auto_assigned, pool,
+ interface
+ FROM floating_ips_backup;
+
+ DROP TABLE fixed_ips_backup;
+ DROP TABLE floating_ips_backup;
+
+COMMIT;
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/070_sqlite_upgrade.sql b/nova/db/sqlalchemy/migrate_repo/versions/070_sqlite_upgrade.sql
new file mode 100644
index 000000000..2b6f7c39a
--- /dev/null
+++ b/nova/db/sqlalchemy/migrate_repo/versions/070_sqlite_upgrade.sql
@@ -0,0 +1,99 @@
+BEGIN TRANSACTION;
+ CREATE TABLE fixed_ips_backup (
+ created_at DATETIME NOT NULL,
+ updated_at DATETIME,
+ deleted_at DATETIME,
+ deleted BOOLEAN NOT NULL,
+ id INTEGER NOT NULL,
+ address VARCHAR(255),
+ virtual_interface_id INTEGER,
+ network_id INTEGER,
+ instance_id INTEGER,
+ allocated BOOLEAN default FALSE,
+ leased BOOLEAN default FALSE,
+ reserved BOOLEAN default FALSE,
+ host VARCHAR(255),
+ PRIMARY KEY (id)
+ );
+
+ CREATE TABLE floating_ips_backup (
+ created_at DATETIME,
+ updated_at DATETIME,
+ deleted_at DATETIME,
+ deleted BOOLEAN,
+ id INTEGER NOT NULL,
+ address VARCHAR(255),
+ fixed_ip_id INTEGER,
+ project_id VARCHAR(255),
+ host VARCHAR(255),
+ auto_assigned BOOLEAN,
+ pool VARCHAR(255),
+ interface VARCHAR(255),
+ PRIMARY KEY (id)
+ );
+
+ INSERT INTO fixed_ips_backup
+ SELECT created_at, updated_at, deleted_at, deleted, id, address,
+ virtual_interface_id, network_id, instance_id, allocated,
+ leased, reserved, host
+ FROM fixed_ips;
+
+ INSERT INTO floating_ips_backup
+ SELECT created_at, updated_at, deleted_at, deleted, id, address,
+ fixed_ip_id, project_id, host, auto_assigned, pool,
+ interface
+ FROM floating_ips;
+
+ DROP TABLE fixed_ips;
+ DROP TABLE floating_ips;
+
+ CREATE TABLE fixed_ips (
+ created_at DATETIME NOT NULL,
+ updated_at DATETIME,
+ deleted_at DATETIME,
+ deleted BOOLEAN NOT NULL,
+ id INTEGER NOT NULL,
+ address VARCHAR(255),
+ virtual_interface_id INTEGER,
+ network_id INTEGER,
+ instance_id INTEGER,
+ allocated BOOLEAN default FALSE,
+ leased BOOLEAN default FALSE,
+ reserved BOOLEAN default FALSE,
+ host VARCHAR(255),
+ PRIMARY KEY (id)
+ );
+
+ CREATE TABLE floating_ips (
+ created_at DATETIME,
+ updated_at DATETIME,
+ deleted_at DATETIME,
+ deleted BOOLEAN,
+ id INTEGER NOT NULL,
+ address VARCHAR(255),
+ fixed_ip_id INTEGER,
+ project_id VARCHAR(255),
+ host VARCHAR(255),
+ auto_assigned BOOLEAN,
+ pool VARCHAR(255),
+ interface VARCHAR(255),
+ PRIMARY KEY (id),
+ CHECK (deleted IN (0, 1))
+ );
+
+ INSERT INTO fixed_ips
+ SELECT created_at, updated_at, deleted_at, deleted, id, address,
+ virtual_interface_id, network_id, instance_id, allocated,
+ leased, reserved, host
+ FROM fixed_ips_backup;
+
+ INSERT INTO floating_ips
+ SELECT created_at, updated_at, deleted_at, deleted, id, address,
+ fixed_ip_id, project_id, host, auto_assigned, pool,
+ interface
+ FROM floating_ips_backup;
+
+ DROP TABLE fixed_ips_backup;
+ DROP TABLE floating_ips_backup;
+
+COMMIT;
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/070_untie_nova_network_models.py b/nova/db/sqlalchemy/migrate_repo/versions/070_untie_nova_network_models.py
new file mode 100644
index 000000000..83114b451
--- /dev/null
+++ b/nova/db/sqlalchemy/migrate_repo/versions/070_untie_nova_network_models.py
@@ -0,0 +1,98 @@
+# Copyright 2011 OpenStack LLC.
+#
+# 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 sqlalchemy import MetaData, Table
+from migrate import ForeignKeyConstraint
+
+from nova import log as logging
+
+meta = MetaData()
+
+
+def upgrade(migrate_engine):
+ # Upgrade operations go here. Don't create your own engine;
+ # bind migrate_engine to your metadata
+ meta.bind = migrate_engine
+ dialect = migrate_engine.url.get_dialect().name
+ if dialect.startswith('sqlite'):
+ return
+
+ instances = Table('instances', meta, autoload=True)
+ networks = Table('networks', meta, autoload=True)
+ vifs = Table('virtual_interfaces', meta, autoload=True)
+ fixed_ips = Table('fixed_ips', meta, autoload=True)
+ floating_ips = Table('floating_ips', meta, autoload=True)
+
+ try:
+ fkeys = list(fixed_ips.c.network_id.foreign_keys)
+ if fkeys:
+ fkey_name = fkeys[0].constraint.name
+ ForeignKeyConstraint(columns=[fixed_ips.c.network_id],
+ refcolumns=[networks.c.id],
+ name=fkey_name).drop()
+
+ fkeys = list(fixed_ips.c.virtual_interface_id.foreign_keys)
+ if fkeys:
+ fkey_name = fkeys[0].constraint.name
+ ForeignKeyConstraint(columns=[fixed_ips.c.virtual_interface_id],
+ refcolumns=[vifs.c.id],
+ name=fkey_name).drop()
+
+ fkeys = list(fixed_ips.c.instance_id.foreign_keys)
+ if fkeys:
+ fkey_name = fkeys[0].constraint.name
+ ForeignKeyConstraint(columns=[fixed_ips.c.instance_id],
+ refcolumns=[instances.c.id],
+ name=fkey_name).drop()
+
+ fkeys = list(floating_ips.c.fixed_ip_id.foreign_keys)
+ if fkeys:
+ fkey_name = fkeys[0].constraint.name
+ ForeignKeyConstraint(columns=[floating_ips.c.fixed_ip_id],
+ refcolumns=[fixed_ips.c.id],
+ name=fkey_name).drop()
+
+ except Exception:
+ logging.error(_("foreign key constraint couldn't be removed"))
+ raise
+
+
+def downgrade(migrate_engine):
+ # Operations to reverse the above upgrade go here.
+ meta.bind = migrate_engine
+ dialect = migrate_engine.url.get_dialect().name
+ if dialect.startswith('sqlite'):
+ return
+
+ instances = Table('instances', meta, autoload=True)
+ networks = Table('networks', meta, autoload=True)
+ vifs = Table('virtual_interfaces', meta, autoload=True)
+ fixed_ips = Table('fixed_ips', meta, autoload=True)
+ floating_ips = Table('floating_ips', meta, autoload=True)
+
+ try:
+ ForeignKeyConstraint(columns=[fixed_ips.c.network_id],
+ refcolumns=[networks.c.id]).create()
+
+ ForeignKeyConstraint(columns=[fixed_ips.c.virtual_interface_id],
+ refcolumns=[vifs.c.id]).create()
+
+ ForeignKeyConstraint(columns=[fixed_ips.c.instance_id],
+ refcolumns=[instances.c.id]).create()
+
+ ForeignKeyConstraint(columns=[floating_ips.c.fixed_ip_id],
+ refcolumns=[fixed_ips.c.id]).create()
+ except Exception:
+ logging.error(_("foreign key constraint couldn't be added"))
+ raise
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index 92c9bb27f..4ad6dff1f 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -683,19 +683,9 @@ class FixedIp(BASE, NovaBase):
__tablename__ = 'fixed_ips'
id = Column(Integer, primary_key=True)
address = Column(String(255))
- network_id = Column(Integer, ForeignKey('networks.id'), nullable=True)
- network = relationship(Network, backref=backref('fixed_ips'))
- virtual_interface_id = Column(Integer, ForeignKey('virtual_interfaces.id'),
- nullable=True)
- virtual_interface = relationship(VirtualInterface,
- backref=backref('fixed_ips'))
- instance_id = Column(Integer, ForeignKey('instances.id'), nullable=True)
- instance = relationship(Instance,
- backref=backref('fixed_ips'),
- foreign_keys=instance_id,
- primaryjoin='and_('
- 'FixedIp.instance_id == Instance.id,'
- 'FixedIp.deleted == False)')
+ network_id = Column(Integer, nullable=True)
+ virtual_interface_id = Column(Integer, nullable=True)
+ instance_id = Column(Integer, nullable=True)
# associated means that a fixed_ip has its instance_id column set
# allocated means that a fixed_ip has a its virtual_interface_id column set
allocated = Column(Boolean, default=False)
@@ -710,13 +700,7 @@ class FloatingIp(BASE, NovaBase):
__tablename__ = 'floating_ips'
id = Column(Integer, primary_key=True)
address = Column(String(255))
- fixed_ip_id = Column(Integer, ForeignKey('fixed_ips.id'), nullable=True)
- fixed_ip = relationship(FixedIp,
- backref=backref('floating_ips'),
- foreign_keys=fixed_ip_id,
- primaryjoin='and_('
- 'FloatingIp.fixed_ip_id == FixedIp.id,'
- 'FloatingIp.deleted == False)')
+ fixed_ip_id = Column(Integer, nullable=True)
project_id = Column(String(255))
host = Column(String(255)) # , ForeignKey('hosts.id'))
auto_assigned = Column(Boolean, default=False, nullable=False)