Project

General

Profile

Actions

Bug #21929

open

need short host name matchers

Added by Partha Aji over 6 years ago. Updated almost 3 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Difficulty:
Triaged:
Yes
Fixed in Releases:
Found in Releases:

Description

Short Host Name
--------------

http://projects.theforeman.org/issues/17521 introduces the idea of a system with a short name.
However certain customers have hosts with the following configuration
1) Short name for hostname in db. So when using the api they want to be able operate the system based on short name. They consider the name of a host merely an alias to be used in their existing scripts.
2) Hosts have an interface attached. So puppet fact on FDQN indicates a fully formed name (i.e. foo.example.com)
3) Also have the UUID_for_certificates enabled via 'Settings -> Puppet -> Use UUID for certificates'

However customers with short host names are not going to be able to match based on either the short host name or fqdn.
This is because of matching code that says
https://github.com/theforeman/foreman/blob/develop/app/models/lookup_value.rb#L80-L89 -> ensure_fqdn_exists method says

   return true if Host.unscoped.find_by_name(fqdn) || host_or_hostgroup.try(:new_record?) ||
        (host_or_hostgroup.present? && host_or_hostgroup.type_changed? && host_or_hostgroup.type == "Host::Managed")

and https://github.com/theforeman/foreman/blob/develop/app/models/host/base.rb#L325-L327 that says

    def lookup_value_match
      "fqdn=#{fqdn || name}" 
    end
 

If the customer says
"fqdn matcher with the name -> foo.example.com" -> "Host.unscoped.find_by_name(fqdn)" is going to fail.
OTOH
If the customer says
"fqdn matcher with the name -> foo" -> "fqdn=#{fqdn || name}" of the lookup_value_match is going to fail.

Appropriate solution is to either

1) make the fqdn matcher actually match fqdn facts along with name (so Host.unscoped.find_by_name or Host.unscoped.find_by_fqdn_fact) . Somethign like

diff --git a/app/models/lookup_value.rb b/app/models/lookup_value.rb
index 24741d24a6..3a557b8b3c 100644
--- a/app/models/lookup_value.rb
+++ b/app/models/lookup_value.rb
@@ -81,7 +81,8 @@ def ensure_fqdn_exists
     md = ensure_matcher(/fqdn=(.*)/)
     return md if md == true || md == false
     fqdn = md[1].split(LookupKey::KEY_DELM)[0]
-    return true if Host.unscoped.find_by_name(fqdn) || host_or_hostgroup.try(:new_record?) ||
+    fqdn_matched = Host.unscoped.where(:name => fqdn).any? || Host.unscoped.search_for("facts.fqdn=#{fqdn}").any?
+    return true if fqdn_matched || host_or_hostgroup.try(:new_record?) ||
         (host_or_hostgroup.present? && host_or_hostgroup.type_changed? && host_or_hostgroup.type == "Host::Managed")
     errors.add(:match, _("%{match} does not match an existing host") % { :match => "fqdn=#{fqdn}" })

OR

2)
Create a new short hostname matcher and add the appropriate plumbing so that the customer can set a matcher that says
"shortname with value => foo" and make that figure out.


Related issues 1 (0 open1 closed)

Blocked by Foreman - Feature #17521: need support for 'use_shortname_for_vms' for all hosts not just vmsClosedPartha Aji11/29/2016Actions
Actions #1

Updated by Partha Aji over 6 years ago

Corrections:
"However customers with short host names are not going to be able to match based on either the short host name or fqdn. " - Referring to the Puppet smart classes override page here

Configure -> Puppet Classes -> Classname -> Smart Class Parameter -> <Class> -> Add Matchers under (Specify Matcher).
Referring to the FQDN matcher there.

Actions #2

Updated by Partha Aji over 6 years ago

  • Blocked by Feature #17521: need support for 'use_shortname_for_vms' for all hosts not just vms added
Actions #3

Updated by Partha Aji over 6 years ago

Update after the merge of http://projects.theforeman.org/issues/17521

We decided to go with option 2.
2) Create a new short hostname matcher and add the appropriate plumbing so that the customer can set a matcher that says
"shortname with value => foo" and make that figure out.

Actions #4

Updated by Ondřej Pražák over 4 years ago

  • Bugzilla link set to 1687552
Actions #5

Updated by Leos Stejskal almost 3 years ago

  • Triaged changed from No to Yes
Actions

Also available in: Atom PDF