motoko 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8863037ff395360857c200013862b108d7a101ee7a939911ee30f3d24d7fcd08
4
+ data.tar.gz: 4aefa7a9fd5a9ed4573f39c15a823f486d876d4cd7fa6b21f6e39fc3ef91e67b
5
+ SHA512:
6
+ metadata.gz: 9ba38d76902c83f1edbfcb344668610fe5d57aa842e5e64ac93daddc9cb9031a9bfdf763931f07ee5c8d70e4e1cc40bc4533bbead7ef65800f450f98db5bdd01
7
+ data.tar.gz: 1be988997f339b9fada99d3118d643e752deedc509089665871069d5be6691aa0a5ca885002eb26ad9cc667149838dbc9d7aeb72f834b165ed4e9b5b04401272
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: "CI"
3
+
4
+ on:
5
+ push:
6
+ branches:
7
+ - "main"
8
+ pull_request:
9
+ branches:
10
+ - "main"
11
+
12
+ jobs:
13
+ rubocop:
14
+ runs-on: "ubuntu-latest"
15
+ steps:
16
+ - uses: "actions/checkout@v2"
17
+ - name: "Setup Ruby"
18
+ uses: "ruby/setup-ruby@v1"
19
+ with:
20
+ ruby-version: "3.0"
21
+ bundler-cache: true
22
+ - name: "Run rubocop"
23
+ run: "bundle exec rubocop"
24
+ test:
25
+ runs-on: "ubuntu-latest"
26
+ strategy:
27
+ matrix:
28
+ ruby-version:
29
+ - "2.5"
30
+ - "2.6"
31
+ - "2.7"
32
+ - "3.0"
33
+ steps:
34
+ - uses: "actions/checkout@v2"
35
+ - name: "Setup Ruby"
36
+ uses: "ruby/setup-ruby@v1"
37
+ with:
38
+ ruby-version: ${{ matrix.ruby-version }}
39
+ bundler-cache: true
40
+ - name: "Run the test suite"
41
+ run: "bundle exec rake"
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,27 @@
1
+ ---
2
+ require:
3
+ - "rubocop-rake"
4
+ - "rubocop-rspec"
5
+ AllCops:
6
+ NewCops: "enable"
7
+ TargetRubyVersion: "2.5"
8
+ Layout/HashAlignment:
9
+ EnforcedHashRocketStyle: "table"
10
+ Layout/LineLength:
11
+ Enabled: false
12
+ Metrics/BlockLength:
13
+ Enabled: false
14
+ Metrics/MethodLength:
15
+ Enabled: false
16
+ RSpec/NestedGroups:
17
+ Max: 4
18
+ Style/Documentation:
19
+ Enabled: false
20
+ Style/NumericLiterals:
21
+ Enabled: false
22
+ Style/TrailingCommaInArguments:
23
+ EnforcedStyleForMultiline: "comma"
24
+ Style/TrailingCommaInArrayLiteral:
25
+ EnforcedStyleForMultiline: "comma"
26
+ Style/TrailingCommaInHashLiteral:
27
+ EnforcedStyleForMultiline: "comma"
data/.simplecov ADDED
@@ -0,0 +1,10 @@
1
+ # vim:set filetype=ruby:
2
+ # frozen_string_literal: true
3
+
4
+ SimpleCov.start do
5
+ add_filter '/spec/'
6
+
7
+ add_group 'Formatters', '/lib/motoko/formatters/'
8
+ add_group 'Resolvers', '/lib/motoko/resolvers/'
9
+ add_group 'Utils', '/lib/motoko/utils/'
10
+ end
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at romain@blogreen.org. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in inventory.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.0'
10
+ gem 'rubocop'
11
+ gem 'rubocop-rake'
12
+ gem 'rubocop-rspec'
13
+ gem 'simplecov'
14
+ gem 'timecop'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Romain Tartière
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,183 @@
1
+ # Motoko
2
+
3
+ A gem to get inventories of nodes in a Puppet / Choria deployment.
4
+
5
+ ## Installation
6
+
7
+ Take care to install this tool in the Puppet envrionment. If you are using the AIO package, you can install with:
8
+
9
+ ```
10
+ /opt/puppetlabs/puppet/bin/gem install --bindir /opt/puppetlabs/bin puppetdb_cli
11
+ ```
12
+
13
+ Alternatively, you can install using Puppet:
14
+
15
+ ```puppet
16
+ package { 'motoko':
17
+ ensure => installed,
18
+ provider => 'puppet_gem',
19
+ }
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ Two inventroy scripts are currently provided:
25
+
26
+ * `exe/inventory` use Choria discovery and return live data from your infrastructure;
27
+ * `exe/pdb-inventory` use PuppetDB querying and return what Puppet thinks about your infrastructure.
28
+
29
+ Both have a similar feature-set, and a full list of available options can be obtained by running them with `--help`.
30
+
31
+ ### Basic usage
32
+
33
+ #### Which nodes are currently up and running
34
+
35
+ ```sh-session
36
+ romain@zappy ~ % inventory
37
+ ```
38
+
39
+ #### Which nodes are known to puppet
40
+
41
+ ```sh-session
42
+ romain@zappy ~ % pdb-inventory
43
+ ```
44
+
45
+ ### Accessing facts
46
+
47
+ By default, the report display the node name, along with it's `customer` and `role` facts (if these facts are available). You can request additional facts are just replace the list. The syntax is the same for both the choria and puppetdb inventory scripts.
48
+
49
+ #### Add more facts to the output
50
+
51
+ ```sh-session
52
+ romain@zappy ~ % inventory -a datacenter,city,country
53
+ ```
54
+
55
+ ### Filtering
56
+
57
+ The usual filtering knobs are available for the choria inventory script. The puppetdb inventory script has a minimal support for choria-like filtering.
58
+
59
+ #### Which nodes have burned in Strasbourg
60
+
61
+ The initial work on querying PuppetDB is due to the fact that you can't ask Choria for information about nodes which are gone. On March 9th 2021, [OVH lost (part of) it's Strasboug datacenter](https://twitter.com/olesovhcom/status/1369478732247932929?ref_src=twsrc%5Etfw) and the frustration of not being able to conviniently build a list of affected nodes and customers was a pain. with motoko we can now just query PuppetDB:
62
+
63
+ ```sh-session
64
+ romain@zappy ~ % pdb-inventory -F datacenter=/sbg/
65
+ ```
66
+ ## Configuration
67
+
68
+ At startup, Motoko will load system-wide configuration from `/etc/motoko/config.yaml`, and then user configuration from `~/.config/motoko/config.yaml`.
69
+
70
+ ### Columns
71
+
72
+ Set the list of columns to display by default:
73
+
74
+ ```yaml
75
+ columns:
76
+ - "host"
77
+ - "customer"
78
+ - "role"
79
+ - "country"
80
+ - "city"
81
+ ```
82
+
83
+ ### Column Specifications
84
+
85
+ Customize how columns are displayed:
86
+
87
+ * `human_name`: what title should be used for the column (defaults to a capitalized version of the column name);
88
+ * `resolver`: which [resolver](#resolvers) to use to gather the information (defaults to `fact`);
89
+ * `formatter`: which [formatter](#formatters) to use to print the value (none by default);
90
+ * `align`: how to align the formatted value in the column (default to `left`).
91
+
92
+ ```yaml
93
+ columns_spec:
94
+ host:
95
+ resolver: "identity"
96
+ customer:
97
+ formatter: "ellipsis"
98
+ max_length: 20
99
+ cpu:
100
+ resolver: "cpu"
101
+ os:
102
+ human_name: "Operating System"
103
+ resolver: "os"
104
+ reboot_required:
105
+ human_name: "R"
106
+ resolver: "reboot_required"
107
+ formatter: "boolean"
108
+ ```
109
+
110
+ ### Shortcuts
111
+
112
+ ```yaml
113
+ shortcuts:
114
+ dc:
115
+ description: "Show physical node locations"
116
+ add_columns:
117
+ - "datacenter"
118
+ - "server_rack"
119
+ - "server_id"
120
+ with_fact:
121
+ - "virtual=physical"
122
+ ```
123
+
124
+ This add a new command switch `--dc` equivalent to `--add-columns datacenter,server_rack,server_id --with-fact virtual=physical`.
125
+
126
+ ## Resolvers
127
+
128
+ | Resolver name | Desciption |
129
+ |-------------------|------------|
130
+ | `cpu` | Aggregate information about the CPU |
131
+ | `fact` | Gather the value of the fact `fact` (default to the column name if unset) |
132
+ | `identity` | Gather the node identity |
133
+ | `os` | Aggregate information about the OS |
134
+ | `reboot_required` | Combine value of various facts to determine if a reboot is required |
135
+
136
+ ### Extending Motoko with custom resolvers
137
+
138
+ Custom resolvers can be droped in the `<motoko-config-directory>/resolvers/` directory. They are automatically loaded on startup.
139
+
140
+ ## Formatters
141
+
142
+ | Formatter name | Desciption |
143
+ |-----------------|------------|
144
+ | `boolean` | Display a checkmark for things that evaluate to `true` |
145
+ | `datetime` | Display a date and time in the local time zone |
146
+ | `datetime_ago` | Display a date and time as a duration |
147
+ | `ellipsis` | Display a value truncated at `max_length` chars (default: 20) |
148
+ | `timestamp` | Display a timestamp (number of seconds since the Unix epoch) in the local time zone |
149
+ | `timestamp_ago` | Display a timestamp (number of seconds since the Unix epoch) as a duration |
150
+
151
+ ### Extending Motoko with custom formatters
152
+
153
+ Custom formatters can be droped in the `<motoko-config-directory>/formatters/` directory. They are automatically loaded on startup.
154
+
155
+ ## Development
156
+
157
+ In order to use the Puppet environment, use the version of bundler bundled with Puppet:
158
+
159
+ ```
160
+ /opt/puppetlabs/puppet/bin/bundle install
161
+ /opt/puppetlabs/puppet/bin/bundle exec rake spec
162
+ /opt/puppetlabs/puppet/bin/bundle exec exe/inventory
163
+ ```
164
+
165
+ Iy you want to install this development code:
166
+
167
+ ```
168
+ /opt/puppetlabs/puppet/bin/gem build motoko.gemspec
169
+ sudo /opt/puppetlabs/puppet/bin/gem install --bindir /opt/puppetlabs/bin motoko-x.y.z.gem
170
+ ```
171
+
172
+ ## Contributing
173
+
174
+ Bug reports and pull requests are welcome on GitHub at https://github.com/smortex/motoko. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/smortex/motoko/blob/master/CODE_OF_CONDUCT.md).
175
+
176
+
177
+ ## License
178
+
179
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
180
+
181
+ ## Code of Conduct
182
+
183
+ Everyone interacting in the Motoko project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/smortex/motoko/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'inventory'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here