Class: IONe::PostDeployActivities

Inherits:
Object
  • Object
show all
Includes:
Deferable
Defined in:
lib/creative_funcs/main.rb

Overview

Class for pst-deploy activities methods All methods will receive creative methods params, new vm ID, and host, where VM was deployed

Instance Method Summary collapse

Methods included from Deferable

#defer

Constructor Details

#initialize(client) ⇒ PostDeployActivities

Returns a new instance of PostDeployActivities



438
439
440
# File 'lib/creative_funcs/main.rb', line 438

def initialize client
    @ione = IONe.new(client, $db)
end

Instance Method Details

#AnsibleController(params, vmid, host = nil) ⇒ Object

Executes given playbooks at fresh-deployed vm



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
# File 'lib/creative_funcs/main.rb', line 443

def AnsibleController(params, vmid, host = nil)
    LOG_CALL(id = id_gen(), true, __method__)
    onblock(:vm, vmid).wait_for_state
    sleep(60)
    unless params['ansible_local_id'].nil? then
        LOG_DEBUG "Ansible Local ID: #{params['ansible_local_id']}"
        LOG_DEBUG('Starting process')
        install_process =
        AnsiblePlaybookProcess.new(
            playbook_id:    params['ansible_local_id'],
            uid:            params['userid'],
            hosts:          { vmid => ["#{@ione.GetIP(vmid)}:#{$ione_conf['OpenNebula']['users-vms-ssh-port']}"]}, #!!!
            vars:           params['ansible_vars'],
            comment:        "Post-Deploy Activity - Ansible",
            auth:           'default'
        )
        LOG_DEBUG "Proc ID #{install_process.install_id}"
        install_process.run
        LOG_DEBUG "Runned"
        params['ansible-service']
    else
        LOG_DEBUG "Starting not local playbook"
        Thread.new do
            @ione.AnsibleController(params.merge({
                'super' => '', 'host' => "#{@ione.GetIP(vmid)}:#{$ione_conf['OpenNebula']['users-vms-ssh-port']}", 'vmid' => vmid
            }))
        end
    end
    LOG_COLOR "Install-thread started, you should wait until the #{params['ansible-service']} will be installed", 'AnsibleController', 'light_yellow'
rescue => e
    LOG_DEBUG e.message
    LOG_DEBUG e.backtrace
ensure
    LOG_CALL(id, false, 'AnsibleController')
end

#LimitsController(params, vmid, host = nil) ⇒ Object

If Cluster type is vCenter, sets up Limits at the node



479
480
481
482
483
484
485
486
487
488
489
490
491
492
# File 'lib/creative_funcs/main.rb', line 479

def LimitsController(params, vmid, host = nil)
    LOG_CALL(id = id_gen(), true, __method__)
    defer { LOG_CALL(id, false, 'LimitsController') }
    onblock(:vm, vmid) do | vm |
        lim_res = vm.setResourcesAllocationLimits(
            cpu: params['cpu'] * $ione_conf['vCenter']['cpu-limits-koef'], ram: params['ram'] * (params['units'] == 'GB' ? 1024 : 1), iops: params['iops']
        )
        unless lim_res.nil? then
            err, back = lim_res.split("<|>")
            LOG_ERROR "Limits was not set, error: #{err}"
            LOG_DEBUG "Limits was not set, error: #{err}\n#{back}"
        end
    end if ClusterType(host) == 'vcenter'
end

#TrialController(params, vmid, host = nil) ⇒ Object

If VM is trial, starts time and schedule suspend method



494
495
496
497
498
499
500
501
502
503
504
505
# File 'lib/creative_funcs/main.rb', line 494

def TrialController(params, vmid, host = nil)
    LOG_CALL(id = id_gen(), true, __method__)        
    LOG "VM #{vmid} suspend action scheduled", 'TrialController'
    action_time = Time.now.to_i + ( params['trial-suspend-delay'].nil? ?
                        TRIAL_SUSPEND_DELAY :
                        params['trial-suspend-delay'] )
    onblock(:vm, vmid).wait_for_state
    if !onblock(:vm, vmid).schedule('suspend', action_time).nil? then
        LOG_ERROR 'Scheduler process error', 'TrialController'
    end
    LOG_CALL(id, false, 'TrialController')
end