Class: OpenNebula::Role
- Inherits:
-
Object
- Object
- OpenNebula::Role
- Defined in:
- lib/models/role.rb
Overview
Service Role class
Constant Summary collapse
- SCHEDULE_ACTIONS =
Actions that can be performed on the VMs of a given Role
%w[ terminate terminate-hard undeploy undeploy-hard hold release stop suspend resume reboot reboot-hard poweroff poweroff-hard snapshot-create snapshot-revert snapshot-delete disk-snapshot-create disk-snapshot-revert disk-snapshot-delete ]
- STATE =
{ 'PENDING' => 0, 'DEPLOYING' => 1, 'RUNNING' => 2, 'UNDEPLOYING' => 3, 'WARNING' => 4, 'DONE' => 5, 'FAILED_UNDEPLOYING' => 6, 'FAILED_DEPLOYING' => 7, 'SCALING' => 8, 'FAILED_SCALING' => 9, 'COOLDOWN' => 10 }
- STATE_STR =
%w[ PENDING DEPLOYING RUNNING UNDEPLOYING WARNING DONE FAILED_UNDEPLOYING FAILED_DEPLOYING SCALING FAILED_SCALING COOLDOWN ]
- RECOVER_DEPLOY_STATES =
%w[ FAILED_DEPLOYING DEPLOYING PENDING ]
- RECOVER_UNDEPLOY_STATES =
%w[ FAILED_UNDEPLOYING UNDEPLOYING ]
- RECOVER_SCALE_STATES =
%w[ FAILED_SCALING SCALING ]
- VM_FAILURE_STATES =
%w[ BOOT_FAILURE BOOT_MIGRATE_FAILURE PROLOG_MIGRATE_FAILURE PROLOG_FAILURE EPILOG_FAILURE EPILOG_STOP_FAILURE EPILOG_UNDEPLOY_FAILURE PROLOG_MIGRATE_POWEROFF_FAILURE PROLOG_MIGRATE_SUSPEND_FAILURE PROLOG_MIGRATE_UNKNOWN_FAILURE BOOT_UNDEPLOY_FAILURE BOOT_STOPPED_FAILURE PROLOG_RESUME_FAILURE PROLOG_UNDEPLOY_FAILURE ]
- SCALE_WAYS =
{ 'UP' => 0, 'DOWN' => 1 }
- IMMUTABLE_ATTRS =
List of attributes that can’t be changed in update operation cardinality: this is internal information managed by OneFlow server last_vmname: this is internal information managed by OneFlow server nodes: this is internal information managed by OneFlow server parents: this has only sense in deploy operation state: this is internal information managed by OneFlow server vm_template: this will affect scale operation
%w[ cardinality last_vmname nodes parents state vm_template ]
- VM_INFO =
VM information to save in document
%w[ID UID GID UNAME GNAME NAME]
- LOG_COMP =
'ROL'
Instance Attribute Summary collapse
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Class Method Summary collapse
-
.init_default_cooldown(default_cooldown) ⇒ Object
rubocop:disable Style/ClassVars.
- .init_default_shutdown(shutdown_action) ⇒ Object
- .init_default_vm_name_template(vm_name_template) ⇒ Object
- .init_force_deletion(force_deletion) ⇒ Object
-
.vm_failure?(vm_state, lcm_state) ⇒ true, false
Returns true if the VM state is failure.
Instance Method Summary collapse
-
#batch_action(action, period, vms_per_period, args) ⇒ Object
Schedule the given action on all the VMs that belong to the Role.
- #can_recover_deploy? ⇒ Boolean
- #can_recover_scale? ⇒ Boolean
- #can_recover_undeploy? ⇒ Boolean
-
#cardinality ⇒ Integer
Returns the role cardinality.
-
#check_new_template(template) ⇒ Boolean, String
Check that changes values are correct.
-
#chown(uid, gid) ⇒ Array<true, nil>, Array<false, String>
Changes the owner/group of all the nodes in this role.
- #clean_scale_way ⇒ Object
- #cooldown ⇒ Object
-
#delete ⇒ Array<true, nil>
Delete all the nodes in this role.
-
#deploy ⇒ Array<true, nil>, Array<false, String>
Deploys all the nodes in this role were created, false and the error reason if there was a problem creating the VMs.
- #elasticity_policies ⇒ Object
-
#info ⇒ nil, OpenNebula::Error
Retrieves the VM information for each Node in this Role.
- #info_nodes(vm_pool) ⇒ Object
-
#initialize(body, service) ⇒ Role
constructor
A new instance of Role.
-
#max_cardinality ⇒ Integer?
Returns the role max cardinality.
-
#min_cardinality ⇒ Integer?
Returns the role min cardinality.
- #name ⇒ Object
-
#nodes ⇒ Array
Returns the nodes of the role.
- #nodes_ids ⇒ Object
-
#parents ⇒ Array
Returns the role parents.
-
#recover_deploy(report) ⇒ Object
Recover.
-
#recover_scale(report) ⇒ Object
def recover_warning end.
- #recover_undeploy ⇒ Object
-
#scale?(vm_pool) ⇒ Array<Integer>
Returns a positive, 0, or negative number of nodes to adjust, according to the elasticity and scheduled policies.
- #scale_way(way) ⇒ Object
- #scheduled_policies ⇒ Object
-
#set_cardinality(target_cardinality) ⇒ Object
Sets a new cardinality for this role rubocop:disable Naming/AccessorMethodName.
-
#set_state(state) ⇒ true, false
Sets a new state rubocop:disable Naming/AccessorMethodName.
-
#shutdown(recover) ⇒ Array<true, nil>, Array<false, String>
Terminate all the nodes in this role.
-
#state ⇒ Integer
Returns the role state.
-
#state_str ⇒ String
Returns the string representation of the service state.
-
#update(template) ⇒ nil, OpenNebula::Error
Updates the role.
- #update_cooldown(new_cooldown) ⇒ Object
- #update_elasticity_policies(new_policies) ⇒ Object
- #update_scheduled_policies(new_policies) ⇒ Object
Constructor Details
#initialize(body, service) ⇒ Role
Returns a new instance of Role.
144 145 146 147 148 149 150 |
# File 'lib/models/role.rb', line 144 def initialize(body, service) @body = body @service = service @body['cooldown'] = @@default_cooldown if @body['cooldown'].nil? @body['nodes'] ||= [] end |
Instance Attribute Details
#service ⇒ Object (readonly)
Returns the value of attribute service.
32 33 34 |
# File 'lib/models/role.rb', line 32 def service @service end |
Class Method Details
.init_default_cooldown(default_cooldown) ⇒ Object
rubocop:disable Style/ClassVars
652 653 654 |
# File 'lib/models/role.rb', line 652 def self.init_default_cooldown(default_cooldown) @@default_cooldown = default_cooldown end |
.init_default_shutdown(shutdown_action) ⇒ Object
656 657 658 |
# File 'lib/models/role.rb', line 656 def self.init_default_shutdown(shutdown_action) @@default_shutdown = shutdown_action end |
.init_default_vm_name_template(vm_name_template) ⇒ Object
664 665 666 |
# File 'lib/models/role.rb', line 664 def self.init_default_vm_name_template(vm_name_template) @@vm_name_template = vm_name_template end |
.init_force_deletion(force_deletion) ⇒ Object
660 661 662 |
# File 'lib/models/role.rb', line 660 def self.init_force_deletion(force_deletion) @@force_deletion = force_deletion end |
.vm_failure?(vm_state, lcm_state) ⇒ true, false
Returns true if the VM state is failure
639 640 641 642 643 644 645 646 647 648 649 |
# File 'lib/models/role.rb', line 639 def self.vm_failure?(vm_state, lcm_state) vm_state_str = VirtualMachine::VM_STATE[vm_state.to_i] lcm_state_str = VirtualMachine::LCM_STATE[lcm_state.to_i] if vm_state_str == 'ACTIVE' && VM_FAILURE_STATES.include?(lcm_state_str) return true end false end |
Instance Method Details
#batch_action(action, period, vms_per_period, args) ⇒ Object
Schedule the given action on all the VMs that belong to the Role
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 592 593 594 595 596 597 598 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 |
# File 'lib/models/role.rb', line 554 def batch_action(action, period, vms_per_period, args) vms_id = [] error_msgs = [] nodes = @body['nodes'] now = Time.now.to_i time_offset = 0 # if role is done, return error if state == 5 return OpenNebula::Error.new("Role #{name} is in DONE state") end do_offset = (!period.nil? && period.to_i > 0 && !vms_per_period.nil? && vms_per_period.to_i > 0) nodes.each_with_index do |node, index| vm_id = node['deploy_id'] vm = OpenNebula::VirtualMachine.new_with_id(vm_id, @service.client) rc = vm.info if OpenNebula.is_error?(rc) msg = "Role #{name} : VM #{vm_id} monitorization failed;"\ " #{rc.}" error_msgs << msg Log.error LOG_COMP, msg, @service.id @service.log_error(msg) else ids = vm.retrieve_elements('USER_TEMPLATE/SCHED_ACTION/ID') id = 0 if !ids.nil? && !ids.empty? ids.map! {|e| e.to_i } id = ids.max + 1 end tmp_str = vm.user_template_str if do_offset offset = (index / vms_per_period.to_i).floor time_offset = offset * period.to_i end tmp_str << "\nSCHED_ACTION = [" tmp_str << "ID = #{id}," tmp_str << "ACTION = #{action}," tmp_str << "ARGS = \"#{args}\"," if args tmp_str << "TIME = #{now + time_offset}]" rc = vm.update(tmp_str) if OpenNebula.is_error?(rc) msg = "Role #{name} : VM #{vm_id} error scheduling "\ "action; #{rc.}" error_msgs << msg Log.error LOG_COMP, msg, @service.id @service.log_error(msg) else vms_id << vm.id end end end log_msg = "Action:#{action} scheduled on Role:#{name}"\ "VMs:#{vms_id.join(',')}" Log.info LOG_COMP, log_msg, @service.id return [true, log_msg] if error_msgs.empty? error_msgs << log_msg [false, error_msgs.join('\n')] end |
#can_recover_deploy? ⇒ Boolean
162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/models/role.rb', line 162 def can_recover_deploy? if state != STATE['PENDING'] return RECOVER_DEPLOY_STATES.include? STATE_STR[state] end parents.each do |parent| next unless @service.roles[parent] return false if @service.roles[parent].state != STATE['RUNNING'] end true end |
#can_recover_scale? ⇒ Boolean
192 193 194 195 196 |
# File 'lib/models/role.rb', line 192 def can_recover_scale? return false unless RECOVER_SCALE_STATES.include? STATE_STR[state] true end |
#can_recover_undeploy? ⇒ Boolean
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/models/role.rb', line 176 def can_recover_undeploy? if !RECOVER_UNDEPLOY_STATES.include? STATE_STR[state] # TODO, check childs if !empty? check if can be undeployed @service.roles.each do |role_name, role| next if role_name == name if role.parents.include?(name) && role.state != STATE['DONE'] return false end end end true end |
#cardinality ⇒ Integer
Returns the role cardinality
206 207 208 |
# File 'lib/models/role.rb', line 206 def cardinality @body['cardinality'].to_i end |
#check_new_template(template) ⇒ Boolean, String
Check that changes values are correct
711 712 713 714 715 716 717 718 719 |
# File 'lib/models/role.rb', line 711 def check_new_template(template) IMMUTABLE_ATTRS.each do |attr| next if template[attr] == @body[attr] return [false, "role/#{attr}"] end [true, nil] end |
#chown(uid, gid) ⇒ Array<true, nil>, Array<false, String>
Changes the owner/group of all the nodes in this role
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 |
# File 'lib/models/role.rb', line 519 def chown(uid, gid) nodes.each do |node| vm_id = node['deploy_id'] Log.debug LOG_COMP, "Role #{name} : Chown for VM #{vm_id}", @service.id vm = OpenNebula::VirtualMachine.new_with_id(vm_id, @service.client) rc = vm.chown(uid, gid) if OpenNebula.is_error?(rc) msg = "Role #{name} : Chown failed for VM #{vm_id}; " \ "#{rc.}" Log.error LOG_COMP, msg, @service.id @service.log_error(msg) return [false, rc.] else Log.debug LOG_COMP, "Role #{name} : Chown success for VM #{vm_id}", @service.id end end [true, nil] end |
#clean_scale_way ⇒ Object
356 357 358 |
# File 'lib/models/role.rb', line 356 def clean_scale_way @body.delete('scale_way') end |
#cooldown ⇒ Object
314 315 316 |
# File 'lib/models/role.rb', line 314 def cooldown @body['cooldown'] end |
#delete ⇒ Array<true, nil>
Delete all the nodes in this role
507 508 509 |
# File 'lib/models/role.rb', line 507 def delete raise 'role.delete is not defined' end |
#deploy ⇒ Array<true, nil>, Array<false, String>
Deploys all the nodes in this role were created, false and the error reason if there was a problem creating the VMs
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 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 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/models/role.rb', line 373 def deploy deployed_nodes = [] n_nodes = cardinality - nodes.size return [deployed_nodes, nil] if n_nodes == 0 @body['last_vmname'] ||= 0 template_id = @body['vm_template'] template = OpenNebula::Template.new_with_id(template_id, @service.client) if @body['vm_template_contents'] extra_template = @body['vm_template_contents'].dup # If the extra_template contains APPEND="<attr1>,<attr2>", it # will add the attributes that already exist in the template, # instead of replacing them. append = extra_template .match(/^\s*APPEND=\"?(.*?)\"?\s*$/)[1] .split(',') rescue nil if append && !append.empty? rc = template.info if OpenNebula.is_error?(rc) msg = "Role #{name} : Info template #{template_id};" \ " #{rc.}" Log.error LOG_COMP, msg, @service.id @service.log_error(msg) return [false, 'Error fetching Info to instantiate' \ " VM Template #{template_id} in Role " \ "#{name}: #{rc.}"] end et = template.template_like_str('TEMPLATE', true, append.join('|')) et = et << "\n" << extra_template extra_template = et end else extra_template = '' end extra_template << "\nSERVICE_ID = #{@service.id}" extra_template << "\nROLE_NAME = \"#{@body['name']}\"" n_nodes.times do 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', @body['last_vmname'].to_s) @body['last_vmname'] += 1 Log.debug LOG_COMP, "Role #{name} : Trying to instantiate " \ "template #{template_id}, with name #{vm_name}", @service.id vm_id = template.instantiate(vm_name, false, extra_template) deployed_nodes << vm_id if OpenNebula.is_error?(vm_id) msg = "Role #{name} : Instantiate failed for template " \ "#{template_id}; #{vm_id.}" Log.error LOG_COMP, msg, @service.id @service.log_error(msg) return [false, 'Error trying to instantiate the VM ' \ "Template #{template_id} in Role " \ "#{name}: #{vm_id.}"] end Log.debug LOG_COMP, "Role #{name} : Instantiate success," \ " VM ID #{vm_id}", @service.id node = { 'deploy_id' => vm_id } vm = OpenNebula::VirtualMachine.new_with_id(vm_id, @service.client) rc = vm.info if OpenNebula.is_error?(rc) node['vm_info'] = nil else hash_vm = vm.to_hash['VM'] vm_info = {} vm_info['VM'] = hash_vm.select {|v| VM_INFO.include?(v) } node['vm_info'] = vm_info end @body['nodes'] << node end [deployed_nodes, nil] end |
#elasticity_policies ⇒ Object
298 299 300 |
# File 'lib/models/role.rb', line 298 def elasticity_policies @body['elasticity_policies'] end |
#info ⇒ nil, OpenNebula::Error
Retrieves the VM information for each Node in this Role. If a Node is to be disposed and it is found in DONE, it will be cleaned
365 366 367 |
# File 'lib/models/role.rb', line 365 def info raise 'role.info is not defined' end |
#info_nodes(vm_pool) ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/models/role.rb', line 263 def info_nodes(vm_pool) ret = [] monitoring = vm_pool[:monitoring] vm_pool = vm_pool[:vm_pool] @body['nodes'].each do |node| id = node['deploy_id'] vm = vm_pool.retrieve_xmlelements("/VM_POOL/VM[ID=#{id}]")[0] if vm.nil? Log.error LOG_COMP, "Error getting VM #{id}", @service.id else obj = {} obj['deploy_id'] = node['deploy_id'] hash = vm.to_hash vm_monit = monitoring.select {|v| v['ID'].to_i == id }[0] hash['VM']['MONITORING'] = vm_monit if vm_monit obj['vm_info'] = hash ret << obj end end ret end |
#max_cardinality ⇒ Integer?
Returns the role max cardinality
233 234 235 236 237 238 239 |
# File 'lib/models/role.rb', line 233 def max_cardinality max = @body['max_vms'] return if max.nil? max.to_i end |
#min_cardinality ⇒ Integer?
Returns the role min cardinality
243 244 245 246 247 248 249 |
# File 'lib/models/role.rb', line 243 def min_cardinality min = @body['min_vms'] return if min.nil? min.to_i end |
#name ⇒ Object
152 153 154 |
# File 'lib/models/role.rb', line 152 def name @body['name'] end |
#nodes ⇒ Array
Returns the nodes of the role
259 260 261 |
# File 'lib/models/role.rb', line 259 def nodes @body['nodes'] end |
#nodes_ids ⇒ Object
294 295 296 |
# File 'lib/models/role.rb', line 294 def nodes_ids @body['nodes'].map {|node| node['deploy_id'] } end |
#parents ⇒ Array
Returns the role parents
200 201 202 |
# File 'lib/models/role.rb', line 200 def parents @body['parents'] || [] end |
#recover_deploy(report) ⇒ Object
Recover
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 |
# File 'lib/models/role.rb', line 725 def recover_deploy(report) nodes = @body['nodes'] deployed_nodes = [] nodes.each do |node| vm_id = node['deploy_id'] vm = OpenNebula::VirtualMachine.new_with_id(vm_id, @service.client) rc = vm.info if OpenNebula.is_error?(rc) msg = "Role #{name} : Retry failed for VM "\ "#{vm_id}; #{rc.}" Log.error LOG_COMP, msg, @service.id next true end vm_state = vm.state lcm_state = vm.lcm_state # ACTIVE/RUNNING next false if vm_state == 3 && lcm_state == 3 && !report next true if vm_state == '6' # Delete DONE nodes if Role.vm_failure?(vm_state, lcm_state) rc = vm.recover(2) if OpenNebula.is_error?(rc) msg = "Role #{name} : Retry failed for VM "\ "#{vm_id}; #{rc.}" Log.error LOG_COMP, msg, @service.id @service.log_error(msg) else deployed_nodes << vm_id end else vm.resume deployed_nodes << vm_id end end rc = deploy deployed_nodes.concat(rc[0]) if rc[1].nil? deployed_nodes end |
#recover_scale(report) ⇒ Object
def recover_warning end
792 793 794 795 796 797 798 799 800 801 802 |
# File 'lib/models/role.rb', line 792 def recover_scale(report) rc = nil if @body['scale_way'] == SCALE_WAYS['UP'] rc = [recover_deploy(report), true] elsif @body['scale_way'] == SCALE_WAYS['DOWN'] rc = [recover_undeploy, false] end rc end |
#recover_undeploy ⇒ Object
779 780 781 782 783 784 785 786 787 |
# File 'lib/models/role.rb', line 779 def recover_undeploy undeployed_nodes = [] rc = shutdown(true) undeployed_nodes.concat(rc[0]) if rc[1].nil? undeployed_nodes end |
#scale?(vm_pool) ⇒ Array<Integer>
Returns a positive, 0, or negative number of nodes to adjust,
according to the elasticity and scheduled policies
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 |
# File 'lib/models/role.rb', line 808 def scale?(vm_pool) elasticity_pol = @body['elasticity_policies'] scheduled_pol = @body['scheduled_policies'] elasticity_pol ||= [] scheduled_pol ||= [] scheduled_pol.each do |policy| diff, cooldown_duration = scale_time?(policy) return [diff, cooldown_duration] if diff != 0 end elasticity_pol.each do |policy| diff, cooldown_duration = scale_attributes?(policy, vm_pool) next if diff == 0 cooldown_duration = @body['cooldown'] if cooldown_duration.nil? cooldown_duration = @@default_cooldown if cooldown_duration.nil? return [diff, cooldown_duration] end # Implicit rule that scales up to maintain the min_cardinality, with # no cooldown period if cardinality < min_cardinality.to_i return [min_cardinality.to_i - cardinality, 0] end [0, 0] end |
#scale_way(way) ⇒ Object
352 353 354 |
# File 'lib/models/role.rb', line 352 def scale_way(way) @body['scale_way'] = SCALE_WAYS[way] end |
#scheduled_policies ⇒ Object
306 307 308 |
# File 'lib/models/role.rb', line 306 def scheduled_policies @body['scheduled_policies'] end |
#set_cardinality(target_cardinality) ⇒ Object
Sets a new cardinality for this role rubocop:disable Naming/AccessorMethodName
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/models/role.rb', line 213 def set_cardinality(target_cardinality) # rubocop:enable Naming/AccessorMethodName if target_cardinality > cardinality dir = 'up' else dir = 'down' end msg = "Role #{name} scaling #{dir} from #{cardinality} to " \ "#{target_cardinality} nodes" Log.info LOG_COMP, msg, @service.id @service.log_info(msg) @body['cardinality'] = target_cardinality.to_i end |
#set_state(state) ⇒ true, false
Sets a new state rubocop:disable Naming/AccessorMethodName
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/models/role.rb', line 326 def set_state(state) # rubocop:enable Naming/AccessorMethodName if state < 0 || state > STATE_STR.size return false end @body['state'] = state.to_i if state == STATE['SCALING'] elasticity_pol = @body['elasticity_policies'] if !elasticity_pol.nil? elasticity_pol.each do |policy| policy.delete('true_evals') end end end Log.info LOG_COMP, "Role #{name} new state: #{STATE_STR[state]}", @service.id true end |
#shutdown(recover) ⇒ Array<true, nil>, Array<false, String>
Terminate all the nodes in this role
were terminated, false and the error reason if there was a problem shutting down the VMs
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/models/role.rb', line 488 def shutdown(recover) if nodes.size != cardinality n_nodes = nodes.size - cardinality else n_nodes = nodes.size end rc = shutdown_nodes(nodes, n_nodes, recover) unless rc[0] return [false, "Error undeploying nodes for role `#{name}`"] end [rc[1], nil] end |
#state ⇒ Integer
Returns the role state
158 159 160 |
# File 'lib/models/role.rb', line 158 def state @body['state'].to_i end |
#state_str ⇒ String
Returns the string representation of the service state
253 254 255 |
# File 'lib/models/role.rb', line 253 def state_str STATE_STR[state] end |
#update(template) ⇒ nil, OpenNebula::Error
Updates the role
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 |
# File 'lib/models/role.rb', line 677 def update(template) force = template['force'] == true new_cardinality = template['cardinality'] return if new_cardinality.nil? new_cardinality = new_cardinality.to_i if !force if new_cardinality < min_cardinality.to_i return OpenNebula::Error.new( "Minimum cardinality is #{min_cardinality}" ) elsif !max_cardinality.nil? && new_cardinality > max_cardinality.to_i return OpenNebula::Error.new( "Maximum cardinality is #{max_cardinality}" ) end end set_cardinality(new_cardinality) nil end |
#update_cooldown(new_cooldown) ⇒ Object
318 319 320 |
# File 'lib/models/role.rb', line 318 def update_cooldown(new_cooldown) @body['cooldown'] = new_cooldown unless new_cooldown.nil? end |
#update_elasticity_policies(new_policies) ⇒ Object
302 303 304 |
# File 'lib/models/role.rb', line 302 def update_elasticity_policies(new_policies) @body['elasticity_policies'] = new_policies end |
#update_scheduled_policies(new_policies) ⇒ Object
310 311 312 |
# File 'lib/models/role.rb', line 310 def update_scheduled_policies(new_policies) @body['scheduled_policies'] = new_policies end |