Class: OsCtld::Commands::NetInterface::List

Inherits:
Base
  • Object
show all
Defined in:
lib/osctld/commands/net_interface/list.rb

Constant Summary collapse

FIELDS =
%i(
  name
  index
  type
  link
  dhcp
  gateways
  veth
)

Instance Attribute Summary

Attributes inherited from Base

#client, #client_handler, #id, #opts

Instance Method Summary collapse

Methods inherited from Base

#base_execute, #call_cmd, #call_cmd!, cmd, #error, #error!, handle, #handled, #indirect?, #initialize, #manipulate, #manipulation_holder, #ok, #progress, #request_stop, run, run!

Constructor Details

This class inherits a constructor from OsCtld::Commands::Base

Instance Method Details

#add_ct(ct) ⇒ Object (protected)



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/osctld/commands/net_interface/list.rb', line 42

def add_ct(ct)
  ct.inclusively do
    ct.netifs.map do |netif|
      next if opts[:type] && !opts[:type].include?(netif.type.to_s)
      next if opts[:link] && (netif.type != :bridge || !opts[:link].include?(netif.link))

      Hash[FIELDS.map do |f|
        next [f, nil] unless netif.respond_to?(f)
        [f, netif.send(f)]
      end].merge(
        pool: ct.pool.name,
        ctid: ct.id,
      )
    end.compact
  end
end

#ctsObject (protected)



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/osctld/commands/net_interface/list.rb', line 28

def cts
  if opts[:id]
    ct = DB::Containers.find(opts[:id], opts[:pool])
    ct || error!('container not found')
    [ct]

  elsif opts[:pool]
    DB::Container.get.select { |ct| ct.pool.name == opts[:pool] }

  else
    DB::Containers.get
  end
end

#executeObject



17
18
19
20
21
22
23
24
25
# File 'lib/osctld/commands/net_interface/list.rb', line 17

def execute
  ret = []

  cts.each do |ct|
    ret.concat(add_ct(ct))
  end

  ok(ret)
end