code: def extract_ipv4(roster_order, ipv4):
      '''
      Extract the preferred IP address from the ipv4 grain
      '''
      for ip_type in roster_order:
          for ip_ in ipv4:
              if ':' in ip_:
                  continue
              if not salt.utils.validate.net.ipv4_addr(ip_):
                  continue
              if ip_type == 'local' and ip_.startswith('127.'):
                  return ip_
              elif ip_type == 'private' and not salt.utils.cloud.is_public_ip(ip_):
                  return ip_
              elif ip_type == 'public' and salt.utils.cloud.is_public_ip(ip_):
                  return ip_
      return Nonf extract_ipv4(roster_order, ipv4):
      '''
      Extract the preferred IP address from the ipv4 grain
      '''
      for ip_type in roster_order:
          for ip_ in ipv4:
              if ':' in ip_:
                  continue
              if not salt.utils.validate.net.ipv4_addr(ip_):
                  continue
              if ip_type == 'local' and ip_.startswith('127.'):
                  return ip_
              elif ip_type == 'private' and not salt.utils.cloud.is_public_ip(ip_):
                  return ip_
              elif ip_type == 'public' and salt.utils.cloud.is_public_ip(ip_):
                  return ip_
      return None
docs: Extract the preferred IP address from the ipv4 grain