Class: OpenNebula::Role

Inherits:
Object
  • Object
show all
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
}
VM_INFO =

VM information to save in document

%w[ID UID GID UNAME GNAME NAME]
LOG_COMP =
'ROL'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, service) ⇒ Role

Returns a new instance of Role.



128
129
130
131
132
133
134
# File 'lib/models/role.rb', line 128

def initialize(body, service)
    @body     = body
    @service  = service

    @body['cooldown'] = @@default_cooldown if @body['cooldown'].nil?
    @body['nodes']    ||= []
end

Instance Attribute Details

#serviceObject (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



635
636
637
# File 'lib/models/role.rb', line 635

def self.init_default_cooldown(default_cooldown)
    @@default_cooldown = default_cooldown
end

.init_default_shutdown(shutdown_action) ⇒ Object



639
640
641
# File 'lib/models/role.rb', line 639

def self.init_default_shutdown(shutdown_action)
    @@default_shutdown = shutdown_action
end

.init_default_vm_name_template(vm_name_template) ⇒ Object



647
648
649
# File 'lib/models/role.rb', line 647

def self.init_default_vm_name_template(vm_name_template)
    @@vm_name_template = vm_name_template
end

.init_force_deletion(force_deletion) ⇒ Object



643
644
645
# File 'lib/models/role.rb', line 643

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

Parameters:

  • vm_state (Integer)

    VM state

  • lcm_state (Integer)

    VM LCM state

Returns:

  • (true, false)

    True if the lcm state is one of *_FAILURE



622
623
624
625
626
627
628
629
630
631
632
# File 'lib/models/role.rb', line 622

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

Parameters:

  • action (String)

    one of the available SCHEDULE_ACTIONS

  • period (Integer)
  • vm_per_period (Integer)
  • action (String)

    arguments



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
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
# File 'lib/models/role.rb', line 537

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.message}"

            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.message}"

                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

Returns:

  • (Boolean)


146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/models/role.rb', line 146

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

Returns:

  • (Boolean)


175
176
177
178
179
# File 'lib/models/role.rb', line 175

def can_recover_scale?
    return false unless RECOVER_SCALE_STATES.include? STATE_STR[state]

    true
end

#can_recover_undeploy?Boolean

Returns:

  • (Boolean)


160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/models/role.rb', line 160

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
                return false if role.state != STATE['DONE']
            end
        end
    end

    true
end

#cardinalityInteger

Returns the role cardinality

Returns:

  • (Integer)

    the role cardinality



189
190
191
# File 'lib/models/role.rb', line 189

def cardinality
    @body['cardinality'].to_i
end

#chown(uid, gid) ⇒ Array<true, nil>, Array<false, String>

Changes the owner/group of all the nodes in this role

Parameters:

  • uid (Integer)

    the new owner id. Set to -1 to leave the current

  • gid (Integer)

    the new group id. Set to -1 to leave the current

Returns:

  • (Array<true, nil>, Array<false, String>)

    true if all the VMs were updated, false and the error reason if there was a problem updating the VMs



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
# File 'lib/models/role.rb', line 502

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.message}"

            Log.error LOG_COMP, msg, @service.id
            @service.log_error(msg)

            return [false, rc.message]
        else
            Log.debug LOG_COMP,
                      "Role #{name} : Chown success for VM #{vm_id}",
                      @service.id
        end
    end

    [true, nil]
end

#clean_scale_wayObject



339
340
341
# File 'lib/models/role.rb', line 339

def clean_scale_way
    @body.delete('scale_way')
end

#cooldownObject



297
298
299
# File 'lib/models/role.rb', line 297

def cooldown
    @body['cooldown']
end

#deleteArray<true, nil>

Delete all the nodes in this role

Returns:

  • (Array<true, nil>)

    All the VMs are deleted, and the return ignored



490
491
492
# File 'lib/models/role.rb', line 490

def delete
    raise 'role.delete is not defined'
end

#deployArray<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

Returns:

  • (Array<true, nil>, Array<false, String>)

    true if all the VMs



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
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
# File 'lib/models/role.rb', line 356

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.message}"

                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.message}"]
            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.message}"

            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.message}"]
        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_policiesObject



281
282
283
# File 'lib/models/role.rb', line 281

def elasticity_policies
    @body['elasticity_policies']
end

#infonil, 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

Returns:



348
349
350
# File 'lib/models/role.rb', line 348

def info
    raise 'role.info is not defined'
end

#info_nodes(vm_pool) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/models/role.rb', line 246

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_cardinalityInteger?

Returns the role max cardinality

Returns:

  • (Integer, nil)

    the role cardinality or nil if it isn’t defined



216
217
218
219
220
221
222
# File 'lib/models/role.rb', line 216

def max_cardinality
    max = @body['max_vms']

    return if max.nil?

    max.to_i
end

#min_cardinalityInteger?

Returns the role min cardinality

Returns:

  • (Integer, nil)

    the role cardinality or nil if it isn’t defined



226
227
228
229
230
231
232
# File 'lib/models/role.rb', line 226

def min_cardinality
    min = @body['min_vms']

    return if min.nil?

    min.to_i
end

#nameObject



136
137
138
# File 'lib/models/role.rb', line 136

def name
    @body['name']
end

#nodesArray

Returns the nodes of the role

Returns:

  • (Array)

    the nodes



242
243
244
# File 'lib/models/role.rb', line 242

def nodes
    @body['nodes']
end

#nodes_idsObject



277
278
279
# File 'lib/models/role.rb', line 277

def nodes_ids
    @body['nodes'].map {|node| node['deploy_id'] }
end

#parentsArray

Returns the role parents

Returns:

  • (Array)

    the role parents



183
184
185
# File 'lib/models/role.rb', line 183

def parents
    @body['parents'] || []
end

#recover_deploy(report) ⇒ Object

Recover



692
693
694
695
696
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
740
741
742
743
744
# File 'lib/models/role.rb', line 692

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.message}"
            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.message}"

                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



759
760
761
762
763
764
765
766
767
768
769
# File 'lib/models/role.rb', line 759

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_undeployObject



746
747
748
749
750
751
752
753
754
# File 'lib/models/role.rb', line 746

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

Returns:

  • (Array<Integer>)

    positive, 0, or negative number of nodes to adjust, plus the cooldown period duration



775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
# File 'lib/models/role.rb', line 775

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



335
336
337
# File 'lib/models/role.rb', line 335

def scale_way(way)
    @body['scale_way'] = SCALE_WAYS[way]
end

#scheduled_policiesObject



289
290
291
# File 'lib/models/role.rb', line 289

def scheduled_policies
    @body['scheduled_policies']
end

#set_cardinality(target_cardinality) ⇒ Object

Sets a new cardinality for this role rubocop:disable Naming/AccessorMethodName

Parameters:

  • the (Integer)

    new cardinality



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/models/role.rb', line 196

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

Parameters:

  • the (Integer)

    new state

Returns:

  • (true, false)

    true if the value was changed



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/models/role.rb', line 309

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

Parameters:

  • scale_down (true, false)

    true to terminate and dispose the number of VMs needed to get down to cardinality nodes

Returns:

  • (Array<true, nil>, Array<false, String>)

    true if all the VMs



471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# File 'lib/models/role.rb', line 471

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

#stateInteger

Returns the role state

Returns:

  • (Integer)

    the role state



142
143
144
# File 'lib/models/role.rb', line 142

def state
    @body['state'].to_i
end

#state_strString

Returns the string representation of the service state

Returns:

  • (String)

    the state string



236
237
238
# File 'lib/models/role.rb', line 236

def state_str
    STATE_STR[state]
end

#update(template) ⇒ nil, OpenNebula::Error

Updates the role

Parameters:

  • template (Hash)

Returns:



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
# File 'lib/models/role.rb', line 660

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



301
302
303
# File 'lib/models/role.rb', line 301

def update_cooldown(new_cooldown)
    @body['cooldown'] = new_cooldown unless new_cooldown.nil?
end

#update_elasticity_policies(new_policies) ⇒ Object



285
286
287
# File 'lib/models/role.rb', line 285

def update_elasticity_policies(new_policies)
    @body['elasticity_policies'] = new_policies
end

#update_scheduled_policies(new_policies) ⇒ Object



293
294
295
# File 'lib/models/role.rb', line 293

def update_scheduled_policies(new_policies)
    @body['scheduled_policies'] = new_policies
end