Class: OsCtl::Image::Operations::Config::ParseAttrs

Inherits:
Base
  • Object
show all
Includes:
Lib::Utils::Log, Lib::Utils::System
Defined in:
lib/osctl/image/operations/config/parse_attrs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

run

Constructor Details

#initialize(base_dir, type, name) ⇒ ParseAttrs

Returns a new instance of ParseAttrs.

Parameters:

  • base_dir (String)
  • type (:builder, :image)
  • name (String)


21
22
23
24
25
26
# File 'lib/osctl/image/operations/config/parse_attrs.rb', line 21

def initialize(base_dir, type, name)
  super()
  @base_dir = base_dir
  @type = type
  @name = name
end

Instance Attribute Details

#base_dirString (readonly)

Returns:

  • (String)


10
11
12
# File 'lib/osctl/image/operations/config/parse_attrs.rb', line 10

def base_dir
  @base_dir
end

#nameString (readonly)

Returns:

  • (String)


16
17
18
# File 'lib/osctl/image/operations/config/parse_attrs.rb', line 16

def name
  @name
end

#typeSymbol (readonly)

Returns:

  • (Symbol)


13
14
15
# File 'lib/osctl/image/operations/config/parse_attrs.rb', line 13

def type
  @type
end

Instance Method Details

#executeHash

Returns:

  • (Hash)

Raises:

  • (OsCtl::Lib::SystemCommandFailed)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/osctl/image/operations/config/parse_attrs.rb', line 30

def execute
  ret = {}

  syscmd([
    File.join(base_dir, 'bin', 'config'),
    type.to_s,
    'show',
    name
  ].join(' ')).output.split("\n").each do |line|
    eq = line.index('=')
    next if eq.nil?

    var = line[0..eq - 1]
    val = line[eq + 1..]

    next if val.empty?

    ret[var] = val
  end

  ret
end