class OpenNebula::VRRole
Virtual Route Role class
Attributes
service[R]
Public Instance Methods
batch_action(_, _, _, _)
click to toggle source
Scheduler
# File lib/models/vrrole.rb, line 64 def batch_action(_, _, _, _) return OpenNebula::Error.new( "Virtual Router role #{name} does not support schedule actions" ) end
chown(uid, gid)
click to toggle source
Operations
# File lib/models/vrrole.rb, line 28 def chown(uid, gid) vrouter_id = @body['vrouter_id'] vrouter = OpenNebula::VirtualRouter.new_with_id( vrouter_id, @service.client ) rc = vrouter.chown(uid, gid) if OpenNebula.is_error?(rc) msg = "Role #{name} : Chown failed for VR #{vrouter_id}; " \ "#{rc.message}" Log.error(LOG_COMP, msg, @service.id) @service.log_error(msg) return [false, rc.message] else msg = "Role #{name} : Chown success for VR #{vrouter_id}" Log.debug(LOG_COMP, msg, @service.id) end [true, nil] end
clean_scale_way()
click to toggle source
# File lib/models/vrrole.rb, line 110 def clean_scale_way [] end
cooldown()
click to toggle source
# File lib/models/vrrole.rb, line 98 def cooldown [] end
deploy()
click to toggle source
Deploys all the nodes in this role
@return [Array<true, nil>, Array<false, String>] true if all the VMs
were created, false and the error reason if there was a problem creating the VMs
# File lib/models/vrrole.rb, line 123 def deploy deployed_nodes = [] n_nodes = cardinality - nodes.size return [deployed_nodes, nil] if n_nodes == 0 vr_name = @@vr_name_template .gsub('$SERVICE_ID', @service.id.to_s) .gsub('$SERVICE_NAME', @service.name.to_s) .gsub('$ROLE_NAME', name.to_s) @body['template_contents']['NAME'] = vr_name template_id, _, extra_template = init_template_attributes # Create vrouter Object and description vrouter = VirtualRouter.new( VirtualRouter.build_xml(@service.uid), @service.client ) Log.debug( LOG_COMP, "Role #{name} : Creating service VRouter", @service.id ) # Allocating VR with role description provided rc = vrouter.allocate(extra_template) if OpenNebula.is_error?(rc) msg = "Role #{name} : Allocate failed for Vrouter " \ "#{template_id}; #{rc.message}" Log.error(LOG_COMP, msg, @service.id) @service.log_error(msg) return [false, "Error allocating Vrouter #{template_id} in Role " \ "#{name}: #{rc.message}"] end Log.debug( LOG_COMP, "Role #{name} : Instantiating VRouter #{vrouter.id}", @service.id ) # Instantiating Vrouters vm_name = @@vm_name_template .gsub('$SERVICE_ID', @service.id.to_s) .gsub('$SERVICE_NAME', @service.name.to_s) .gsub('$ROLE_NAME', name.to_s) .gsub('$VM_NUMBER', '%i') rc = vrouter.instantiate( n_nodes, template_id, vm_name, on_hold?, extra_template ) if OpenNebula.is_error?(rc) msg = "Role #{name} : Instantiate failed for Vrouter " \ "#{vrouter.id}; #{rc.message}" Log.error(LOG_COMP, msg, @service.id) @service.log_error(msg) return [false, "Error instantiating Vrouter #{vrouter.id} in Role " \ "#{name}: #{rc.message}"] end vrouter.info # Once deployed, save VM info in role node body deployed_nodes.concat(vrouter.vm_ids) deployed_nodes.each do |vm_id| fill_node_info(vm_id) end @body['vrouter_id'] = vrouter.id # Fill vrouter IP in vrouter role body vrouter_nics = vrouter.to_hash['VROUTER']['TEMPLATE']['NIC'] || [] vrouter_nics = [vrouter_nics] if vrouter_nics.is_a?(Hash) @body['vrouter_ips'] = vrouter_nics.map do |nic| next unless nic.is_a?(Hash) && nic.key?('VROUTER_IP') { 'NETWORK_ID' => nic['NETWORK_ID'].to_i, 'VROUTER_IP' => nic['VROUTER_IP'] } end.compact [deployed_nodes, nil] end
elasticity_policies()
click to toggle source
# File lib/models/vrrole.rb, line 90 def elasticity_policies [] end
max_cardinality()
click to toggle source
Returns the role max cardinality @return [Integer,nil] the role cardinality
# File lib/models/vrrole.rb, line 76 def max_cardinality return cardinality end
min_cardinality()
click to toggle source
Returns the role min cardinality @return [Integer,nil] the role cardinality
# File lib/models/vrrole.rb, line 82 def min_cardinality return cardinality end
recover_scale(_)
click to toggle source
VRs do not support scale operations, returing empty array with zero nodes deployed / shutdown
# File lib/models/vrrole.rb, line 228 def recover_scale(_) [] end
scale?(_)
click to toggle source
# File lib/models/vrrole.rb, line 86 def scale?(_) return [0, 0] end
scale_way(_)
click to toggle source
# File lib/models/vrrole.rb, line 106 def scale_way(_) [] end
shutdown_nodes(_nodes, n_nodes, _)
click to toggle source
Shutdown all nodes associated with a Virtual Router.
@param nodes [Array<Hash>] list of node definitions for the role @param n_nodes [Integer] number of nodes to shutdown @param _ [Object] unused parameter (placeholder for recover att)
@return [Array<(Boolean, Array<Integer>)>] a tuple:
- Boolean indicating overall success (`true` if VR was deleted successfully) - Array of VM IDs that were associated with the Virtual Router
If the router could not be deleted, returns `false` and an empty list.
# File lib/models/vrrole.rb, line 247 def shutdown_nodes(_nodes, n_nodes, _) vrouter_id = @body['vrouter_id'] return [true, []] if vrouter_id.nil? msg = "Role #{name} : Terminating VR #{vrouter_id} (#{n_nodes} VMs associated)" Log.debug(LOG_COMP, msg, @service.id) vrouter = OpenNebula::VirtualRouter.new_with_id(vrouter_id, @service.client) rc = vrouter.info if OpenNebula.is_error?(rc) msg = "Role #{name} : Error getting VR #{vrouter_id}: #{rc.message}" Log.error(LOG_COMP, msg, @service.id) @service.log_error(msg) return [false, []] end vm_ids = vrouter.vm_ids rc = vrouter.delete if OpenNebula.is_error?(rc) && rc.errno != OpenNebula::Error::ENO_EXISTS msg = "Role #{name} : Delete failed for VR #{vrouter_id}: #{rc.message}" Log.error(LOG_COMP, msg, @service.id) @service.log_error(msg) return [false, []] end msg = "Role #{name} : Delete success for VR #{vrouter_id}" Log.debug(LOG_COMP, msg, @service.id) [true, vm_ids] end
update(_)
click to toggle source
# File lib/models/vrrole.rb, line 54 def update(_) return OpenNebula::Error.new( "Virtual Router role #{name} does not support cardinality update" ) end
update_cooldown(_)
click to toggle source
# File lib/models/vrrole.rb, line 102 def update_cooldown(_) [] end
update_elasticity_policies(_)
click to toggle source
# File lib/models/vrrole.rb, line 94 def update_elasticity_policies(_) [] end