Skip to content

Commit

Permalink
Merge "Create vrouter-vm link with prop-map update"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Feb 16, 2016
2 parents c884946 + 889016c commit bbf6cbf
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/config/api-server/vnc_cfg_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def _kvp_to_dict(kvps):
# end _kvp_to_dict

@classmethod
def _check_vrouter_link(cls, obj_dict, kvp_dict, db_conn):
def _check_vrouter_link(cls, kvp_dict, obj_dict, db_conn):
host_id = kvp_dict.get('host_id')
vm_refs = obj_dict.get('virtual_machine_refs')

Expand Down Expand Up @@ -514,15 +514,16 @@ def post_dbe_create(cls, tenant_name, obj_dict, db_conn):
# end post_dbe_create

@classmethod
def pre_dbe_update(cls, id, fq_name, obj_dict, db_conn, **kwargs):
def pre_dbe_update(cls, id, fq_name, obj_dict, db_conn,
prop_collection_updates=None, **kwargs):

vmi_id = {'uuid': id}

try:
(read_ok, read_result) = db_conn.dbe_read('virtual-machine-interface', vmi_id)
(ok, read_result) = db_conn.dbe_read('virtual-machine-interface', vmi_id)
except cfgm_common.exceptions.NoIdError as e:
return (False, (404, str(e)))
if not read_ok:
if not ok:
return (False, (500, read_result))

if ('virtual_machine_interface_refs' in obj_dict and
Expand All @@ -545,15 +546,20 @@ def pre_dbe_update(cls, id, fq_name, obj_dict, db_conn, **kwargs):
kvp_dict = cls._kvp_to_dict(kvps)
old_vnic_type = kvp_dict.get('vnic_type', 'normal')

if 'virtual_machine_interface_bindings' in obj_dict:
bindings = obj_dict['virtual_machine_interface_bindings']
if 'key_value_pair' in bindings:
kvps = bindings['key_value_pair']
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"))
cls._check_vrouter_link(kvp_dict, obj_dict, db_conn)
bindings = obj_dict.get('virtual_machine_interface_bindings', {})
kvps = bindings.get('key_value_pair', [])

for oper_param in prop_collection_updates or []:
if (oper_param['field'] == 'virtual_machine_interface_bindings' and
oper_param['operation'] == 'set'):
kvps.append(oper_param['value'])

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"))
cls._check_vrouter_link(kvp_dict, obj_dict, db_conn)

return True, ""
# end pre_dbe_update
Expand Down

0 comments on commit bbf6cbf

Please sign in to comment.