Class: Distem::Resource::VNode
- Inherits:
-
Object
- Object
- Distem::Resource::VNode
- Defined in:
- lib/distem/resource/vnode.rb
Overview
Abstact representation of a virtual node resource
Constant Summary
- MODE_GATEWAY =
The virtual node is a gateway node
"GATEWAY"
- MODE_NORMAL =
The virtual node is not a gateway node
"NORMAL"
- @@ids =
0
Instance Attribute Summary (collapse)
-
- (Object) filesystem
The FileSystem resource object associated to this virtual node.
-
- (Object) gateway
Boolean describing if this node is in gateway mode or not.
-
- (Object) host
The PNode object describing the machine that hosts this virtual node.
-
- (Object) id
readonly
The unique id of this virtual node.
-
- (Object) name
readonly
The (unique) name of the virtual node.
-
- (Object) sshkey
SSH key pair to be used on the virtual node (Hash).
-
- (Object) status
The status of the Virtual node (see Status).
-
- (Object) vcpu
readonly
The VCPU resource object associated to this virtual node.
-
- (Object) vifaces
readonly
The Array of VIface representing this node virtual network interfaces resources.
-
- (Object) vmem
The memory limitation object associated to this virtual node.
Instance Method Summary (collapse)
-
- (Object) ==(vnode)
Compare two virtual nodes ==== Attributes *
vnode
The VNode object ==== Returns Boolean value. -
- (Object) add_vcpu(corenb, val, unit)
Create a virtual CPU on this virtual node specifying it's virtual core number and their frequencies ==== Attributes *
corenb
The number of virtual cores this virtual CPU have *val
The speed of the virtual CPU defined by a frequency or a ratio (percentage of the physical core frequency *unit
Define if val is a frequency or a ratio (allowed values are mhz and ratio). -
- (Object) add_viface(viface)
Add a virtual network interface to this virtual node ==== Attributes *
viface
The VIface object. - - (Object) add_vmem(opts)
-
- (Boolean) connected_to?(vnetwork)
Check if this virtual node is connected to a specified virtual network ==== Attributes *
vnetwork
The VNetwork object ==== Returns Boolean value. - - (Object) DELETE viface
-
- (Boolean) gateway?
Check if the virtual node is in gateway mode ==== Returns Boolean value.
-
- (Object) get_viface_by_name(vifacename)
Get a virtual network interface associated to this virtual node specifying it's name ==== Attributes *
vifacename
The name of the virtual network interface ==== Returns VIface object or nil if not found. -
- (Object) get_viface_by_network(network)
Get the virtual network interface that's allow this virtual node to be connected on a specified virtual network ==== Attributes *
network
The VNetwork object ==== Returns VIface object or nil if not found. -
- (Object) get_vnetworks
Get the list of every virtual networks a virtual node is connected to ==== Returns Array of VNetwork objects.
-
- (VNode) initialize(name, ssh_key = nil)
constructor
Create a new Virtual Node specifying it's filesystem ==== Attributes *
name
The name of that Virtual Node *filesystem
The FileSystem object *host
The Physical Node that will host the Virtual one *ssh_key
SSH key to be used on the virtual node (Hash with key 'public' and 'private'). -
- (Object) remove_vcpu
Removes the virtual CPU associated to this virtual node, detach each virtual core from the physical core it was associated with.
-
- (Object) remove_viface(viface)
Remove a virtual network interface from this virtual node ==== Attributes *
viface
The VIface object. - - (Object) remove_vmem
- - (Object) to_s
- - (Object) update_vmem(opts)
Constructor Details
- (VNode) initialize(name, ssh_key = nil)
Create a new Virtual Node specifying it's filesystem
Attributes
-
name
The name of that Virtual Node -
filesystem
The FileSystem object -
host
The Physical Node that will host the Virtual one -
ssh_key
SSH key to be used on the virtual node (Hash with key 'public' and 'private')
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/distem/resource/vnode.rb', line 45 def initialize(name, ssh_key = nil) raise unless name.is_a?(String) @id = @@ids if name.empty? @name = "vnode" + @id.to_s else @name = name end @host = nil @filesystem = nil if ssh_key.is_a?(Hash) and !ssh_key.empty? @sshkey = ssh_key else @sshkey = nil end @gateway = false @vifaces = [] @vcpu = nil @vmem = nil @status = Status::INIT @@ids += 1 end |
Instance Attribute Details
- (Object) filesystem
The FileSystem resource object associated to this virtual node
29 30 31 |
# File 'lib/distem/resource/vnode.rb', line 29 def filesystem @filesystem end |
- (Object) gateway
Boolean describing if this node is in gateway mode or not
33 34 35 |
# File 'lib/distem/resource/vnode.rb', line 33 def gateway @gateway end |
- (Object) host
The PNode object describing the machine that hosts this virtual node
21 22 23 |
# File 'lib/distem/resource/vnode.rb', line 21 def host @host end |
- (Object) id (readonly)
The unique id of this virtual node
17 18 19 |
# File 'lib/distem/resource/vnode.rb', line 17 def id @id end |
- (Object) name (readonly)
The (unique) name of the virtual node
19 20 21 |
# File 'lib/distem/resource/vnode.rb', line 19 def name @name end |
- (Object) sshkey
SSH key pair to be used on the virtual node (Hash)
35 36 37 |
# File 'lib/distem/resource/vnode.rb', line 35 def sshkey @sshkey end |
- (Object) status
The status of the Virtual node (see Status)
31 32 33 |
# File 'lib/distem/resource/vnode.rb', line 31 def status @status end |
- (Object) vcpu (readonly)
The VCPU resource object associated to this virtual node
25 26 27 |
# File 'lib/distem/resource/vnode.rb', line 25 def vcpu @vcpu end |
- (Object) vifaces (readonly)
The Array of VIface representing this node virtual network interfaces resources
23 24 25 |
# File 'lib/distem/resource/vnode.rb', line 23 def vifaces @vifaces end |
- (Object) vmem
The memory limitation object associated to this virtual node
27 28 29 |
# File 'lib/distem/resource/vnode.rb', line 27 def vmem @vmem end |
Instance Method Details
- (Object) ==(vnode)
Compare two virtual nodes
Attributes
-
vnode
The VNode object
Returns
Boolean value
187 188 189 |
# File 'lib/distem/resource/vnode.rb', line 187 def ==(vnode) vnode.is_a?(VNode) and (@name == vnode.name) end |
- (Object) add_vcpu(corenb, val, unit)
Create a virtual CPU on this virtual node specifying it's virtual core number and their frequencies
Attributes
-
corenb
The number of virtual cores this virtual CPU have -
val
The speed of the virtual CPU defined by a frequency or a ratio (percentage of the physical core frequency -
unit
Define if val is a frequency or a ratio (allowed values are mhz and ratio)
152 153 154 155 156 |
# File 'lib/distem/resource/vnode.rb', line 152 def add_vcpu(corenb,val,unit) raise Lib::AlreadyExistingResourceError, 'VCPU' if @vcpu @vcpu = VCPU.new(self) corenb.times { @vcpu.add_vcore(val,unit) } end |
- (Object) add_viface(viface)
Add a virtual network interface to this virtual node
Attributes
-
viface
The VIface object
76 77 78 79 80 81 |
# File 'lib/distem/resource/vnode.rb', line 76 def add_viface(viface) raise unless viface.is_a?(VIface) raise Lib::AlreadyExistingResourceError, viface.name \ if @vifaces.include?(viface) @vifaces << viface end |
- (Object) add_vmem(opts)
164 165 166 |
# File 'lib/distem/resource/vnode.rb', line 164 def add_vmem(opts) @vmem = VMem.new(opts) end |
- (Boolean) connected_to?(vnetwork)
Check if this virtual node is connected to a specified virtual network
Attributes
-
vnetwork
The VNetwork object
Returns
Boolean value
140 141 142 143 144 |
# File 'lib/distem/resource/vnode.rb', line 140 def connected_to?(vnetwork) raise unless vnetwork.is_a?(VNetwork) ret = @vifaces.select{|viface| viface.connected_to?(vnetwork)} return (ret.size > 0) end |
- (Object) DELETE viface
88 |
# File 'lib/distem/resource/vnode.rb', line 88 @vifaces.delete(viface) |
- (Boolean) gateway?
Check if the virtual node is in gateway mode
Returns
Boolean value
95 96 97 |
# File 'lib/distem/resource/vnode.rb', line 95 def gateway? return @gateway end |
- (Object) get_viface_by_name(vifacename)
Get a virtual network interface associated to this virtual node specifying it's name
Attributes
-
vifacename
The name of the virtual network interface
Returns
VIface object or nil if not found
105 106 107 |
# File 'lib/distem/resource/vnode.rb', line 105 def get_viface_by_name(vifacename) return @vifaces.select{|viface| viface.name == vifacename}[0] end |
- (Object) get_viface_by_network(network)
Get the virtual network interface that's allow this virtual node to be connected on a specified virtual network
Attributes
-
network
The VNetwork object
Returns
VIface object or nil if not found
115 116 117 118 119 120 |
# File 'lib/distem/resource/vnode.rb', line 115 def get_viface_by_network(network) network = network.address if network.is_a?(VNetwork) raise network.class.to_s unless network.is_a?(IPAddress) return @vifaces.select{|viface| network.include?(viface.address)}[0] end |
- (Object) get_vnetworks
Get the list of every virtual networks a virtual node is connected to
Returns
Array of VNetwork objects
126 127 128 129 130 131 132 |
# File 'lib/distem/resource/vnode.rb', line 126 def get_vnetworks ret = [] @vifaces.each do |viface| ret << viface.vnetwork if viface.attached? and !ret.include?(viface.vnetwork) end return ret end |
- (Object) remove_vcpu
Removes the virtual CPU associated to this virtual node, detach each virtual core from the physical core it was associated with
159 160 161 162 |
# File 'lib/distem/resource/vnode.rb', line 159 def remove_vcpu() @vcpu.detach if @vcpu and @vcpu.attached? @vcpu = nil end |
- (Object) remove_viface(viface)
Remove a virtual network interface from this virtual node
Attributes
-
viface
The VIface object
87 88 89 |
# File 'lib/distem/resource/vnode.rb', line 87 def remove_viface(viface) @vifaces.delete(viface) end |
- (Object) remove_vmem
173 174 175 176 177 178 179 |
# File 'lib/distem/resource/vnode.rb', line 173 def remove_vmem if @vmem @host.memory.deallocate({:mem => @vmem.mem, :swap => @vmem.swap}) if @host @vmem.remove() @vmem = nil end end |
- (Object) to_s
191 192 193 |
# File 'lib/distem/resource/vnode.rb', line 191 def to_s return @name end |
- (Object) update_vmem(opts)
168 169 170 171 |
# File 'lib/distem/resource/vnode.rb', line 168 def update_vmem(opts) remove_vmem if @vmem add_vmem(opts) end |