Class: OsCtld::Commands::NetInterface::IpAdd
- Includes:
- OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System, Utils::SwitchUser
- Defined in:
- lib/osctld/commands/net_interface/ip_add.rb
Instance Attribute Summary
Attributes inherited from Base
#client, #client_handler, #id, #opts
Instance Method Summary collapse
Methods included from Utils::SwitchUser
Methods inherited from Logged
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
#execute(ct) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/osctld/commands/net_interface/ip_add.rb', line 17 def execute(ct) netif = ct.netifs[opts[:name]] return error('network interface not found') unless netif addr = IPAddress.parse(opts[:addr]) ip_v = addr.ipv4? ? 4 : 6 manipulate(ct) do # TODO: check that no other container has this IP next error('this address is already assigned') if netif.has_ip?(addr) case netif.type when :routed netif.add_ip(addr, route(netif, addr)) else netif.add_ip(addr) end ct.save_config ct.lxc_config.configure_network DistConfig.run(ct.get_run_conf, :network) if ct.can_dist_configure_network? ok end end |
#find ⇒ Object
12 13 14 15 |
# File 'lib/osctld/commands/net_interface/ip_add.rb', line 12 def find ct = DB::Containers.find(opts[:id], opts[:pool]) ct || error!('container not found') end |
#route(_netif, addr) ⇒ Object (protected)
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/osctld/commands/net_interface/ip_add.rb', line 46 def route(_netif, addr) if opts[:route] === true addr.network elsif opts[:route] ret = IPAddress.parse(opts[:route]) if ret.class != addr.class error!('IP version mismatch') elsif !ret.include?(addr) error!("#{ret.to_string} does not include #{addr.to_string}") end ret end end |