Class: OsCtl::Cli::UgidFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/osctl/cli/ugid_finder.rb

Instance Method Summary collapse

Constructor Details

#initialize(header: true) ⇒ UgidFinder

Returns a new instance of UgidFinder.



3
4
5
# File 'lib/osctl/cli/ugid_finder.rb', line 3

def initialize(header: true)
  @header = header
end

Instance Method Details

#find_by(uids: [], gids: []) ⇒ Object (protected)



45
46
47
48
49
50
51
# File 'lib/osctl/cli/ugid_finder.rb', line 45

def find_by(uids: [], gids: [])
  c = OsCtl::Client.new
  c.open
  ret = c.cmd_data!(:ct_find_by_ugid, uids:, gids:)
  c.close
  ret
end

#header(*cols) ⇒ Object (protected)



53
54
55
# File 'lib/osctl/cli/ugid_finder.rb', line 53

def header(*cols)
  puts format('%-10s %-20s %-10s', *cols)
end

#list_by_gid(gids) ⇒ Object

Parameters:

  • gids (Array<Integer>)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/osctl/cli/ugid_finder.rb', line 26

def list_by_gid(gids)
  results = find_by(gids:) if gids.any?

  header('GID', 'CONTAINER', 'CT_GID') if @header
  return if gids.empty?

  gids.each do |gid|
    _, cts = results[:by_gid].detect { |id, _cts| id == gid }

    if cts.nil?
      print(gid, nil)
    else
      cts.each { |ct| print(gid, ct) }
    end
  end
end

#list_by_uid(uids) ⇒ Object

Parameters:

  • uids (Array<Integer>)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/osctl/cli/ugid_finder.rb', line 8

def list_by_uid(uids)
  results = find_by(uids:) if uids.any?

  header('UID', 'CONTAINER', 'CT_UID') if @header
  return if uids.empty?

  uids.each do |uid|
    _, cts = results[:by_uid].detect { |id, _cts| id == uid }

    if cts.nil?
      print(uid, nil)
    else
      cts.each { |ct| print(uid, ct) }
    end
  end
end


57
58
59
60
61
62
63
64
# File 'lib/osctl/cli/ugid_finder.rb', line 57

def print(ugid, ct)
  puts format(
    '%-10d %-20s %-10s',
    ugid,
    ct ? "#{ct[:ct][:pool]}:#{ct[:ct][:id]}" : '-',
    ct ? ct[:ns_id].to_s : '-'
  )
end