Class: OsCtld::Commands::NetInterface::Set
- Defined in:
- lib/osctld/commands/net_interface/set.rb
Constant Summary collapse
- UNCHANGEABLE_AT_RUNTIME =
%i[hwaddr link dhcp gateways].freeze
Instance Method Summary collapse
- #bridge_opts(_netif) ⇒ Object protected
- #execute(ct) ⇒ Object
- #find ⇒ Object
- #generic_opts ⇒ Object protected
- #routed_opts(_netif) ⇒ Object protected
Methods inherited from Logged
Instance Method Details
#bridge_opts(_netif) ⇒ Object (protected)
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/osctld/commands/net_interface/set.rb', line 42 def bridge_opts(_netif) ret = { link: opts[:link] } ret[:dhcp] = opts[:dhcp] if opts.has_key?(:dhcp) if opts[:gateways] ret[:gateways] = opts[:gateways].transform_keys { |k| k.to_s.to_i } end ret end |
#execute(ct) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/osctld/commands/net_interface/set.rb', line 15 def execute(ct) manipulate(ct) do if ct.state != :stopped opts.each_key do |k| if UNCHANGEABLE_AT_RUNTIME.include?(k) error!('the container must be stopped to change network interface') end end end netif = ct.netifs[opts[:name]] netif || error!('network interface not found') change_opts = generic_opts change_opts.update(send("#{netif.type}_opts", netif)) netif.set(change_opts) ct.save_config ct.lxc_config.configure_network ok end end |
#find ⇒ Object
10 11 12 13 |
# File 'lib/osctld/commands/net_interface/set.rb', line 10 def find ct = DB::Containers.find(opts[:id], opts[:pool]) ct || error!('container not found') end |
#generic_opts ⇒ Object (protected)
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/osctld/commands/net_interface/set.rb', line 57 def generic_opts ret = {} if opts.has_key?(:hwaddr) if opts[:hwaddr].is_a?(String) && opts[:hwaddr].length == 17 ret[:hwaddr] = opts[:hwaddr] elsif opts[:hwaddr].nil? ret[:hwaddr] = nil else error!('hwaddr has to be a 17 character string or null') end end %i[tx_queues rx_queues].each do |v| next unless opts[v] if !opts[v].is_a?(Integer) || opts[v] < 1 error!("#{v} must be a number greater or equal to 1") end ret[v] = opts[v] end %i[max_tx max_rx].each do |v| next unless opts[v] if !opts[v].is_a?(Integer) || opts[v] < 0 error!("#{v} must be a number greater or equal to zero") end ret[v] = opts[v] end %i[enable].each do |v| next unless opts.has_key?(v) unless [TrueClass, FalseClass].include?(opts[v].class) error!("#{v} must be a boolean") end ret[v] = opts[v] end ret end |
#routed_opts(_netif) ⇒ Object (protected)
53 54 55 |
# File 'lib/osctld/commands/net_interface/set.rb', line 53 def routed_opts(_netif) {} end |