Skip to content

Commit

Permalink
In an external network, even though a floatingIP is reserved, it can …
Browse files Browse the repository at this point in the history
…be created as an InstanceIP.

This patch corrects that bug

Backported from master

Closes-bug: #1368691

Change-Id: Ifc2203a05901f03a787fb3652c07de0e09542017
  • Loading branch information
anbu-enovance committed Oct 22, 2014
1 parent b83e675 commit 463f909
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/config/api-server/tests/test_crud_basic.py
Expand Up @@ -31,6 +31,7 @@
from vnc_api.common import exceptions as vnc_exceptions
import vnc_api.gen.vnc_api_test_gen
from vnc_api.gen.resource_test import *
import cfgm_common

sys.path.append('../common/tests')
from test_utils import *
Expand Down
20 changes: 20 additions & 0 deletions src/config/api-server/vnc_cfg_types.py
Expand Up @@ -168,6 +168,17 @@ def _get_subnet_name(cls, vn_dict, subnet_uuid):
subnet_dict['ip_prefix_len'])
return subnet_name

@classmethod
def _is_gateway_ip(cls, vn_dict, ip_addr):
ipam_refs = vn_dict.get('network_ipam_refs', [])
for ipam in ipam_refs:
ipam_subnets = ipam['attr'].get('ipam_subnets', [])
for subnet in ipam_subnets:
if subnet['default_gateway'] == ip_addr:
return True

return False

@classmethod
def http_post_collection(cls, tenant_name, obj_dict, db_conn):
vn_fq_name = obj_dict['virtual_network_refs'][0]['to']
Expand All @@ -187,6 +198,15 @@ def http_post_collection(cls, tenant_name, obj_dict, db_conn):
sub = cls._get_subnet_name(vn_dict, subnet_uuid) if subnet_uuid else None
if subnet_uuid and not sub:
return (False, (404, "Subnet id " + subnet_uuid + " not found"))

# If its an external network, check whether floating IP equivalent to
# requested fixed-IP is already reserved.
router_external = vn_dict.get('router_external', None)
if req_ip and router_external and \
not cls._is_gateway_ip(vn_dict, req_ip) and \
cls.addr_mgmt.is_ip_allocated(req_ip, vn_fq_name):
return (False, (403, 'Ip address already in use'))

try:
ip_addr = cls.addr_mgmt.ip_alloc_req(
vn_fq_name, sub=sub, asked_ip_addr=req_ip)
Expand Down
4 changes: 4 additions & 0 deletions src/config/common/tests/test_utils.py
Expand Up @@ -781,6 +781,10 @@ def create(self, path, value='', *args, **kwargs):
self._values[path] = value
# end create

def get(self, path):
return self._values[path]
# end get

def delete(self, path, recursive=False):
if not recursive:
try:
Expand Down

0 comments on commit 463f909

Please sign in to comment.