Class: OsCtld::Commands::Group::Create
- Includes:
- OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System
- Defined in:
- lib/osctld/commands/group/create.rb
Instance Attribute Summary
Attributes inherited from Base
#client, #client_handler, #id, #opts
Instance Method Summary collapse
Methods inherited from Logged
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(grp) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/osctld/commands/group/create.rb', line 39 def execute(grp) manipulate(grp) do # Create parent groups if opts[:parents] t = '' opts[:name].split('/')[0..-2].each do |n| t = File.join('/', t, n) g = DB::Groups.by_path(grp.pool, t) next if g pgrp = Group.new(grp.pool, t, load: false) pgrp.configure DB::Groups.add(pgrp) end end # Create last group grp.configure grp.cgparams.set(grp.cgparams.import(opts[:cgparams] || [])) DB::Groups.add(grp) end ok rescue CGroupSubsystemNotFound, CGroupParameterNotFound => e error(e.) end |
#find ⇒ Object
10 11 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 |
# File 'lib/osctld/commands/group/create.rb', line 10 def find pool = DB::Pools.get_or_default(opts[:pool]) error!('pool not found') unless pool error!('group name has to start with /') unless opts[:name].start_with?('/') groups = opts[:name].split('/').drop(1) rx = /^[a-z0-9_-]{1,100}$/i groups.each do |grp| next if rx =~ grp error!("invalid name, allowed format: #{rx.source}") end grp = Group.new(pool, opts[:name], load: false) error!('group already exists') if DB::Groups.contains?(grp.name, pool) unless opts[:parents] begin grp.parents rescue GroupNotFound => e error!(e) end end grp end |