Class: Distem::Resource::VCPU::VCore

Inherits:
Object
  • Object
show all
Defined in:
lib/distem/resource/vcpu.rb

Overview

Abstract representation of a virtual Core resource

Constant Summary

@@ids =
0

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (VCore) initialize(val, unit)

Create a new VCore

Attributes

  • val Frequency or ration to set ti this VCore. If it is a frequency, it has to be specified in KHz, if it is a ratio, it as to be between 0 and 1 (taken as a percentage of the frequency of the future physical Core frequency that will be attached to this virtual core)

  • +unit Tell if val is a frequency or a ratio



21
22
23
24
25
26
27
28
# File 'lib/distem/resource/vcpu.rb', line 21

def initialize(val,unit)
  @pcore = nil
  @frequency = nil
  @val = val
  @unit = unit
  @id = @@ids
  @@ids += 1
end

Instance Attribute Details

- (Object) frequency

The frequency to be set to this physical resource (KHz)



15
16
17
# File 'lib/distem/resource/vcpu.rb', line 15

def frequency
  @frequency
end

- (Object) id (readonly)

The (unique) id of this virtual resource



11
12
13
# File 'lib/distem/resource/vcpu.rb', line 11

def id
  @id
end

- (Object) pcore

The physical Core associated to this virtual resource



13
14
15
# File 'lib/distem/resource/vcpu.rb', line 13

def pcore
  @pcore
end

Instance Method Details

- (Object) attach(pcore)

Attach a physical core to this virtual one

Attributes

  • pcore The Core object that describes the physical core to attach



34
35
36
37
# File 'lib/distem/resource/vcpu.rb', line 34

def attach(pcore)
  @pcore = pcore
  update(@val,@unit)
end

- (Boolean) attached?

Returns:

  • (Boolean)


39
40
41
# File 'lib/distem/resource/vcpu.rb', line 39

def attached?
  return @pcore != nil
end

- (Object) update(val, unit)

Modify the frequency of this virtual one (to be used after attaching the vcore)

Attributes

  • val The new value (frequency or ratio)

  • unit The way val is defined (mhz or ration values are allowed)



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/distem/resource/vcpu.rb', line 47

def update(val,unit)
  val = val.to_f
  if attached?
    case unit
    when 'mhz'
      raise Lib::InvalidParameterError, val if val > @pcore.frequency or val <= 0
      @frequency = (val * 1000).to_i
    when 'ratio'
      @frequency = (@pcore.frequency * val).to_i
    else
      raise Lib::InvalidParameterError, unit
    end
  else
    @val = val
    @unit = unit
  end
end