Class: HP::Cloud::VolumeHelper
- Inherits:
-
BaseHelper
- Object
- BaseHelper
- HP::Cloud::VolumeHelper
- Defined in:
- lib/hpcloud/volume_helper.rb
Constant Summary collapse
- @@serverous =
nil
Instance Attribute Summary collapse
-
#availability_zone ⇒ Object
Returns the value of attribute availability_zone.
-
#created ⇒ Object
Returns the value of attribute created.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#imageref ⇒ Object
Returns the value of attribute imageref.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#name ⇒ Object
Returns the value of attribute name.
-
#servers ⇒ Object
Returns the value of attribute servers.
-
#size ⇒ Object
Returns the value of attribute size.
-
#snapshot_id ⇒ Object
Returns the value of attribute snapshot_id.
-
#status ⇒ Object
Returns the value of attribute status.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from BaseHelper
Class Method Summary collapse
Instance Method Summary collapse
- #attach(server, device) ⇒ Object
- #detach ⇒ Object
-
#initialize(connection, foggy = nil) ⇒ VolumeHelper
constructor
A new instance of VolumeHelper.
- #map_device(device) ⇒ Object
- #save ⇒ Object
Methods inherited from BaseHelper
#destroy, #is_valid?, #set_error, #to_hash
Constructor Details
#initialize(connection, foggy = nil) ⇒ VolumeHelper
Returns a new instance of VolumeHelper.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/hpcloud/volume_helper.rb', line 33 def initialize(connection, foggy = nil) super(connection, foggy) if foggy.nil? return end @id = foggy.id @name = foggy.name @size = foggy.size @type = foggy.type @created = foggy.created_at @status = foggy.status @description = foggy.description @availability_zone = foggy.availability_zone @servers = '' @@serverous = Servers.new if @@serverous.nil? foggy..each { |x| srv = @@serverous.get(x["server_id"].to_s) if srv.is_valid? == false next end if @servers.length > 0 @servers += ',' end @servers += srv.name } end |
Instance Attribute Details
#availability_zone ⇒ Object
Returns the value of attribute availability_zone.
26 27 28 |
# File 'lib/hpcloud/volume_helper.rb', line 26 def availability_zone @availability_zone end |
#created ⇒ Object
Returns the value of attribute created.
26 27 28 |
# File 'lib/hpcloud/volume_helper.rb', line 26 def created @created end |
#description ⇒ Object
Returns the value of attribute description.
26 27 28 |
# File 'lib/hpcloud/volume_helper.rb', line 26 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
26 27 28 |
# File 'lib/hpcloud/volume_helper.rb', line 26 def id @id end |
#imageref ⇒ Object
Returns the value of attribute imageref.
26 27 28 |
# File 'lib/hpcloud/volume_helper.rb', line 26 def imageref @imageref end |
#meta ⇒ Object
Returns the value of attribute meta.
27 28 29 |
# File 'lib/hpcloud/volume_helper.rb', line 27 def @meta end |
#name ⇒ Object
Returns the value of attribute name.
26 27 28 |
# File 'lib/hpcloud/volume_helper.rb', line 26 def name @name end |
#servers ⇒ Object
Returns the value of attribute servers.
26 27 28 |
# File 'lib/hpcloud/volume_helper.rb', line 26 def servers @servers end |
#size ⇒ Object
Returns the value of attribute size.
26 27 28 |
# File 'lib/hpcloud/volume_helper.rb', line 26 def size @size end |
#snapshot_id ⇒ Object
Returns the value of attribute snapshot_id.
26 27 28 |
# File 'lib/hpcloud/volume_helper.rb', line 26 def snapshot_id @snapshot_id end |
#status ⇒ Object
Returns the value of attribute status.
26 27 28 |
# File 'lib/hpcloud/volume_helper.rb', line 26 def status @status end |
#type ⇒ Object
Returns the value of attribute type.
26 27 28 |
# File 'lib/hpcloud/volume_helper.rb', line 26 def type @type end |
Class Method Details
.clear_cache ⇒ Object
102 103 104 |
# File 'lib/hpcloud/volume_helper.rb', line 102 def self.clear_cache @@serverous = nil end |
.get_keys ⇒ Object
29 30 31 |
# File 'lib/hpcloud/volume_helper.rb', line 29 def self.get_keys() return [ "id", "name", "size", "type", "created", "status", "description", "servers", "availability_zone" ] end |
Instance Method Details
#attach(server, device) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/hpcloud/volume_helper.rb', line 82 def attach(server, device) begin @fog.attach(server.id, device) rescue Exception => e set_error("Error attaching '#{name}' on server '#{server.name}' to device '#{device}'.") return false end return true end |
#detach ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/hpcloud/volume_helper.rb', line 92 def detach() begin @fog.detach rescue Exception => e set_error("Error detaching '#{name}' from '#{@servers}'.") return false end return true end |
#map_device(device) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/hpcloud/volume_helper.rb', line 106 def map_device(device) begin return "/dev/vda" if device == "0" i = device.to_i return device if i < 1 || i > 26 i = i + 96 return "/dev/vd" + i.chr rescue Exception => e end return device end |
#save ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/hpcloud/volume_helper.rb', line 60 def save return false if is_valid? == false if @fog.nil? hsh = {:name => @name, :description => @description, :size => @size} hsh[:snapshot_id] = @snapshot_id unless @snapshot_id.nil? hsh[:image_id] = @imageref unless @imageref.nil? hsh[:availability_zone] = @availability_zone unless @availability_zone.nil? volume = @connection.block.volumes.create(hsh) if volume.nil? set_error("Error creating volume '#{@name}'") return false end @id = volume.id @fog = volume return true else raise "Update not implemented" end end |