nodeattr 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +1 -0
- data/bin/nodeattr +33 -0
- data/example/genders +2 -0
- data/lib/nodeattr/version.rb +3 -0
- data/lib/nodeattr.rb +75 -0
- data/nodeattr.gemspec +23 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 158b050787682c80dc268baf61210ce64a3127e9
|
4
|
+
data.tar.gz: a09d648866a46d2ded7b1b51e7521f675d813c11
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a70d928f393fae8891de967b6853efa219bf409bccd91a61cf098f9b416509d449848b7d94d32a8eaa331993ce9777c33103053e0efc948439f95655784d4a84
|
7
|
+
data.tar.gz: 5b1fb523c51a544c29123b8e0e0bf6f4400726132d6670c90f5548effef68df06212469b0375764d4abd2399af28e11e1a2e3d49237679557eb1105436ad8bc0
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Doug Everly
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Nodeattr
|
2
|
+
|
3
|
+
Ruby implementation of nodeattr.
|
4
|
+
|
5
|
+
The goal is to replicate functionality of nodeattr as defined by the Genders library developed by [LLNL](https://computing.llnl.gov/linux/genders.html).
|
6
|
+
|
7
|
+
Current implementation is very limited in that only simple gender query works. This will be expanded upon to provide union, intersection, and exclusion of genders. Values are also not yet supported, but are planned for a future update.
|
8
|
+
|
9
|
+
Included are the nodeattr class and the nodeattr command line tool.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'nodeattr'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install nodeattr
|
24
|
+
|
25
|
+
## Class Usage
|
26
|
+
|
27
|
+
require 'nodeattr'
|
28
|
+
|
29
|
+
n = NodeAttr.new
|
30
|
+
|
31
|
+
if nodes = n.query(@gender)
|
32
|
+
puts nodes.join(@sep)
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
## Command Line Usage
|
37
|
+
|
38
|
+
Usage: nodeattr [options] query
|
39
|
+
|
40
|
+
-f genders genders file
|
41
|
+
-n space separated list
|
42
|
+
-s newline separated list
|
43
|
+
-c comma separated list
|
44
|
+
|
45
|
+
nodeattr -f example/genders -s unix
|
46
|
+
web-01 web-02 web-03 web-04 mail-01 mail-02 mail-03 mail-04 mail-05 mail-06 mail-07 mail-08 mail-09 mail-10
|
47
|
+
|
48
|
+
nodeattr -f example/genders web
|
49
|
+
web-01
|
50
|
+
web-02
|
51
|
+
web-03
|
52
|
+
web-04
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/nodeattr
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'nodeattr'
|
2
|
+
|
3
|
+
@genders_file = nil;
|
4
|
+
@sep = "\n"
|
5
|
+
|
6
|
+
optparse = OptionParser.new do |opts|
|
7
|
+
opts.banner = "\nUsage: #{$0} [options] query"
|
8
|
+
|
9
|
+
opts.on('-f genders', "genders file") do |file|
|
10
|
+
@genders_file = file
|
11
|
+
end
|
12
|
+
|
13
|
+
opts.on('-n', "space separated list") do
|
14
|
+
@sep = "\n"
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on('-s', "newline separated list") do
|
18
|
+
@sep = ' '
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on('-c', "comma separated list") do
|
22
|
+
@sep = ','
|
23
|
+
end
|
24
|
+
|
25
|
+
end.parse!
|
26
|
+
|
27
|
+
@gender = ARGV.shift
|
28
|
+
|
29
|
+
n = NodeAttr.new @genders_file
|
30
|
+
|
31
|
+
if nodes = n.query(@gender)
|
32
|
+
puts nodes.join(@sep)
|
33
|
+
end
|
data/example/genders
ADDED
data/lib/nodeattr.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require "nodeattr/version"
|
2
|
+
|
3
|
+
require 'OptParse'
|
4
|
+
|
5
|
+
class NodeAttr
|
6
|
+
|
7
|
+
attr_accessor :genders
|
8
|
+
|
9
|
+
def initialize(filename = nil)
|
10
|
+
|
11
|
+
@genders = Hash.new { |hash, key| hash[key] = [] }
|
12
|
+
|
13
|
+
if not filename.nil?
|
14
|
+
file = File.readlines(filename)
|
15
|
+
elsif File.exists?('~/.genders')
|
16
|
+
file = File.readlines('~/.genders')
|
17
|
+
elsif File.exists?('/etc/genders')
|
18
|
+
file = IO.readlines('/etc/genders', "\n")
|
19
|
+
end
|
20
|
+
load file
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def load(file)
|
25
|
+
file.each do |line|
|
26
|
+
nodes = []
|
27
|
+
next if line =~ /^#/
|
28
|
+
next if line =~ /^\s+$/
|
29
|
+
line.chomp!
|
30
|
+
nodes_part, genders_part = line.split(/\s+/)
|
31
|
+
nodes << explode_nodes(nodes_part)
|
32
|
+
# puts genders_part
|
33
|
+
if genders_part
|
34
|
+
genders = genders_part.split(',')
|
35
|
+
genders.each do |gender|
|
36
|
+
@genders[gender] = @genders[gender] + nodes.flatten
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def explode_nodes(nodes)
|
43
|
+
h = Array.new
|
44
|
+
m = nodes.match(/^(.*)\[(.*)\]$/)
|
45
|
+
if m
|
46
|
+
base = m[1]
|
47
|
+
instances = m[2].split(',')
|
48
|
+
instances.each do |i|
|
49
|
+
if i.match(/-/)
|
50
|
+
left, right = i.split('-')
|
51
|
+
padding = left.match(/^0+/)
|
52
|
+
(left.to_i .. right.to_i).each do |j|
|
53
|
+
h << sprintf("%s%0#{padding.to_s.length + 1}d", base, j)
|
54
|
+
end
|
55
|
+
else
|
56
|
+
padding = i.match(/^0+/).size - 1
|
57
|
+
if padding.size > 1
|
58
|
+
pad = '0' * (padding.size -1)
|
59
|
+
end
|
60
|
+
h << sprintf("%s%0#{padding.to_s.length + 1}d", base, j)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
h
|
65
|
+
end
|
66
|
+
|
67
|
+
def query(filter)
|
68
|
+
if @genders.has_key?(filter)
|
69
|
+
@genders[filter]
|
70
|
+
else
|
71
|
+
[]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
data/nodeattr.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nodeattr/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nodeattr"
|
8
|
+
spec.version = Nodeattr::VERSION
|
9
|
+
spec.authors = ["Doug Everly"]
|
10
|
+
spec.email = ["Doug@Everly.org"]
|
11
|
+
spec.description = %q{Ruby implementation of nodeattr}
|
12
|
+
spec.summary = %q{Ruby implementation of nodeattr that is included with libgenders. https://computing.llnl.gov/linux/genders.html}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nodeattr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Doug Everly
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Ruby implementation of nodeattr
|
42
|
+
email:
|
43
|
+
- Doug@Everly.org
|
44
|
+
executables:
|
45
|
+
- nodeattr
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/nodeattr
|
56
|
+
- example/genders
|
57
|
+
- lib/nodeattr.rb
|
58
|
+
- lib/nodeattr/version.rb
|
59
|
+
- nodeattr.gemspec
|
60
|
+
homepage: ''
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.0.3
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Ruby implementation of nodeattr that is included with libgenders. https://computing.llnl.gov/linux/genders.html
|
84
|
+
test_files: []
|