Class: OsCtl::Image::Operations::Builder::GetRootUgid

Inherits:
OsCtl::Image::Operations::Base show all
Defined in:
lib/osctl/image/operations/builder/get_root_ugid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from OsCtl::Image::Operations::Base

run

Constructor Details

#initialize(builder) ⇒ GetRootUgid

Returns a new instance of GetRootUgid.

Parameters:



9
10
11
12
# File 'lib/osctl/image/operations/builder/get_root_ugid.rb', line 9

def initialize(builder)
  super()
  @builder = builder
end

Instance Attribute Details

#builderBuilder (readonly)

Returns:



6
7
8
# File 'lib/osctl/image/operations/builder/get_root_ugid.rb', line 6

def builder
  @builder
end

Instance Method Details

#executeArray(Integer, Integer)

Returns ugid, gid.

Returns:

  • (Array(Integer, Integer))

    ugid, gid



15
16
17
18
19
20
21
# File 'lib/osctl/image/operations/builder/get_root_ugid.rb', line 15

def execute
  OsCtldClient.new.batch do |client|
    ct = client.find_container(builder.ctid)
    idmap = client.user_idmap(ct[:user])
    [find_root(idmap, 'uid'), find_root(idmap, 'gid')]
  end
end

#find_root(idmap, type) ⇒ Object (protected)

Raises:



25
26
27
28
29
30
31
32
33
# File 'lib/osctl/image/operations/builder/get_root_ugid.rb', line 25

def find_root(idmap, type)
  idmap.each do |entry|
    if entry[:type] == type && entry[:ns_id] == 0
      return entry[:host_id]
    end
  end

  raise OperationError, "unable to find root #{type} in id map"
end