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.

This commit is contained in:
Tushar Patil 2011-03-31 14:52:19 +00:00 committed by Tarmac
commit de1b0dcf58

View File

@ -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']