diff options
| author | Ilya Alekseyev <ilyaalekseyev@acm.org> | 2011-06-28 00:23:19 +0000 |
|---|---|---|
| committer | Tarmac <> | 2011-06-28 00:23:19 +0000 |
| commit | f192f6f0d3f28f0d629a2a97ef6faec85ba24b2e (patch) | |
| tree | 2f1ec4e1d4eff32fbc80ecd2f0aec0835c9fb331 /nova/db | |
| parent | 2cc5d8916b8827faba416a0e317b106afa453ae7 (diff) | |
| parent | 7c4f83bc8f119ff4486f913bd3e5ef7eff5b338f (diff) | |
| download | nova-f192f6f0d3f28f0d629a2a97ef6faec85ba24b2e.tar.gz nova-f192f6f0d3f28f0d629a2a97ef6faec85ba24b2e.tar.xz nova-f192f6f0d3f28f0d629a2a97ef6faec85ba24b2e.zip | |
Added floating IP support in OS API
Diffstat (limited to 'nova/db')
| -rw-r--r-- | nova/db/api.py | 8 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/api.py | 43 |
2 files changed, 49 insertions, 2 deletions
diff --git a/nova/db/api.py b/nova/db/api.py index e6a46aec9..7d2e3053d 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -223,6 +223,9 @@ def certificate_update(context, certificate_id, values): ################### +def floating_ip_get(context, floating_ip_id): + return IMPL.floating_ip_get(context, floating_ip_id) + def floating_ip_allocate_address(context, host, project_id): """Allocate free floating ip and return the address. @@ -289,6 +292,11 @@ def floating_ip_get_by_address(context, address): return IMPL.floating_ip_get_by_address(context, address) +def floating_ip_get_by_ip(context, ip): + """Get a floating ip by floating address.""" + return IMPL.floating_ip_get_by_ip(context, ip) + + 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) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index b6f5cc717..3ace3254f 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -428,6 +428,29 @@ def certificate_update(context, certificate_id, values): ################### +@require_context +def floating_ip_get(context, id): + session = get_session() + result = None + if is_admin_context(context): + result = session.query(models.FloatingIp).\ + options(joinedload('fixed_ip')).\ + options(joinedload_all('fixed_ip.instance')).\ + filter_by(id=id).\ + filter_by(deleted=can_read_deleted(context)).\ + first() + elif is_user_context(context): + result = session.query(models.FloatingIp).\ + options(joinedload('fixed_ip')).\ + options(joinedload_all('fixed_ip.instance')).\ + filter_by(project_id=context.project_id).\ + filter_by(id=id).\ + filter_by(deleted=False).\ + first() + if not result: + raise exception.FloatingIpNotFoundForFixedAddress() + + return result @require_context @@ -582,7 +605,23 @@ def floating_ip_get_by_address(context, address, session=None): filter_by(deleted=can_read_deleted(context)).\ first() if not result: - raise exception.FloatingIpNotFound(fixed_ip=address) + raise exception.FloatingIpNotFoundForFixedAddress(fixed_ip=address) + + return result + + +@require_context +def floating_ip_get_by_ip(context, ip, session=None): + if not session: + session = get_session() + + result = session.query(models.FloatingIp).\ + filter_by(address=ip).\ + filter_by(deleted=can_read_deleted(context)).\ + first() + + if not result: + raise exception.FloatingIpNotFound(floating_ip=ip) return result @@ -722,7 +761,7 @@ def fixed_ip_get_by_address(context, address, session=None): options(joinedload('instance')).\ first() if not result: - raise exception.FloatingIpNotFound(fixed_ip=address) + raise exception.FloatingIpNotFoundForFixedAddress(fixed_ip=address) if is_user_context(context): authorize_project_context(context, result.instance.project_id) |
