File: resource_tag.rb

package info (click to toggle)
puppet 3.7.2-4+deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 18,912 kB
  • ctags: 13,168
  • sloc: ruby: 210,410; sh: 2,050; xml: 1,554; lisp: 300; makefile: 142; python: 108; sql: 103; yacc: 72
file content (26 lines) | stat: -rw-r--r-- 1,003 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Puppet::Rails::ResourceTag < ActiveRecord::Base
  belongs_to :puppet_tag
  belongs_to :resource

  def to_label
    "#{self.puppet_tag.name}"
  end

  # returns an array of hash containing tags of resource
  def self.find_all_tags_from_resource(db_resource)
    tags = ActiveRecord::Base.connection.select_all("SELECT t.id, t.resource_id, p.name FROM resource_tags t INNER JOIN puppet_tags p ON t.puppet_tag_id=p.id WHERE t.resource_id=#{db_resource.id}")
    tags.each do |val|
      val['resource_id'] = Integer(val['resource_id'])
    end
    tags
  end

  # returns an array of hash containing tags of a host
  def self.find_all_tags_from_host(db_host)
    tags = ActiveRecord::Base.connection.select_all("SELECT t.id, t.resource_id, p.name FROM resource_tags t INNER JOIN resources r ON t.resource_id=r.id INNER JOIN puppet_tags p ON t.puppet_tag_id=p.id WHERE r.host_id=#{db_host.id}")
    tags.each do |val|
      val['resource_id'] = Integer(val['resource_id'])
    end
    tags
  end
end