Class: HP::Cloud::SnapshotHelper

Inherits:
BaseHelper show all
Defined in:
lib/hpcloud/snapshot_helper.rb

Constant Summary collapse

@@volumous =
nil

Instance Attribute Summary collapse

Attributes inherited from BaseHelper

#connection, #cstatus, #fog

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseHelper

#destroy, #is_valid?, #set_error, #to_hash

Constructor Details

#initialize(connection, foggy = nil) ⇒ SnapshotHelper

Returns a new instance of SnapshotHelper.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/hpcloud/snapshot_helper.rb', line 32

def initialize(connection, foggy = nil)
  super(connection, foggy)
  return if foggy.nil?
  @id = foggy.id
  @name = foggy.name
  set_volume(foggy.volume_id)
  @size = foggy.size
  @created = foggy.created_at
  @status = foggy.status
  @description = foggy.description
end

Instance Attribute Details

#createdObject

Returns the value of attribute created.



26
27
28
# File 'lib/hpcloud/snapshot_helper.rb', line 26

def created
  @created
end

#descriptionObject

Returns the value of attribute description.



26
27
28
# File 'lib/hpcloud/snapshot_helper.rb', line 26

def description
  @description
end

#idObject

Returns the value of attribute id.



26
27
28
# File 'lib/hpcloud/snapshot_helper.rb', line 26

def id
  @id
end

#nameObject

Returns the value of attribute name.



26
27
28
# File 'lib/hpcloud/snapshot_helper.rb', line 26

def name
  @name
end

#sizeObject

Returns the value of attribute size.



26
27
28
# File 'lib/hpcloud/snapshot_helper.rb', line 26

def size
  @size
end

#statusObject

Returns the value of attribute status.



26
27
28
# File 'lib/hpcloud/snapshot_helper.rb', line 26

def status
  @status
end

#volumeObject

Returns the value of attribute volume.



26
27
28
# File 'lib/hpcloud/snapshot_helper.rb', line 26

def volume
  @volume
end

Class Method Details

.clear_cacheObject



73
74
75
# File 'lib/hpcloud/snapshot_helper.rb', line 73

def self.clear_cache
  @@volumous = nil
end

.get_keysObject



28
29
30
# File 'lib/hpcloud/snapshot_helper.rb', line 28

def self.get_keys()
  return [ "id", "name", "volume", "size", "created", "status", "description" ]
end

Instance Method Details

#saveObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/hpcloud/snapshot_helper.rb', line 54

def save
  return false if is_valid? == false
  if @fog.nil?
    hsh = {:name => @name,
       :volume_id => @volume_obj.id,
       :description => @description}
    snapshot = @connection.block.snapshots.create(hsh)
    if snapshot.nil?
      set_error("Error creating snapshot '#{@name}'")
      return false
    end
    @id = snapshot.id
    @fog = snapshot
    return true
  else
    raise "Update not implemented"
  end
end

#set_volume(volume_name_id) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/hpcloud/snapshot_helper.rb', line 44

def set_volume(volume_name_id)
  @@volumous = Volumes.new if @@volumous.nil?
  @volume_obj = @@volumous.get(volume_name_id.to_s)
  if @volume_obj.is_valid? == false
    return false
  end
  @volume = @volume_obj.name
  return true
end