Class: PuppetdbHost

Inherits:
Object
  • Object
show all
Defined in:
app/services/puppetdb_host.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ PuppetdbHost

Returns a new instance of PuppetdbHost.



6
7
8
9
# File 'app/services/puppetdb_host.rb', line 6

def initialize(opts = {})
  self.facts = HashWithIndifferentAccess.new
  parse_facts(opts.fetch(:facts))
end

Instance Attribute Details

#certnameObject

Returns the value of attribute certname.



4
5
6
# File 'app/services/puppetdb_host.rb', line 4

def certname
  @certname
end

#environmentObject

Returns the value of attribute environment.



4
5
6
# File 'app/services/puppetdb_host.rb', line 4

def environment
  @environment
end

#factsObject

Returns the value of attribute facts.



4
5
6
# File 'app/services/puppetdb_host.rb', line 4

def facts
  @facts
end

Instance Method Details

#to_hostObject



11
12
13
14
15
16
# File 'app/services/puppetdb_host.rb', line 11

def to_host
  host = Host::Managed.import_host(facts[:fqdn], certname)
  HostFactImporter.new(host).import_facts(facts)
  host.update_attribute(environment: environment) if environment   # rubocop:disable Rails/SkipsModelValidations
  host
end