Class: Deltacloud::Metric

Inherits:
BaseModel show all
Defined in:
lib/deltacloud/models/metric.rb

Defined Under Namespace

Classes: Property

Constant Summary collapse

MOCK_METRICS_NAMES =
[
  'cpuUtilization',
  'diskReadRequestCount',
  'diskReadSector',
  'diskWriteRequestCount',
  'diskWriteSector',
  'nicInputByte',
  'nicInputPacket',
  'nicOutputByte',
  'nicOutputPacket'
]

Instance Attribute Summary collapse

Attributes inherited from BaseModel

#description, #name

Instance Method Summary collapse

Methods inherited from BaseModel

attr_accessor, attributes, #attributes, #id, #initialize, #to_entity

Constructor Details

This class inherits a constructor from Deltacloud::BaseModel

Instance Attribute Details

#entityObject

Returns the value of attribute entity.



19
20
21
# File 'lib/deltacloud/models/metric.rb', line 19

def entity
  @entity
end

#propertiesObject

Returns the value of attribute properties.



20
21
22
# File 'lib/deltacloud/models/metric.rb', line 20

def properties
  @properties
end

Instance Method Details

#add_property(name, values = nil) ⇒ Object



38
39
40
41
42
43
# File 'lib/deltacloud/models/metric.rb', line 38

def add_property(name, values=nil)
  self.properties ||= []
  return self if self.properties.any? { |p| p.name == name }
  self.properties << Property.new(name, values)
  self
end

#to_hash(context) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/deltacloud/models/metric.rb', line 45

def to_hash(context)
  {
    :id => self.id,
    :href => context.metric_url(self.id),
    :entity => entity,
    :properties => properties.map { |p| p.to_hash(context) }
  }
end

#unknown?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/deltacloud/models/metric.rb', line 34

def unknown?
  self.entity == :unknown
end