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/route_add.rb', line 17
def execute(ct)
netif = ct.netifs[opts[:name]]
netif || error!('network interface not found')
netif.type == :routed || error!('not a routed interface')
addr = IPAddress.parse(opts[:addr])
via = opts[:via] && IPAddress.parse(opts[:via])
manipulate(ct) do
if netif.routes.route?(addr)
error!('this address is already routed')
elsif via && !netif.has_ip?(via, prefix: false)
error!("host address #{via} not found on #{netif.name}")
end
netif.add_route(addr, via:)
ct.save_config
ct.lxc_config.configure_network
DistConfig.run(ct.get_run_conf, :network) if ct.can_dist_configure_network?
ok
end
end
|