'Apply the current in-memory set of iptables rules.
This will blow away any rules left over from previous runs of the
same component of Nova, and replace them with our current set of
rules. This happens atomically, thanks to iptables-restore.'

@utils.synchronized('iptables', external=True)
def _apply(self):

    s = [('iptables', self.ipv4)]
    if CONF.use_ipv6:
        s += [('ip6tables', self.ipv6)]
    for (cmd, tables) in s:
        (all_tables, _err) = self.execute(('%s-save' % (cmd,)), '-c', run_as_root=True, attempts=5)
        all_lines = all_tables.split('\n')
        for (table_name, table) in tables.items():
            (start, end) = self._find_table(all_lines, table_name)
            all_lines[start:end] = self._modify_rules(all_lines[start:end], table, table_name)
            table.dirty = False
        self.execute(('%s-restore' % (cmd,)), '-c', run_as_root=True, process_input=six.b('\n'.join(all_lines)), attempts=5)
    LOG.debug('IPTablesManager.apply    completed    with    success')
