Class: DeltacloudVM::Client::StorageVolume

Inherits:
Base
  • Object
show all
Includes:
Methods::Common, Methods::Instance, Methods::StorageSnapshot, Methods::StorageVolume
Defined in:
lib/deltacloud_vm/client/models/storage_volume.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#description, #name, #obj_id, #url

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Methods::StorageSnapshot

#create_storage_snapshot, #destroy_storage_snapshot, #storage_snapshot, #storage_snapshots

Methods included from Methods::StorageVolume

#attach_storage_volume, #create_storage_volume, #destroy_storage_volume, #detach_storage_volume, #storage_volume, #storage_volumes

Methods included from Methods::Instance

#create_instance, #destroy_instance, #instances, #reboot_instance, #start_instance, #stop_instance

Methods included from Methods::Common

#create_resource, #destroy_resource

Methods inherited from Base

#client, #connection, convert, #entrypoint, from_collection, #id, #initialize, #original_body, #to_s, #update_instance_variables!, validate_attrs!

Methods included from Helpers::XmlHelper

#extract_xml_body

Methods included from Methods::Api

#api_uri, #current_driver, #current_provider, #feature?, #features, #must_support!, #path, #support?, #supported_collections, #version

Methods included from Helpers::Model

#error, #from_collection, #from_resource, #model

Constructor Details

This class inherits a constructor from DeltacloudVM::Client::Base

Instance Attribute Details

#capacityObject

Returns the value of attribute capacity.



26
27
28
# File 'lib/deltacloud_vm/client/models/storage_volume.rb', line 26

def capacity
  @capacity
end

#capacity_unitObject

Returns the value of attribute capacity_unit.



27
28
29
# File 'lib/deltacloud_vm/client/models/storage_volume.rb', line 27

def capacity_unit
  @capacity_unit
end

#createdObject

Returns the value of attribute created.



24
25
26
# File 'lib/deltacloud_vm/client/models/storage_volume.rb', line 24

def created
  @created
end

#deviceObject

Returns the value of attribute device.



28
29
30
# File 'lib/deltacloud_vm/client/models/storage_volume.rb', line 28

def device
  @device
end

#kindObject

Returns the value of attribute kind.



30
31
32
# File 'lib/deltacloud_vm/client/models/storage_volume.rb', line 30

def kind
  @kind
end

#mountObject

Returns the value of attribute mount.



31
32
33
# File 'lib/deltacloud_vm/client/models/storage_volume.rb', line 31

def mount
  @mount
end

#realm_idObject

Returns the value of attribute realm_id.



29
30
31
# File 'lib/deltacloud_vm/client/models/storage_volume.rb', line 29

def realm_id
  @realm_id
end

#stateObject

Returns the value of attribute state.



25
26
27
# File 'lib/deltacloud_vm/client/models/storage_volume.rb', line 25

def state
  @state
end

Class Method Details

.parse(xml_body) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/deltacloud_vm/client/models/storage_volume.rb', line 69

def self.parse(xml_body)
  {
    :created =>             xml_body.text_at('created'),
    :state =>               xml_body.text_at('state'),
    :device =>              xml_body.text_at('device'),
    :capacity =>            xml_body.text_at('capacity'),
    :capacity_unit =>       xml_body.attr_at('capacity', :unit),
    :state =>               xml_body.text_at('state'),
    :realm_id =>            xml_body.attr_at('realm', :id),
    :kind  =>               xml_body.text_at('kind'),
    :mount  =>              {
      :instance => xml_body.attr_at('mount/instance', :id),
      :device => xml_body.attr_at('mount/device', :name)
    }
  }
end

Instance Method Details

#attach(instance_id, device = nil) ⇒ Object

Attach this volume to the instance



41
42
43
# File 'lib/deltacloud_vm/client/models/storage_volume.rb', line 41

def attach(instance_id, device=nil)
  attach_storage_volume(_id, instance_id, device) && reload!
end

#attached?Boolean

Check if the current volume is attached to an Instance

Returns:

  • (Boolean)


35
36
37
# File 'lib/deltacloud_vm/client/models/storage_volume.rb', line 35

def attached?
  !mount[:instance].nil?
end

#destroy!Object

Destroy the storage volume



53
54
55
# File 'lib/deltacloud_vm/client/models/storage_volume.rb', line 53

def destroy!
  destroy_storage_volume(_id)
end

#detach!Object

Detach this volume from the currently attached instance



47
48
49
# File 'lib/deltacloud_vm/client/models/storage_volume.rb', line 47

def detach!
  detach_storage_volume(_id) && reload!
end

#instanceObject



65
66
67
# File 'lib/deltacloud_vm/client/models/storage_volume.rb', line 65

def instance
  super(mount[:instance])
end

#snapshot!(snapshot_opts = {}) ⇒ Object

Syntax sugar for creating a snapshot from volume See: create_storage_snapshot



60
61
62
63
# File 'lib/deltacloud_vm/client/models/storage_volume.rb', line 60

def snapshot!(snapshot_opts={})
  snap = create_storage_snapshot(_id, snapshot_opts)
  reload! && snap
end