specinfra 2.23.0 → 2.24.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: cfd61185b0ebcd78346dd1c4f967f068ecbc38a3
4
- data.tar.gz: 29739a15583eb339d5f32d8d21b9b6192bf93758
3
+ metadata.gz: 36304d05e8dc32b0aca739dc27b5794b4ad98d33
4
+ data.tar.gz: 9df5c5f46c9eb95cb2127ca6afd2fac5df8acda8
5
5
  SHA512:
6
- metadata.gz: 10782176063c73a571e5d60d6f58c93ba3a0a5cb2eb7822314237ff09c43297321c8aa61d8dd321a977c19fecf875b471f3230c4c2f0fd658070dd1681c702c1
7
- data.tar.gz: defd5e7c88132840fe9e46403ee22560ee09c4a0d71d40568451f17f00b2ddb8b79e6aeac733c8d50e06f8907669b3af0a41b20492841a01ed55ac6152967c8b
6
+ metadata.gz: c3e754f052c2814056e1f0eb1a461454376df60abbf48a5117f88ae6a0070a7385adb352325d85a78de1e8c710e5abe6015ff248790dbfdb938a2e7060b99999
7
+ data.tar.gz: 508181175062039ba2c075706fb22b8de1530fb17019f52d2562f6f24a412a523fee756ff43e155b5034f181abe11f143bd967d678cb1e4cc21c0197b3a455a9
@@ -34,6 +34,10 @@ module Specinfra::Backend
34
34
  CommandFactory.new(os_info)
35
35
  end
36
36
 
37
+ def host_inventory
38
+ @inventory ||= HostInventory.new(self)
39
+ end
40
+
37
41
  def set_example(e)
38
42
  @example = e
39
43
  end
@@ -90,7 +90,7 @@ module Specinfra::Backend
90
90
  tmp = File.join('/tmp', File.basename(to))
91
91
  scp = get_config(:scp)
92
92
  scp.upload!(from, tmp, opt)
93
- run_command(Specinfra.command.get(:move_file, tmp, to))
93
+ run_command(command.get(:move_file, tmp, to))
94
94
  end
95
95
 
96
96
  def ssh_exec!(command)
@@ -1,7 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module Specinfra
3
3
  class Ec2Metadata
4
- def initialize
4
+ def initialize(host_inventory)
5
+ @host_inventory = host_inventory
6
+
5
7
  @base_uri = 'http://169.254.169.254/latest/meta-data/'
6
8
  @metadata = {}
7
9
  end
@@ -16,7 +18,7 @@ module Specinfra
16
18
  begin
17
19
  require "specinfra/ec2_metadata/#{key}"
18
20
  inventory_class = Specinfra::Ec2Metadata.const_get(key.to_s.to_camel_case)
19
- @metadata[key] = inventory_class.get
21
+ @metadata[key] = inventory_class.new(@host_inventory).get
20
22
  rescue LoadError
21
23
  @metadata[key] = nil
22
24
  end
@@ -59,7 +61,7 @@ module Specinfra
59
61
  def get_metadata(path='')
60
62
  metadata = {}
61
63
 
62
- keys = Specinfra::Runner.run_command("curl -s #{@base_uri}#{path}").stdout.split("\n")
64
+ keys = @host_inventory.backend.run_command("curl -s #{@base_uri}#{path}").stdout.split("\n")
63
65
 
64
66
  keys.each do |key|
65
67
  if key =~ %r{/$}
@@ -79,7 +81,7 @@ module Specinfra
79
81
  end
80
82
 
81
83
  def get_endpoint(path)
82
- ret = Specinfra::Runner.run_command("curl -s #{@base_uri}#{path}")
84
+ ret = @host_inventory.backend.run_command("curl -s #{@base_uri}#{path}")
83
85
  if ret.success?
84
86
  ret.stdout
85
87
  else
@@ -1,11 +1,29 @@
1
1
  module Specinfra
2
2
  class HostInventory
3
- include Singleton
3
+ KEYS = %w{
4
+ memory
5
+ ec2
6
+ hostname
7
+ domain
8
+ fqdn
9
+ platform
10
+ platform_version
11
+ filesystem
12
+ cpu
13
+ }
14
+
4
15
  include Enumerable
5
16
 
6
- def initialize
17
+ attr_reader :backend
18
+
19
+ def self.instance
7
20
  property[:host_inventory] ||= {}
8
- @inventory = property[:host_inventory]
21
+ self.new(Specinfra.backend, property[:host_inventory])
22
+ end
23
+
24
+ def initialize(backend, inventory = {})
25
+ @backend = backend
26
+ @inventory = inventory
9
27
  end
10
28
 
11
29
  def [](key)
@@ -13,7 +31,7 @@ module Specinfra
13
31
  if @inventory[key.to_sym].empty?
14
32
  begin
15
33
  inventory_class = Specinfra::HostInventory.const_get(key.to_s.to_camel_case)
16
- @inventory[key.to_sym] = inventory_class.get
34
+ @inventory[key.to_sym] = inventory_class.new(self).get
17
35
  rescue
18
36
  @inventory[key.to_sym] = nil
19
37
  end
@@ -22,39 +40,27 @@ module Specinfra
22
40
  end
23
41
 
24
42
  def each
25
- keys.each do |k|
43
+ KEYS.each do |k|
26
44
  yield k, self[k]
27
45
  end
28
46
  end
29
47
 
30
48
  def each_key
31
- keys.each do |k|
49
+ KEYS.each do |k|
32
50
  yield k
33
51
  end
34
52
  end
35
53
 
36
54
  def each_value
37
- keys.each do |k|
55
+ KEYS.each do |k|
38
56
  yield self[k]
39
57
  end
40
58
  end
41
59
 
42
- def keys
43
- %w{
44
- memory
45
- ec2
46
- hostname
47
- domain
48
- fqdn
49
- platform
50
- platform_version
51
- filesystem
52
- cpu
53
- }
54
- end
55
60
  end
56
61
  end
57
62
 
58
- Specinfra::HostInventory.instance.keys.each do |k|
63
+ require "specinfra/host_inventory/base"
64
+ Specinfra::HostInventory::KEYS.each do |k|
59
65
  require "specinfra/host_inventory/#{k}"
60
66
  end
@@ -0,0 +1,14 @@
1
+ module Specinfra
2
+ class HostInventory
3
+ class Base
4
+ def initialize(host_inventory)
5
+ @host_inventory = host_inventory
6
+ end
7
+
8
+ def backend
9
+ @host_inventory.backend
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -1,12 +1,12 @@
1
1
  module Specinfra
2
2
  class HostInventory
3
- class Cpu
4
- def self.get
5
- cmd = Specinfra.command.get(:get_inventory_cpu)
6
- ret = Specinfra.backend.run_command(cmd).stdout
3
+ class Cpu < Base
4
+ def get
5
+ cmd = backend.command.get(:get_inventory_cpu)
6
+ ret = backend.run_command(cmd).stdout
7
7
  parse(ret)
8
8
  end
9
- def self.parse(cmd_ret)
9
+ def parse(cmd_ret)
10
10
  cpuinfo = {}
11
11
  cpus = cmd_ret.split(/[^^]processor/)
12
12
  cpuinfo['total'] = cpus.length.to_s
@@ -1,9 +1,9 @@
1
1
  module Specinfra
2
2
  class HostInventory
3
- class Domain
4
- def self.get
5
- cmd = Specinfra.command.get(:get_inventory_domain)
6
- Specinfra.backend.run_command(cmd).stdout.strip
3
+ class Domain < Base
4
+ def get
5
+ cmd = backend.command.get(:get_inventory_domain)
6
+ backend.run_command(cmd).stdout.strip
7
7
  end
8
8
  end
9
9
  end
@@ -2,9 +2,9 @@ require 'specinfra/ec2_metadata'
2
2
 
3
3
  module Specinfra
4
4
  class HostInventory
5
- class Ec2
6
- def self.get
7
- Specinfra::Ec2Metadata.new.get
5
+ class Ec2 < Base
6
+ def get
7
+ Specinfra::Ec2Metadata.new(@host_inventory).get
8
8
  end
9
9
  end
10
10
  end
@@ -1,10 +1,10 @@
1
1
  module Specinfra
2
2
  class HostInventory
3
- class Filesystem
4
- def self.get
5
- cmd = Specinfra.command.get(:get_inventory_filesystem)
3
+ class Filesystem < Base
4
+ def get
5
+ cmd = backend.command.get(:get_inventory_filesystem)
6
6
  filesystem = {}
7
- Specinfra.backend.run_command(cmd).stdout.lines do |line|
7
+ backend.run_command(cmd).stdout.lines do |line|
8
8
  next if line =~ /^Filesystem\s+/
9
9
  if line =~ /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
10
10
  device = $1
@@ -1,9 +1,9 @@
1
1
  module Specinfra
2
2
  class HostInventory
3
- class Fqdn
4
- def self.get
5
- cmd = Specinfra.command.get(:get_inventory_fqdn)
6
- Specinfra.backend.run_command(cmd).stdout.strip
3
+ class Fqdn < Base
4
+ def get
5
+ cmd = backend.command.get(:get_inventory_fqdn)
6
+ backend.run_command(cmd).stdout.strip
7
7
  end
8
8
  end
9
9
  end
@@ -1,9 +1,9 @@
1
1
  module Specinfra
2
2
  class HostInventory
3
- class Hostname
4
- def self.get
5
- cmd = Specinfra.command.get(:get_inventory_hostname)
6
- Specinfra.backend.run_command(cmd).stdout.strip
3
+ class Hostname < Base
4
+ def get
5
+ cmd = backend.command.get(:get_inventory_hostname)
6
+ backend.run_command(cmd).stdout.strip
7
7
  end
8
8
  end
9
9
  end
@@ -1,9 +1,9 @@
1
1
  module Specinfra
2
2
  class HostInventory
3
- class Memory
4
- def self.get
5
- cmd = Specinfra.command.get(:get_inventory_memory)
6
- ret = Specinfra.backend.run_command(cmd).stdout
3
+ class Memory < Base
4
+ def get
5
+ cmd = backend.command.get(:get_inventory_memory)
6
+ ret = backend.run_command(cmd).stdout
7
7
  memory = { 'swap' => {} }
8
8
  ret.each_line do |line|
9
9
  case line
@@ -1,8 +1,8 @@
1
1
  module Specinfra
2
2
  class HostInventory
3
- class Platform
4
- def self.get
5
- os[:family]
3
+ class Platform < Base
4
+ def get
5
+ backend.os_info[:family]
6
6
  end
7
7
  end
8
8
  end
@@ -1,8 +1,8 @@
1
1
  module Specinfra
2
2
  class HostInventory
3
- class PlatformVersion
4
- def self.get
5
- os[:release]
3
+ class PlatformVersion < Base
4
+ def get
5
+ backend.os_info[:release]
6
6
  end
7
7
  end
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module Specinfra
2
- VERSION = "2.23.0"
2
+ VERSION = "2.24.0"
3
3
  end
@@ -55,8 +55,9 @@ power management:
55
55
  EOH
56
56
 
57
57
  describe Specinfra::HostInventory::Cpu do
58
+ let(:host_inventory) { nil }
58
59
  describe 'Example of Ubuntu 14.04.1 LTS Kernel version 3.13.11' do
59
- ret = Specinfra::HostInventory::Cpu.parse(str)
60
+ ret = Specinfra::HostInventory::Cpu.new(host_inventory).parse(str)
60
61
  example do
61
62
  expect(ret["0"]).to include(
62
63
  "vendor_id" => "GenuineIntel",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specinfra
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.23.0
4
+ version: 2.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gosuke Miyashita
@@ -356,6 +356,7 @@ files:
356
356
  - lib/specinfra/helper/properties.rb
357
357
  - lib/specinfra/helper/set.rb
358
358
  - lib/specinfra/host_inventory.rb
359
+ - lib/specinfra/host_inventory/base.rb
359
360
  - lib/specinfra/host_inventory/cpu.rb
360
361
  - lib/specinfra/host_inventory/domain.rb
361
362
  - lib/specinfra/host_inventory/ec2.rb