Module: Proctor::Resource::Lookup

Instance Method Summary collapse

Instance Method Details

#lookup_valid_group_template(manager, node, env) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/proctor/resource/lookup.rb', line 46

def lookup_valid_group_template(manager, node, env)
  key1 = "#{manager}_#{node}_g"
  key2 = "#{manager}_default_g"
  names = env.template_files.names
  tmpl_name = [key1, key2].find {|key| names.include?(key)}
  if tmpl_name.nil?
    msg = "group template not found for #{manager}/#{node}"
    raise TemplateNotFound, msg
  end
  env.template_files.find_by_name(tmpl_name)
end

#lookup_valid_manager(mgr_name, env) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/proctor/resource/lookup.rb', line 7

def lookup_valid_manager(mgr_name, env)
  names = env.managers.names
  msg = "unrecognized manager (#{mgr_name}) use one of [#{names.join('|')}]"
  unless names.include?(mgr_name)
    raise UnrecognizedManagerName, msg
  end
  env.managers.find_by_name(mgr_name)
end

#lookup_valid_node(node_name, env) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/proctor/resource/lookup.rb', line 25

def lookup_valid_node(node_name, env)
  names = env.nodes.names
  msg = "unrecognized node (#{node_name}) use one of [#{names.join('|')}]"
  unless names.include?(node_name)
    raise UnrecognizedNodeName, msg
  end
  env.nodes.find_by_name(node_name)
end

#lookup_valid_service(svc_name, env) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/proctor/resource/lookup.rb', line 16

def lookup_valid_service(svc_name, env)
  names = env.services.names
  msg = "unrecognized service (#{svc_name}) use one of [#{names.join('|')}]"
  unless names.include?(svc_name)
    raise UnrecognizedServiceName, msg
  end
  env.services.find_by_name(svc_name)
end

#lookup_valid_service_template(manager, service, env) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/proctor/resource/lookup.rb', line 34

def lookup_valid_service_template(manager, service, env)
  key1 = "#{manager}_#{service}_s"
  key2 = "#{manager}_default_s"
  names = env.template_files.names
  tmpl_name = [key1, key2].find {|key| names.include?(key)}
  if tmpl_name.nil?
    msg = "service template not found for #{manager}/#{service}"
    raise TemplateNotFound, msg
  end
  env.template_files.find_by_name(tmpl_name)
end

#lookup_valid_services(node_name, env) ⇒ Object



58
59
60
61
# File 'lib/proctor/resource/lookup.rb', line 58

def lookup_valid_services(node_name, env)
  node = lookup_valid_node(node_name, env)
  node.services.map {|service| lookup_valid_service(service, env)}
end

#lookup_valid_services_hash(node_name, env) ⇒ Object



63
64
65
# File 'lib/proctor/resource/lookup.rb', line 63

def lookup_valid_services_hash(node_name, env)
  lookup_valid_services(node_name, env).reduce({}) {|a,v| a[v.name]=v; a}
end