octofacts-updater 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/lib/octofacts_updater/cli.rb +33 -11
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05efcd40e8410c43eb2fd197165de57b754d0e28
4
- data.tar.gz: ad65e6ce8d288593e0b2b03075fcda6f52fbd4cb
3
+ metadata.gz: b4b50c8a2fec8f9a4246634633180bf12276c66e
4
+ data.tar.gz: 41484ac0bc84813a554ff68c7e92ebee525756e3
5
5
  SHA512:
6
- metadata.gz: 507c0eecd6dd8c7c281e6734f1dbdde0731ee2e8cfcedd2bc5f9d7fc68fc7805207d5032d3ffc1d20df0e75154afb3786e0ff6f93d03af9e271592d9d45996ec
7
- data.tar.gz: e017a38aa6681a768d06cc085f4dc4480e4ef736d6782fd6f05a9d2b24b391bc5911b9e0d47791f080ea3321c96b3117f44cd864e60ba2108f95c22c675e60f7
6
+ metadata.gz: cbd45aa3e9cb4d6e7e79e25dc85339887c3a6044d958ddc4e20fb8664310909c2be3d37e6a8315e15b80076779747d1f66a840d34178b23347839a2ee76ef345
7
+ data.tar.gz: f74a33d55190ff784ced6238717266ed6ff94c07a8f4e4bfa09e5c159f389b95ec56a2c28b4e6040c84eddb25c2914c4d0a99e893dcd330d4455b6df840ad704
data/.version CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -16,8 +16,8 @@ module OctofactsUpdater
16
16
  end
17
17
 
18
18
  opts.on("-c", "--config <config_file>", String, "Path to configuration file") do |f|
19
- raise "Invalid configuration file" unless File.file?(f)
20
- @opts[:config] = f
19
+ @opts[:config] = File.expand_path(f)
20
+ raise "Invalid configuration file #{@opts[:config].inspect}" unless File.file?(@opts[:config])
21
21
  end
22
22
 
23
23
  opts.on("-H", "--hostname <hostname>", String, "FQDN of the host whose facts are to be gathered") do |h|
@@ -67,11 +67,12 @@ module OctofactsUpdater
67
67
  end
68
68
 
69
69
  def usage
70
- puts "Usage: octofacts-updater --action <action> [--config-file /path/to/config.yaml] [other options]"
70
+ puts "Usage: octofacts-updater --action <action> [--config /path/to/config.yaml] [other options]"
71
71
  puts ""
72
72
  puts "Available actions:"
73
- puts " bulk: Update fixtures and index in bulk"
74
- puts " facts: Obtain facts for one node (requires --hostname <hostname>)"
73
+ puts " bulk: Update fixtures and index in bulk"
74
+ puts " facts: Obtain facts for one node (requires --hostname <hostname>)"
75
+ puts " reindex: Build a new index from the existing fact fixtures"
75
76
  puts ""
76
77
  end
77
78
 
@@ -106,6 +107,7 @@ module OctofactsUpdater
106
107
 
107
108
  return handle_action_bulk if opts[:action] == "bulk"
108
109
  return handle_action_facts if opts[:action] == "facts"
110
+ return handle_action_bulk if opts[:action] == "reindex"
109
111
 
110
112
  usage
111
113
  exit 255
@@ -126,19 +128,39 @@ module OctofactsUpdater
126
128
  end
127
129
  end
128
130
 
129
- def handle_action_bulk
130
- facts_to_index = @config.fetch("index", {})["indexed_facts"]
131
- unless facts_to_index.is_a?(Array)
132
- raise ArgumentError, "Must declare index:indexed_facts in configuration to use bulk update"
133
- end
131
+ def nodes_for_bulk
132
+ if opts[:action] == "reindex"
133
+ @opts[:quick] = true
134
+
135
+ path = if opts[:path]
136
+ File.expand_path(opts[:path])
137
+ elsif @config.fetch("index", {})["node_path"]
138
+ File.expand_path(@config.fetch("index", {})["node_path"], File.dirname(opts[:config]))
139
+ else
140
+ raise ArgumentError, "Must set --path, or define index:node_path to a valid directory in configuration"
141
+ end
142
+
143
+ unless File.directory?(path)
144
+ raise Errno::ENOENT, "--path must be a directory (#{path.inspect} is not)"
145
+ end
134
146
 
135
- nodes = if opts[:host_list]
147
+ Dir.glob("#{path}/*.yaml").map { |f| File.basename(f, ".yaml") }
148
+ elsif opts[:host_list]
136
149
  opts[:host_list]
137
150
  elsif opts[:hostname]
138
151
  [opts[:hostname]]
139
152
  else
140
153
  OctofactsUpdater::FactIndex.load_file(index_file).nodes(true)
141
154
  end
155
+ end
156
+
157
+ def handle_action_bulk
158
+ facts_to_index = @config.fetch("index", {})["indexed_facts"]
159
+ unless facts_to_index.is_a?(Array)
160
+ raise ArgumentError, "Must declare index:indexed_facts in configuration to use bulk update"
161
+ end
162
+
163
+ nodes = nodes_for_bulk
142
164
  if nodes.empty?
143
165
  raise ArgumentError, "Cannot run bulk update with no nodes to check"
144
166
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octofacts-updater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub, Inc.
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-10-06 00:00:00.000000000 Z
13
+ date: 2017-10-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: diffy