Class: OpenStack::Volume::Volume

Inherits:
Object
  • Object
show all
Defined in:
lib/openstack/volume/volume.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, volume_info) ⇒ Volume

Returns a new instance of Volume.



19
20
21
22
23
# File 'lib/openstack/volume/volume.rb', line 19

def initialize(connection, volume_info)
  @connection = connection.connection
  @volume_path = connection.volume_path
  self.populate(volume_info)
end

Instance Attribute Details

#attachmentsObject (readonly)

Returns the value of attribute attachments.



14
15
16
# File 'lib/openstack/volume/volume.rb', line 14

def attachments
  @attachments
end

#availability_zoneObject (readonly)

Returns the value of attribute availability_zone.



12
13
14
# File 'lib/openstack/volume/volume.rb', line 12

def availability_zone
  @availability_zone
end

#connectionObject (readonly)

Returns the value of attribute connection.



6
7
8
# File 'lib/openstack/volume/volume.rb', line 6

def connection
  @connection
end

#created_atObject (readonly)

Returns the value of attribute created_at.



15
16
17
# File 'lib/openstack/volume/volume.rb', line 15

def created_at
  @created_at
end

#display_descriptionObject (readonly)

Returns the value of attribute display_description.



8
9
10
# File 'lib/openstack/volume/volume.rb', line 8

def display_description
  @display_description
end

#display_nameObject (readonly)

Returns the value of attribute display_name.



7
8
9
# File 'lib/openstack/volume/volume.rb', line 7

def display_name
  @display_name
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/openstack/volume/volume.rb', line 5

def id
  @id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



11
12
13
# File 'lib/openstack/volume/volume.rb', line 11

def 
  @metadata
end

#sizeObject (readonly)

Returns the value of attribute size.



9
10
11
# File 'lib/openstack/volume/volume.rb', line 9

def size
  @size
end

#snapshot_idObject (readonly)

Returns the value of attribute snapshot_id.



13
14
15
# File 'lib/openstack/volume/volume.rb', line 13

def snapshot_id
  @snapshot_id
end

#statusObject (readonly)

Returns the value of attribute status.



17
18
19
# File 'lib/openstack/volume/volume.rb', line 17

def status
  @status
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



16
17
18
# File 'lib/openstack/volume/volume.rb', line 16

def updated_at
  @updated_at
end

#volume_typeObject (readonly)

Returns the value of attribute volume_type.



10
11
12
# File 'lib/openstack/volume/volume.rb', line 10

def volume_type
  @volume_type
end

Instance Method Details

#delete!Object



66
67
68
69
70
# File 'lib/openstack/volume/volume.rb', line 66

def delete!
  response = @connection.req("DELETE", "/#{@volume_path}/#{@id}")
  OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
  true
end

#extend!(size) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/openstack/volume/volume.rb', line 45

def extend!(size)
  data = JSON.generate({'os-extend' => {'new_size' => size}})
  response = @connection.req('POST', "/#{@volume_path}/#{@id}/action", {:data => data})
  OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
  self.populate
  true
end

#populate(volume_info = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/openstack/volume/volume.rb', line 25

def populate(volume_info = nil)
  if not volume_info and @id
    response = @connection.req("GET", "/#{@volume_path}/#{@id}")
    volume_info = JSON.parse(response.body)["volume"]
  end

  @id  = volume_info["id"]
  @display_name  = volume_info["display_name"] || volume_info["displayName"] || volume_info["name"]
  @display_description  = volume_info["display_description"] || volume_info["displayDescription"]
  @size  = volume_info["size"]
  @volume_type  = volume_info["volume_type"] || volume_info["volumeType"]
  @metadata  = volume_info["metadata"]
  @availability_zone  = volume_info["availability_zone"] || volume_info["availabilityZone"]
  @snapshot_id  = volume_info["snapshot_id"] || volume_info["snapshotId"]
  @attachments  = volume_info["attachments"]
  @created_at  = volume_info["created_at"] || volume_info["createdAt"]
  @updated_at  = volume_info["updated_at"]
  @status = volume_info["status"]
end

#status!(status, attach_status = nil) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/openstack/volume/volume.rb', line 53

def status!(status, attach_status = nil)
  data = {'status' => status}
  if attach_status
    data.merge!({'attach_status' => attach_status})
  end
  response = @connection.req('POST', "/#{@volume_path}/#{@id}/action", {
      :data => JSON.generate({'os-reset_status' => data})
  })
  OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
  self.populate
  true
end