Class: Xen::VDI

Inherits:
Base
  • Object
show all
Defined in:
lib/xen/vdi.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #record, #to_s, #uuid

Constructor Details

This class inherits a constructor from Xen::Base

Class Method Details

.create(name, dev, host) ⇒ Object

Create method, takes a name, a device (p.ex. ‘phy:/dev/storage/slice’) and a host



11
12
13
14
15
16
17
18
# File 'lib/xen/vdi.rb', line 11

def self.create(name, dev, host)
  sr = host.get_local_sr
  config = @initial_config.merge({:name_label => name, 
                                      :other_config => {:location => dev}, 
                                      :SR => sr.uuid })
  uuid = host.get_value("VDI.create", config)
  self.new(uuid, host)
end

.find_by_device(dev, host) ⇒ Object

Finds a device when given a devicename



21
22
23
24
25
26
27
# File 'lib/xen/vdi.rb', line 21

def self.find_by_device(dev, host)
  host.get_value('VDI.get_all').each do |vdi|
    vdirecord = host.get_value('VDI.get_record', vdi) 
    return self.new(vdi, host) if vdirecord['other_config']['location'] == dev
  end
  nil
end

Instance Method Details

#destroy!Object

Destroys the current VDI



30
31
32
# File 'lib/xen/vdi.rb', line 30

def destroy!
  @host.call 'VDI.destroy', self.uuid
end

#humanize(prepend) ⇒ Object

Gives some human string



42
43
44
45
46
47
48
49
# File 'lib/xen/vdi.rb', line 42

def humanize(prepend)
  r = self.record
  if !r 
    prepend + "Unknown vdi #{self.uuid}"
  else
    prepend + "VDI #{self.uuid} is device #{r['other_config']['location']}"
  end
end

#vbdsObject

Gets all the VDBs connected



35
36
37
38
39
# File 'lib/xen/vdi.rb', line 35

def vbds
  @host.get_value('VDI.get_VBDs', self.uuid).collect do |vbd|
    Xen::VBD.new(vbd, @host)
  end
end