Skip to content

Commit

Permalink
Allow to update vnic_type when port is not bound
Browse files Browse the repository at this point in the history
Updating vnic type is legal procedure, and is used by Ironic. This patch
allows to update vnic type when port is not bound (doesn't have
references to VM or Vrouter)

Closes-Bug: 1719268

Change-Id: Ic7b6a7232316c698b2f8521a9b3d46fb755d4e3d
  • Loading branch information
Andrey Shestakov authored and jumpojoy committed Nov 2, 2017
1 parent 5df793d commit 3ef7d84
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/config/api-server/vnc_cfg_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,19 @@ def _check_service_health_check_type(cls, obj_dict, db_dict, db_conn):

return (True, '')

@classmethod
def _is_port_bound(cls, obj_dict):
"""Check whatever port is bound.
We assume port is bound when it is linked to either VM or Vrouter.
:param obj_dict: Port dict to check
:returns: True if port is bound, False otherwise.
"""

return (obj_dict.get('logical_router_back_refs') or
obj_dict.get('virtual_machine_refs'))

@classmethod
def pre_dbe_create(cls, tenant_name, obj_dict, db_conn):
vn_dict = obj_dict['virtual_network_refs'][0]
Expand Down Expand Up @@ -1393,8 +1406,10 @@ def pre_dbe_update(cls, id, fq_name, obj_dict, db_conn,
if kvps:
kvp_dict = cls._kvp_to_dict(kvps)
new_vnic_type = kvp_dict.get('vnic_type', old_vnic_type)
if (old_vnic_type != new_vnic_type):
return (False, (409, "Vnic_type can not be modified"))
if (old_vnic_type != new_vnic_type):
if cls._is_port_bound(read_result):
return (False, (409, "Vnic_type can not be modified when "
"port is linked to Vrouter or VM."))

if old_vnic_type == cls.portbindings['VNIC_TYPE_DIRECT']:
cls._check_vrouter_link(read_result, kvp_dict, obj_dict, db_conn)
Expand Down

0 comments on commit 3ef7d84

Please sign in to comment.