Module: BjnInventory
- Defined in:
- lib/bjn_inventory/service_map.rb,
lib/inventory.rb,
lib/bjn_inventory/list.rb,
lib/bjn_inventory/bykey.rb,
lib/bjn_inventory/device.rb,
lib/bjn_inventory/ansible.rb,
lib/bjn_inventory/context.rb,
lib/bjn_inventory/version.rb,
lib/bjn_inventory/metadata.rb,
lib/bjn_inventory/inventory.rb,
lib/bjn_inventory/data_files.rb,
lib/bjn_inventory/util/filter.rb,
lib/bjn_inventory/default_logger.rb,
lib/bjn_inventory/source_command.rb,
lib/bjn_inventory/inventory/source.rb,
lib/bjn_inventory/util/filter/json_aws.rb,
lib/bjn_inventory/source_command/aws_ec2.rb,
lib/bjn_inventory/source_command/aws_elb.rb,
lib/bjn_inventory/source_command/aws_rds.rb
Overview
Defined Under Namespace
Modules: Util
Classes: ByKey, Context, DefaultLogger, Device, Inventory, List, SourceCommand
Constant Summary
collapse
- DEFAULT_MODEL =
{
name: nil,
service_level: nil,
environment: nil,
chef_runlist: [],
roles: [],
interfaces: [],
ipaddress: nil,
management_ipaddress: nil,
tags: [],
region: nil,
type: nil,
os: nil,
os_release: nil
}
- VERSION =
"1.7.1"
- AUTHOR =
'Jeremy Brinkley'
- EMAIL =
'[email protected]'
- LICENSE =
'All rights reserved'
- SUMMARY =
'Generate inventory lists based on flexible sources, rules and a standard device model'
- URL =
'https://git.corp.bluejeans.com:8443/projects/AS/repos/bjn_inventory/browse'
Class Method Summary
collapse
Class Method Details
.get_groups_data(inventory, ansible_spec) ⇒ Object
3
4
5
6
7
|
# File 'lib/bjn_inventory/data_files.rb', line 3
def self.get_groups_data(inventory, ansible_spec)
ansible_inventory = inventory.to_ansible(ansible_spec)
groups_data = ansible_inventory.reject {|group, devices| group == '_meta'}
groups_data
end
|
.map(origin, &block) ⇒ Object
9
10
11
|
# File 'lib/bjn_inventory/device.rb', line 9
def self.map(origin, &block)
return block
end
|
.refresh_inventory_data(type, data, opt) ⇒ Object
9
10
11
12
13
14
15
16
|
# File 'lib/bjn_inventory/data_files.rb', line 9
def self.refresh_inventory_data(type, data, opt)
type_dir = "#{opt[:datadir]}/#{type}"
IO.write("#{opt[:datadir]}/#{type}.json", JSON.pretty_generate(data))
if !Dir.exist?(type_dir)
Dir.mkdir(type_dir)
end
refresh_inventory_entries(type, data, type_dir)
end
|
.refresh_inventory_entries(type, data, type_dir) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/bjn_inventory/data_files.rb', line 18
def self.refresh_inventory_entries(type, data, type_dir)
previous_entries = Dir.entries(type_dir).reject {|listing| (listing == '.' || listing == '..' || listing == "#{type}.json")}
previous_entries = previous_entries.map { |file| file.sub('.json', '') }
current_entries = data.keys
remove_entries = previous_entries - current_entries
remove_entries.each do |name|
entry = "#{type_dir}/#{name}.json"
File.delete(entry)
end
current_entries.each do |name|
node_name = name
includes_slash = node_name.include?('/')
if includes_slash
split_name = node_name.split('/')
tmp_name = split_name.join('-')
node_name = tmp_name
end
entry = "#{type_dir}/#{node_name}.json"
tmp_file = "#{type_dir}/.#{node_name}.#{Process.pid}.tmp"
begin
IO.write(tmp_file, JSON.pretty_generate(data[name]))
rescue
puts "could not create temp file: #{tmp_file}"
end
begin
IO.copy_stream(tmp_file, entry)
rescue
puts "could not copy #{tmp_file} to #{entry}"
end
File.delete(tmp_file)
end
end
|