Class: OsCtl::Lib::Zfs::ZpoolStatus::ConfigParser

Inherits:
Object
  • Object
show all
Defined in:
lib/libosctl/zfs/zpool_status.rb

Instance Method Summary collapse

Constructor Details

#initialize(pool) ⇒ ConfigParser

Returns a new instance of ConfigParser.

Parameters:



139
140
141
142
# File 'lib/libosctl/zfs/zpool_status.rb', line 139

def initialize(pool)
  @pool = pool
  @role = :storage
end

Instance Method Details

#create_vdev(vdev, state, read, write, checksum) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/libosctl/zfs/zpool_status.rb', line 185

def create_vdev(vdev, state, read, write, checksum)
  VirtualDevice.new(
    role: @role,
    name: vdev,
    type: vdev.start_with?('/') ? 'disk' : vdev.split('-').first,
    state: state.downcase.to_sym,
    read: read.to_i,
    write: write.to_i,
    checksum: checksum.to_i,
    virtual_devices: []
  )
end

#parse_line(line, stripped) ⇒ Object

Parse config line from zpool status

Lines start with a tab and then we decide based on indent level. Pool name has no indentation, vdev for redundancy is indented by two spaces and leaf vdevs by four spaces. If is replace going on or if there’s a spare, leaf vdevs are pushed to a lower level.



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/libosctl/zfs/zpool_status.rb', line 150

def parse_line(line, stripped)
  return unless line.start_with?("\t")

  indent_level = line[1..][/\A */].size
  vdev, state, read, write, checksum = stripped.split

  if indent_level == 0
    case vdev
    when 'logs'
      @role = :log
    when 'cache'
      @role = :cache
    end
    return
  end

  if indent_level == 2
    @vdev_1st = create_vdev(vdev, state, read, write, checksum)
    @pool.virtual_devices << @vdev_1st
    return
  end

  if indent_level == 4
    @vdev_2nd = create_vdev(vdev, state, read, write, checksum)
    @vdev_1st.virtual_devices << @vdev_2nd
    return
  end

  return unless indent_level == 6

  @vdev_3rd = create_vdev(vdev, state, read, write, checksum)
  @vdev_2nd.virtual_devices << @vdev_3rd
  nil
end