Class: OsCtld::Commands::User::LxcUsernet
- Defined in:
- lib/osctld/commands/user/lxc_usernet.rb
Constant Summary collapse
- LXC_USERNET =
'/etc/lxc/lxc-usernet'
- @@mutex =
Mutex.new
Instance Attribute Summary
Attributes inherited from Base
#client, #client_handler, #id, #opts
Instance Method Summary collapse
- #execute ⇒ Object
- #generate ⇒ Object protected
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!
Constructor Details
This class inherits a constructor from OsCtld::Commands::Base
Instance Method Details
#execute ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/osctld/commands/user/lxc_usernet.rb', line 11 def execute @@mutex.synchronize do generate end ok end |
#generate ⇒ Object (protected)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/osctld/commands/user/lxc_usernet.rb', line 20 def generate f = File.open("#{LXC_USERNET}.new", 'w') net_cnt = 0 DB::Containers.get { |cts| cts.each { |ct| net_cnt += ct.netifs.count } } DB::Users.get.each do |u| # TODO: we need to investigate why it's not enough to set the number # of allowed veths to the number of user's container's interfaces, but # why it has to be the total number interfaces from _all_ containers. bridges = {} routed_cnt = 0 # Count interfaces per type u.containers.each do |ct| ct.netifs.each do |netif| case netif.type when :bridge bridges[netif.link] ||= 0 bridges[netif.link] += 1 when :routed routed_cnt += 1 else fail "unknown netif type '#{netif.type}'" end end end # Write results f.write("#{u.sysusername} veth none #{net_cnt}\n") # TODO: use routed_cnt bridges.each do |br, n| f.write("#{u.sysusername} veth #{br} #{net_cnt}\n") # TODO: use n end end f.close File.rename("#{LXC_USERNET}.new", LXC_USERNET) end |