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



531
532
533
# File 'lib/creative_funcs/main.rb', line 531

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



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

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



572
573
574
575
576
577
578
579
580
581
582
583
584
585
# File 'lib/creative_funcs/main.rb', line 572

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.id) == 'vcenter'
end

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

If VM is trial, starts time and schedule suspend method



587
588
589
590
591
592
593
594
595
596
597
598
# File 'lib/creative_funcs/main.rb', line 587

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