From 205810c3da4652fd0f5203f53299cd998ac7cf82 Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Fri, 18 Feb 2011 11:44:06 +0100 Subject: added functionality to list only fixed ip addresses of one node and added exception handling to list method # nova-manage fixed list XXXX network IP address MAC address hostname host 10.xx.xx.0/24 10.xx.xx.5 02:16:3e:3f:33:b6 i-00000547 XXXX 10.xx.xx.0/24 10.xx.xx.9 02:16:3e:14:03:d6 i-00000548 XXXX 10.xx.xx.0/24 10.xx.xx.12 02:16:3e:20:1b:e7 i-00000549 XXXX --- nova/db/api.py | 5 +++++ nova/db/sqlalchemy/api.py | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'nova') diff --git a/nova/db/api.py b/nova/db/api.py index d7f3746d2..6053c0352 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -293,6 +293,11 @@ def fixed_ip_get_all(context): return IMPL.fixed_ip_get_all(context) +def fixed_ip_get_all_by_host(context, host): + """Get all defined fixed ips used by a host.""" + return IMPL.fixed_ip_get_all_by_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) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 2697fac73..d07c53759 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -594,6 +594,28 @@ def fixed_ip_get_all(context, session=None): return result +@require_admin_context +def fixed_ip_get_all_by_host(context, host=None): + session = get_session() + + # FIXME: I'm sure that SQLAlchemy can handle this in a nicer way + instances = session.query(models.Instance).\ + filter_by(state=1).\ + filter_by(host=host).\ + all() + + result = [] + for instance in instances: + result.append(session.query(models.FixedIp).\ + filter_by(instance_id=instance['id']).\ + first()) + + if not result: + raise exception.NotFound(_('No fixed ips for this host defined')) + + return result + + @require_context def fixed_ip_get_by_address(context, address, session=None): if not session: -- cgit From 2714b2df0d21ecb08966c4d145d2d75fa1bb201d Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Sun, 27 Feb 2011 00:07:03 +0100 Subject: fixed FIXME --- nova/db/sqlalchemy/api.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'nova') diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index d07c53759..828d24c78 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -598,17 +598,11 @@ def fixed_ip_get_all(context, session=None): def fixed_ip_get_all_by_host(context, host=None): session = get_session() - # FIXME: I'm sure that SQLAlchemy can handle this in a nicer way - instances = session.query(models.Instance).\ - filter_by(state=1).\ - filter_by(host=host).\ - all() - - result = [] - for instance in instances: - result.append(session.query(models.FixedIp).\ - filter_by(instance_id=instance['id']).\ - first()) + result = session.query(models.FixedIp).\ + join(models.FixedIp.instance).\ + filter_by(state=1).\ + filter_by(host=host).\ + all() if not result: raise exception.NotFound(_('No fixed ips for this host defined')) -- cgit