Class: OsCtld::Commands::NetInterface::Set
- Inherits:
-
Logged
- Object
- Base
- Logged
- OsCtld::Commands::NetInterface::Set
show all
- Defined in:
- lib/osctld/commands/net_interface/set.rb
Instance Attribute Summary
Attributes inherited from Base
#client, #client_handler, #id, #opts
Instance Method Summary
collapse
Methods inherited from Logged
#base_execute
Methods inherited from Base
#base_execute, #call_cmd, #call_cmd!, cmd, #error, #error!, handle, #handled, #indirect?, #initialize, #manipulate, #manipulation_holder, #ok, #progress, #request_stop, run, run!
Instance Method Details
#bridge_opts(netif) ⇒ Object
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/osctld/commands/net_interface/set.rb', line 35
def bridge_opts(netif)
ret = {link: opts[:link]}
ret[:dhcp] = opts[:dhcp] if opts.has_key?(:dhcp)
if opts[:gateways]
ret[:gateways] = Hash[ opts[:gateways].map { |k,v| [k.to_s.to_i, v] } ]
end
ret
end
|
#execute(ct) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/osctld/commands/net_interface/set.rb', line 13
def execute(ct)
manipulate(ct) do
if ct.state != :stopped
error!('the container must be stopped to change network interface')
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
8
9
10
11
|
# File 'lib/osctld/commands/net_interface/set.rb', line 8
def find
ct = DB::Containers.find(opts[:id], opts[:pool])
ct || error!('container not found')
end
|
#generic_opts ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/osctld/commands/net_interface/set.rb', line 50
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
ret
end
|
#routed_opts(netif) ⇒ Object
46
47
48
|
# File 'lib/osctld/commands/net_interface/set.rb', line 46
def routed_opts(netif)
{}
end
|