Skip to content

Commit

Permalink
Changes to not allow deletion of a vmi, if it has sub-interfaces conn…
Browse files Browse the repository at this point in the history
…ected to it

Partial-Bug: 1540789

Change-Id: If0f4103285b99714af23bd09284ed43f0a97862b
  • Loading branch information
cijohnson committed Feb 5, 2016
1 parent 72003c1 commit a08fc04
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/config/api-server/vnc_cfg_api_server.py
Expand Up @@ -832,6 +832,9 @@ def undo_delete(result):

def stateful_delete():
get_context().set_state('PRE_DBE_DELETE')
(ok, del_result) = r_class.pre_dbe_delete(id, read_result, db_conn)
if not ok:
return (ok, del_result)
# Delete default children first
for child_field in r_class.children_fields:
child_type, is_derived = r_class.children_field_types[child_field]
Expand All @@ -842,9 +845,6 @@ def stateful_delete():
continue
self.delete_default_children(child_type, read_result)

(ok, del_result) = r_class.pre_dbe_delete(id, read_result, db_conn)
if not ok:
return (ok, del_result)
callable = getattr(r_class, 'http_delete_fail', None)
if callable:
cleanup_on_failure.append((callable, [id, read_result, db_conn]))
Expand Down
25 changes: 21 additions & 4 deletions src/config/api-server/vnc_cfg_types.py
Expand Up @@ -10,8 +10,6 @@
from cfgm_common import jsonutils as json
import re
import itertools
import copy
import bottle
import socket

import cfgm_common
Expand All @@ -21,8 +19,7 @@
import uuid
from vnc_quota import QuotaHelper

import context
from context import get_context, set_context, get_request
from context import get_context
from gen.resource_xsd import *
from gen.resource_common import *
from gen.resource_server import *
Expand Down Expand Up @@ -528,6 +525,14 @@ def pre_dbe_update(cls, id, fq_name, obj_dict, db_conn, **kwargs):
if not read_ok:
return (False, (500, read_result))

if ('virtual_machine_interface_refs' in obj_dict and
'virtual_machine_interface_refs' in read_result):
for ref in read_result['virtual_machine_interface_refs']:
if ref not in obj_dict['virtual_machine_interface_refs']:
# Dont allow remove of vmi ref during update
msg = "VMI ref delete not allowed during update"
return (False, (409, msg))

aap_config = obj_dict.get(
'virtual_machine_interface_allowed_address_pairs', {})
for aap in aap_config.get('allowed_address_pair', []):
Expand All @@ -552,6 +557,18 @@ def pre_dbe_update(cls, id, fq_name, obj_dict, db_conn, **kwargs):

return True, ""
# end pre_dbe_update

@classmethod
def pre_dbe_delete(cls, id, obj_dict, db_conn):
if ('virtual_machine_interface_refs' in obj_dict and
'virtual_machine_interface_properties' in obj_dict):
vmi_props = obj_dict['virtual_machine_interface_properties']
if 'sub_interface_vlan_tag' not in vmi_props:
msg = "Cannot delete vmi with existing ref to sub interface"
return (False, (409, msg))

return True, ""
# end pre_dbe_delete
# end class VirtualMachineInterfaceServer

class ServiceApplianceSetServer(Resource, ServiceApplianceSet):
Expand Down
2 changes: 1 addition & 1 deletion src/config/common/vnc_cassandra.py
Expand Up @@ -296,7 +296,7 @@ def object_create(self, res_type, obj_id, obj_dict):
# Properties
for prop_field in obj_class.prop_fields:
field = obj_dict.get(prop_field)
if field is None:
if not field:
continue
if prop_field == 'id_perms':
field['created'] = datetime.datetime.utcnow().isoformat()
Expand Down

0 comments on commit a08fc04

Please sign in to comment.