Class: Distem::Resource::VCPU
- Inherits:
-
Object
- Object
- Distem::Resource::VCPU
- Defined in:
- lib/distem/resource/vcpu.rb
Overview
Abstract representation of a virtual CPU resource
Defined Under Namespace
Classes: VCore
Instance Attribute Summary (collapse)
-
- (Object) pcpu
The physical CPU associated to this virtual one.
-
- (Object) vcores
readonly
Hash describing the associated virtual cores (key: VCore.id, val: VCore).
Instance Method Summary (collapse)
-
- (Object) add_vcore(val, unit)
Adds a new virtual core to this virtual CPU ==== Attributes *
val
The value to set on the virtual core, can be a frequency in mhz or a ratio *unit
Tell if val is a frequency in MHz or if it is a ratio (allowed values are mhz or ratio). -
- (Object) attach
Attach a physical cpu to this virtual one.
- - (Boolean) attached?
- - (Object) DELETE id
- - (Object) detach
-
- (Object) get_vcore(id)
Gets a VCore specifying it's id ==== Attributes *
id
The ID (VCore.id) of the VCore to return ==== Returns VCore object. -
- (VCPU) initialize(vnode)
constructor
Create a new VCPU.
-
- (Object) remove_vcore(id)
Remove a VCore from this VCPU ==== Attributes *
id
The if of the VCore to remove. -
- (Object) update_vcores(val, unit)
Update every virtual cores of this virtual CPU ==== Attributes *
val
The value to set on the virtual cores, can be a frequency in mhz or a ratio *unit
Tell if the val is a frequency in MHz or if it is a ratio (allowed values are mhz or ratio).
Constructor Details
- (VCPU) initialize(vnode)
Create a new VCPU
73 74 75 76 77 |
# File 'lib/distem/resource/vcpu.rb', line 73 def initialize(vnode) @vcores = {} @vnode = vnode @pcpu = nil end |
Instance Attribute Details
- (Object) pcpu
The physical CPU associated to this virtual one
67 68 69 |
# File 'lib/distem/resource/vcpu.rb', line 67 def pcpu @pcpu end |
- (Object) vcores (readonly)
Hash describing the associated virtual cores (key: VCore.id, val: VCore)
69 70 71 |
# File 'lib/distem/resource/vcpu.rb', line 69 def vcores @vcores end |
Instance Method Details
- (Object) add_vcore(val, unit)
Adds a new virtual core to this virtual CPU
Attributes
-
val
The value to set on the virtual core, can be a frequency in mhz or a ratio -
unit
Tell if val is a frequency in MHz or if it is a ratio (allowed values are mhz or ratio)
108 109 110 111 |
# File 'lib/distem/resource/vcpu.rb', line 108 def add_vcore(val,unit) vcore = VCore.new(val,unit) @vcores[vcore.id] = vcore end |
- (Object) attach
Attach a physical cpu to this virtual one
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/distem/resource/vcpu.rb', line 80 def attach raise Lib::UninitializedResourceError 'vnode.host' unless @vnode.host @pcpu = @vnode.host.cpu cores = @pcpu.alloc_cores(@vnode,@vcores.size, (@vnode.host.algorithms[:cpu] == Algorithm::CPU::GOV) ) i = 0 @vcores.each_value do |vcore| vcore.attach(cores[i]) i += 1 end end |
- (Boolean) attached?
95 96 97 |
# File 'lib/distem/resource/vcpu.rb', line 95 def attached? return @pcpu != nil end |
- (Object) DELETE id
128 |
# File 'lib/distem/resource/vcpu.rb', line 128 @vcores.delete(id) |
- (Object) detach
99 100 101 |
# File 'lib/distem/resource/vcpu.rb', line 99 def detach @pcpu.free_cores(@vnode) if @pcpu end |
- (Object) get_vcore(id)
Gets a VCore specifying it's id
Attributes
-
id
The ID (VCore.id) of the VCore to return
Returns
VCore object
119 120 121 |
# File 'lib/distem/resource/vcpu.rb', line 119 def get_vcore(id) return @vcores[id] end |
- (Object) remove_vcore(id)
Remove a VCore from this VCPU
Attributes
-
id
The if of the VCore to remove
127 128 129 |
# File 'lib/distem/resource/vcpu.rb', line 127 def remove_vcore(id) @vcores.delete(id) end |
- (Object) update_vcores(val, unit)
Update every virtual cores of this virtual CPU
Attributes
-
val
The value to set on the virtual cores, can be a frequency in mhz or a ratio -
unit
Tell if the val is a frequency in MHz or if it is a ratio (allowed values are mhz or ratio)
136 137 138 |
# File 'lib/distem/resource/vcpu.rb', line 136 def update_vcores(val,unit) @vcores.each_value { |vcore| vcore.update(val,unit) } end |