code: def save_iptables(rules_file='/etc/sysconfig/iptables'):
      
      log = logging.getLogger(mod_logger + '.save_iptables')
  
      # Run iptables-save to get the output
      command = ['iptables-save']
      log.debug('Running command: iptables-save')
      try:
          iptables_out = run_command(command, timeout_sec=20)
      except CommandError:
          _, ex, trace = sys.exc_info()
          msg = 'There was a problem running iptables command: {c}\n{e}'.format(c=' '.join(command), e=str(ex))
          raise OSError, msg, trace
  
      # Error if iptables-save did not exit clean
      if int(iptables_out['code']) != 0:
          raise OSError('Command [{g}] exited with code [{c}] and output:\n{o}'.format(
              g=' '.join(command), c=iptables_out['code'], o=iptables_out['output']))
  
      # Back up the existing rules file if it exists
      if os.path.isfile(rules_file):
          time_now = datetime.now().strftime('%Y%m%d-%H%M%S')
          backup_file = '{f}.{d}'.format(f=rules_file, d=time_now)
          log.debug('Creating backup file: {f}'.format(f=backup_file))
          shutil.copy2(rules_file, backup_file)
  
      # Save the output to the rules file
      log.debug('Creating file: {f}'.format(f=rules_file))
      with open(rules_file, 'w') as f:
          f.write(iptables_out['output'])
docs: Saves iptables rules to the provided rules file
  
      :return: None
      :raises OSError