summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorTushar Patil <tushar.vitthal.patil@gmail.com>2011-03-31 14:52:19 +0000
committerTarmac <>2011-03-31 14:52:19 +0000
commitde1b0dcf585bdfe2cefa1a7ec561a53ac8c515b8 (patch)
treefe7755f401199c3ea694382b4398462e362c6746 /nova
parenteda275741f5865a1bf58d0176b36d4d99bfeb015 (diff)
parent7d86a9e478c92ac9f79039c4592c6355c91b8b61 (diff)
If the floating ip address is not allocated or is allocated to another project, then the user trying to associate the floating ip address to an instance should get a proper error message.
Diffstat (limited to 'nova')
-rw-r--r--nova/network/api.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/nova/network/api.py b/nova/network/api.py
index 4ee1148cb..c56e3062b 100644
--- a/nova/network/api.py
+++ b/nova/network/api.py
@@ -66,6 +66,21 @@ class API(base.Base):
if isinstance(fixed_ip, str) or isinstance(fixed_ip, unicode):
fixed_ip = self.db.fixed_ip_get_by_address(context, fixed_ip)
floating_ip = self.db.floating_ip_get_by_address(context, floating_ip)
+ # Check if the floating ip address is allocated
+ if floating_ip['project_id'] is None:
+ raise exception.ApiError(_("Address (%s) is not allocated") %
+ floating_ip['address'])
+ # Check if the floating ip address is allocated to the same project
+ if floating_ip['project_id'] != context.project_id:
+ LOG.warn(_("Address (%(address)s) is not allocated to your "
+ "project (%(project)s)"),
+ {'address': floating_ip['address'],
+ 'project': context.project_id})
+ raise exception.ApiError(_("Address (%(address)s) is not "
+ "allocated to your project"
+ "(%(project)s)") %
+ {'address': floating_ip['address'],
+ 'project': context.project_id})
# NOTE(vish): Perhaps we should just pass this on to compute and
# let compute communicate with network.
host = fixed_ip['network']['host']