Class: DCloud::StorageVolume

Inherits:
BaseModel show all
Defined in:
lib/dcloud/storage_volume.rb

Instance Attribute Summary

Attributes inherited from BaseModel

#uri

Instance Method Summary collapse

Methods inherited from BaseModel

attribute, build_reader, #id, xml_tag_name

Constructor Details

#initialize(client, uri, xml = nil) ⇒ StorageVolume

Returns a new instance of StorageVolume.



31
32
33
# File 'lib/dcloud/storage_volume.rb', line 31

def initialize(client, uri, xml=nil)
  super( client, uri, xml )
end

Instance Method Details

#load_payload(xml = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dcloud/storage_volume.rb', line 45

def load_payload(xml=nil)
  super(xml)
  unless xml.nil?
    @created = xml.text( 'created' )
    @state = xml.text( 'state' )
    @capacity = xml.text( 'capacity' ).to_f
    @device = xml.text( 'device' )
    instances = xml.get_elements( 'instance' )
    if ( ! instances.empty? )
      instance = instances.first
      instance_href = instance.attributes['href']
      if ( instance_href )
        @instance = Instance.new( @client, instance_href )
      end
    end
  end
end

#to_plainObject



35
36
37
38
39
40
41
42
43
# File 'lib/dcloud/storage_volume.rb', line 35

def to_plain
  sprintf("%-10s | %15s GB | %-10s | %-10s | %-15s",
    self.id[0,10],
    self.capacity ? self.capacity.to_s[0,15] : 'unknown',
    self.device ? self.device[0,10] : 'unknown',
    self.state ? self.state[0,10] : 'unknown',
    self.instance ? self.instance.name[0,15] : 'unknown'
  )
end