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
  hwaddr
  tx_queues
  rx_queues
  max_tx
  max_rx
].freeze

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!, #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)



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/osctld/commands/net_interface/list.rb', line 48

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))

      FIELDS.to_h 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)



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/osctld/commands/net_interface/list.rb', line 34

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



22
23
24
25
26
27
28
29
30
# File 'lib/osctld/commands/net_interface/list.rb', line 22

def execute
  ret = []

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

  ok(ret)
end