Class: OsCtld::Commands::Pool::Install

Inherits:
Base
  • Object
show all
Includes:
OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System
Defined in:
lib/osctld/commands/pool/install.rb

Instance Attribute Summary

Attributes inherited from Base

#client, #client_handler, #id, #opts

Instance Method Summary collapse

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

#executeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/osctld/commands/pool/install.rb', line 11

def execute
  if opts[:dataset] && !opts[:dataset].start_with?("#{opts[:name]}/")
    return error("dataset '#{opts[:dataset]}' is not from zpool '#{opts[:name]}'")
  end

  pool = Pool.new(opts[:name], opts[:dataset])
  return error('pool already exists') if DB::Pools.contains?(pool.name)

  manipulate(pool) do
    props = ["#{Pool::PROPERTY_ACTIVE}=yes"]
    props << "#{Pool::PROPERTY_DATASET}=\"#{opts[:dataset]}\"" if opts[:dataset]

    zfs(:set, props.join(' '), pool.name)
    OsUp.init(pool.name, force: true)
    pool.setup

    DB::Pools.add(pool)
  end

  ok
end