koma 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -4
- data/lib/koma/cli.rb +3 -3
- data/lib/koma/ext/specinfra/command/redhat/base/inventory.rb +4 -0
- data/lib/koma/ext/specinfra/command/redhat/v7/inventory.rb +7 -0
- data/lib/koma/ext/specinfra/host_inventory/base.rb +35 -0
- data/lib/koma/ext/specinfra/host_inventory/parser/base.rb +16 -0
- data/lib/koma/ext/specinfra/host_inventory/parser/redhat/base/service.rb +19 -0
- data/lib/koma/ext/specinfra/host_inventory/parser/redhat/base.rb +2 -0
- data/lib/koma/ext/specinfra/host_inventory/parser/redhat/v7/service.rb +19 -0
- data/lib/koma/ext/specinfra/host_inventory/parser/redhat/v7.rb +1 -0
- data/lib/koma/ext/specinfra/host_inventory/parser/redhat.rb +2 -0
- data/lib/koma/ext/specinfra/host_inventory/parser.rb +10 -0
- data/lib/koma/ext/specinfra/host_inventory/service.rb +20 -0
- data/lib/koma/ext/specinfra/host_inventory.rb +4 -1
- data/lib/koma/ext.rb +3 -0
- data/lib/koma/version.rb +1 -1
- data/stdout_sample.json +3885 -0
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba14ba42f09152b6d30fb5806378955b624bc54f
|
4
|
+
data.tar.gz: b5285a745b7a381849079f3105a66485360efa7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13375bf06a378b82895c8e0eb4c37ffe59a02e467554590472d9f0c6f34980b42a0b6c9a3578cc22d13045a428d1865f111144d6d6f8836a9e604e1021e4896c
|
7
|
+
data.tar.gz: f2b517d4a3fe7f5fe7d83a2fdf142a2559614eb22e9bd3e6a5e37cb716b8c83a330914af53f9fbd1c7d69a11a3d3ca5f28125c6196e3d1d26ca9035fd1f977a5
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Koma [![Build Status](https://travis-ci.org/k1LoW/koma.svg?branch=master)](https://travis-ci.org/k1LoW/koma)
|
1
|
+
# Koma [![Gem](https://img.shields.io/gem/v/koma.svg)](https://rubygems.org/gems/koma) [![Build Status](https://travis-ci.org/k1LoW/koma.svg?branch=master)](https://travis-ci.org/k1LoW/koma)
|
2
2
|
|
3
3
|
Koma gather host inventory without agent.
|
4
4
|
|
@@ -12,15 +12,47 @@ gem 'koma'
|
|
12
12
|
|
13
13
|
And then execute:
|
14
14
|
|
15
|
-
|
15
|
+
```sh
|
16
|
+
$ bundle
|
17
|
+
```
|
16
18
|
|
17
19
|
Or install it yourself as:
|
18
20
|
|
19
|
-
|
21
|
+
```sh
|
22
|
+
$ gem install koma
|
23
|
+
```
|
20
24
|
|
21
25
|
## Usage
|
22
26
|
|
23
|
-
|
27
|
+
If you login remote server via `ssh example.com`, you can execute:
|
28
|
+
|
29
|
+
```sh
|
30
|
+
$ koma ssh example.com
|
31
|
+
```
|
32
|
+
|
33
|
+
And get stdout like [this](stdout_sample.json).
|
34
|
+
|
35
|
+
## Host inventory keys
|
36
|
+
|
37
|
+
```sh
|
38
|
+
$ koma keys
|
39
|
+
memory
|
40
|
+
ec2
|
41
|
+
hostname
|
42
|
+
domain
|
43
|
+
fqdn
|
44
|
+
platform
|
45
|
+
platform_version
|
46
|
+
filesystem
|
47
|
+
cpu
|
48
|
+
virtualization
|
49
|
+
kernel
|
50
|
+
block_device
|
51
|
+
package
|
52
|
+
user
|
53
|
+
group
|
54
|
+
service
|
55
|
+
```
|
24
56
|
|
25
57
|
## Contributing
|
26
58
|
|
data/lib/koma/cli.rb
CHANGED
@@ -5,7 +5,7 @@ include Specinfra::Helper::Set
|
|
5
5
|
|
6
6
|
module Koma
|
7
7
|
class CLI < Thor
|
8
|
-
desc 'ssh', 'stdout
|
8
|
+
desc 'ssh', 'stdout remote host inventory'
|
9
9
|
option :key,
|
10
10
|
type: :string,
|
11
11
|
banner: '<key1,key2,..>',
|
@@ -34,7 +34,7 @@ module Koma
|
|
34
34
|
puts JSON.pretty_generate out(options[:key])
|
35
35
|
end
|
36
36
|
|
37
|
-
desc 'exec', 'stdout local inventory'
|
37
|
+
desc 'exec', 'stdout local host inventory'
|
38
38
|
option :key,
|
39
39
|
type: :string,
|
40
40
|
banner: '<key1,key2,..>',
|
@@ -45,7 +45,7 @@ module Koma
|
|
45
45
|
puts JSON.pretty_generate out(options[:key])
|
46
46
|
end
|
47
47
|
|
48
|
-
desc 'keys', '
|
48
|
+
desc 'keys', 'host inventory keys'
|
49
49
|
def keys
|
50
50
|
inventory_keys.each do |key|
|
51
51
|
puts key
|
@@ -1,5 +1,9 @@
|
|
1
1
|
class Specinfra::Command::Redhat::Base::Inventory < Specinfra::Command::Linux::Base::Inventory
|
2
2
|
class << self
|
3
|
+
def get_service
|
4
|
+
"chkconfig --list"
|
5
|
+
end
|
6
|
+
|
3
7
|
def get_package
|
4
8
|
"rpm -qa --queryformat 'name:%{NAME}\tversion:%{VERSION}\trelease:%{RELEASE}\tarch:%{ARCH}\tinstalltime:%{INSTALLTIME}\tbuildtime:%{BUILDTIME}\n'"
|
5
9
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Specinfra
|
2
|
+
class HostInventory
|
3
|
+
class Base
|
4
|
+
private
|
5
|
+
|
6
|
+
def create_parser_class(resource_type)
|
7
|
+
os_info = backend.os
|
8
|
+
family = os_info[:family]
|
9
|
+
version = os_info[:release] ? "V#{os_info[:release].to_i}" : nil
|
10
|
+
common_class = Specinfra::HostInventory::Parser
|
11
|
+
base_class = common_class.const_get('Base')
|
12
|
+
os_class = family.nil? ? base_class : common_class.const_get(family.capitalize)
|
13
|
+
|
14
|
+
if family && version
|
15
|
+
begin
|
16
|
+
version_class = os_class.const_get(version)
|
17
|
+
rescue
|
18
|
+
version_class = os_class.const_get('Base')
|
19
|
+
end
|
20
|
+
elsif family.nil?
|
21
|
+
version_class = os_class
|
22
|
+
elsif family != 'base' && version.nil?
|
23
|
+
version_class = os_class.const_get('Base')
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
parser_class = version_class.const_get(resource_type.to_camel_case)
|
28
|
+
rescue
|
29
|
+
end
|
30
|
+
|
31
|
+
parser_class.create(backend)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Specinfra::HostInventory::Parser::Redhat::Base::Service < Specinfra::HostInventory::Parser::Base
|
2
|
+
class << self
|
3
|
+
def parse(cmd_ret)
|
4
|
+
services = {}
|
5
|
+
lines = cmd_ret.split(/\n/)
|
6
|
+
lines.each do |line|
|
7
|
+
status = line.split("\t")
|
8
|
+
service = status[0].strip
|
9
|
+
enabled = status[4].include?(':on') # level 3
|
10
|
+
cmd = backend.command.get(:check_service_is_running, service)
|
11
|
+
services[service] = {
|
12
|
+
enabled: enabled,
|
13
|
+
running: backend.run_command(cmd).success?
|
14
|
+
}
|
15
|
+
end
|
16
|
+
services
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Specinfra::HostInventory::Parser::Redhat::V7::Service < Specinfra::HostInventory::Parser::Base
|
2
|
+
class << self
|
3
|
+
def parse(cmd_ret)
|
4
|
+
services = {}
|
5
|
+
lines = cmd_ret.split(/\n/)
|
6
|
+
lines.each do |line|
|
7
|
+
status = line.split(/ +/)
|
8
|
+
next unless status.count == 2
|
9
|
+
service = status[0].gsub(/\.service\z/, '')
|
10
|
+
cmd = backend.command.get(:check_service_is_running, service)
|
11
|
+
services[service] = {
|
12
|
+
enabled: status[1].include?('enabled'),
|
13
|
+
running: backend.run_command(cmd).success?
|
14
|
+
}
|
15
|
+
end
|
16
|
+
services
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
class Specinfra::HostInventory::Parser::Redhat::V7;end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class Specinfra::HostInventory::Parser;end;
|
2
|
+
|
3
|
+
require 'koma/ext/specinfra/host_inventory/parser/base'
|
4
|
+
require 'koma/ext/specinfra/host_inventory/parser/redhat'
|
5
|
+
require 'koma/ext/specinfra/host_inventory/parser/redhat/base'
|
6
|
+
require 'koma/ext/specinfra/host_inventory/parser/redhat/base/service'
|
7
|
+
require 'koma/ext/specinfra/host_inventory/parser/redhat/v7'
|
8
|
+
require 'koma/ext/specinfra/host_inventory/parser/redhat/v7/service'
|
9
|
+
|
10
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Specinfra
|
2
|
+
class HostInventory
|
3
|
+
class Service < Base
|
4
|
+
def get
|
5
|
+
cmd = backend.command.get(:get_inventory_service)
|
6
|
+
ret = backend.run_command(cmd)
|
7
|
+
if ret.success?
|
8
|
+
parse(ret.stdout)
|
9
|
+
else
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse(cmd_ret)
|
15
|
+
parser = create_parser_class('service')
|
16
|
+
parser.parse(cmd_ret)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
|
+
require 'koma/ext/specinfra/host_inventory/base'
|
2
|
+
require 'koma/ext/specinfra/host_inventory/parser'
|
3
|
+
|
1
4
|
module Specinfra
|
2
5
|
class HostInventory
|
3
|
-
EXTRA_KEYS = %w(package user group)
|
6
|
+
EXTRA_KEYS = %w(package user group service)
|
4
7
|
|
5
8
|
def self.inventory_keys
|
6
9
|
KEYS + EXTRA_KEYS
|
data/lib/koma/ext.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
1
|
require 'koma/ext/specinfra/host_inventory'
|
2
|
+
require 'koma/ext/specinfra/host_inventory/parser'
|
3
|
+
|
2
4
|
require 'koma/ext/specinfra/command/base/inventory'
|
3
5
|
require 'koma/ext/specinfra/command/redhat/base/inventory'
|
6
|
+
require 'koma/ext/specinfra/command/redhat/v7/inventory'
|
data/lib/koma/version.rb
CHANGED