Class: ForemanChef::FactParser
- Inherits:
-
FactParser
- Object
- FactParser
- ForemanChef::FactParser
- Defined in:
- app/models/foreman_chef/fact_parser.rb
Constant Summary collapse
- VIRTUAL =
/\A([a-z0-9]+)[:.](\d+)\Z/- VIRTUAL_NAMES =
/#{VIRTUAL}|#{BRIDGES}|#{BONDS}/
Instance Method Summary collapse
- #architecture ⇒ Object
- #boot_timestamp ⇒ Object
- #certname ⇒ Object
- #domain ⇒ Object
-
#environment ⇒ Object
we don’t want to parse puppet environment, foreman_chef already has its own environment.
- #ipmi_interface ⇒ Object
- #model ⇒ Object
- #operatingsystem ⇒ Object
- #parse_interfaces? ⇒ Boolean
- #support_interfaces_parsing? ⇒ Boolean
Instance Method Details
#architecture ⇒ Object
57 58 59 60 61 |
# File 'app/models/foreman_chef/fact_parser.rb', line 57 def architecture name = facts['kernel::machine'] name = "x86_64" if name == "amd64" Architecture.where(:name => name).first_or_create unless name.blank? end |
#boot_timestamp ⇒ Object
95 96 97 |
# File 'app/models/foreman_chef/fact_parser.rb', line 95 def Time.zone.now.to_i - facts['system_uptime::seconds'].to_i end |
#certname ⇒ Object
83 84 85 |
# File 'app/models/foreman_chef/fact_parser.rb', line 83 def certname facts['chef_node_name'] end |
#domain ⇒ Object
72 73 74 75 |
# File 'app/models/foreman_chef/fact_parser.rb', line 72 def domain name = facts['domain'] Domain.where(:name => name).first_or_create unless name.blank? end |
#environment ⇒ Object
we don’t want to parse puppet environment, foreman_chef already has its own environment
53 54 55 |
# File 'app/models/foreman_chef/fact_parser.rb', line 53 def environment nil end |
#ipmi_interface ⇒ Object
77 78 79 80 81 |
# File 'app/models/foreman_chef/fact_parser.rb', line 77 def ipmi_interface if facts['ipmi::mac_address'].present? { 'ipaddress' => facts['ipmi::address'], 'macaddress' => facts['ipmi::mac_address'] }.with_indifferent_access end end |
#model ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'app/models/foreman_chef/fact_parser.rb', line 63 def model if facts['virtualization'].present? name = facts['virtualization']['system'] else name = facts['dmi::system::product_name'] end Model.where(:name => name.strip).first_or_create unless name.blank? end |
#operatingsystem ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/foreman_chef/fact_parser.rb', line 6 def os_name = facts['lsb::id'] || facts['platform'] release = facts['lsb::release'] || facts['platform_version'] # if we have no release information we can't assign OS properly (e.g. missing redhat-lsb) if release.nil? major, minor = 1, nil else major, minor = release.split('.') end if facts['platform'] == 'windows' release_name = facts['kernel::name'] os_name = os_name.capitalize else # to keep OS names consistent with other cfgmgt agents we skip description importing # description = facts['lsb::description'] release_name = facts['lsb::codename'] end # convert OHAI names to Foreman common OS names case os_name when 'RedHatEnterpriseServer' os_name = 'RedHat' end # So far only CentOS needs exception case os_name when 'CentOS' if major.to_i >= 7 # get the minor.build number, e.g. 7.2.1511 -> 2.1511 minor = release[2..-1] end end begin klass = os_name.constantize rescue NameError => e logger.debug "unknown operating system #{os_name}, fallback to generic type" klass = Operatingsystem end args = { :name => os_name, :major => major.to_s, :minor => minor.to_s } klass.where(args).first || klass.new(args.merge(:release_name => release_name)).tap(&:save!) end |
#parse_interfaces? ⇒ Boolean
91 92 93 |
# File 'app/models/foreman_chef/fact_parser.rb', line 91 def parse_interfaces? support_interfaces_parsing? && !Setting['ignore_puppet_facts_for_provisioning'] end |
#support_interfaces_parsing? ⇒ Boolean
87 88 89 |
# File 'app/models/foreman_chef/fact_parser.rb', line 87 def support_interfaces_parsing? true end |