Class: OsCtld::Commands::Pool::Import

Inherits:
Base
  • Object
show all
Includes:
OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System
Defined in:
lib/osctld/commands/pool/import.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
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
# File 'lib/osctld/commands/pool/import.rb', line 11

def execute
  DB::Pools.sync do
    if opts[:all]
      props = [
        'name',
        'mounted',
        Pool::PROPERTY_ACTIVE,
        Pool::PROPERTY_DATASET,
      ]

      zfs(
        :list,
        "-H -d0 -o #{props.join(',')}",
        ''
      )[:output].split("\n").each do |line|
        name, mounted, active, dataset = line.split
        next if active != 'yes' || mounted != 'yes' || DB::Pools.contains?(name)

        begin
          import(name, dataset)

        rescue PoolUpgradeError => e
          log(:warn, "Pool upgrade failed: #{e.message}")
          next
        end
      end

      ok

    else
      next error('pool already imported') if DB::Pools.contains?(opts[:name])

      mounted, dataset = zfs(
        :get,
        "-H -o value mounted,#{Pool::PROPERTY_DATASET}",
        opts[:name]
      )[:output].strip.split

      next error('the pool is not mounted') if mounted != 'yes'

      begin
        import(opts[:name], dataset)
        ok

      rescue PoolUpgradeError => e
        next error(e.message)
      end
    end
  end
end

#import(name, dataset) ⇒ Object (protected)



63
64
65
66
67
68
69
70
71
# File 'lib/osctld/commands/pool/import.rb', line 63

def import(name, dataset)
  upgrade(name)
  pool = Pool.new(name, dataset == '-' ? nil : dataset)
  manipulate(pool) do
    pool.setup
    DB::Pools.add(pool)
    pool.autostart if opts[:autostart]
  end
end

#upgrade(name) ⇒ Object (protected)



73
74
75
76
77
78
79
80
81
# File 'lib/osctld/commands/pool/import.rb', line 73

def upgrade(name)
  OsUp.upgrade(name)

rescue OsUp::PoolUpToDate
  # pass

rescue => e
  raise PoolUpgradeError.new(name, e)
end