Class: Oxford::Host

Inherits:
ActiveLdap::Base
  • Object
show all
Defined in:
lib/oxford/host.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find(host) ⇒ Object

belongs_to :groups, :class_name => ‘WebsagesLDAP::Group’, :many => ‘memberUid’



7
8
9
10
11
12
13
# File 'lib/oxford/host.rb', line 7

def self.find(host)
  begin
    super(host)
  rescue ActiveLdap::EntryNotFound
    return []
  end
end

Instance Method Details

#add_network(name, value) ⇒ Object

Raises:

  • (StandardError)


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/oxford/host.rb', line 23

def add_network(name, value)
  begin
    a = Network.find(name, :prefix => "cn=#{self.commonName},ou=Hosts")
  rescue
    a = Network.new(name)
    a.base = "cn=#{self.commonName},ou=Hosts"
  end
  value.each { |fact, value| a.__send__("fact#{fact}=", value.to_s) }
  raise StandardError unless a.valid?
  a.save
end

#add_processor(name, value) ⇒ Object

Raises:

  • (StandardError)


35
36
37
38
39
40
41
42
43
44
45
# File 'lib/oxford/host.rb', line 35

def add_processor(name, value)
  begin
    a = Processor.find(name, :prefix => "cn=#{self.commonName},ou=Hosts")
  rescue
    a = Processor.new(name)
    a.base = "cn=#{self.commonName},ou=Hosts"
  end
  value.each { |fact, value| a.__send__("fact#{fact}=", value.to_s) }
  raise StandardError unless a.valid?
  a.save
end

#networks(name = '*') ⇒ Object



15
16
17
# File 'lib/oxford/host.rb', line 15

def networks(name='*')
  Network.all(:prefix => "cn=#{self.commonName},ou=Hosts", :filter => "(cn=#{name})")
end

#processors(search = {}) ⇒ Object



19
20
21
# File 'lib/oxford/host.rb', line 19

def processors(search = {})
  Processor.all(:prefix => "cn=#{self.commonName},ou=Hosts")
end

#update!Object



47
48
49
50
51
# File 'lib/oxford/host.rb', line 47

def update!
  time = Time.now.to_i
  self.factLastUpdated = time.to_s
  self.save
end