koma 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 130b27ad7fffcfc9288a25e0d4a733894cf4d5a2
4
+ data.tar.gz: 1256c3fb51e24093907288d2db1bce98f8634dba
5
+ SHA512:
6
+ metadata.gz: 8a89537f280ddac5f313e19b5e707b4ce26a23478e409efd1833a84226954d8e57ef9f237aad898a5cd9edb68c0113eb1a756decdac1bb2fa4a8f2fa24db0cbe
7
+ data.tar.gz: 7a90efa899dc54613578aa2a0460976b53699b78612db2ae892078e0b8fc3eab7d197ba877a1525e7cf3b56ff38fa29000b3d0edc93426eb850c24e801470429
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,71 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.1
3
+ Exclude:
4
+ - 'lib/koma/ext/**/*'
5
+ - 'spec/specinfra/**/*'
6
+
7
+ Lint/Eval:
8
+ Enabled: false
9
+
10
+ Lint/HandleExceptions:
11
+ Enabled: false
12
+
13
+ Lint/UselessAssignment:
14
+ Enabled: false
15
+
16
+ Metrics/AbcSize:
17
+ Max: 50
18
+
19
+ Metrics/ClassLength:
20
+ Max: 120
21
+
22
+ Metrics/CyclomaticComplexity:
23
+ Max: 15
24
+
25
+ Metrics/LineLength:
26
+ Max: 120
27
+
28
+ Metrics/MethodLength:
29
+ Max: 30
30
+
31
+ Metrics/PerceivedComplexity:
32
+ Max: 15
33
+
34
+ Performance/StringReplacement:
35
+ Enabled: false
36
+
37
+ Style/Alias:
38
+ Enabled: false
39
+
40
+ Style/BarePercentLiterals:
41
+ Enabled: false
42
+
43
+ Style/ClassAndModuleChildren:
44
+ Enabled: false
45
+
46
+ Style/Documentation:
47
+ Enabled: false
48
+
49
+ Style/MutableConstant:
50
+ Enabled: false
51
+
52
+ Style/MultilineOperationIndentation:
53
+ Enabled: false
54
+
55
+ Style/StabbyLambdaParentheses:
56
+ Enabled: false
57
+
58
+ Style/PercentLiteralDelimiters:
59
+ Enabled: false
60
+
61
+ Style/PredicateName:
62
+ Enabled: false
63
+
64
+ Style/RedundantSelf:
65
+ Enabled: false
66
+
67
+ Style/SymbolProc:
68
+ Enabled: false
69
+
70
+ Style/BracesAroundHashParameters:
71
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ - 2.2.4
5
+ - 2.1.8
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in koma.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 k1LoW
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,31 @@
1
+ # Koma [![Build Status](https://travis-ci.org/k1LoW/koma.svg?branch=master)](https://travis-ci.org/k1LoW/koma)
2
+
3
+ Koma gather host inventory without agent.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'koma'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install koma
20
+
21
+ ## Usage
22
+
23
+ $ koma ssh example.com
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/k1LoW/koma/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'octorelease'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'koma'
5
+ require 'pry'
6
+
7
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/koma ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'koma'
4
+
5
+ Koma::CLI.start
data/koma.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'koma/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'koma'
8
+ spec.version = Koma::VERSION
9
+ spec.authors = ['k1LoW']
10
+ spec.email = ['k1lowxb@gmail.com']
11
+
12
+ spec.summary = 'Koma gather host inventory without agent.'
13
+ spec.description = 'Koma gather host inventory without agent.'
14
+ spec.homepage = 'https://github.com/k1LoW/koma'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_runtime_dependency 'thor'
23
+ spec.add_runtime_dependency 'highline'
24
+ spec.add_runtime_dependency 'specinfra', '~> 2.48'
25
+ spec.add_development_dependency 'bundler', '~> 1.9'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec'
28
+ spec.add_development_dependency 'rubocop'
29
+ spec.add_development_dependency 'octorelease'
30
+ spec.add_development_dependency 'pry'
31
+ end
data/lib/koma/cli.rb ADDED
@@ -0,0 +1,72 @@
1
+ require 'thor'
2
+ require 'json'
3
+
4
+ include Specinfra::Helper::Set
5
+
6
+ module Koma
7
+ class CLI < Thor
8
+ desc 'ssh', 'stdout server inventory'
9
+ option :key,
10
+ type: :string,
11
+ banner: '<key1,key2,..>',
12
+ desc: 'inventory keys',
13
+ aliases: :k
14
+ option :identity_file,
15
+ type: :string,
16
+ banner: '<identity_file>',
17
+ desc: 'identity file',
18
+ aliases: :i
19
+ def ssh(host)
20
+ user, host = host.split('@') if host.include?('@')
21
+ set :backend, :ssh
22
+ set :host, host
23
+ set :request_pty, true
24
+ ssh_options = Net::SSH::Config.for(host)
25
+ ssh_options[:user] = user if user
26
+ ssh_options[:keys] = [options[:identity_file]] if options[:identity_file]
27
+ set :ssh_options, ssh_options
28
+ puts JSON.pretty_generate out(options[:key])
29
+ end
30
+
31
+ desc 'exec', 'stdout local inventory'
32
+ option :key,
33
+ type: :string,
34
+ banner: '<key1,key2,..>',
35
+ desc: 'inventory keys',
36
+ aliases: :k
37
+ def exec
38
+ set :backend, :exec
39
+ puts JSON.pretty_generate out(options[:key])
40
+ end
41
+
42
+ desc 'keys', 'server inventory keys'
43
+ def keys
44
+ inventory_keys.each do |key|
45
+ puts key
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def inventory_keys
52
+ Specinfra::HostInventory.inventory_keys
53
+ end
54
+
55
+ def out(key = nil)
56
+ out = {}
57
+ keys = if key.nil?
58
+ inventory_keys
59
+ else
60
+ key.split(',')
61
+ end
62
+ keys.each do |k|
63
+ begin
64
+ out[k] = Specinfra.backend.host_inventory[k]
65
+ rescue NotImplementedError
66
+ out[k] = nil
67
+ end
68
+ end
69
+ out
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,11 @@
1
+ class Specinfra::Command::Base::Inventory < Specinfra::Command::Base
2
+ class << self
3
+ def get_user
4
+ 'getent passwd'
5
+ end
6
+
7
+ def get_group
8
+ 'getent group'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ class Specinfra::Command::Redhat::Base::Inventory < Specinfra::Command::Linux::Base::Inventory
2
+ class << self
3
+ def get_package
4
+ "rpm -qa --queryformat 'name:%{NAME}\tversion:%{VERSION}\trelease:%{RELEASE}\tarch:%{ARCH}\tinstalltime:%{INSTALLTIME}\tbuildtime:%{BUILDTIME}\n'"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,34 @@
1
+ module Specinfra
2
+ class HostInventory
3
+ class Group < Base
4
+ def get
5
+ cmd = backend.command.get(:get_inventory_group)
6
+ ret = backend.run_command(cmd)
7
+ if ret.exit_status == 0
8
+ parse(ret.stdout)
9
+ else
10
+ nil
11
+ end
12
+ end
13
+
14
+ def parse(cmd_ret)
15
+ groups = {}
16
+ lines = cmd_ret.split(/\n/)
17
+ lines.each do |line|
18
+ group = line.split(':')
19
+ members = if group[3]
20
+ group[3].split(',')
21
+ else
22
+ []
23
+ end
24
+ groups[group[0]] = {
25
+ 'name' => group[0],
26
+ 'gid' => group[2],
27
+ 'members' => members
28
+ }
29
+ end
30
+ groups
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ module Specinfra
2
+ class HostInventory
3
+ class Package < Base
4
+ def get
5
+ cmd = backend.command.get(:get_inventory_package)
6
+ ret = backend.run_command(cmd)
7
+ if ret.exit_status == 0
8
+ parse(ret.stdout)
9
+ else
10
+ nil
11
+ end
12
+ end
13
+
14
+ def parse(cmd_ret)
15
+ packages = {}
16
+ lines = cmd_ret.split(/\n/)
17
+ lines.each do |line|
18
+ h = Hash[line.split("\t").map { |f| f.split(':', 2) }]
19
+ idx = h['name']
20
+ packages[idx] = h
21
+ end
22
+ packages
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ module Specinfra
2
+ class HostInventory
3
+ class User < Base
4
+ def get
5
+ cmd = backend.command.get(:get_inventory_user)
6
+ ret = backend.run_command(cmd)
7
+ if ret.exit_status == 0
8
+ parse(ret.stdout)
9
+ else
10
+ nil
11
+ end
12
+ end
13
+
14
+ def parse(cmd_ret)
15
+ users = {}
16
+ lines = cmd_ret.split(/\n/)
17
+ lines.each do |line|
18
+ user = line.split(':')
19
+ users[user[0]] = {
20
+ 'name' => user[0],
21
+ 'uid' => user[2],
22
+ 'gid' => user[3],
23
+ 'gecos' => user[4],
24
+ 'directory' => user[5],
25
+ 'shell' => user[6]
26
+ }
27
+ end
28
+ users
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ module Specinfra
2
+ class HostInventory
3
+ EXTRA_KEYS = %w(package user group)
4
+
5
+ def self.inventory_keys
6
+ KEYS + EXTRA_KEYS
7
+ end
8
+
9
+ def each
10
+ inventory_keys.each do |k|
11
+ yield k, self[k]
12
+ end
13
+ end
14
+
15
+ def each_key
16
+ inventory_keys.each do |k|
17
+ yield k
18
+ end
19
+ end
20
+
21
+ def each_value
22
+ inventory_keys.each do |k|
23
+ yield self[k]
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ Specinfra::HostInventory::EXTRA_KEYS.each do |k|
30
+ require "koma/ext/specinfra/host_inventory/#{k}"
31
+ end
data/lib/koma/ext.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'koma/ext/specinfra/host_inventory'
2
+ require 'koma/ext/specinfra/command/base/inventory'
3
+ require 'koma/ext/specinfra/command/redhat/base/inventory'
@@ -0,0 +1,3 @@
1
+ module Koma
2
+ VERSION = '0.1.0'
3
+ end
data/lib/koma.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'net/ssh'
3
+ require 'specinfra'
4
+ require 'specinfra/helper/set'
5
+ require 'koma/ext'
6
+ require 'koma/cli'
7
+ require 'koma/version'
8
+
9
+ module Koma
10
+ end
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: koma
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - k1LoW
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: highline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: specinfra
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.48'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.48'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: octorelease
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Koma gather host inventory without agent.
140
+ email:
141
+ - k1lowxb@gmail.com
142
+ executables:
143
+ - koma
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".rubocop.yml"
150
+ - ".travis.yml"
151
+ - Gemfile
152
+ - LICENSE.txt
153
+ - README.md
154
+ - Rakefile
155
+ - bin/console
156
+ - bin/setup
157
+ - exe/koma
158
+ - koma.gemspec
159
+ - lib/koma.rb
160
+ - lib/koma/cli.rb
161
+ - lib/koma/ext.rb
162
+ - lib/koma/ext/specinfra/command/base/inventory.rb
163
+ - lib/koma/ext/specinfra/command/redhat/base/inventory.rb
164
+ - lib/koma/ext/specinfra/host_inventory.rb
165
+ - lib/koma/ext/specinfra/host_inventory/group.rb
166
+ - lib/koma/ext/specinfra/host_inventory/package.rb
167
+ - lib/koma/ext/specinfra/host_inventory/user.rb
168
+ - lib/koma/version.rb
169
+ homepage: https://github.com/k1LoW/koma
170
+ licenses:
171
+ - MIT
172
+ metadata: {}
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ requirements: []
188
+ rubyforge_project:
189
+ rubygems_version: 2.2.2
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: Koma gather host inventory without agent.
193
+ test_files: []