Class: Specinfra::HostInventory::Group

Inherits:
Base
  • Object
show all
Defined in:
lib/specinfra/host_inventory/group.rb

Instance Method Summary collapse

Methods inherited from Base

#backend, #initialize

Constructor Details

This class inherits a constructor from Specinfra::HostInventory::Base

Instance Method Details

#getObject



4
5
6
7
8
9
10
11
12
# File 'lib/specinfra/host_inventory/group.rb', line 4

def get
  cmd = backend.command.get(:get_inventory_group)
  ret = backend.run_command(cmd)
  if ret.exit_status == 0
    parse(ret.stdout)
  else
    nil
  end
end

#parse(cmd_ret) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/specinfra/host_inventory/group.rb', line 14

def parse(cmd_ret)
  groups = {}
  lines = cmd_ret.split(/\n/)
  lines.each do |line|
    group = line.split(':')
    members = if group[3]
                group[3].split(',')
              else
                []
              end
    groups[group[0]] = {
      'name' => group[0],
      'gid' => group[2],
      'members' => members
    }
  end
  groups
end