Module: OvirtProvisionPlugin::HostExtensions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/ovirt_provision_plugin/host_extensions.rb
Instance Method Summary collapse
- #get_ovirt_client ⇒ Object
- #get_ovirt_host ⇒ Object
- #get_ovirt_host_id ⇒ Object
- #get_ovirt_host_name ⇒ Object
- #is_ovirt_node? ⇒ Boolean
- #ovirt_host? ⇒ Boolean
- #ovirt_host_callback ⇒ Object
- #status_installing? ⇒ Boolean
Instance Method Details
#get_ovirt_client ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/concerns/ovirt_provision_plugin/host_extensions.rb', line 59 def get_ovirt_client begin cr_id = parameters.find_by_name("compute_resource_id").value cr = ComputeResource.find_by_id(cr_id) connection_opts = {} if not cr.public_key.blank? connection_opts[:datacenter_id] = cr.uuid connection_opts[:ca_cert_store] = OpenSSL::X509::Store.new.add_cert(OpenSSL::X509::Certificate.new(cr.public_key)) end return OVIRT::Client.new("#{cr.user}", "#{cr.password}", "#{cr.url}", connection_opts) rescue OVIRT::OvirtException logger.error "OvirtProvisionPlugin:: compute resource id was not found" return false rescue NoMethodError logger.error "OvirtProvisionPlugin:: fail to read compute_rescource_id on host #{self.name}, id #{cr_id}" return false else logger.error "OvirtProvisionPlugin:: error occured during get_ovirt_client" return false end end |
#get_ovirt_host ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'app/models/concerns/ovirt_provision_plugin/host_extensions.rb', line 81 def get_ovirt_host client = self.get_ovirt_client if not client logger.error "OvirtProvisionPlugin:: couldn't get ovirt_host" return "" else return client.host(get_ovirt_host_id) end end |
#get_ovirt_host_id ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/models/concerns/ovirt_provision_plugin/host_extensions.rb', line 100 def get_ovirt_host_id begin return self.parameters.find_by_name("host_ovirt_id").value rescue OVIRT::OvirtException logger.error "OvirtProvisionPlugin:: host ovirt id was not found" return false rescue NoMethodError logger.error "OvirtProvisionPlugin:: fail to read host_ovirt_id on host #{self.name}" return false else logger.error "OvirtProvisionPlugin:: error occured during get_ovirt_host_id" return false end end |
#get_ovirt_host_name ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'app/models/concerns/ovirt_provision_plugin/host_extensions.rb', line 91 def get_ovirt_host_name h = self.get_ovirt_host if not h return "" else return h.name end end |
#is_ovirt_node? ⇒ Boolean
33 34 35 36 37 38 39 40 |
# File 'app/models/concerns/ovirt_provision_plugin/host_extensions.rb', line 33 def is_ovirt_node? is_ovirt_node = self..name == "oVirt-Node" or self..name == "RHEV-H" if is_ovirt_node logger.info "OvirtProvisionPlugin:: Provisioned ovirt node host" return true end return false end |
#ovirt_host? ⇒ Boolean
42 43 44 45 46 47 48 |
# File 'app/models/concerns/ovirt_provision_plugin/host_extensions.rb', line 42 def ovirt_host? if self.get_ovirt_host_id logger.info "OvirtProvisionPlugin:: host related to oVirt" return true end return false end |
#ovirt_host_callback ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/concerns/ovirt_provision_plugin/host_extensions.rb', line 5 def ovirt_host_callback logger.info "OvirtProvisionPlugin:: Running provision callback.." max_tries = 10; if self.is_ovirt_node? logger.info "OvirtProvisionPlugin:: Node provisioning is done." else while max_tries > 0 && self.ovirt_host? && self.status_installing? if (self.error?) logger.warn "OvirtProvisionPlugin:: Failed to run classes. Trying again (#{max_tries})" puppetrun! max_tries = max_tries - 1 else begin logger.info "OvirtProvisionPlugin:: Running ovirt_host_callback on \"#{self.get_ovirt_host_name}\"" host_id = self.get_ovirt_host_id client = self.get_ovirt_client client.reinstall_host("#{host_id}") logger.info "OvirtProvisionPlugin:: Sent reinstall command successfully" rescue OVIRT::OvirtException logger.warn "OvirtProvisionPlugin:: Failed to reinstall host. Trying again (#{max_tries})" puppetrun! max_tries = max_tries - 1 end end end end end |
#status_installing? ⇒ Boolean
50 51 52 53 54 55 56 57 |
# File 'app/models/concerns/ovirt_provision_plugin/host_extensions.rb', line 50 def status_installing? h = self.get_ovirt_host if h != "" && h.status.strip == "installing_os" logger.info "OvirtProvisionPlugin:: host in status installing" return true end return false end |