Class: EasyType::Classifier

Inherits:
PuppetService show all
Defined in:
lib/easy_type/classifier.rb

Instance Method Summary collapse

Methods inherited from PuppetService

#get, #post

Constructor Details

#initializeClassifier

Returns a new instance of Classifier.



6
7
8
9
10
11
# File 'lib/easy_type/classifier.rb', line 6

def initialize
  super
  port         = 4433
  prefix       = '/classifier-api' 
  @base_url    = "https://#{@server}:#{port}#{prefix}"
end

Instance Method Details

#em_groupObject

The top level group containin all licensed nodes



15
16
17
# File 'lib/easy_type/classifier.rb', line 15

def em_group
  'EM licensed nodes'
end

#em_group?(group) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/easy_type/classifier.rb', line 48

def em_group?(group)
  full_name_for(group).include?(em_group)
end

#em_groupsObject



32
33
34
# File 'lib/easy_type/classifier.rb', line 32

def em_groups
  node_groups.select {|g| em_group?(g) }
end

#find_by_id(id) ⇒ Object



23
24
25
# File 'lib/easy_type/classifier.rb', line 23

def find_by_id(id)
  node_groups.find {|g| g['id'] == id }
end

#find_by_name(name) ⇒ Object



19
20
21
# File 'lib/easy_type/classifier.rb', line 19

def find_by_name(name)
  node_groups.find {|g| g['name'] == name }
end

#full_name_for(group) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/easy_type/classifier.rb', line 36

def full_name_for(group)
  value = [group['name']]
  current_group = group
  while true do
    parent_group = node_groups.find {|g| g['id'] == current_group['parent'] }
    break if current_group['id'] == parent_group['id']
    value << parent_group['name']
    current_group = parent_group
  end
  group['full_name'] = "/#{value.reverse.join('/')}"
end

#node_groupsObject



27
28
29
30
# File 'lib/easy_type/classifier.rb', line 27

def node_groups
  return @node_groups if @node_groups
  @node_groups = get('/v1/groups')
end

#rule_to_pdb_query(rules) ⇒ Object



52
53
54
# File 'lib/easy_type/classifier.rb', line 52

def rule_to_pdb_query(rules)
  post('/v1/rules/translate', rules)
end