class Dopv::PersistentDisk::Entry

Constants

DISK_DESC_KEYS

Attributes

id[RW]
name[RW]
node[RW]
pool[RW]
size[RW]

Public Class Methods

new(attrs) click to toggle source
# File lib/dopv/persistent_disk.rb, line 12
def initialize(attrs)
  if attrs.is_a?(Hash) && attrs.keys.sort == DISK_DESC_KEYS
    @node = attrs[:node]
    @name = attrs[:name]
    @id   = attrs[:id]
    @pool = attrs[:pool]
    @size = attrs[:size].to_i
  else
    raise PersistentDiskError, "Invalid disk entry"
  end
end

Public Instance Methods

==(other) click to toggle source
# File lib/dopv/persistent_disk.rb, line 24
def ==(other)
  case other
  when Entry
    @node == other.node && @name == other.name && @id == other.id && @pool == other.pool
  when Hash
    @node == other[:node] && @name == other[:name] && @id == other[:id] && @pool == other[:pool]
  else
    false
  end
end
to_hash() click to toggle source
# File lib/dopv/persistent_disk.rb, line 49
def to_hash
  { :name => @name, :id => @id, :pool => @pool, :size => @size }
end
to_s() click to toggle source
# File lib/dopv/persistent_disk.rb, line 45
def to_s
  "Disk: #{@name}\n  Node: #{@node}\n  Id: #{@id}\n  Pool: #{@pool}\n  Size: #{@size}"
end
update(attrs={}) click to toggle source
# File lib/dopv/persistent_disk.rb, line 35
def update(attrs={})
  raise PersistentDiskError, "Update attributes must be a hash" unless attrs.is_a?(Hash)
  @node = attrs[:node] if attrs[:node]
  @name = attrs[:name] if attrs[:name]
  @id   = attrs[:id]   if attrs[:id]
  @pool = attrs[:pool] if attrs[:pool]
  @size = attrs[:size].to_i if attrs[:size]
  self
end