koma 0.14.0 → 0.15.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce41129abc2085330f040e7d51db8dd1f5ef2653
4
- data.tar.gz: 726a1778def941727237e40eb11f385df5e90251
3
+ metadata.gz: f46ff7aca0cb294d271c2303a06e036ca557b4d1
4
+ data.tar.gz: 889bcf68fefb14832aa53709621dcd844a1c4e60
5
5
  SHA512:
6
- metadata.gz: 6941ee3cc399bcc5806557da2d84ba2b35a6dd3c34c4f80e4de234485dbfeaa206919f18bf6851274d4f639a540da2c877507dcaf4ccc187678e90a59f7473ab
7
- data.tar.gz: 823cbea35c3d79c90fd0535ae83f0ff4e6fb009656e5b64e3a10e6f2c73ba20effe52b037265335422a7b9621a075e77b67a9f14c45abcd5234a2527f359a076
6
+ metadata.gz: 6fcbb276e6518cbe64883858c3f49485a3607f0111b25513828af277ea2dd248d1ba55c20c250adde0b4c6734c3b25ff864db7939e309b92c8d7832bdf0c38f9
7
+ data.tar.gz: f91c31e0247d7667dc06b29bec966de40c3b7ea168ae22363f1f09252310dda4983c37589917c48bfa1d3665d82b394fe7d28a23c49c1d14d9fdc5c188212a91
data/lib/koma/cli.rb CHANGED
@@ -5,7 +5,7 @@ require 'yaml'
5
5
  module Koma
6
6
  class CLI < Thor
7
7
  class_option :version, type: :boolean, aliases: :V
8
-
8
+
9
9
  desc 'ssh <host1,host2,..>', 'stdout remote host inventory'
10
10
  option :key, type: :string, banner: '<key1,key2,..>', desc: 'inventory keys', aliases: :k
11
11
  option :yaml, type: :boolean, desc: 'stdout YAML', aliases: :Y
data/lib/koma/ext.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'koma/ext/specinfra/host_inventory/base'
2
+ require 'koma/ext/specinfra/host_inventory/parser_factory'
2
3
  require 'koma/ext/specinfra/host_inventory/parser'
3
4
 
4
5
  require 'koma/ext/specinfra/command/redhat/base/inventory'
@@ -1,34 +1,8 @@
1
1
  module Specinfra
2
2
  class HostInventory
3
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)
4
+ def parser
5
+ Specinfra::HostInventory::ParserFactory.instance
32
6
  end
33
7
  end
34
8
  end
@@ -4,7 +4,7 @@ module Specinfra
4
4
  def get
5
5
  cmd = backend.command.get(:get_inventory_package)
6
6
  ret = backend.run_command(cmd)
7
- if ret.exit_status == 0
7
+ if ret.success?
8
8
  parse(ret.stdout)
9
9
  else
10
10
  nil
@@ -12,14 +12,7 @@ module Specinfra
12
12
  end
13
13
 
14
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
15
+ parser.get('package').parse(cmd_ret)
23
16
  end
24
17
  end
25
18
  end
@@ -1,10 +1,17 @@
1
1
  class Specinfra::HostInventory::Parser;end;
2
2
 
3
3
  require 'koma/ext/specinfra/host_inventory/parser/base'
4
+ require 'koma/ext/specinfra/host_inventory/parser/base/package'
5
+ require 'koma/ext/specinfra/host_inventory/parser/base/service'
6
+
7
+ require 'koma/ext/specinfra/host_inventory/parser/linux'
8
+ require 'koma/ext/specinfra/host_inventory/parser/linux/base'
9
+ require 'koma/ext/specinfra/host_inventory/parser/linux/base/package'
10
+ require 'koma/ext/specinfra/host_inventory/parser/linux/base/service'
11
+
4
12
  require 'koma/ext/specinfra/host_inventory/parser/redhat'
5
13
  require 'koma/ext/specinfra/host_inventory/parser/redhat/base'
14
+ require 'koma/ext/specinfra/host_inventory/parser/redhat/base/package'
6
15
  require 'koma/ext/specinfra/host_inventory/parser/redhat/base/service'
7
16
  require 'koma/ext/specinfra/host_inventory/parser/redhat/v7'
8
17
  require 'koma/ext/specinfra/host_inventory/parser/redhat/v7/service'
9
-
10
-
@@ -0,0 +1,2 @@
1
+ class Specinfra::HostInventory::Parser::Base::Package < Specinfra::HostInventory::Parser::Base
2
+ end
@@ -0,0 +1 @@
1
+ class Specinfra::HostInventory::Parser::Base::Service < Specinfra::HostInventory::Parser::Base;end
@@ -0,0 +1 @@
1
+ class Specinfra::HostInventory::Parser::Linux; end
@@ -0,0 +1,2 @@
1
+ class Specinfra::HostInventory::Parser::Linux::Base < Specinfra::HostInventory::Parser::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ class Specinfra::HostInventory::Parser::Linux::Package < Specinfra::HostInventory::Parser::Base::Package
2
+ end
@@ -0,0 +1,2 @@
1
+ class Specinfra::HostInventory::Parser::Linux::Service < Specinfra::HostInventory::Parser::Base::Service
2
+ end
@@ -0,0 +1,14 @@
1
+ class Specinfra::HostInventory::Parser::Redhat::Base::Package < Specinfra::HostInventory::Parser::Linux::Package
2
+ class << self
3
+ def parse(cmd_ret)
4
+ packages = {}
5
+ lines = cmd_ret.split(/\n/)
6
+ lines.each do |line|
7
+ h = Hash[line.split("\t").map { |f| f.split(':', 2) }]
8
+ idx = h['name']
9
+ packages[idx] = h
10
+ end
11
+ packages
12
+ end
13
+ end
14
+ end
@@ -1,4 +1,4 @@
1
- class Specinfra::HostInventory::Parser::Redhat::Base::Service < Specinfra::HostInventory::Parser::Base
1
+ class Specinfra::HostInventory::Parser::Redhat::Base::Service < Specinfra::HostInventory::Parser::Linux::Service
2
2
  class << self
3
3
  def parse(cmd_ret)
4
4
  services = {}
@@ -1,4 +1,4 @@
1
- class Specinfra::HostInventory::Parser::Redhat::V7::Service < Specinfra::HostInventory::Parser::Base
1
+ class Specinfra::HostInventory::Parser::Redhat::V7::Service < Specinfra::HostInventory::Parser::Redhat::Base::Service
2
2
  class << self
3
3
  def parse(cmd_ret)
4
4
  services = {}
@@ -0,0 +1,53 @@
1
+ module Specinfra
2
+ class HostInventory
3
+ class ParserFactory
4
+ def self.instance
5
+ self.new(os)
6
+ end
7
+
8
+ def initialize(os_info)
9
+ @os_info = os_info
10
+ end
11
+
12
+ def get(resource_type)
13
+ create_parser_class(resource_type)
14
+ end
15
+
16
+ private
17
+
18
+ def create_parser_class(resource_type)
19
+ family = @os_info[:family]
20
+ version = @os_info[:release] ? "V#{@os_info[:release].to_i}" : nil
21
+ common_class = Specinfra::HostInventory::Parser
22
+ base_class = common_class.const_get('Base')
23
+ begin
24
+ os_class = family.nil? ? base_class : common_class.const_get(family.capitalize)
25
+ rescue
26
+ parser_class = base_class.const_get(resource_type.to_camel_case)
27
+ return parser_class.create(Specinfra.backend)
28
+ end
29
+
30
+ if family && version
31
+ begin
32
+ version_class = os_class.const_get(version)
33
+ rescue
34
+ version_class = os_class.const_get('Base')
35
+ end
36
+ elsif family.nil?
37
+ version_class = os_class
38
+ elsif family != 'base' && version.nil?
39
+ version_class = os_class.const_get('Base')
40
+ end
41
+
42
+ begin
43
+ parser_class = version_class.const_get(resource_type.to_camel_case)
44
+ rescue
45
+ version_class = os_class.const_get('Base')
46
+ parser_class = version_class.const_get(resource_type.to_camel_case)
47
+ end
48
+
49
+ parser_class.create(Specinfra.backend)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -12,8 +12,7 @@ module Specinfra
12
12
  end
13
13
 
14
14
  def parse(cmd_ret)
15
- parser = create_parser_class('service')
16
- parser.parse(cmd_ret)
15
+ parser.get('service').parse(cmd_ret)
17
16
  end
18
17
  end
19
18
  end
data/lib/koma/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Koma
2
- VERSION = '0.14.0'
2
+ VERSION = '0.15.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-06 00:00:00.000000000 Z
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -198,11 +198,19 @@ files:
198
198
  - lib/koma/ext/specinfra/host_inventory/package.rb
199
199
  - lib/koma/ext/specinfra/host_inventory/parser.rb
200
200
  - lib/koma/ext/specinfra/host_inventory/parser/base.rb
201
+ - lib/koma/ext/specinfra/host_inventory/parser/base/package.rb
202
+ - lib/koma/ext/specinfra/host_inventory/parser/base/service.rb
203
+ - lib/koma/ext/specinfra/host_inventory/parser/linux.rb
204
+ - lib/koma/ext/specinfra/host_inventory/parser/linux/base.rb
205
+ - lib/koma/ext/specinfra/host_inventory/parser/linux/base/package.rb
206
+ - lib/koma/ext/specinfra/host_inventory/parser/linux/base/service.rb
201
207
  - lib/koma/ext/specinfra/host_inventory/parser/redhat.rb
202
208
  - lib/koma/ext/specinfra/host_inventory/parser/redhat/base.rb
209
+ - lib/koma/ext/specinfra/host_inventory/parser/redhat/base/package.rb
203
210
  - lib/koma/ext/specinfra/host_inventory/parser/redhat/base/service.rb
204
211
  - lib/koma/ext/specinfra/host_inventory/parser/redhat/v7.rb
205
212
  - lib/koma/ext/specinfra/host_inventory/parser/redhat/v7/service.rb
213
+ - lib/koma/ext/specinfra/host_inventory/parser_factory.rb
206
214
  - lib/koma/ext/specinfra/host_inventory/service.rb
207
215
  - lib/koma/host_inventory.rb
208
216
  - lib/koma/version.rb