palletjack 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -0
- data/.gitignore +53 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +243 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/palletjack.rb +71 -0
- data/lib/palletjack/keytransformer.rb +264 -0
- data/lib/palletjack/pallet.rb +80 -0
- data/lib/palletjack/tool.rb +463 -0
- data/lib/palletjack/version.rb +5 -0
- data/palletjack.gemspec +36 -0
- metadata +164 -0
- metadata.gz.sig +1 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2e67d0b124d14adf092a78bf3c3c9e0c2b653698
|
4
|
+
data.tar.gz: f4e2e35cb63690e534c6f00865cfbea1a36a3621
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e70c5757bdb8bb3836582cdaf3c8a9f457c7831e9d9753065be15de846039848a5d61b7f19746eb760714611e407ecc70c72975d934475355ddb1fee597d0758
|
7
|
+
data.tar.gz: 5d4aee420d2ec7acebd6c5b8fa500a518e1f265eb5403dfa5521adbba4e209a9a4c67460e7b5a4cf544817a3dfc15a795152b92a042f6112408a973723abb097
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
Gemfile.lock
|
46
|
+
.ruby-version
|
47
|
+
.ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
51
|
+
*~
|
52
|
+
# Ignore personal preferences for rspec output
|
53
|
+
.rspec
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 saab-simc-admin
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,243 @@
|
|
1
|
+
# Pallet Jack
|
2
|
+
Pallet Jack is a lightweight configuration management database, utilizing
|
3
|
+
the power of a Posix file system to store yaml serialized key-value trees.
|
4
|
+
|
5
|
+
A database is created from a warehouse (directory) of different kinds
|
6
|
+
(directory) of pallets (directory), each containing boxes (yaml files)
|
7
|
+
with keys. Pallets can also contain references to other pallets (symlinks)
|
8
|
+
to build a Directed Acyclic Graph of key-value search nodes.
|
9
|
+
|
10
|
+
The entire structure is indended to live beside configuration management
|
11
|
+
code and data in a version control system repository, to enable tagged
|
12
|
+
releases of both code, data and metadata.
|
13
|
+
|
14
|
+
The toplevel `transforms.yaml` file defines key-value transforms to perform
|
15
|
+
when loading the database, e.g. synthesize key-values from pallet metadata.
|
16
|
+
|
17
|
+
```
|
18
|
+
warehouse
|
19
|
+
├── building
|
20
|
+
│ └── 1
|
21
|
+
│ └── location.yaml
|
22
|
+
├── chassis
|
23
|
+
│ └── Example:FastServer-128:1234ABCD
|
24
|
+
│ ├── identity.yaml
|
25
|
+
│ ├── location.yaml
|
26
|
+
│ └── rack -> ../../rack/1-A-2/
|
27
|
+
├── domain
|
28
|
+
│ └── example.com
|
29
|
+
│ ├── dns.yaml
|
30
|
+
│ ├── ipv4_network -> ../../ipv4_network/192.168.0.0_24/
|
31
|
+
│ └── services.yaml
|
32
|
+
├── ipv4_interface
|
33
|
+
│ ├── 192.168.0.1
|
34
|
+
│ │ ├── dns.yaml
|
35
|
+
│ │ ├── domain -> ../../domain/example.com/
|
36
|
+
│ │ ├── ipv4_network -> ../../ipv4_network/192.168.0.0_24/
|
37
|
+
│ │ ├── phy_nic -> ../../phy_nic/14:18:77:ab:cd:ef/
|
38
|
+
│ │ └── system -> ../../system/vmhost1/
|
39
|
+
│ └── 192.168.0.2
|
40
|
+
│ ├── domain -> ../../domain/example.com/
|
41
|
+
│ ├── ipv4_network -> ../../ipv4_network/192.168.0.0_24/
|
42
|
+
│ ├── phy_nic -> ../../phy_nic/52:54:00:12:34:56/
|
43
|
+
│ └── system -> ../../system/testvm/
|
44
|
+
├── ipv4_network
|
45
|
+
│ └── 192.168.0.0_24
|
46
|
+
│ ├── dhcp.yaml
|
47
|
+
│ └── identity.yaml
|
48
|
+
├── machine
|
49
|
+
│ ├── testvm
|
50
|
+
│ │ ├── host -> ../../system/vmhost1/
|
51
|
+
│ │ └── type.yaml
|
52
|
+
│ └── vmhost1
|
53
|
+
│ ├── chassis -> ../../chassis/Example:FastServer-128:1234ABCD/
|
54
|
+
│ └── type.yaml
|
55
|
+
├── netinstall
|
56
|
+
│ ├── CentOS-7.2.1511-x86_64-Kickstart_sda
|
57
|
+
│ │ ├── kickstart.yaml
|
58
|
+
│ │ └── os -> ../../os/CentOS-7.2.1511-x86_64
|
59
|
+
│ ├── CentOS-7.2.1511-x86_64-Kickstart_vda
|
60
|
+
│ │ ├── kickstart.yaml
|
61
|
+
│ │ └── os -> ../../os/CentOS-7.2.1511-x86_64
|
62
|
+
│ └── CentOS-7.2.1511-x86_64-Manual
|
63
|
+
│ ├── kickstart.yaml
|
64
|
+
│ └── os -> ../../os/CentOS-7.2.1511-x86_64
|
65
|
+
├── os
|
66
|
+
│ └── CentOS-7.2.1511-x86_64
|
67
|
+
│ └── kickstart.yaml
|
68
|
+
├── phy_nic
|
69
|
+
│ ├── 14:18:77:ab:cd:ef
|
70
|
+
│ │ ├── chassis -> ../../chassis/Example:FastServer-128:1234ABCD/
|
71
|
+
│ │ └── location.yaml
|
72
|
+
│ └── 52:54:00:12:34:56
|
73
|
+
│ ├── identity.yaml
|
74
|
+
│ └── phy_nic -> ../../phy_nic/14:18:77:ab:cd:ef/
|
75
|
+
├── rack
|
76
|
+
│ └── 1-A-2
|
77
|
+
│ ├── location.yaml
|
78
|
+
│ └── room -> ../../room/server-room-1/
|
79
|
+
├── room
|
80
|
+
│ └── server-room-1
|
81
|
+
│ ├── building -> ../../building/1
|
82
|
+
│ ├── identity.yaml
|
83
|
+
│ └── location.yaml
|
84
|
+
├── service
|
85
|
+
│ ├── dhcp-server-example-net
|
86
|
+
│ │ └── kea.yaml
|
87
|
+
│ └── dns-resolver-example-com
|
88
|
+
│ └── unbound.yaml
|
89
|
+
├── system
|
90
|
+
│ ├── testvm
|
91
|
+
│ │ ├── architecture.yaml
|
92
|
+
│ │ ├── domain -> ../../domain/example.com/
|
93
|
+
│ │ ├── machine -> ../../machine/testvm/
|
94
|
+
│ │ ├── netinstall -> ../../netinstall/CentOS-7.2.1511-x86_64-Kickstart_vda/
|
95
|
+
│ │ └── role.yaml
|
96
|
+
│ └── vmhost1
|
97
|
+
│ ├── architecture.yaml
|
98
|
+
│ ├── domain -> ../../domain/example.com/
|
99
|
+
│ ├── machine -> ../../machine/vmhost1/
|
100
|
+
│ ├── netinstall -> ../../netinstall/CentOS-7.2.1511-x86_64-Kickstart_sda/
|
101
|
+
│ └── role.yaml
|
102
|
+
└── transforms.yaml
|
103
|
+
```
|
104
|
+
|
105
|
+
```bash
|
106
|
+
% irb -r palletjack
|
107
|
+
2.3.1 :001 > jack = PalletJack.new('warehouse')
|
108
|
+
2.3.1 :002 > testvm = jack.fetch('system', name:'testvm')
|
109
|
+
=> #<PalletJack::Pallet:148ac64>
|
110
|
+
2.3.1 :003 > testvm['host.type']
|
111
|
+
=> "virtual"
|
112
|
+
2.3.1 :004 > jack['system'].each {|pallet| puts "#{pallet['net.dns.name']}: #{pallet['chassis.serial']}" }
|
113
|
+
vmhost1: 1234ABCD
|
114
|
+
testvm: 1234ABCD
|
115
|
+
=> #<Set: {#<PalletJack::Pallet:16abed0>, #<PalletJack::Pallet:148ac64>}>
|
116
|
+
2.3.1 :005 > jack['system', with_all:{'host.type' => 'virtual'}].each {|system| puts system['net.dns.name'] }
|
117
|
+
testvm
|
118
|
+
=> #<Set: {#<PalletJack::Pallet:148ac64>}>
|
119
|
+
```
|
120
|
+
|
121
|
+
## Installation
|
122
|
+
|
123
|
+
Add this line to your application's Gemfile:
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
gem 'palletjack'
|
127
|
+
```
|
128
|
+
|
129
|
+
And then execute:
|
130
|
+
|
131
|
+
$ bundle
|
132
|
+
|
133
|
+
Or install it yourself as:
|
134
|
+
|
135
|
+
$ gem install palletjack
|
136
|
+
|
137
|
+
## Creating warehouse objects
|
138
|
+
|
139
|
+
Warehouse objects are simple directories, so you can create them using
|
140
|
+
`mkdir`. To simplify the process, there are some tools that create
|
141
|
+
objects with standard links and YAML structures for you. Example:
|
142
|
+
|
143
|
+
```bash
|
144
|
+
$ create_domain --warehouse /tmp/warehouse --domain example.com --network 192.168.42.0/24
|
145
|
+
$ create_system --warehouse /tmp/warehouse --system vmhost --domain example.com --os CentOS-7.2.1511-x86_64
|
146
|
+
$ create_ipv4_interface --warehouse /tmp/warehouse --system vmhost --domain example.com --mac 52:54:00:8d:be:fe --ipv4 192.168.42.1 --network 192.168.42.0/24
|
147
|
+
$ dump_pallet --warehouse /tmp/warehouse --type ipv4_interface 192.168.42.1
|
148
|
+
```
|
149
|
+
|
150
|
+
```yaml
|
151
|
+
---
|
152
|
+
pallet:
|
153
|
+
ipv4_network: 192.168.42.0_24
|
154
|
+
boxes: []
|
155
|
+
references:
|
156
|
+
ipv4_network: 192.168.42.0_24
|
157
|
+
domain: example.com
|
158
|
+
phy_nic: 52:54:00:8d:be:fe
|
159
|
+
os: CentOS-7.2.1511-x86_64
|
160
|
+
system: vmhost
|
161
|
+
domain: example.com
|
162
|
+
phy_nic: 52:54:00:8d:be:fe
|
163
|
+
os: CentOS-7.2.1511-x86_64
|
164
|
+
system: vmhost
|
165
|
+
ipv4_interface: 192.168.42.1
|
166
|
+
net:
|
167
|
+
dhcp:
|
168
|
+
tftp-server: ''
|
169
|
+
boot-file: ''
|
170
|
+
ipv4:
|
171
|
+
gateway: ''
|
172
|
+
prefixlen: '24'
|
173
|
+
cidr: 192.168.42.0/24
|
174
|
+
address: 192.168.42.1
|
175
|
+
dns:
|
176
|
+
resolver:
|
177
|
+
- ''
|
178
|
+
ns:
|
179
|
+
- ''
|
180
|
+
soa-ns: ''
|
181
|
+
soa-contact: ''
|
182
|
+
domain: example.com
|
183
|
+
name: vmhost
|
184
|
+
fqdn: vmhost.example.com
|
185
|
+
service:
|
186
|
+
syslog:
|
187
|
+
- address: syslog-archive.example.com
|
188
|
+
port: 514
|
189
|
+
protocol: udp
|
190
|
+
- address: logstash.example.com
|
191
|
+
port: 5514
|
192
|
+
protocol: tcp
|
193
|
+
layer2:
|
194
|
+
name: ''
|
195
|
+
address: 52:54:00:8d:be:fe
|
196
|
+
host:
|
197
|
+
kickstart:
|
198
|
+
baseurl: http://mirror.centos.org/centos/7.2.1511/os/x86_64/
|
199
|
+
pxelinux:
|
200
|
+
kernel: "/boot/CentOS-7.2.1511-x86_64/vmlinuz"
|
201
|
+
config: CentOS-7.2.1511-x86_64
|
202
|
+
system:
|
203
|
+
os: CentOS-7.2.1511-x86_64
|
204
|
+
role:
|
205
|
+
- ''
|
206
|
+
name: vmhost
|
207
|
+
```
|
208
|
+
|
209
|
+
## Development
|
210
|
+
|
211
|
+
After checking out the repo, run `bin/setup` to install
|
212
|
+
dependencies. Then, run `rake spec` to run the tests. You can also run
|
213
|
+
`bin/console` for an interactive prompt that will allow you to
|
214
|
+
experiment.
|
215
|
+
|
216
|
+
To install this gem onto your local machine, run `bundle exec rake
|
217
|
+
install`.
|
218
|
+
|
219
|
+
## Contributing
|
220
|
+
|
221
|
+
We are happy to accept contributions in the form of issues and pull requests on [GitHub](https://github.com/saab-simc-admin/palletjack). Please follow these guidelines to make the experience as smooth as possible:
|
222
|
+
|
223
|
+
- All development takes place in feature branches, with master only accepting non-fast-forward merges.
|
224
|
+
|
225
|
+
- Others shall be able to use the Pallet Jack library to build their own tools. To facilitate this, the library and the included tools are packaged as two different Ruby gems, and are intended to be loosely coupled. If you introduce API changes, please increment version numbers according to [semantic versioning](http://semver.org/).
|
226
|
+
|
227
|
+
- All code will be reviewed before it is merged. To help the reviewer, send your work as a series of logically separate changes, not as one gigantic squash commit. Make sure bisection will work by ensuring the code actually works after each change.
|
228
|
+
|
229
|
+
- GnuPG sign all your commits and tags, with a key that is [validated by GitHub](https://help.github.com/articles/about-gpg-commit-and-tag-signatures/).
|
230
|
+
|
231
|
+
- GitHub's web UI cannot generate signed merges when accepting pull requests. Instead, we use [a custom tool](https://github.com/saab-simc-admin/workflow-tools/tree/master/git-ghpr) to accept them. You can still send them through the web as usual.
|
232
|
+
|
233
|
+
- Your code shall be signed by you. Therefore, the maintainer cannot fix any merge conflicts arising from your pull request. If there are any conflicts, please rebase onto current master before sending your pull request.
|
234
|
+
|
235
|
+
- Document your work.
|
236
|
+
|
237
|
+
- At an absolute minimum, Ruby code shall have [RDoc](https://rdoc.github.io/rdoc/) blocks documenting each function, with analogues for other languages (e.g. Python [docstrings](https://www.python.org/dev/peps/pep-0257/)).
|
238
|
+
|
239
|
+
- User-visible features shall have examples in the [`examples/` directory](https://github.com/saab-simc-admin/palletjack/tree/master/examples). In particular, [the example warehouse](https://github.com/saab-simc-admin/palletjack/tree/master/examples/warehouse) shall include demonstrations of all keys used by any included tool.
|
240
|
+
|
241
|
+
- If your code needs larger chunks of static data to work, please provide it in a separate directory under `examples/`. See e.g. [the `examples/pxelinux/` tree](https://github.com/saab-simc-admin/palletjack/tree/master/examples/pxelinux), which contains files required to make sense of the output from `palletjack2pxelinux`.
|
242
|
+
|
243
|
+
- Write your commit messages in the usual Git style: a short summary in the first line, then paragraphs of explanatory text, line wrapped.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "palletjack"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/palletjack.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'yaml'
|
3
|
+
require 'kvdag'
|
4
|
+
require 'palletjack/version'
|
5
|
+
require 'palletjack/keytransformer'
|
6
|
+
require 'palletjack/pallet'
|
7
|
+
|
8
|
+
class PalletJack < KVDAG
|
9
|
+
attr_reader :pallets
|
10
|
+
attr_reader :keytrans_reader
|
11
|
+
attr_reader :keytrans_writer
|
12
|
+
|
13
|
+
def self.load(warehouse)
|
14
|
+
new.load(warehouse)
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
super
|
19
|
+
@pallets = Hash.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def load(warehouse)
|
23
|
+
@warehouse = File.expand_path(warehouse)
|
24
|
+
key_transforms = YAML::load_file(File.join(@warehouse, "transforms.yaml"))
|
25
|
+
@keytrans_reader = KeyTransformer::Reader.new(key_transforms)
|
26
|
+
@keytrans_writer = KeyTransformer::Writer.new(key_transforms)
|
27
|
+
|
28
|
+
Dir.foreach(@warehouse) do |kind|
|
29
|
+
kindpath = File.join(@warehouse, kind)
|
30
|
+
next unless File.directory?(kindpath) and kind !~ /^\.{1,2}$/
|
31
|
+
|
32
|
+
Dir.foreach(kindpath) do |pallet|
|
33
|
+
palletpath = File.join(kindpath, pallet)
|
34
|
+
next unless File.directory?(palletpath) and pallet !~ /^\.{1,2}$/
|
35
|
+
Pallet.new(self, palletpath)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
# Search for pallets in a PalletJack warehouse
|
42
|
+
#
|
43
|
+
# The search is filtered by KVDAG::Vertex#match? expressions.
|
44
|
+
#
|
45
|
+
# Useful Pallet methods to match for include:
|
46
|
+
#
|
47
|
+
# kind:: the kind of pallet
|
48
|
+
# name:: the filesystem +basename+ of the pallet
|
49
|
+
|
50
|
+
def [](filter = {})
|
51
|
+
vertices(filter)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Fetch a single pallet from a PalletJack warehouse
|
55
|
+
#
|
56
|
+
# The search is filtered by KVDAG::Vertex#match? expressions.
|
57
|
+
#
|
58
|
+
# Useful Pallet methods to match for include:
|
59
|
+
#
|
60
|
+
# kind:: the kind of pallet
|
61
|
+
# name:: the filesystem +basename+ of the pallet
|
62
|
+
|
63
|
+
def fetch(filter = {})
|
64
|
+
result = self[filter]
|
65
|
+
|
66
|
+
if result.length != 1
|
67
|
+
raise KeyError.new("#{options} matched #{result.length} pallets")
|
68
|
+
end
|
69
|
+
result.first
|
70
|
+
end
|
71
|
+
end
|