Class: OsCtld::Commands::NetInterface::Show

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

Constant Summary collapse

FIELDS =
%i[
  name
  index
  type
  link
  dhcp
  veth
].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

#executeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/osctld/commands/net_interface/show.rb', line 16

def execute
  ct = DB::Containers.find(opts[:id], opts[:pool])
  return error('container not found') unless ct

  ct.inclusively do
    netif = ct.netifs[opts[:name]]
    next error('interface not found') unless netif

    ok(
      FIELDS.to_h do |f|
        next [f, nil] unless netif.respond_to?(f)

        [f, netif.send(f)]
      end
    )
  end
end