Class: Distem::Daemon::DistemCoordinator
- Inherits:
-
Object
- Object
- Distem::Daemon::DistemCoordinator
- Defined in:
- lib/distem/daemon/distemcoordinator.rb
Constant Summary
- MAC_PREFIX =
See en.wikipedia.org/wiki/MAC_address#Address_details for allowed addresses
"fe:#{rand(256).to_s(16).rjust(2,"0")}:#{rand(256).to_s(16).rjust(2,"0")}"
- WINDOW_SIZE =
250
- ADMIN_NETWORK_IP =
'220.0.0.0/8'
- ADMIN_NETWORK_NAME =
'adm'
- @@lockslock =
Mutex.new
- @@locks =
{ :vnetsync => {}, }
- @@threads =
{ :pnode_init => {}, :vnode_stop => {}, }
- @@mac_id =
0
- @@mac_id_lock =
Mutex.new
- @@vxlan_id =
0
- @@vxlan_mcast_id =
0
- @@vxlan_id_lock =
Mutex.new
Instance Attribute Summary (collapse)
-
- (Object) daemon_resources
readonly
The VPlatform object that describes each resources in the experimental platform.
Instance Method Summary (collapse)
-
- (Object) event_manager_start
Start the churn.
-
- (Object) event_manager_stop
Stop the churn.
-
- (Object) event_random_add(resource_desc, event_type, generator_desc, first_value = nil)
Add an random generated event to a resource.
-
- (Object) event_trace_add(resource_desc, event_type, trace)
Add an event trace to a resource.
-
- (Object) event_trace_string_add(resource_desc, event_type, trace)
Add an event trace to a resource, from a string.
-
- (DistemCoordinator) initialize(enable_admin_network = false, vxlan_id = 1)
constructor
A new instance of DistemCoordinator.
-
- (Object) pcpu_get(hostname, raising = true)
Get the description of the cpu of a physical node.
-
- (Object) pmemory_get(hostname, raising = true)
Get the description of the memory of a physical node.
-
- (Object) pnode_create(targets, desc = {}, async = false)
Initialise a physical machine (launching daemon, creating cgroups, …) This step have to be performed to be able to create virtual nodes on a machine ==== Attributes *
target
the name/address of the physical machine *properties
async,max_vifaces,cpu_algorithm ==== Returns Resource::PNode object ==== Exceptions. -
- (Object) pnode_get(hostname, raising = true)
Get the description of a virtual node.
-
- (Object) pnode_update(target, desc)
Update PNode properties.
-
- (Object) pnode_wait(target)
Wait for a PNode to be ready.
-
- (Object) pnodes_delete_probes
Delete the probes on every PNode.
-
- (Object) pnodes_get
Get the list of the the currently created physical nodes ==== Returns Array of Resource::PNode objects ==== Exceptions.
-
- (Object) pnodes_get_probes_data
Get the data collected bu the probes ==== Returns Hash with one entry per probe.
-
- (Object) pnodes_launch_probes(desc, _)
Launch a set of probes on every PNode.
-
- (Object) pnodes_quit
Quit distem on all the physical machines (remove everything that was created) ==== Returns Array of Resource::PNode objects ==== Exceptions.
-
- (Object) pnodes_restart_probes
Restart the probes on every PNode.
-
- (Object) pnodes_stop_probes
Stop the probes on every PNode.
- - (Object) set_global_arptable(param = nil, arp_file = nil)
- - (Object) set_global_etchosts(param = nil)
- - (Object) set_peers_latencies(vnodes, matrix)
-
- (Object) vcpu_create(vnodename, desc)
Create a new virtual cpu on the targeted virtual node.
- - (Object) vcpu_remove(vnodename)
- - (Object) vcpu_update(vnodename, desc)
- - (Object) vfilesystem_create(vnodename, desc)
-
- (Object) vfilesystem_get(vnodename)
Retrieve informations about the virtual node filesystem ==== Returns Resource::FileSystem object ==== Exceptions.
- - (Object) vfilesystem_update(vnodename, desc)
-
- (Object) viface_attach(vnodename, vifacename, desc)
Connect a virtual node on a virtual network specifying which of it's virtual interface to use The IP address is auto assigned to the virtual interface Dettach the virtual interface if properties is empty You can change the traffic specification on the fly, only specifying a vtraffic property ==== Attributes *
vnodename
The VNode name (String) *vifacename
The VIface name (String) *properties
the address or the vnetwork to connect the virtual interface with (JSON, 'address' or 'vnetwork'), the traffic the interface will have to emulate (not mandatory, JSON, 'vtraffic', INPUT/OUTPUT) == Usage ==== Returns Resource::VIface object ==== Exceptions. -
- (Object) viface_create(vnodename, vifacename, desc)
Create a new virtual interface on the targeted virtual node (without attaching it to any network -> no ip address) ==== Attributes *
name
the name of the virtual interface (need to be unique on this virtual node) ==== Returns Resource::VIface object ==== Exceptions. -
- (Object) viface_detach(vnodename, vifacename)
Disconnect a virtual network interface from every networks it's connected to ==== Attributes *
vnodename
The VNode name (String) *vifacename
The VIface name (String) ==== Returns Resource::PNode object ==== Exceptions. -
- (Object) viface_get(vnodename, vifacename, raising = true)
Get the description of a virtual network interface ==== Returns Resource::VIface object ==== Exceptions.
-
- (Object) viface_remove(vnodename, vifacename)
Remove the virtual interface ==== Returns Resource::VIface object ==== Exceptions.
- - (Object) viface_update(vnodename, vifacename, desc)
- - (Object) vinput_get(vnodename, vifacename, raising = true)
- - (Object) vinput_update(vnodename, vifacename, desc)
- - (Object) vmem_create(vnodename, opts)
-
- (Object) vnetwork_create(name, address, opts = nil)
Create a new virtual network specifying his range of IP address (IPv4 atm).
-
- (Object) vnetwork_get(name, raising = true)
Get the description of a virtual network ==== Returns Resource::VNetwork object ==== Exceptions.
-
- (Object) vnetwork_remove(name)
Delete the virtual network ==== Returns Resource::VNetwork object ==== Exceptions.
- - (Object) vnetwork_sync(vnet, pnode, lock = true)
-
- (Object) vnetworks_get
Get the list of the the currently created virtual networks ==== Returns Array of Resource::VNetwork objects ==== Exceptions.
-
- (Object) vnetworks_remove
Delete every virtual networks ==== Returns Array of Resource::VNetwork objects ==== Exceptions.
- - (Object) vnode_attach(name, host)
-
- (Object) vnode_create(names, desc, ssh_key = {}, async = false)
Create a virtual node using a compressed file system image.
-
- (Object) vnode_execute(vnodename, command)
Execute and get the result of a command on a virtual node ==== Attributes *
command
the command to be executed ==== Returns Hash object: { 'command' => , 'result' => } ==== Exceptions. -
- (Object) vnode_get(name, raising = true)
Get the description of a virtual node ==== Returns Resource::VNode object ==== Exceptions.
-
- (Object) vnode_get_info(vnodename)
Get the description of a vnode.
-
- (Object) vnode_mode_update(name, mode)
Change the mode of a virtual node (normal or gateway) ==== Attributes *
mode
“Normal” or “Gateway” ==== Returns Resource::VNode object ==== Exceptions. -
- (Object) vnode_remove(names)
Remove the virtual node (“Cascade” removing -> remove all the vroutes it apears as gateway) ==== Returns Resource::VNode object ==== Exceptions.
-
- (Object) vnode_start(names, async = false)
Same as vnode_set_status(name,Resource::Status::RUNNING,properties).
-
- (Object) vnode_status_update(names, status, async = false)
Change the status of the -previously created- virtual node.
-
- (Object) vnode_stop(names, async = false)
Same as vnode_set_status(name,Resource::Status::DOWN,properties).
-
- (Object) vnode_update(names, description, async = false)
Update the vnode resource.
- - (Object) vnodes_execute(names, command)
- - (Object) vnodes_freeze(names, async = false)
-
- (Object) vnodes_get
Get the list of the the currently created virtual nodes ==== Returns Array of Resource::PNode objects ==== Exceptions.
-
- (Object) vnodes_get_info
Get the description of the vnodes.
-
- (Object) vnodes_remove(names)
Remove the given virtual nodes, or every if names is nil ==== Returns Array of Resource::PNode objects ==== Exceptions.
- - (Object) vnodes_start(names, async = false)
- - (Object) vnodes_stop(names, async = false)
- - (Object) vnodes_unfreeze(names, async = false)
- - (Object) voutput_get(vnodename, vifacename, raising = true)
- - (Object) voutput_update(vnodename, vifacename, desc)
-
- (Object) vplatform_create(format, data, rootfs = nil)
Load a configuration ==== Attributes *
data
data to be applied *format
the format of the data *rootfs
the rootfs to boot vnodes ==== Returns Resource::VPlatform object ==== Exceptions. -
- (Object) vplatform_get
Get the description file of the current platform in a specified format (JSON if not specified) ==== Returns String value that reprents the platform in the format form ==== Exceptions.
-
- (Object) vroute_complete
Try to create every possible virtual routes between the current set of virtual nodes automagically finding and setting up the gateways to use ==== Returns Array of Resource::VRoute objects ==== Exceptions.
-
- (Object) vroute_create(networksrc, networkdst, nodegw)
Create a virtual route (“go from to via ”).
-
- (Object) vtraffic_update(vnodename, vifacename, desc)
Configure the virtual traffic on a virtual network interface, replacing previous values ==== Attributes *
vnodename
The VNode name (String) *vifacename
The VIface name (String) *desc
Hash that represents the VTraffic description (see Lib::Validator) ==== Returns Resource::VIface object ==== Exceptions. - - (Object) wait_vnodes(opts)
Constructor Details
- (DistemCoordinator) initialize(enable_admin_network = false, vxlan_id = 1)
Returns a new instance of DistemCoordinator
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 40 def initialize(enable_admin_network = false, vxlan_id = 1) #Thread::abort_on_exception = true @node_name = Socket::gethostname @daemon_resources = Resource::VPlatform.new @daemon_resources_lock = Mutex.new @vnet_id = 0 @event_trace = Events::Trace.new @event_manager = Events::EventManager.new(@event_trace) @admin_network = nil # Since a vxlan_id is a 24 bits value, this allows to hage 16 instances of 2^20 vxlan networks @@vxlan_id = vxlan_id.to_i * 2**20 @@vxlan_mcast_id = vxlan_id.to_i if enable_admin_network @admin_network = vnetwork_create(ADMIN_NETWORK_NAME, ADMIN_NETWORK_IP, {'network_type' => 'vxlan', 'vxlan_id' => vxlan_id}) end end |
Instance Attribute Details
- (Object) daemon_resources (readonly)
The VPlatform object that describes each resources in the experimental platform
15 16 17 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 15 def daemon_resources @daemon_resources end |
Instance Method Details
- (Object) event_manager_start
Start the churn
1442 1443 1444 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1442 def event_manager_start @event_manager.run end |
- (Object) event_manager_stop
Stop the churn
1447 1448 1449 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1447 def event_manager_stop @event_manager.stop end |
- (Object) event_random_add(resource_desc, event_type, generator_desc, first_value = nil)
Add an random generated event to a resource
1436 1437 1438 1439 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1436 def event_random_add(resource_desc, event_type, generator_desc, first_value = nil) event = Events::EventGenerator.new(resource_desc, event_type, generator_desc, first_value) @event_trace.add_event(event.get_next_date, event) end |
- (Object) event_trace_add(resource_desc, event_type, trace)
Add an event trace to a resource
1421 1422 1423 1424 1425 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1421 def event_trace_add(resource_desc, event_type, trace) trace.to_a.each do |date, event_value| @event_trace.add_event(date.to_f, Events::Event.new(resource_desc, event_type, event_value)) end end |
- (Object) event_trace_string_add(resource_desc, event_type, trace)
Add an event trace to a resource, from a string
1428 1429 1430 1431 1432 1433 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1428 def event_trace_string_add(resource_desc, event_type, trace) trace.strip.split(/\n+/).each do |trace_line| date, event_value = trace_line.split @event_trace.add_event(date.to_f, Events::Event.new(resource_desc, event_type, event_value)) end end |
- (Object) pcpu_get(hostname, raising = true)
Get the description of the cpu of a physical node
287 288 289 290 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 287 def pcpu_get(hostname, raising = true) pnode = pnode_get(hostname) return pnode.cpu end |
- (Object) pmemory_get(hostname, raising = true)
Get the description of the memory of a physical node
293 294 295 296 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 293 def pmemory_get(hostname, raising = true) pnode = pnode_get(hostname) return pnode.memory end |
- (Object) pnode_create(targets, desc = {}, async = false)
Initialise a physical machine (launching daemon, creating cgroups, …) This step have to be performed to be able to create virtual nodes on a machine
Attributes
-
target
the name/address of the physical machine -
properties
async,max_vifaces,cpu_algorithm
Returns
Resource::PNode object
Exceptions
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 68 def pnode_create(targets,desc={},async=false) l = lambda { |target| begin async = parse_bool(async) pnode = @daemon_resources.get_pnode_by_address(target) pnode = Resource::PNode.new(target) unless pnode @daemon_resources.add_pnode(pnode) block = Proc.new { Admin.pnode_run_server(pnode) cl = NetAPI::Client.new(target, 4568) ret = cl.pnode_init(nil,desc,async) # here ret should always contains one element updateobj_pnode(pnode,ret) pnode.status = Resource::Status::RUNNING if @admin_network && (target == @node_name) vnetwork_sync(@admin_network,pnode) end } if async #thr = @@threads[:pnode_init][pnode.address.to_s] = Thread.new { @@threads[:pnode_init][pnode.address.to_s] = Thread.new { block.call } #thr.abort_on_exception = true else block.call end pnode_update(pnode.address.to_s,desc) return pnode rescue Lib::AlreadyExistingResourceError raise rescue Exception destroy(pnode) if pnode raise end } if targets.is_a?(Array) then threads_info = {} targets.each { |target| threads_info[target] = {} threads_info[target]['tid'] = Thread.new { threads_info[target]['ret'] = l.call(target) } } ret = [] threads_info.each_value { |host| host['tid'].join ret << host['ret'] } return ret else return [l.call(targets)] end end |
- (Object) pnode_get(hostname, raising = true)
Get the description of a virtual node
Attributes
193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 193 def pnode_get(hostname, raising = true) pnode = nil hostname = '' unless hostname begin address = Resolv.getaddress(hostname) rescue Resolv::ResolvError raise Lib::InvalidParameterError, hostname end pnode = @daemon_resources.get_pnode_by_address(address) raise Lib::ResourceNotFoundError, hostname if raising and !pnode return pnode end |
- (Object) pnode_update(target, desc)
Update PNode properties
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 128 def pnode_update(target,desc) pnode = pnode_get(target) if desc['algorithms'] if desc['algorithms']['cpu'] algo = desc['algorithms']['cpu'].upcase raise InvalidParameterError "algorithms/cpu" unless \ [Algorithm::CPU::GOV.upcase, Algorithm::CPU::HOGS.upcase].include?(algo) pnode.algorithms[:cpu] = algo return {'algorithms' => {'cpu'=> algo }} end end end |
- (Object) pnode_wait(target)
Wait for a PNode to be ready
144 145 146 147 148 149 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 144 def pnode_wait(target) pnode = pnode_get(target) @@threads[:pnode_init][pnode.address.to_s].join if \ @@threads[:pnode_init][pnode.address.to_s] end |
- (Object) pnodes_delete_probes
Delete the probes on every PNode
257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 257 def pnodes_delete_probes() w = Distem::Lib::Synchronization::SlidingWindow.new(WINDOW_SIZE) @daemon_resources.pnodes.each_value {|pnode| block = Proc.new { cl = NetAPI::Client.new(pnode.address.to_s, 4568) cl.pnodes_delete_probes() } w.add(block) } w.run end |
- (Object) pnodes_get
Get the list of the the currently created physical nodes
Returns
Array of Resource::PNode objects
Exceptions
212 213 214 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 212 def pnodes_get() return @daemon_resources.pnodes end |
- (Object) pnodes_get_probes_data
Get the data collected bu the probes
Returns
Hash with one entry per probe. Every entry is an Array containing a time series
272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 272 def pnodes_get_probes_data() result = {} w = Distem::Lib::Synchronization::SlidingWindow.new(WINDOW_SIZE) @daemon_resources.pnodes.each_value {|pnode| block = Proc.new { cl = NetAPI::Client.new(pnode.address.to_s, 4568) result[Resolv.getname(pnode.address)] = cl.pnodes_get_probes_data() } w.add(block) } w.run return result end |
- (Object) pnodes_launch_probes(desc, _)
Launch a set of probes on every PNode
217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 217 def pnodes_launch_probes(desc,_) w = Distem::Lib::Synchronization::SlidingWindow.new(WINDOW_SIZE) @daemon_resources.pnodes.each_value {|pnode| block = Proc.new { cl = NetAPI::Client.new(pnode.address.to_s, 4568) cl.pnodes_launch_probes(desc, Time.now.to_f) } w.add(block) } w.run end |
- (Object) pnodes_quit
Quit distem on all the physical machines (remove everything that was created)
Returns
Array of Resource::PNode objects
Exceptions
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 156 def pnodes_quit() ret = @daemon_resources.pnodes.dup first_node = Resolv.getaddress(@node_name).to_s tids = [] distant_quit = lambda { |target| pnode = pnode_get(target,false) cl = NetAPI::Client.new(target, 4568) cl.pnode_quit(target) @daemon_resources.remove_pnode(pnode) } @daemon_resources.pnodes.each_value { |pnode| tids << Thread.new { pnode.status = Resource::Status::CONFIGURING vnodes = [] @daemon_resources.vnodes.each_value { |vnode| if vnode.host != nil && (vnode.host.address.to_s == pnode.address.to_s) vnodes << vnode end } vn = vnodes.map { |vnode| vnode.name } vnodes_stop(vn, false) vnodes_remove(vn) distant_quit.call(pnode.address.to_s) if pnode.address.to_s != first_node pnode.status = Resource::Status::READY } } tids.each { |tid| tid.join } distant_quit.call(first_node) return ret end |
- (Object) pnodes_restart_probes
Restart the probes on every PNode
231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 231 def pnodes_restart_probes() w = Distem::Lib::Synchronization::SlidingWindow.new(WINDOW_SIZE) @daemon_resources.pnodes.each_value {|pnode| block = Proc.new { cl = NetAPI::Client.new(pnode.address.to_s, 4568) cl.pnodes_restart_probes() } w.add(block) } w.run end |
- (Object) pnodes_stop_probes
Stop the probes on every PNode
244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 244 def pnodes_stop_probes() w = Distem::Lib::Synchronization::SlidingWindow.new(WINDOW_SIZE) @daemon_resources.pnodes.each_value {|pnode| block = Proc.new { cl = NetAPI::Client.new(pnode.address.to_s, 4568) cl.pnodes_stop_probes() } w.add(block) } w.run end |
- (Object) set_global_arptable(param = nil, arp_file = nil)
1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1599 def set_global_arptable(param = nil, arp_file = nil) results = [] @daemon_resources.vnodes.each_value {|vnode| vnode.vifaces.each {|viface| if viface.vnetwork results << viface.macaddress + " " + viface.address.address.to_s end } } data = Base64.encode64(Zlib::Deflate.deflate(results.join("\n"))) arp_file = '/tmp/fullarptable' w = Distem::Lib::Synchronization::SlidingWindow.new(WINDOW_SIZE) @daemon_resources.pnodes.each_value {|pnode| block = Proc.new { cl = NetAPI::Client.new(pnode.address.to_s, 4568) cl.set_global_arptable(data, arp_file) } w.add(block) } w.run end |
- (Object) set_global_etchosts(param = nil)
1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1569 def set_global_etchosts(param = nil) results = [] @daemon_resources.vnodes.each_value {|vnode| vnode.vifaces.each do |viface| if viface.vnetwork if viface.default results << viface.address.address.to_s + " " + vnode.name end results << viface.address.address.to_s + " " + vnode.name + "-" + viface.vnetwork.name end end } data = Base64.encode64(Zlib::Deflate.deflate(results.join("\n"))) w = Distem::Lib::Synchronization::SlidingWindow.new(WINDOW_SIZE) @daemon_resources.pnodes.each_value {|pnode| block = Proc.new { cl = NetAPI::Client.new(pnode.address.to_s, 4568) cl.set_global_etchosts(data) } w.add(block) } w.run end |
- (Object) set_peers_latencies(vnodes, matrix)
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1525 def set_peers_latencies(vnodes, matrix) #sanity check if (vnodes.length == matrix.length) matrix.each { |row| if row.length != vnodes.length return false end } else return false end vnodesbyhost = {} #group vnodes by pnode vnodes.each { |name| vnode = vnode_get(name) vnode.status = Resource::Status::CONFIGURING host = vnode.host.address vnodesbyhost[host] = {} if !vnodesbyhost.has_key?(host) vnodesbyhost[host][vnode.name] = {} row = matrix[vnodes.index(name)] rules = {} (0...matrix.length).each { |i| if row[i] != 0 dest_vnode = vnode_get(vnodes[i]) rules[dest_vnode.vifaces[0].address.to_s] = row[i] end } vnodesbyhost[host][vnode.name] = vnode.vifaces[0].latency_filters = rules } tids = [] vnodesbyhost.each_pair { |pnode,vnodeshash| tids << Thread.new { cl = NetAPI::Client.new(pnode, 4568) cl.set_peers_latencies(nil, vnodeshash) } } tids.each { |tid| tid.join } vnodes.each { |name| vnode = vnode_get(name) vnode.status = Resource::Status::RUNNING } return true end |
- (Object) vcpu_create(vnodename, desc)
Create a new virtual cpu on the targeted virtual node. By default all the virtual nodes on a same physical one are sharing available CPU resources, using this method you can allocate some cores to a virtual node and apply some limitations on them
Attributes
-
corenb
the number of cores to allocate (need to have enough free ones on the physical node) -
frequency
(optional) the frequency each node have to be set (need to be lesser or equal than the physical core frequency). If the frequency is included in ]0,1] it'll be interpreted as a percentage of the physical core frequency, otherwise the frequency will be set to the specified number
Returns
Resource::VCPU object
Exceptions
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1031 def vcpu_create(vnodename,desc) begin vnode = vnode_get(vnodename) downkeys(desc) corenb = nil val = nil unit = 'mhz' if desc['vcores'] raise Lib::InvalidParameterError, 'vcores' unless desc['vcores'].is_a?(Array) val = desc['vcores'][0]['frequency'] corenb = desc['vcores'].size else if desc['val'] val = desc['val'] unit = desc['unit'] if desc.has_key?('unit') else val = 1 unit = 'ratio' end corenb = desc['corenb'].to_i || 1 end vnode.add_vcpu(corenb,val,unit) vnode.vcpu.attach if vnode.host if vnode.status == Resource::Status::RUNNING vnode.status = Resource::Status::CONFIGURING cl = NetAPI::Client.new(vnode.host.address, 4568) cl.vcpu_update(vnode.name,val,unit) vnode.status = Resource::Status::RUNNING end return vnode.vcpu rescue Lib::AlreadyExistingResourceError raise rescue Exception vnode.remove_vcpu() if vnode raise end end |
- (Object) vcpu_remove(vnodename)
1117 1118 1119 1120 1121 1122 1123 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1117 def vcpu_remove(vnodename) vnode = vnode_get(vnodename) raise Lib::UninitializedResourceError, 'vcpu' unless vnode.vcpu vcpu = vnode.vcpu vnode.remove_vcpu() return vcpu end |
- (Object) vcpu_update(vnodename, desc)
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1077 def vcpu_update(vnodename,desc) begin vnode = vnode_get(vnodename) raise Lib::UninitializedResourceError, 'vcpu' unless vnode.vcpu vcpu = vnode.vcpu downkeys(desc) val = nil unit = 'mhz' if desc['vcores'] raise Lib::InvalidParameterError, 'vcores' unless desc['vcores'].is_a?(Array) val = desc['vcores'][0]['frequency'] else if desc['val'] val = desc['val'] unit = desc['unit'] if desc.has_key?('unit') else val = 1 unit = 'ratio' end end vcpu.update_vcores(val,unit) if vnode.status == Resource::Status::RUNNING vnode.status = Resource::Status::CONFIGURING cl = NetAPI::Client.new(vnode.host.address, 4568) cl.vcpu_update(vnode.name,val,unit) vnode.status = Resource::Status::RUNNING end return vnode.vcpu rescue Lib::AlreadyExistingResourceError raise rescue Exception vnode.remove_vcpu() if vnode raise end end |
- (Object) vfilesystem_create(vnodename, desc)
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1126 def vfilesystem_create(vnodename,desc) vnode = vnode_get(vnodename) raise Lib::AlreadyExistingResourceError, 'filesystem' if vnode.filesystem raise Lib::MissingParameterError, "filesystem/image" unless \ desc['image'] desc['shared'] = parse_bool(desc['shared']) desc['cow'] = parse_bool(desc['cow']) if desc.has_key?('disk_throttling') && desc['disk_throttling'] desc['disk_throttling'].each_key { |k| raise Lib::InvalidParameterError, "filesystem/disk_throttling/#{k}" if !['device','read_limit', 'write_limit'].include?(k) } raise Lib::MissingParameterError, "filesystem/disk_throttling/device" if (desc['disk_throttling'].has_key?('read_limit') || desc['disk_throttling'].has_key?('write_limit')) && !desc['disk_throttling'].has_key?('device') else desc['disk_throttling'] = nil end vnode.filesystem = Resource::FileSystem.new(vnode,desc['image'],desc['shared'],desc['cow'],desc['disk_throttling']) return vnode.filesystem end |
- (Object) vfilesystem_get(vnodename)
Retrieve informations about the virtual node filesystem
Returns
Resource::FileSystem object
Exceptions
1160 1161 1162 1163 1164 1165 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1160 def vfilesystem_get(vnodename) vnode = vnode_get(vnodename) raise Lib::UninitializedResourceError, "filesystem" unless \ vnode.filesystem return vnode.filesystem end |
- (Object) vfilesystem_update(vnodename, desc)
1145 1146 1147 1148 1149 1150 1151 1152 1153 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1145 def vfilesystem_update(vnodename,desc) vnode = vnode_get(vnodename) raise Lib::UninitializedResourceError, "filesystem" unless \ vnode.filesystem vnode.filesystem.image = URI.encode(desc['image']) if desc['image'] vnode.filesystem.shared = parse_bool(desc['shared']) if desc['shared'] vnode.filesystem.cow = parse_bool(desc['cow']) if desc['cow'] return vnode.filesystem end |
- (Object) viface_attach(vnodename, vifacename, desc)
Connect a virtual node on a virtual network specifying which of it's virtual interface to use The IP address is auto assigned to the virtual interface Dettach the virtual interface if properties is empty You can change the traffic specification on the fly, only specifying a vtraffic property
Attributes
-
vnodename
The VNode name (String) -
vifacename
The VIface name (String) -
properties
the address or the vnetwork to connect the virtual interface with (JSON, 'address' or 'vnetwork'), the traffic the interface will have to emulate (not mandatory, JSON, 'vtraffic', INPUT/OUTPUT)
Usage
Returns
Resource::VIface object
Exceptions
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 844 def viface_attach(vnodename,vifacename,desc) begin vnode = vnode_get(vnodename) viface = viface_get(vnodename,vifacename) downkeys(desc) desc['vnetwork'] = desc['vnetwork'].gsub(' ','_') if desc['vnetwork'] raise Lib::MissingParameterError, "address|vnetwork" if \ ((!desc['address'] or desc['address'].empty?) \ and (!desc['vnetwork'] or desc['vnetwork'].empty?)) vplatform = @daemon_resources address = '' if desc['address'] and !desc['address'].empty? begin address = IPAddress.parse(desc['address']) rescue ArgumentError raise Lib::InvalidParameterError, desc['address'] end prop = desc['address'] vnetwork = vplatform.get_vnetwork_by_address(prop) end if (!desc.has_key?('macaddress')) || (desc['macaddress'] == nil) || (desc['macaddress'] == '') @@mac_id_lock.synchronize { mac_suffix = [@@mac_id/65536, @@mac_id%65536/256, @@mac_id%65536%256].map {|i| i.to_s(16).rjust(2,"0")}.join(":") viface.macaddress = "#{MAC_PREFIX}:#{mac_suffix}" @@mac_id += 1 } else if desc['macaddress'].match(/^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$/) viface.macaddress = desc['macaddress'] else raise Lib::InvalidParameterError, desc['macaddress'] end end if desc['vnetwork'] and !desc['vnetwork'].empty? prop = desc['vnetwork'] vnetwork = vplatform.get_vnetwork_by_name(prop) end raise Lib::ResourceNotFoundError, "vnetwork:#{prop}" unless vnetwork if desc['address'] vnetwork.add_vnode(vnode,viface,address) else vnetwork.add_vnode(vnode,viface) end desc.delete('address') desc.delete('vnetwork') vtraffic_update(vnode.name,viface.name,desc) unless desc.empty? return viface rescue Lib::AlreadyExistingResourceError raise rescue Exception vnetwork.remove_vnode(vnode) if vnetwork raise end end |
- (Object) viface_create(vnodename, vifacename, desc)
Create a new virtual interface on the targeted virtual node (without attaching it to any network -> no ip address)
Attributes
-
name
the name of the virtual interface (need to be unique on this virtual node)
Returns
Resource::VIface object
Exceptions
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 780 def viface_create(vnodename,vifacename,desc) begin vifacename = vifacename.gsub(' ','_') vnode = vnode_get(vnodename) downkeys(desc) default = desc.has_key?('default') ? desc['default'] : false viface = Resource::VIface.new(vifacename,vnode,default) vnode.add_viface(viface) viface_update(vnode.name,viface.name,desc) return viface rescue Lib::AlreadyExistingResourceError raise rescue Exception vnode.remove_viface(viface) if vnode and viface raise end end |
- (Object) viface_detach(vnodename, vifacename)
Disconnect a virtual network interface from every networks it's connected to
Attributes
-
vnodename
The VNode name (String) -
vifacename
The VIface name (String)
Returns
Resource::PNode object
Exceptions
916 917 918 919 920 921 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 916 def viface_detach(vnodename,vifacename) viface = viface_get(vnodename,vifacename) viface.detach() return viface end |
- (Object) viface_get(vnodename, vifacename, raising = true)
Get the description of a virtual network interface
Returns
Resource::VIface object
Exceptions
928 929 930 931 932 933 934 935 936 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 928 def viface_get(vnodename,vifacename,raising = true) vifacename = vifacename.gsub(' ','_') vnode = vnode_get(vnodename,raising) viface = vnode.get_viface_by_name(vifacename) raise Lib::ResourceNotFoundError, vifacename if raising and !viface return viface end |
- (Object) viface_remove(vnodename, vifacename)
Remove the virtual interface
Returns
Resource::VIface object
Exceptions
803 804 805 806 807 808 809 810 811 812 813 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 803 def viface_remove(vnodename,vifacename) vnode = vnode_get(vnodename) @daemon_resources_lock.synchronize { vnode.host.local_vifaces -= 1 if vnode.host } viface = viface_get(vnodename,vifacename) viface_detach(vnode.name,viface.name) vnode.remove_viface(viface) return viface end |
- (Object) viface_update(vnodename, vifacename, desc)
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 815 def viface_update(vnodename,vifacename,desc) ret = nil downkeys(desc) if !desc or desc.empty? ret = viface_detach(vnodename,vifacename) else if (desc.keys - ['input'] - ['output']).size == 0 #only vtraffic change ret = vtraffic_update(vnodename,vifacename,desc) else ret = viface_attach(vnodename,vifacename,desc) end end return ret end |
- (Object) vinput_get(vnodename, vifacename, raising = true)
959 960 961 962 963 964 965 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 959 def vinput_get(vnodename,vifacename, raising = true) viface = viface_get(vnodename,vifacename) raise Lib::UninitializedResourceError, 'input' if raising and !viface.vinput return viface.vinput end |
- (Object) vinput_update(vnodename, vifacename, desc)
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 967 def vinput_update(vnodename,vifacename,desc) vnode = vnode_get(vnodename) viface = viface_get(vnodename,vifacename) downkeys(desc) if desc and !desc.empty? viface.vinput = Resource::VIface::VTraffic.new(viface, Resource::VIface::VTraffic::Direction::INPUT,desc) else viface.vinput = nil end if vnode.status == Resource::Status::RUNNING vnode.status = Resource::Status::CONFIGURING cl = NetAPI::Client.new(vnode.host.address, 4568) cl.vinput_update(vnode.name,viface.name,desc) vnode.status = Resource::Status::RUNNING end return viface.vinput end |
- (Object) vmem_create(vnodename, opts)
1593 1594 1595 1596 1597 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1593 def vmem_create(vnodename, opts) vnode = vnode_get(vnodename) vnode.add_vmem(opts) return opts end |
- (Object) vnetwork_create(name, address, opts = nil)
Create a new virtual network specifying his range of IP address (IPv4 atm).
Attributes
-
name
the -unique- name of the virtual network (it will be used in a lot of methods) -
address
the address in the CIDR (10.0.0.1/24) or IP/NetMask (10.0.0.1/255.255.255.0) format -
opts
Returns
Resource::VNetwork object
Exceptions
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1252 def vnetwork_create(name,address,opts=nil) begin if name name = name.gsub(' ','_') else name = "vnetwork#{@vnet_id}" @vnet_id += 1 end if !opts opts = {} end if opts.has_key?('network_type') raise Lib::InvalidParameterError, opts['network_type'] if !['classical','vxlan'].include?(opts['network_type']) else opts['network_type'] = 'classical' end if opts['network_type'] == 'vxlan' opts['vxlan_id'] = @@vxlan_id @@vxlan_id_lock.synchronize { @@vxlan_id += 1 } opts['vxlan_mcast_id'] = @@vxlan_mcast_id end vnetwork = Resource::VNetwork.new(address, name, @daemon_resources.pnodes.length, opts) @daemon_resources.add_vnetwork(vnetwork) return vnetwork rescue Lib::AlreadyExistingResourceError raise rescue Exception destroy(vnetwork) if vnetwork raise end end |
- (Object) vnetwork_get(name, raising = true)
Get the description of a virtual network
Returns
Resource::VNetwork object
Exceptions
1323 1324 1325 1326 1327 1328 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1323 def vnetwork_get(name,raising = true) name = name.gsub(' ','_') vnetwork = @daemon_resources.get_vnetwork_by_name(name) raise Lib::ResourceNotFoundError, name if raising and !vnetwork return vnetwork end |
- (Object) vnetwork_remove(name)
Delete the virtual network
Returns
Resource::VNetwork object
Exceptions
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1292 def vnetwork_remove(name) vnetwork = vnetwork_get(name) vnetwork.vnodes.each_pair do |vnode,viface| viface_detach(vnode.name,viface.name) end @daemon_resources.remove_vnetwork(vnetwork) vnetwork.visibility.each do |pnode| if (pnode.status == Resource::Status::RUNNING) cl = NetAPI::Client.new(pnode.address.to_s, 4568) cl.vnetwork_remove(vnetwork.name) end end return vnetwork end |
- (Object) vnetwork_sync(vnet, pnode, lock = true)
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1211 def vnetwork_sync(vnet, pnode, lock=true) block = Proc.new do if !vnet.visibility.include?(pnode) vnet.visibility << pnode cl = NetAPI::Client.new(pnode.address.to_s, 4568) # Adding VNetwork on the pnode opts = vnet.opts opts['nb_pnodes'] = @daemon_resources.pnodes.length opts['pnode_index'] = @daemon_resources.pnodes.keys.index(pnode.address.to_s) cl.vnetwork_create(vnet.name,vnet.address.to_string,opts) # Adding VRoutes to the new VNetwork vnet.vroutes.values.each do |vroute| vnetwork_sync(vroute.dstnet,pnode,false) cl.vroute_create(vnet.name,vroute.dstnet.name,vroute.gw.to_s) end end end if lock @@lockslock.synchronize { @@locks[:vnetsync][pnode] = Mutex.new unless \ @@locks[:vnetsync][pnode] } @@locks[:vnetsync][pnode].synchronize do block.call end else block.call end end |
- (Object) vnetworks_get
Get the list of the the currently created virtual networks
Returns
Array of Resource::VNetwork objects
Exceptions
1335 1336 1337 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1335 def vnetworks_get() return @daemon_resources.vnetworks end |
- (Object) vnetworks_remove
Delete every virtual networks
Returns
Array of Resource::VNetwork objects
Exceptions
1312 1313 1314 1315 1316 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1312 def vnetworks_remove() vnetworks = @daemon_resources.vnetworks vnetworks.each_value { |vnetwork| vnetwork_remove(vnetwork.name) } return vnetworks end |
- (Object) vnode_attach(name, host)
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 439 def vnode_attach(name,host) vnode = vnode_get(name) pnode = @daemon_resources.get_pnode_by_address(host) if pnode raise Lib::UninitializedResourceError, pnode.address.to_s unless \ pnode.status == Resource::Status::RUNNING else raise Lib::ResourceNotFoundError host if host end if vnode.host and vnode.status == Resource::Status::RUNNING raise Lib::AlreadyExistingResourceError, 'host' else vnode.host = pnode end return vnode end |
- (Object) vnode_create(names, desc, ssh_key = {}, async = false)
Create a virtual node using a compressed file system image.
Attributes
-
name
the -unique- name of the virtual node to create (it will be used in a lot of methods) -
properties
target,image,async,fs_shared,ssh_key
Returns
Resource::VNode object
Exceptions
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 327 def vnode_create(names,desc,ssh_key={},async=false) begin async = parse_bool(async) downkeys(desc) raise Lib::ArgumentMissingError "names" if !names names = [names] if !names.is_a?(Array) names = names.map { |name| name.gsub(' ','_') } vnodes = [] names.each { |name| vnode = Resource::VNode.new(name,ssh_key) @daemon_resources.add_vnode(vnode) vnodes << vnode } # Creation of an interface connected to the administration network if @admin_network desc['vifaces'] = [] if !desc.has_key?('vifaces') desc['vifaces'] << { 'name' => 'ifadm', 'vnetwork' => ADMIN_NETWORK_NAME } if desc['vifaces'].select {|viface| viface['vnetwork'] == ADMIN_NETWORK_NAME}.empty? end vnode_update(names,desc,async) return vnodes rescue Lib::AlreadyExistingResourceError raise rescue Exception raise end end |
- (Object) vnode_execute(vnodename, command)
Execute and get the result of a command on a virtual node
Attributes
-
command
the command to be executed
Returns
Hash object: { 'command' => <the command that was executed>, 'result' => <the result of the command> }
Exceptions
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1174 def vnode_execute(vnodename,command) ret = "" # >>> TODO: check if vnode exists vnode = vnode_get(vnodename) raise unless vnode raise Lib::UninitializedResourceError, vnode.name unless \ vnode.status == Resource::Status::RUNNING ret = Daemon::Admin.vnode_run(vnode,command) return ret end |
- (Object) vnode_get(name, raising = true)
Get the description of a virtual node
Returns
Resource::VNode object
Exceptions
463 464 465 466 467 468 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 463 def vnode_get(name, raising = true) name = name.gsub(' ','_') vnode = @daemon_resources.get_vnode(name) raise Lib::ResourceNotFoundError, name if raising and !vnode return vnode end |
- (Object) vnode_get_info(vnodename)
Get the description of a vnode
299 300 301 302 303 304 305 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 299 def vnode_get_info(vnodename) vnode = vnode_get(vnodename).dup if vnode.filesystem && vnode.filesystem.image vnode.filesystem.image = CGI.unescape(vnode.filesystem.image) end return vnode end |
- (Object) vnode_mode_update(name, mode)
Change the mode of a virtual node (normal or gateway)
Attributes
-
mode
“Normal” or “Gateway”
Returns
Resource::VNode object
Exceptions
748 749 750 751 752 753 754 755 756 757 758 759 760 761 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 748 def vnode_mode_update(name,mode) vnode = vnode_get(name) case mode.upcase when Resource::VNode::MODE_GATEWAY.upcase vnode.gateway = true when Resource::VNode::MODE_NORMAL.upcase vnode.gateway = false else raise Lib::InvalidParameterError, "mode:#{mode}" end return vnode end |
- (Object) vnode_remove(names)
Remove the virtual node (“Cascade” removing -> remove all the vroutes it apears as gateway)
Returns
Resource::VNode object
Exceptions
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 397 def vnode_remove(names) names = [names] if !names.is_a?(Array) vnodes = names.map { |name| vnode_get(name) } ret = vnodes.dup vnodes_to_remove = [] vnodes.each { |vnode| raise Lib::BusyResourceError, "#{vnode.name}/running" if vnode.status == Resource::Status::RUNNING vnode.vifaces.each { |viface| viface_remove(vnode.name,viface.name) } @daemon_resources_lock.synchronize { vnode.remove_vcpu() vnode.remove_vmem() if vnode.vmem } vnodes_to_remove << vnode if vnode.host @daemon_resources.remove_vnode(vnode) } vnodesperpnode = Hash.new vnodes_to_remove.each { |vnode| vnodesperpnode[vnode.host.address.to_s] = [] if !vnodesperpnode.has_key?(vnode.host.address.to_s) vnodesperpnode[vnode.host.address.to_s] << vnode } w = Distem::Lib::Synchronization::SlidingWindow.new(WINDOW_SIZE) vnodesperpnode.each { |address,vn| block = Proc.new { cl = NetAPI::Client.new(address, 4568) cl.vnodes_remove(vn) } w.add(block) } w.run return ret end |
- (Object) vnode_start(names, async = false)
Same as vnode_set_status(name,Resource::Status::RUNNING,properties)
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 498 def vnode_start(names,async=false) async = parse_bool(async) vnodes = [] vnodes_previous_status = {} names.each { |name| vnode = vnode_get(name) raise Lib::BusyResourceError, vnode.name if \ vnode.status == Resource::Status::CONFIGURING raise Lib::ResourceError, "#{vnode.name} already running" if \ vnode.status == Resource::Status::RUNNING vnodes_previous_status[name] = vnode.status vnode.status = Resource::Status::CONFIGURING if (vnodes_previous_status[name] != Resource::Status::DOWN) @daemon_resources_lock.synchronize { if vnode.host if ((vnode.host.local_vifaces + vnode.vifaces.length) > Node::Admin.vifaces_max) raise Lib::UnavailableResourceError, "Maximum ifaces number of #{Node::Admin.vifaces_max} reached" else vnode.host.local_vifaces += vnode.vifaces.length end else vnode.host = @daemon_resources.get_pnode_available(vnode) end vnode.host.memory.allocate({:mem => vnode.vmem.mem, :swap => vnode.vmem.swap}) if vnode.vmem vnode.vcpu.attach if vnode.vcpu and !vnode.vcpu.attached? } end vnodes << vnode } vnodesperpnode = Hash.new vnodes.each { |vnode| vnodesperpnode[vnode.host.address.to_s] = [] if !vnodesperpnode.has_key?(vnode.host.address.to_s) vnodesperpnode[vnode.host.address.to_s] << vnode } blocks = [] vnodesperpnode.each { |address,vn| blocks << Proc.new { vnodes_to_start = vn.map { |vnode| vnode if (vnodes_previous_status[vnode.name] == Resource::Status::DOWN) }.compact vnodes_to_create = vn.map { |vnode| vnode if (vnodes_previous_status[vnode.name] != Resource::Status::DOWN) }.compact cl = NetAPI::Client.new(address, 4568) ret = nil if vnodes_to_start # Just restart the node n = vnodes_to_start.map { |vnode| vnode.name } ret = cl.vnodes_start(n, async) vnodes_to_start.each_index { |i| updateobj_vnode(vnodes_to_start[i],ret[i]) vnodes_to_start[i].status = Resource::Status::RUNNING } end if vnodes_to_create descs = [] # Create VNetworks on remote PNode # TODO: vectorize vnetwork_sync vnodes_to_create.each { |vnode| vnode.get_vnetworks.each do |vnet| vnetwork_sync(vnet,vnode.host) end desc = TopologyStore::HashWriter.new.visit(vnode) desc['status'] = Resource::Status::RUNNING descs << desc } n = vnodes_to_create.map { |vnode| vnode.name } # we want the node to be runned ret = cl.vnodes_create(n,descs) vnodes_to_create.each_index { |i| updateobj_vnode(vnodes_to_create[i],ret[i]) vnodes_to_create[i].status = Resource::Status::RUNNING } end } } w = Distem::Lib::Synchronization::SlidingWindow.new(WINDOW_SIZE) if async thr = Thread.new { blocks.each { |block| w.add(block) } w.run } thr.abort_on_exception = true else blocks.each { |block| w.add(block) } w.run end return vnodes end |
- (Object) vnode_status_update(names, status, async = false)
Change the status of the -previously created- virtual node.
Attributes
-
status
the status to set: “Running” or “Down” -
properties
async
Returns
Resource::VNode object
Exceptions
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 479 def vnode_status_update(names,status,async=false) async = parse_bool(async) vnodes = [] raise Lib::InvalidParameterError, status unless \ Resource::Status.valid?(status) if status.upcase == Resource::Status::RUNNING vnodes = vnodes_start(names,async) elsif status.upcase == Resource::Status::DOWN vnodes = vnodes_stop(names,async) elsif status.upcase == Resource::Status::INIT #Just do nothing else raise Lib::InvalidParameterError, status end return vnodes end |
- (Object) vnode_stop(names, async = false)
Same as vnode_set_status(name,Resource::Status::DOWN,properties)
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 599 def vnode_stop(names, async=false) async = parse_bool(async) names = [names] if !names.is_a?(Array) vnodes = names.map { |name| vnode_get(name) } status = {} vnodes.each { |vnode| status[vnode.name] = vnode.status raise Lib::BusyResourceError, vnode.name if vnode.status == Resource::Status::CONFIGURING # raise Lib::UninitializedResourceError, vnode.name if vnode.status == Resource::Status::INIT vnode.status = Resource::Status::CONFIGURING } block = Proc.new { vnodesperpnode = Hash.new vnodes.each { |vnode| #Discard vnodes that are not yet initialized if status[vnode.name] != Resource::Status::INIT vnodesperpnode[vnode.host.address.to_s] = [] if !vnodesperpnode.has_key?(vnode.host.address.to_s) vnodesperpnode[vnode.host.address.to_s] << vnode end } w = Distem::Lib::Synchronization::SlidingWindow.new(WINDOW_SIZE) vnodesperpnode.each { |address,vn| sub_block = Proc.new { n = vn.map { |vnode| vnode.name } Distem.client(address, 4568) do |cl| cl.vnodes_stop(n,false) end } w.add(sub_block) } w.run vnodes.each { |vnode| vnode.status = Resource::Status::DOWN } } if async thr = Thread.new { block.call } thr.abort_on_exception = true else block.call end return vnodes end |
- (Object) vnode_update(names, description, async = false)
Update the vnode resource
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 356 def vnode_update(names,description,async=false) async = parse_bool(async) names = [names] if !names.is_a?(Array) vnodes = [] downkeys(description) names.each { |name| desc = Marshal.load(Marshal.dump(description)) vnode = vnode_get(name) vnode.sshkey = desc['ssh_key'] if desc['ssh_key'] and \ (desc['ssh_key'].is_a?(Hash) or desc['ssh_key'].nil?) vnode_attach(vnode.name,desc['host']) if desc['host'] vfilesystem_create(vnode.name,desc['vfilesystem']) if desc['vfilesystem'] if desc['vcpu'] if vnode.vcpu vcpu_update(vnode.name,desc['vcpu']) else vcpu_create(vnode.name,desc['vcpu']) end end if desc['vifaces'] desc['vifaces'].each do |ifdesc| if vnode.get_viface_by_name(ifdesc['name']) viface_update(vnode.name,ifdesc['name'],ifdesc) else viface_create(vnode.name,ifdesc['name'],ifdesc) end end end vmem_create(vnode.name, desc['vmem']) if desc['vmem'] vnode_mode_update(vnode.name,desc['mode']) if desc['mode'] vnodes << vnode } vnode_status_update(names,description['status'],async) if description['status'] return vnodes end |
- (Object) vnodes_execute(names, command)
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1186 def vnodes_execute(names, command) names = [names] if !names.is_a?(Array) vnodes = names.map { |name| vnode_get(name) } ret = {} vnodesperpnode = Hash.new vnodes.each { |vnode| vnodesperpnode[vnode.host.address.to_s] = [] if !vnodesperpnode.has_key?(vnode.host.address.to_s) vnodesperpnode[vnode.host.address.to_s] << vnode } tmp_ret = {} w = Distem::Lib::Synchronization::SlidingWindow.new(WINDOW_SIZE) vnodesperpnode.each { |address,vn| sub_block = Proc.new { n = vn.map { |vnode| vnode.name } Distem.client(address, 4568) do |cl| tmp_ret[address] = cl.vnodes_execute(n, command) end } w.add(sub_block) } w.run tmp_ret.each_value {|v| ret.merge!(v)} return ret end |
- (Object) vnodes_freeze(names, async = false)
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 652 def vnodes_freeze(names, async=false) async = parse_bool(async) vnodes = names.map { |name| vnode_get(name) } vnodes.each { |vnode| raise Lib::BusyResourceError, vnode.name if vnode.status == Resource::Status::CONFIGURING raise Lib::UninitializedResourceError, vnode.name if vnode.status == Resource::Status::INIT vnode.status = Resource::Status::CONFIGURING } block = Proc.new { vnodesperpnode = Hash.new vnodes.each { |vnode| vnodesperpnode[vnode.host.address.to_s] = [] if !vnodesperpnode.has_key?(vnode.host.address.to_s) vnodesperpnode[vnode.host.address.to_s] << vnode } w = Distem::Lib::Synchronization::SlidingWindow.new(WINDOW_SIZE) vnodesperpnode.each { |address,vn| sub_block = Proc.new { n = vn.map { |vnode| vnode.name } Distem.client(address, 4568) do |cl| cl.vnodes_freeze(n, async) end } w.add(sub_block) } w.run vnodes.each { |vnode| vnode.status = Resource::Status::FROZEN } } if async thr = Thread.new { block.call } thr.abort_on_exception = true else block.call end return vnodes end |
- (Object) vnodes_get
Get the list of the the currently created virtual nodes
Returns
Array of Resource::PNode objects
Exceptions
768 769 770 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 768 def vnodes_get() return @daemon_resources.vnodes end |
- (Object) vnodes_get_info
Get the description of the vnodes
308 309 310 311 312 313 314 315 316 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 308 def vnodes_get_info() vnodes = vnodes_get().dup vnodes.each_value { |vnode| if vnode.filesystem && vnode.filesystem.image vnode.filesystem.image = CGI.unescape(vnode.filesystem.image) end } return vnodes end |
- (Object) vnodes_remove(names)
Remove the given virtual nodes, or every if names is nil
Returns
Array of Resource::PNode objects
Exceptions
434 435 436 437 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 434 def vnodes_remove(names) names = @daemon_resources.vnodes.keys if !names return vnode_remove(names) end |
- (Object) vnodes_start(names, async = false)
593 594 595 596 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 593 def vnodes_start(names, async=false) async = parse_bool(async) return vnode_start(names, async) end |
- (Object) vnodes_stop(names, async = false)
646 647 648 649 650 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 646 def vnodes_stop(names, async=false) async = parse_bool(async) names = @daemon_resources.vnodes if !names return vnode_stop(names,async) end |
- (Object) vnodes_unfreeze(names, async = false)
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 697 def vnodes_unfreeze(names, async=false) async = parse_bool(async) vnodes = names.map { |name| vnode_get(name) } vnodes.each { |vnode| raise Lib::BusyResourceError, vnode.name if vnode.status != Resource::Status::FROZEN vnode.status = Resource::Status::CONFIGURING } block = Proc.new { vnodesperpnode = Hash.new vnodes.each { |vnode| vnodesperpnode[vnode.host.address.to_s] = [] if !vnodesperpnode.has_key?(vnode.host.address.to_s) vnodesperpnode[vnode.host.address.to_s] << vnode } w = Distem::Lib::Synchronization::SlidingWindow.new(WINDOW_SIZE) vnodesperpnode.each { |address,vn| sub_block = Proc.new { n = vn.map { |vnode| vnode.name } Distem.client(address, 4568) do |cl| cl.vnodes_unfreeze(n, async) end } w.add(sub_block) } w.run vnodes.each { |vnode| vnode.status = Resource::Status::RUNNING } } if async thr = Thread.new { block.call } thr.abort_on_exception = true else block.call end return vnodes end |
- (Object) voutput_get(vnodename, vifacename, raising = true)
990 991 992 993 994 995 996 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 990 def voutput_get(vnodename,vifacename, raising = true) viface = viface_get(vnodename,vifacename) raise Lib::UninitializedResourceError, 'voutput' if raising and !viface.voutput return viface.voutput end |
- (Object) voutput_update(vnodename, vifacename, desc)
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 998 def voutput_update(vnodename,vifacename,desc) vnode = vnode_get(vnodename) viface = viface_get(vnodename,vifacename) downkeys(desc) if desc and !desc.empty? viface.voutput = Resource::VIface::VTraffic.new(viface, Resource::VIface::VTraffic::Direction::OUTPUT,desc) else viface.voutput = nil end if vnode.status == Resource::Status::RUNNING vnode.status = Resource::Status::CONFIGURING cl = NetAPI::Client.new(vnode.host.address, 4568) cl.voutput_update(vnode.name,viface.name,desc) vnode.status = Resource::Status::RUNNING end return viface.voutput end |
- (Object) vplatform_create(format, data, rootfs = nil)
Load a configuration
Attributes
-
data
data to be applied -
format
the format of the data -
rootfs
the rootfs to boot vnodes
Returns
Resource::VPlatform object
Exceptions
1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1460 def vplatform_create(format,data,rootfs=nil) # >>> TODO: check if there is already a created vplatform raise Lib::MissingParameterError, 'data' unless data parser = nil desc = {} case format.upcase when 'JSON' desc = JSON.parse(data) when 'SIMGRID' raise Lib::MissingParameterError, 'rootfs' unless rootfs parser = TopologyStore::SimgridReader.new(rootfs) desc = parser.parse(data) else raise Lib::InvalidParameterError, format end # Creating vnetworks if desc['vplatform']['vnetworks'] desc['vplatform']['vnetworks'].each do |v| vnetdesc = v[1] vnetwork_create(vnetdesc['name'],vnetdesc['address']) end end # Creating the vnodes if desc['vplatform']['vnodes'] desc['vplatform']['vnodes'].each do |v| vnodedesc = v[1] vnode_create([vnodedesc['name']], vnodedesc).first end end # Creating VRoutes #vroute_complete() if desc['vplatform']['vnetworks'] desc['vplatform']['vnetworks'].each do |v| vnetdesc = v[1] if vnetdesc['vroutes'] vnetdesc['vroutes'].each do |vr| vroutedesc = vr[1] vroute_create(vroutedesc['networksrc'],vroutedesc['networkdst'], vroutedesc['gateway']) end end end end return @daemon_resources end |
- (Object) vplatform_get
Get the description file of the current platform in a specified format (JSON if not specified)
Returns
String value that reprents the platform in the format form
Exceptions
1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1511 def vplatform_get() visitor = TopologyStore::HashWriter.new h = visitor.visit(@daemon_resources) if h["vplatform"]["vnodes"] && !h["vplatform"]["vnodes"].empty? h["vplatform"]["vnodes"].each { |v| vnode = v[1] if vnode["vfilesystem"]["image"] vnode["vfilesystem"]["image"] = CGI.unescape(vnode["vfilesystem"]["image"]) end } end return JSON.pretty_generate(h) end |
- (Object) vroute_complete
Try to create every possible virtual routes between the current set of virtual nodes automagically finding and setting up the gateways to use
Returns
Array of Resource::VRoute objects
Exceptions
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1405 def vroute_complete() ret = [] # >>> TODO: Use vnetworks_get @daemon_resources.vnetworks.each_value do |srcnet| @daemon_resources.vnetworks.each_value do |destnet| next if (srcnet == destnet) or (srcnet == @admin_network) or (destnet == @admin_network) gw = srcnet.perform_vroute(destnet,@admin_network) if gw vnode_mode_update(gw.name,Resource::VNode::MODE_GATEWAY) unless gw.gateway ret << vroute_create(srcnet.name,destnet.name,gw.name) end end end end |
- (Object) vroute_create(networksrc, networkdst, nodegw)
Create a virtual route (“go from <networkname> to <destnetwork> via <gatewaynode>”). The virtual route is applied to all the vnodes of <networkname>. This method automagically set <gatewaynode> in gateway mode (if it's not already the case) and find the right virtual interface to set the virtual route on
Attributes
-
destnetwork
the name of the destination network -
gatewaynode
the name of the virtual node to use as a gateway
Deprecated: * vnode
the virtual node to set the virtual route
on (optional)
Returns
Resource::VRoute object
Exceptions
1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1350 def vroute_create(networksrc,networkdst,nodegw) begin srcnet = vnetwork_get(networksrc) raise Lib::ResourceNotFoundError, networksrc unless srcnet destnet = vnetwork_get(networkdst) raise Lib::ResourceNotFoundError, networkdst unless destnet found = false if IPAddress.valid?(nodegw) @daemon_resources.vnodes.each_value { |vnode| vnode.vifaces.each { |viface| if viface.address.address == nodegw nodegw = vnode.name found = true break end } break if found } end gw = vnode_get(nodegw) raise Lib::ResourceNotFoundError, nodegw unless gw gwaddr = gw.get_viface_by_network(srcnet) gwaddr = gwaddr.address if gwaddr raise Lib::InvalidParameterError, nodegw unless gwaddr vroute = srcnet.get_vroute(destnet) unless vroute vroute = Resource::VRoute.new(srcnet,destnet,gwaddr) srcnet.add_vroute(vroute) end raise Lib::InvalidParameterError, "#{gw.name}->#{srcnet}" unless gw.connected_to?(srcnet) vnode_mode_update(gw.name,Resource::VNode::MODE_GATEWAY) unless gw.gateway srcnet.visibility.each do |pnode| if (pnode.status == Resource::Status::RUNNING) cl = NetAPI::Client.new(pnode.address.to_s, 4568) vnetwork_sync(destnet,pnode) cl.vroute_create(srcnet.name,destnet.name,gwaddr.to_s) end end return vroute rescue Lib::AlreadyExistingResourceError raise rescue Exception destroy(vroute) if srcnet raise end end |
- (Object) vtraffic_update(vnodename, vifacename, desc)
Configure the virtual traffic on a virtual network interface, replacing previous values
Attributes
-
vnodename
The VNode name (String) -
vifacename
The VIface name (String) -
desc
Hash that represents the VTraffic description (see Lib::Validator)
Returns
Resource::VIface object
Exceptions
947 948 949 950 951 952 953 954 955 956 957 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 947 def vtraffic_update(vnodename,vifacename,desc) vnode = vnode_get(vnodename) viface = viface_get(vnodename,vifacename) downkeys(desc) voutput_update(vnode.name,viface.name,desc['output']) if desc['output'] vinput_update(vnode.name,viface.name,desc['input']) if desc['input'] return viface end |
- (Object) wait_vnodes(opts)
1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 |
# File 'lib/distem/daemon/distemcoordinator.rb', line 1621 def wait_vnodes(opts) vnodes = nil timeout = 600 port = 22 if opts if opts.has_key?('vnodes') && (opts['vnodes'] != nil) vnodes = opts['vnodes'].is_a?(Array) ? opts['vnodes'] : [ opts['vnodes'] ] end if opts.has_key?('timeout') && (opts['timeout'] != nil) timeout = opts['timeout'] end if opts.has_key?('port') && (opts['port'] != nil) port = opts['port'] end end vnodesbyhost = nil #group vnodes by pnode if vnodes vnodesbyhost = {} vnodes.each { |name| vnode = vnode_get(name) host = vnode.host.address.to_s vnodesbyhost[host] = [] if !vnodesbyhost.has_key?(host) vnodesbyhost[host] << vnode.name } end w = Distem::Lib::Synchronization::SlidingWindow.new(WINDOW_SIZE) ret = {} if vnodesbyhost vnodesbyhost.each_pair { |pnodeaddress,vn| block = Proc.new { cl = NetAPI::Client.new(pnodeaddress, 4568) ret[pnodeaddress] = cl.wait_vnodes({'port' => port, 'vnodes' => vn, 'timeout' => timeout}) } w.add(block) } else @daemon_resources.pnodes.each_value {|pnode| block = Proc.new { cl = NetAPI::Client.new(pnode.address.to_s, 4568) ret[pnode.address.to_s] = cl.wait_vnodes({'port' => port, 'vnodes' => nil, 'timeout' => timeout}) } w.add(block) } end w.run return ret.values.include?(false) ? ['false'] : ['true'] end |