Class: CloudDB::Flavor

Inherits:
Object
  • Object
show all
Defined in:
lib/clouddb/flavor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, id) ⇒ Flavor

Creates a new CloudDB::Flavor object representing a database flavor.



10
11
12
13
14
15
16
17
18
19
# File 'lib/clouddb/flavor.rb', line 10

def initialize(connection,id)
  @connection    = connection
  @id            = id
  @dbmgmthost   = connection.dbmgmthost
  @dbmgmtpath   = connection.dbmgmtpath
  @dbmgmtport   = connection.dbmgmtport
  @dbmgmtscheme = connection.dbmgmtscheme
  populate
  return self
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/clouddb/flavor.rb', line 4

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/clouddb/flavor.rb', line 5

def name
  @name
end

#ramObject (readonly)

Returns the value of attribute ram.



6
7
8
# File 'lib/clouddb/flavor.rb', line 6

def ram
  @ram
end

#vcpusObject (readonly)

Returns the value of attribute vcpus.



7
8
9
# File 'lib/clouddb/flavor.rb', line 7

def vcpus
  @vcpus
end

Instance Method Details

#populateObject Also known as: refresh

Updates the information about the current Flavor object by making an API call.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/clouddb/flavor.rb', line 22

def populate
  response = @connection.dbreq("GET",@dbmgmthost,"#{@dbmgmtpath}/flavors/#{CloudDB.escape(@id.to_s)}",@dbmgmtport,@dbmgmtscheme)
  CloudDB::Exception.raise_exception(response) unless response.code.to_s.match(/^20.$/)
  data = JSON.parse(response.body)['flavor']
  @id     = data["id"]
  @name   = data["name"]
  @ram    = data["ram"]
  @vcpus  = data["vcpus"]
  @links  = data["links"]
  true
end