Class: ForemanVirtWhoConfigure::Config
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ForemanVirtWhoConfigure::Config
- Includes:
- Authorizable, Encryptable
- Defined in:
- app/models/foreman_virt_who_configure/config.rb
Constant Summary collapse
- PERMITTED_PARAMS =
[ :interval, :organization_id, :compute_resource_id, :whitelist, :blacklist, :hypervisor_id, :hypervisor_type, :hypervisor_server, :hypervisor_username, :hypervisor_password, :debug, :satellite_url, :proxy, :no_proxy, :name, # API parameter filtering_mode gets translated to listing_mode in the controller # We keep both params permitted for compatibility with 1.11 :listing_mode, :filtering_mode ]
- UNLIMITED =
0
- WHITELIST =
1
- BLACKLIST =
2
- FILTERING_MODES =
{ UNLIMITED.to_s => N_('Unlimited'), WHITELIST.to_s => N_('Whitelist'), BLACKLIST.to_s => N_('Blacklist'), }
- WIZARD_STEPS =
{ 'general_information' => N_('General information'), 'schedule' => N_('Schedule'), 'connection' => N_('Connection') }
- HYPERVISOR_IDS =
[ 'hostname', 'uuid', 'hwuuid' ]
- HYPERVISOR_TYPES =
{ 'esx' => 'VMware vSphere / vCenter (esx)', 'rhevm' => 'Red Hat Virtualization Hypervisor (rhevm)', # 'vdsm' => 'Red Hat Enterprise Linux Hypervisor (vdsm)', 'hyperv' => 'Microsoft Hyper-V (hyperv)', 'xen' => 'XenServer (xen)', 'libvirt' => 'libvirt' }
- HYPERVISOR_DEFAULT_TYPE =
'esx'
- AVAILABLE_INTERVALS =
{ '60' => N_('Every hour'), '120' => N_('Every 2 hours'), '240' => N_('Every 4 hours'), '480' => N_('Every 8 hours'), '720' => N_('Every 12 hours'), }
- DEFAULT_INTERVAL =
120
- STATUSES =
{ 'ok' => N_('OK'), 'out_of_date' => N_('No change'), 'unknown' => N_('Unknown') }
- STATUS_DESCRIPTIONS =
Hash.new(N_('Unknown configuration status, caused by unexpected conditions')).merge( { :unknown => N_('The configuration was not deployed yet or the virt-who was unable to report the status'), :ok => N_('The virt-who report arrived within the interval'), :out_of_date => N_('The virt-who report has not arrived within the interval, which indicates there was no change on hypervisor') } )
Class Method Summary collapse
Instance Method Summary collapse
- #create_service_user ⇒ Object
- #destroy_service_user ⇒ Object
-
#humanized_interval ⇒ Object
mapping of supported CR types case config.compute_resource when Foreman::Model::Libvirt ‘libvirt’ when Foreman::Model::Vmware ‘esx’ when Foreman::Model::Ovirt ‘rhevm’ else raise ‘unsupported compute resource type’ end.
- #out_of_date?(deadline = DateTime.now.utc) ⇒ Boolean
- #status ⇒ Object
- #status_description ⇒ Object
- #step_name(step_key) ⇒ Object
- #steps ⇒ Object
- #virt_who_bash_script ⇒ Object
- #virt_who_config_command ⇒ Object
- #virt_who_config_script(format = nil) ⇒ Object
- #virt_who_touch! ⇒ Object
Class Method Details
.search_by_status(key, operator, value) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/models/foreman_virt_who_configure/config.rb', line 108 def self.search_by_status(key, operator, value) condition = case value when 'ok' sanitize_sql_for_conditions([' out_of_date_at >= ? ', DateTime.now.utc.to_s(:db)]) when 'unknown' sanitize_sql_for_conditions({:last_report_at => nil}) when 'out_of_date' sanitize_sql_for_conditions([' out_of_date_at < ? ', DateTime.now.utc.to_s(:db)]) end { :conditions => condition } end |
Instance Method Details
#create_service_user ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/models/foreman_virt_who_configure/config.rb', line 120 def create_service_user password = User.random_password service_user = self.build_service_user user = service_user.build_user user.auth_source = AuthSourceHiddenWithAuthentication.default user.password = password user.login = "virt_who_reporter_#{self.id}" user.organizations = [ self.organization ] user.roles = [ Role.where(:name => 'Virt-who Reporter').first ] user.valid? # to trigger password hashing user.save!(:validate => false) service_user.encrypted_password = password service_user.save! self.update_attribute :service_user_id, service_user.id end |
#destroy_service_user ⇒ Object
138 139 140 141 142 143 |
# File 'app/models/foreman_virt_who_configure/config.rb', line 138 def destroy_service_user # skip validation that prevents hidden user deletion user = service_user.user service_user.destroy user.delete end |
#humanized_interval ⇒ Object
mapping of supported CR types case config.compute_resource
when Foreman::Model::Libvirt
'libvirt'
when Foreman::Model::Vmware
'esx'
when Foreman::Model::Ovirt
'rhevm'
else
raise 'unsupported compute resource type'
end
157 158 159 |
# File 'app/models/foreman_virt_who_configure/config.rb', line 157 def humanized_interval _("every %s hours") % (self.interval / 60) end |
#out_of_date?(deadline = DateTime.now.utc) ⇒ Boolean
161 162 163 |
# File 'app/models/foreman_virt_who_configure/config.rb', line 161 def out_of_date?(deadline = DateTime.now.utc) self.out_of_date_at.present? && self.out_of_date_at < deadline end |
#status ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 |
# File 'app/models/foreman_virt_who_configure/config.rb', line 196 def status case when self.last_report_at.nil? :unknown when !self.out_of_date? :ok else # out of date is currently considered ok too, virt-who does not send any report if there's no change on hypervisor :out_of_date end end |
#status_description ⇒ Object
208 209 210 |
# File 'app/models/foreman_virt_who_configure/config.rb', line 208 def status_description _(STATUS_DESCRIPTIONS[status]) end |
#step_name(step_key) ⇒ Object
165 166 167 |
# File 'app/models/foreman_virt_who_configure/config.rb', line 165 def step_name(step_key) _(WIZARD_STEPS[step_key]) end |
#steps ⇒ Object
169 170 171 |
# File 'app/models/foreman_virt_who_configure/config.rb', line 169 def steps WIZARD_STEPS.keys end |
#virt_who_bash_script ⇒ Object
173 174 175 |
# File 'app/models/foreman_virt_who_configure/config.rb', line 173 def virt_who_bash_script virt_who_config_script(:bash_script) end |
#virt_who_config_command ⇒ Object
186 187 188 |
# File 'app/models/foreman_virt_who_configure/config.rb', line 186 def virt_who_config_command "hammer virt-who-config deploy --id #{self.id}" end |
#virt_who_config_script(format = nil) ⇒ Object
177 178 179 180 181 182 183 184 |
# File 'app/models/foreman_virt_who_configure/config.rb', line 177 def virt_who_config_script(format = nil) generator = OutputGenerator.new(self) if generator.ready_for_virt_who_output? generator.virt_who_output(format) else generator..join("\n") end end |
#virt_who_touch! ⇒ Object
190 191 192 193 194 |
# File 'app/models/foreman_virt_who_configure/config.rb', line 190 def virt_who_touch! self.last_report_at = DateTime.now.utc self.out_of_date_at = self.last_report_at + self.interval.minutes self.save! end |