diff options
| author | Christian Berendt <berendt@b1-systems.de> | 2011-02-18 11:44:06 +0100 |
|---|---|---|
| committer | Christian Berendt <berendt@b1-systems.de> | 2011-02-18 11:44:06 +0100 |
| commit | 205810c3da4652fd0f5203f53299cd998ac7cf82 (patch) | |
| tree | 1f546c2a95591524ef8e18b89051a764701b0fc2 /nova | |
| parent | 5dfa5ce7d1374509fea51f8d0b132ea865f34dc6 (diff) | |
| download | nova-205810c3da4652fd0f5203f53299cd998ac7cf82.tar.gz nova-205810c3da4652fd0f5203f53299cd998ac7cf82.tar.xz nova-205810c3da4652fd0f5203f53299cd998ac7cf82.zip | |
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
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/db/api.py | 5 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/api.py | 22 |
2 files changed, 27 insertions, 0 deletions
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: |
