12
13
14
15
16
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
|
# File 'lib/osctld/commands/net_interface/create.rb', line 12
def execute(ct)
klass = NetInterface.for(opts[:type].to_sym)
return error("'#{opts[:type]}' is not supported") unless klass
ret = manipulate(ct) do
if ct.state != :stopped
next error('the container must be stopped to add network interface')
elsif ct.netifs.contains?(opts[:name])
next error("interface '#{opts[:name]}' already exists")
end
netif = klass.new(ct, ct.netifs.count)
netif.create(opts)
netif.setup
ct.netifs << netif
ct.lxc_config.configure_network
DistConfig.run(ct.get_run_conf, :add_netif, netif:)
ok
end
if ret[:status]
call_cmd(Commands::User::LxcUsernet)
ok
else
ret
end
end
|