Revision 1b38f231
Added by Shimon Shtein over 7 years ago
app/models/concerns/facets/base.rb | ||
---|---|---|
require 'facets'
|
||
|
||
module Facets
|
||
module Base
|
||
extend ActiveSupport::Concern
|
||
|
||
included do
|
||
belongs_to_host
|
||
end
|
||
|
||
# Add facet's details to host's ENC by returning it from this method
|
||
# Basic ENC hash structure:
|
||
# ---
|
||
# classes:
|
||
# ...
|
||
# parameters:
|
||
# ...
|
||
# environment:
|
||
# ...
|
||
def info
|
||
{}
|
||
end
|
||
|
||
# Specify any smart proxy id's used by this facet.
|
||
def smart_proxy_ids
|
||
[]
|
||
end
|
||
|
||
# Add any filters to template selection returned from host
|
||
def template_filter_options(kind)
|
||
{}
|
||
end
|
||
|
||
# Add search criteria for finding a configuration template.
|
||
def provisioning_template_options
|
||
{}
|
||
end
|
||
|
||
module ClassMethods
|
||
# Change attributes that will be sent to an facet based on inherited values from the hostgroup.
|
||
def self.inherited_attributes(hostgroup, facet_attributes)
|
||
facet_attributes
|
||
end
|
||
|
||
# Use this method to populate host's fields based on fact values exposed by the importer.
|
||
# You can populate fields in the associated host's facets too.
|
||
def self.populate_fields_from_facts(host, importer, type, proxy_id)
|
||
end
|
||
end
|
||
end
|
||
end
|
app/models/host_facets/base.rb | ||
---|---|---|
class Base < ActiveRecord::Base
|
||
self.abstract_class = true
|
||
|
||
belongs_to_host
|
||
|
||
# Add facet's details to host's ENC by returning it from this method
|
||
# Basic ENC hash structure:
|
||
# ---
|
||
# classes:
|
||
# ...
|
||
# parameters:
|
||
# ...
|
||
# environment:
|
||
# ...
|
||
def info
|
||
{}
|
||
end
|
||
|
||
# Specify any smart proxy id's used by this facet.
|
||
def smart_proxy_ids
|
||
[]
|
||
end
|
||
|
||
# Add any filters to template selection returned from host
|
||
def template_filter_options(kind)
|
||
{}
|
||
end
|
||
|
||
# Add search criteria for finding a configuration template.
|
||
def provisioning_template_options
|
||
{}
|
||
end
|
||
|
||
# Change attributes that will be sent to an facet based on inherited values from the hostgroup.
|
||
def self.inherited_attributes(hostgroup, facet_attributes)
|
||
facet_attributes
|
||
end
|
||
|
||
# Use this method to populate host's fields based on fact values exposed by the importer.
|
||
# You can populate fields in the associated host's facets too.
|
||
def self.populate_fields_from_facts(host, importer, type, proxy_id)
|
||
end
|
||
include Facets::Base
|
||
end
|
||
end
|
Also available in: Unified diff
Fixes #17439 - Moved facet base to a concern
If the plugin that wants to create a new facet doesn't want to
take the inheritance slot (for example if it already has some
base class), it can `include` the new concern.