def delete_firewall_group(self, context, id): LOG.debug("delete_firewall_group() called on firewall_group %s", id) fwg_db = self._get_firewall_group(context, id) if fwg_db['status'] == nl_constants.ACTIVE: raise f_exc.FirewallGroupInUse(firewall_id=id) fwg_with_rules = (self._make_firewall_group_dict_with_rules( context, id)) fwg_with_rules['del-port-ids'] = self._get_ports_in_firewall_group( context, id) fwg_with_rules['add-port-ids'] = [] if not fwg_with_rules['del-port-ids']: # no ports, no need to talk to the agent self.delete_db_firewall_group_object(context, id) else: status = { "firewall_group": { "status": nl_constants.PENDING_DELETE } } super(FirewallPluginV2, self).update_firewall_group(context, id, status) # Reflect state change in fwg_with_rules fwg_with_rules['status'] = status['firewall_group']['status'] fwg_with_rules['port_details'] = self._get_fwg_port_details( context, fwg_with_rules['del-port-ids']) self.agent_rpc.delete_firewall_group(context, fwg_with_rules)
def delete_firewall_group(self, context, id): # if no such group exists -> don't raise an exception according to # 80fe2ba1, return None try: fwg = self.get_firewall_group(context, id) except f_exc.FirewallGroupNotFound: return if fwg['status'] == nl_constants.ACTIVE: raise f_exc.FirewallGroupInUse(firewall_id=id) self.driver.delete_firewall_group(context, id)
def delete_firewall_group_precommit(self, context, firewall_group): if firewall_group['status'] == nl_constants.ACTIVE: raise f_exc.FirewallGroupInUse(firewall_id=firewall_group['id']) elif firewall_group['status'] != nl_constants.INACTIVE: # Firewall group is in inconsistent state, remove it return if not firewall_group['ports']: # No associated port, can safety remove it return # Need to prevent agent to delete the firewall group before delete it self.firewall_db.update_firewall_group_status( context, firewall_group['id'], nl_constants.PENDING_DELETE) firewall_group['status'] = nl_constants.PENDING_DELETE fwg_with_rules = self.firewall_db.make_firewall_group_dict_with_rules( context, firewall_group['id']) fwg_with_rules['del-port-ids'] = firewall_group['ports'] fwg_with_rules['add-port-ids'] = [] # Reflect state change in fwg_with_rules fwg_with_rules['status'] = nl_constants.PENDING_DELETE fwg_with_rules['port_details'] = self._get_fwg_port_details( context, fwg_with_rules['del-port-ids']) self.agent_rpc.delete_firewall_group(context, fwg_with_rules)