Class: OsCtld::Migration::Commands::ReceiveSkel
- Inherits:
-
Base
- Object
- Commands::Base
- Base
- OsCtld::Migration::Commands::ReceiveSkel
- Defined in:
- lib/osctld/migration/commands/receive_skel.rb
Instance Attribute Summary
Attributes inherited from Commands::Base
#client, #client_handler, #id, #opts
Instance Method Summary collapse
Methods inherited from Base
Methods inherited from Commands::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
8 9 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 38 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 69 70 71 |
# File 'lib/osctld/migration/commands/receive_skel.rb', line 8 def execute client.send({status: true, response: 'continue'}.to_json + "\n", 0) io = client.recv_io f = Tempfile.open('ct-skel') f.write(io.readpartial(16*1024)) until io.eof? f.seek(0) pool = DB::Pools.get_or_default(opts[:pool]) error!('pool not found') unless pool error!('the pool is disabled') unless pool.active? importer = Container::Importer.new(pool, f) data = importer. if data['type'] != 'skel' error!("expected archive type to be 'skel', got '#{data['type']}'") end ct = importer.load_ct(ct_opts: {staged: true, devices: false}) ct.manipulate(self) do builder = Container::Builder.new(ct, cmd: self) unless builder.valid? error!("invalid id, allowed format: #{builder.id_chars}") end begin ct.devices.check_all_available! rescue DeviceNotAvailable, DeviceModeInsufficient => e error!(e.) end unless builder.register error!("container #{pool.name}:#{ct.id} already exists") end ct.devices.init importer.create_datasets(builder) builder.setup_ct_dir builder.setup_lxc_home ct.open_migration_log(:destination, save: true) builder.setup_lxc_configs builder.setup_log_file builder.setup_user_hook_script_dir importer.install_user_hook_scripts(ct) builder.monitor if ct.netifs.any? progress('Reconfiguring LXC usernet') call_cmd(Commands::User::LxcUsernet) end end ok ensure f.close f.unlink end |