Class: IONe::PostDeployActivities
- Inherits:
-
Object
- Object
- IONe::PostDeployActivities
- 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
-
#AnsibleController(params, vmid, _host = nil) ⇒ Object
Executes given playbooks at fresh-deployed vm.
-
#initialize(client) ⇒ PostDeployActivities
constructor
A new instance of PostDeployActivities.
-
#LimitsController(params, vmid, host = nil) ⇒ Object
If Cluster type is vCenter, sets up Limits at the node.
-
#TrialController(params, vmid, _host = nil) ⇒ Object
If VM is trial, starts time and schedule suspend method.
Methods included from Deferable
Constructor Details
#initialize(client) ⇒ PostDeployActivities
Returns a new instance of PostDeployActivities.
526 527 528 |
# File 'lib/creative_funcs/main.rb', line 526 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
531 532 533 534 535 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 |
# File 'lib/creative_funcs/main.rb', line 531 def AnsibleController(params, vmid, _host = nil) 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' => '', 'vmid' => vmid, 'host' => "#{@ione.GetIP(vmid)}:#{$ione_conf['OpenNebula']['users-vms-ssh-port']}" } ) ) 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. LOG_DEBUG e.backtrace end |
#LimitsController(params, vmid, host = nil) ⇒ Object
If Cluster type is vCenter, sets up Limits at the node
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 |
# File 'lib/creative_funcs/main.rb', line 571 def LimitsController(params, vmid, host = nil) onblock(:vm, vmid) do | vm | key = IONe::Settings['VCENTER_CPU_LIMIT_FREQ_PER_CORE'][host.name!].nil? ? 'default' : host.name! lim_res = vm.setResourcesAllocationLimits( cpu: params['cpu'] * IONe::Settings['VCENTER_CPU_LIMIT_FREQ_PER_CORE'][key], 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
588 589 590 591 592 593 594 595 596 597 |
# File 'lib/creative_funcs/main.rb', line 588 def TrialController(params, vmid, _host = nil) LOG "VM #{vmid} suspend action scheduled", 'TrialController' action_time = Time.now.to_i + (params['trial-suspend-delay'].nil? ? IONe::Settings['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 end |