Class: HP::Cloud::DatabaseHelper

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

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) ⇒ DatabaseHelper

Returns a new instance of DatabaseHelper.



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

def initialize(connection, foggy = nil)
  super(connection, foggy)
  if foggy.nil?
    @meta = HP::Cloud::Metadata.new(nil)
    return
  end
  @id = foggy.id
  @name = foggy.name
  @size = foggy.size
  @type = foggy.type
  @status = foggy.status
  @meta = HP::Cloud::Metadata.new(foggy.)
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



25
26
27
# File 'lib/hpcloud/database_helper.rb', line 25

def id
  @id
end

#metaObject

Returns the value of attribute meta.



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

def meta
  @meta
end

#nameObject

Returns the value of attribute name.



25
26
27
# File 'lib/hpcloud/database_helper.rb', line 25

def name
  @name
end

#sizeObject

Returns the value of attribute size.



25
26
27
# File 'lib/hpcloud/database_helper.rb', line 25

def size
  @size
end

#statusObject

Returns the value of attribute status.



25
26
27
# File 'lib/hpcloud/database_helper.rb', line 25

def status
  @status
end

#typeObject

Returns the value of attribute type.



25
26
27
# File 'lib/hpcloud/database_helper.rb', line 25

def type
  @type
end

Class Method Details

.get_keysObject



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

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

Instance Method Details

#saveObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/hpcloud/database_helper.rb', line 46

def save
  if is_valid?
    set_error(@meta.cstatus)
  end
  return false if is_valid? == false
  if @fog.nil?
    hsh = {:name => @name,
       :description => @description,
       :size => @size,
       :metadata => @meta.hsh}
    database = @connection.block.databases.create(hsh)
    if database.nil?
      set_error("Error creating database '#{@name}'")
      return false
    end
    @id = database.id
    @fog = database
    return true
  else
    raise "Update not implemented"
  end
end