Class: Host::Managed

Defined Under Namespace

Classes: Jail

Constant Summary

Constants included from Foreman::Observable

Foreman::Observable::DEFAULT_NAMESPACE

Constants inherited from Base

Base::KERNEL_RELEASE_FACTS, Base::PRIMARY_INTERFACE_ATTRIBUTES

Instance Attribute Summary

Attributes included from HostTemplateHelpers

#url_options

Attributes inherited from Base

#updated_virtuals

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HostTemplateHelpers

#install_path, #jumpstart_path, #medium_provider, #miniroot, #multiboot

Methods included from Foreman::ForemanUrlRenderer

#default_url_options, #foreman_url

Methods included from Orchestration::Realm

#del_realm, #initialize_realm, #realm?, #set_realm, #update_realm

Methods included from Orchestration::Common

#handle_validation_errors, #log_orchestration_errors

Methods included from Orchestration::SSHProvision

#ssh_provision?

Methods included from Orchestration::Compute

#compute_object, #vm_name

Methods included from Orchestration

#enable_orchestration!, #post_queue, #queue, #record_conflicts, #skip_orchestration!, #skip_orchestration?, #skip_orchestration_for_testing?, #valid?, #without_orchestration

Methods included from Orchestration::ProgressReport

#progress_report_id, #progress_report_id=

Methods included from HostCommon

#all_puppetclass_ids, #available_puppetclasses, #cg_class_ids, #classes, #classes_in_groups, #crypt_root_pass, #default_image_file, #hg_class_ids, #host_class_ids, #image_file, #image_file=, #individual_puppetclasses, #medium_provider, #parent_name, #puppet_ca_server, #puppet_ca_server_uri, #puppet_server_uri, #puppetca?, #puppetca_exists?, #puppetclass_ids, #puppetmaster, #url_for_boot

Methods included from PxeLoaderValidator

#validate_pxe_loader

Methods included from ForemanRegister::HostExtensions

#registration_facet!, #registration_template, #registration_token, #registration_url

Methods included from Foreman::ObservableModel

#event_payload_for

Methods included from Foreman::Observable

event_name_for, #trigger_hook

Methods included from HostInfoExtensions

#info

Methods included from SelectiveClone

#selective_clone

Methods included from Hostext::OperatingSystem

#available_template_kinds, #jumpstart?, #provisioning_template, #template_kinds, #templates_used

Methods included from Hostext::Token

#expire_token, #refresh_token_on_build, #set_token, #token_expired?

Methods included from Hostext::SmartProxy

#smart_proxies, #smart_proxy_ids

Methods included from Hostext::PowerInterface

#power, #supports_power?, #supports_power_and_running?

Methods inherited from Base

#==, attributes_protected_by_default, #becomes, #bond_interfaces, #bridge_interfaces, #drop_primary_interface_cache, #drop_provision_interface_cache, #dup, #facts_hash, #import_facts, import_host, #import_missing_ids, #interfaces_with_identifier, #lookup_value_match, #managed_interfaces, #matching?, #missing_ids, #orchestrated?, #overwrite=, #overwrite?, #parse_facts, #primary_interface, #primary_interface_type, #provision_interface, #reload, #render_template, #set_comment, #set_interfaces, #set_non_empty_values, #set_taxonomies, #setup_clone, #skip_orchestration?, taxonomy_conditions

Methods included from PxeLoaderSuggestion

#suggest_default_pxe_loader

Methods included from Facets::BaseHostExtensions

#apply_facet_attributes, #populate_facet_fields

Methods included from Foreman::TelemetryHelper

#telemetry_duration_histogram, #telemetry_increment_counter, #telemetry_observe_histogram, #telemetry_set_gauge

Methods included from Hostext::Ownership

#is_owned_by, #is_owned_by=, #owner, #owner_suggestion

Methods included from InterfaceCloning

#setup_clone, #setup_object_clone

Methods included from DestroyFlag

#being_destroyed?

Methods included from Authorizable

#authorized?, #check_permissions_after_save

Methods inherited from ApplicationRecord

graphql_type, #logger, logger

Methods included from AuditAssociations::AssociationsDefinitions

#audit_associations, #audited, #configure_dirty_associations, #normalize_associations

Constructor Details

#initialize(*args) ⇒ Managed

Returns a new instance of Managed.


75
76
77
78
# File 'app/models/host/managed.rb', line 75

def initialize(*args)
  args.unshift(apply_inherited_attributes(args.shift, false))
  super(*args)
end

Class Method Details

.complete_for(query, opts = {}) ⇒ Object


38
39
40
41
42
43
44
45
46
47
# File 'app/models/host/managed.rb', line 38

def self.complete_for(query, opts = {})
  matcher = /(\s*(?:(?:user\.[a-z]+)|owner)\s*[=~])\s*(\S*)\s*\z/
  matches = matcher.match(query)
  output = super(query, opts)
  if matches.present? && 'current_user'.start_with?(matches[2])
    current_user_result = query.sub(matcher, '\1 current_user')
    output = [current_user_result] + output
  end
  output
end

.count_distribution(association) ⇒ Object

counts each association of a given host e.g. how many hosts belongs to each os returns sorted hash


552
553
554
555
556
557
558
559
560
561
562
# File 'app/models/host/managed.rb', line 552

def self.count_distribution(association)
  output = []
  data = group("#{Host.table_name}.#{association}_id").reorder('').count
  associations = association.to_s.camelize.constantize.where(:id => data.keys).all
  data.each do |k, v|
    output << {:label => associations.detect { |a| a.id == k }.to_label, :data => v } unless v == 0
  rescue
    logger.info "skipped #{k} as it has has no label"
  end
  output
end

.count_habtm(association) ⇒ Object

counts each association of a given host for HABTM relationships TODO: Merge these two into one method e.g. how many hosts belongs to each os returns sorted hash


568
569
570
571
572
# File 'app/models/host/managed.rb', line 568

def self.count_habtm(association)
  counter = Host::Managed.joins(association.tableize.to_sym).group("#{association.tableize.to_sym}.id").reorder('').count
  # Puppetclass.find(counter.keys.compact)...
  association.camelize.constantize.find(counter.keys.compact).map { |i| {:label => i.to_label, :data => counter[i.id]} }
end

.find_permission_name(action) ⇒ Object

Permissions introduced by plugins for this class can cause resource <-> permission names mapping to fail randomly so as a safety precaution, we specify the name more explicitly.


363
364
365
# File 'app/models/host/managed.rb', line 363

def self.find_permission_name(action)
  "#{action}_hosts"
end

.model_nameObject


357
358
359
# File 'app/models/host/managed.rb', line 357

def self.model_name
  ActiveModel::Name.new(Host)
end

.provision_methodsObject


574
575
576
577
578
579
# File 'app/models/host/managed.rb', line 574

def self.provision_methods
  {
    'build' => N_('Network Based'),
    'image' => N_('Image Based'),
  }.merge(registered_provision_methods)
end

.registered_provision_methodsObject


581
582
583
# File 'app/models/host/managed.rb', line 581

def self.registered_provision_methods
  Foreman::Plugin.all.map(&:provision_methods).inject(:merge) || {}
end

.valid_rebuild_only_valuesObject


585
586
587
588
589
590
591
# File 'app/models/host/managed.rb', line 585

def self.valid_rebuild_only_values
  if Host::Managed.respond_to?(:rebuild_methods)
    Nic::Managed.rebuild_methods.values + Host::Managed.rebuild_methods.values
  else
    Nic::Managed.rebuild_methods.values
  end
end

Instance Method Details

#<=>(other) ⇒ Object


349
350
351
# File 'app/models/host/managed.rb', line 349

def <=>(other)
  name <=> other.name
end

#apply_compute_profile(modification) ⇒ Object


915
916
917
# File 'app/models/host/managed.rb', line 915

def apply_compute_profile(modification)
  modification.run(self, compute_resource.try(:compute_profile_for, compute_profile_id))
end

#apply_inherited_attributes(attributes, initialized = true) ⇒ Object


601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
# File 'app/models/host/managed.rb', line 601

def apply_inherited_attributes(attributes, initialized = true)
  return nil unless attributes

  attributes = hash_clone(attributes).with_indifferent_access

  new_hostgroup_id = attributes['hostgroup_id'] || attributes['hostgroup_name'] || attributes['hostgroup'].try(:id)
  # hostgroup didn't change, no inheritance needs update.
  return attributes if new_hostgroup_id.blank?

  new_hostgroup = hostgroup if initialized
  unless [new_hostgroup.try(:id), new_hostgroup.try(:friendly_id)].include? new_hostgroup_id
    new_hostgroup = Hostgroup.friendly.find(new_hostgroup_id)
  end
  return attributes unless new_hostgroup

  inherited_attributes = hostgroup_inherited_attributes - attributes.keys

  inherited_attributes.each do |attribute|
    value = new_hostgroup.send("inherited_#{attribute}")
    attributes[attribute] = value
  end

  attributes = apply_facet_attributes(new_hostgroup, attributes)
  attributes
end

#associate!(cr, vm) ⇒ Object


671
672
673
674
675
# File 'app/models/host/managed.rb', line 671

def associate!(cr, vm)
  self.uuid = vm.identity
  self.compute_resource_id = cr.id
  save!(:validate => false) # don't want to trigger callbacks
end

#attributes_to_import_from_factsObject


476
477
478
479
480
481
482
483
484
485
486
487
488
489
# File 'app/models/host/managed.rb', line 476

def attributes_to_import_from_facts
  attrs = [:architecture]
  if Setting[:update_hostgroup_from_facts]
    attrs << :hostgroup
  end
  if !Setting[:ignore_facts_for_operatingsystem] || (Setting[:ignore_facts_for_operatingsystem] && operatingsystem.blank?)
    attrs << :operatingsystem
  end
  if !Setting[:ignore_facts_for_domain] || (Setting[:ignore_facts_for_domain] && domain.blank?)
    attrs << :domain
  end

  super + attrs
end

#bare_metal_capabilitiesObject


698
699
700
# File 'app/models/host/managed.rb', line 698

def bare_metal_capabilities
  [:build]
end

#bmc_available?Boolean

Returns:

  • (Boolean)

784
785
786
787
788
# File 'app/models/host/managed.rb', line 784

def bmc_available?
  ipmi = bmc_nic
  return false if ipmi.nil?
  (ipmi.password.present? && ipmi.username.present? && ipmi.provider == 'IPMI') || ipmi.provider == 'SSH'
end

#bmc_nicObject


752
753
754
# File 'app/models/host/managed.rb', line 752

def bmc_nic
  interfaces.bmc.first
end

#bmc_proxyObject


780
781
782
# File 'app/models/host/managed.rb', line 780

def bmc_proxy
  @bmc_proxy ||= bmc_nic.proxy
end

#build_global_status(options = {}) ⇒ Object


869
870
871
# File 'app/models/host/managed.rb', line 869

def build_global_status(options = {})
  HostStatus::Global.build(host_statuses, options)
end

#build_hooksObject


80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/models/host/managed.rb', line 80

def build_hooks
  return if previous_changes['build'].nil?
  if build?
    run_callbacks :build do
      logger.debug "custom hook after_build on #{name} will be executed if defined."
      true
    end
  else
    run_callbacks :provision do
      logger.debug "custom hook before_provision on #{name} will be executed if defined."
      true
    end
  end
end

#build_status(options = {}) ⇒ Object


885
886
887
# File 'app/models/host/managed.rb', line 885

def build_status(options = {})
  @build_status ||= get_status(HostStatus::BuildStatus).to_status(options)
end

#build_status_checkerObject


831
832
833
834
835
# File 'app/models/host/managed.rb', line 831

def build_status_checker
  build_status = HostBuildStatus.new(self)
  build_status.check_all_statuses
  build_status
end

#build_status_label(options = {}) ⇒ Object


889
890
891
# File 'app/models/host/managed.rb', line 889

def build_status_label(options = {})
  @build_status_label ||= get_status(HostStatus::BuildStatus).to_label(options)
end

#built(installed = true) ⇒ Object

Called from the host build post install process to indicate that the base build has completed Build is cleared and the boot link and autosign entries are removed A site specific build script is called at this stage that can do site specific tasks


388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'app/models/host/managed.rb', line 388

def built(installed = true)
  # delete all expired tokens
  self.build        = false
  self.otp          = nil
  self.installed_at = Time.now.utc if installed

  if save
    send_built_notification if installed
    true
  else
    logger.warn "Failed to set Build on #{self}: #{errors.full_messages}"
    false
  end
end

#can_be_built?Boolean

Returns:

  • (Boolean)

593
594
595
# File 'app/models/host/managed.rb', line 593

def can_be_built?
  managed? && SETTINGS[:unattended] && !image_build? && !build?
end

#capabilitiesObject


694
695
696
# File 'app/models/host/managed.rb', line 694

def capabilities
  compute_resource ? compute_resource.capabilities : bare_metal_capabilities
end

#certnameObject

if certname does not exist, use hostname instead


684
685
686
# File 'app/models/host/managed.rb', line 684

def certname
  self[:certname] || name
end

#check_interfacesObject


747
748
749
750
# File 'app/models/host/managed.rb', line 747

def check_interfaces
  errors.add(:base, _("An interface marked as provision is missing")) if interfaces.detect(&:provision).nil?
  errors.add(:base, _("An interface marked as primary is missing")) if interfaces.detect(&:primary).nil?
end

#clear_data_on_buildObject


377
378
379
380
381
382
383
# File 'app/models/host/managed.rb', line 377

def clear_data_on_build
  return unless respond_to?(:old) && old && build? && !old.build?
  clear_facts
  clear_reports
  reported_data&.destroy
  self.build_errors = nil
end

#clear_factsObject


373
374
375
# File 'app/models/host/managed.rb', line 373

def clear_facts
  FactValue.where("host_id = #{id}").delete_all
end

#clear_reportsObject


367
368
369
370
371
# File 'app/models/host/managed.rb', line 367

def clear_reports
  # Remove any reports that may be held against this host
  Report.where("host_id = #{id}").delete_all
  self.last_report = nil
end

#cloneObject


735
736
737
738
739
740
741
742
743
744
745
# File 'app/models/host/managed.rb', line 735

def clone
  # do not copy system specific attributes
  host = selective_clone

  host.interfaces = interfaces.map(&:clone)
  if compute_resource
    host.compute_attributes = host.compute_resource.vm_compute_attributes_for(uuid)
  end
  host.refresh_global_status
  host
end

#compute?Boolean

Returns:

  • (Boolean)

334
335
336
# File 'app/models/host/managed.rb', line 334

def compute?
  false
end

#compute_profile_idObject

take from hostgroup if compute_profile_id is nil


799
800
801
# File 'app/models/host/managed.rb', line 799

def compute_profile_id
  self[:compute_profile_id] || hostgroup.try(:compute_profile_id)
end

#compute_provides?(attr) ⇒ Boolean

Returns:

  • (Boolean)

338
339
340
# File 'app/models/host/managed.rb', line 338

def compute_provides?(attr)
  false
end

#compute_resource_or_modelObject


924
925
926
927
# File 'app/models/host/managed.rb', line 924

def compute_resource_or_model
  return compute_resource.name if compute_resource
  hardware_model_name
end

#configuration?Boolean

Determine if host is setup for configuration

Returns:

  • (Boolean)

461
462
463
# File 'app/models/host/managed.rb', line 461

def configuration?
  puppet_proxy_id.present?
end

#configuration_status(options = {}) ⇒ Object


877
878
879
# File 'app/models/host/managed.rb', line 877

def configuration_status(options = {})
  @configuration_status ||= get_status(HostStatus::ConfigurationStatus).to_status(options)
end

#configuration_status_label(options = {}) ⇒ Object


881
882
883
# File 'app/models/host/managed.rb', line 881

def configuration_status_label(options = {})
  @configuration_status_label ||= get_status(HostStatus::ConfigurationStatus).to_label(options)
end

#disabled?Boolean

Returns:

  • (Boolean)

456
457
458
# File 'app/models/host/managed.rb', line 456

def disabled?
  !enabled?
end

#disassociate!Object


677
678
679
680
681
# File 'app/models/host/managed.rb', line 677

def disassociate!
  self.uuid = nil
  self.compute_resource_id = nil
  save!(:validate => false) # don't want to trigger callbacks
end

#disk_layout_sourceObject


417
418
419
420
421
422
423
424
# File 'app/models/host/managed.rb', line 417

def disk_layout_source
  @disk_layout_source ||= if disk.present?
                            Foreman::Renderer::Source::String.new(name: 'Custom disk layout',
                                                                  content: disk.tr("\r", ''))
                          elsif ptable.present?
                            Foreman::Renderer::Source::Database.new(ptable)
                          end
end

#diskLayoutObject

Raises:


437
438
439
440
441
# File 'app/models/host/managed.rb', line 437

def diskLayout
  raise Foreman::Exception, 'Neither disk nor partition table defined for host' unless disk_layout_source
  scope = Foreman::Renderer.get_scope(host: self, source: disk_layout_source)
  Foreman::Renderer.render(disk_layout_source, scope)
end

#error_countObject

reports methods


444
445
446
# File 'app/models/host/managed.rb', line 444

def error_count
  %w[failed failed_restarts].sum { |f| status f }
end

#explicit_pxe_loaderObject


807
808
809
# File 'app/models/host/managed.rb', line 807

def explicit_pxe_loader
  self[:pxe_loader].presence
end

#firmware_typeObject


919
920
921
922
# File 'app/models/host/managed.rb', line 919

def firmware_type
  return unless pxe_loader.present?
  Operatingsystem.firmware_type(pxe_loader)
end

#fqdnObject


330
331
332
# File 'app/models/host/managed.rb', line 330

def fqdn
  facts['fqdn'] || name
end

#get_status(type) ⇒ Object


860
861
862
863
864
865
866
867
# File 'app/models/host/managed.rb', line 860

def get_status(type)
  status = host_statuses.detect { |s| s.type == type.to_s }
  if status.nil?
    host_statuses.new(:host => self, :type => type.to_s)
  else
    status
  end
end

#global_status_label(options = {}) ⇒ Object


873
874
875
# File 'app/models/host/managed.rb', line 873

def global_status_label(options = {})
  HostStatus::Global.build(host_statuses, options).to_label
end

#handle_realmObject

Request a new OTP for a host


404
405
406
407
408
409
410
411
412
413
414
415
# File 'app/models/host/managed.rb', line 404

def handle_realm
  return true unless realm?

  # If no OTP is set, then this is probably a rebuild
  if otp.blank?
    logger.info "Setting realm for host #{name}"
    set_realm :rebuild => true
    save!
  else
    true
  end
end

#hash_clone(value) ⇒ Object


627
628
629
630
631
632
633
634
635
636
637
# File 'app/models/host/managed.rb', line 627

def hash_clone(value)
  if value.is_a? Hash
    # Prefer dup to constructing a new object to perserve permitted state
    # when `value` is an ActionController::Parameters instance
    new_hash = value.dup
    new_hash.each { |k, v| new_hash[k] = hash_clone(v) }
    return new_hash
  end

  value
end

#hostgroup_inherited_attributesObject


597
598
599
# File 'app/models/host/managed.rb', line 597

def hostgroup_inherited_attributes
  %w{puppet_proxy_id puppet_ca_proxy_id environment_id compute_profile_id realm_id compute_resource_id}
end

#image_build?Boolean

Returns:

  • (Boolean)

819
820
821
# File 'app/models/host/managed.rb', line 819

def image_build?
  provision_method == 'image'
end

#importNode(nodeinfo) ⇒ Object

this method accepts a puppets external node yaml output and generate a node in our setup it is assumed that you already have the node (e.g. imported by one of the rack tasks)


511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
# File 'app/models/host/managed.rb', line 511

def importNode(nodeinfo)
  myklasses = []
  # puppet classes
  classes = nodeinfo["classes"]
  classes = classes.keys if classes.is_a?(Hash)
  classes.each do |klass|
    if (pc = Puppetclass.find_by_name(klass.to_s))
      myklasses << pc
    else
      error = _("Failed to import %{klass} for %{name}: doesn't exists in our database - ignoring") % { :klass => klass, :name => name }
      logger.warn error
      $stdout.puts error
    end
    self.puppetclasses = myklasses
  end

  # parameters are a bit more tricky, as some classifiers provide the facts as parameters as well
  # not sure what is puppet priority about it, but we ignore it if has a fact with the same name.
  # additionally, we don't import any non strings values, as puppet don't know what to do with those as well.

  myparams = info["parameters"]
  nodeinfo["parameters"].each_pair do |param, value|
    next if fact_names.exists? :name => param
    next unless value.is_a?(String)

    # we already have this parameter
    next if myparams.has_key?(param) && myparams[param] == value

    unless (hp = host_parameters.create(:name => param, :value => value))
      logger.warn "Failed to import #{param}/#{value} for #{name}: #{hp.errors.full_messages.join(', ')}"
      $stdout.puts $ERROR_INFO
    end
  end

  clear_host_parameters_cache!
  save
end

#inherited_attributesObject


644
645
646
647
648
649
650
651
652
653
# File 'app/models/host/managed.rb', line 644

def inherited_attributes
  inherited_attrs = %w{domain_id}
  if SETTINGS[:unattended]
    inherited_attrs.concat(%w{operatingsystem_id architecture_id compute_resource_id})
    inherited_attrs << "subnet_id" unless compute_provides?(:ip)
    inherited_attrs << "subnet6_id" unless compute_provides?(:ip6)
    inherited_attrs.concat(%w{medium_id ptable_id pxe_loader}) unless image_build?
  end
  inherited_attrs
end

#ipmi_boot(booting_device) ⇒ Object


790
791
792
793
794
795
796
# File 'app/models/host/managed.rb', line 790

def ipmi_boot(booting_device)
  unless bmc_available?
    raise Foreman::Exception.new(
      _("No BMC NIC available for host %s") % self)
  end
  bmc_proxy.boot({:function => 'bootdevice', :device => booting_device})
end

#local_boot_template_name(kind) ⇒ Object


929
930
931
932
# File 'app/models/host/managed.rb', line 929

def local_boot_template_name(kind)
  key = "local_boot_#{kind}"
  host_params[key] || host_params[key.downcase] || Setting[key]
end

#no_reportObject


448
449
450
# File 'app/models/host/managed.rb', line 448

def no_report
  last_report.nil? || last_report < Time.now.utc - origin_interval.minutes && enabled?
end

#origin_intervalObject


452
453
454
# File 'app/models/host/managed.rb', line 452

def origin_interval
  Setting[:"#{last_report.origin.downcase}_interval"] || 0
end

#owner_nameObject


353
354
355
# File 'app/models/host/managed.rb', line 353

def owner_name
  owner.try(:name)
end

#parent_classesObject

the environment used by #clases nees to be self.environment and not self.parent.environment


466
467
468
469
# File 'app/models/host/managed.rb', line 466

def parent_classes
  return [] unless hostgroup
  hostgroup.classes(environment)
end

#parent_config_groupsObject


471
472
473
474
# File 'app/models/host/managed.rb', line 471

def parent_config_groups
  return [] unless hostgroup
  hostgroup.all_config_groups
end

#permission_name(action) ⇒ Object

Permissions introduced by plugins for this class can cause resource <-> permission names mapping to fail randomly so as a safety precaution, we specify the name more explicitly.


936
937
938
# File 'app/models/host/managed.rb', line 936

def permission_name(action)
  "#{action}_hosts"
end

#populate_fields_from_facts(parser, type, source_proxy) ⇒ Object


491
492
493
494
495
# File 'app/models/host/managed.rb', line 491

def populate_fields_from_facts(parser, type, source_proxy)
  super
  update_os_from_facts if operatingsystem_id_changed?
  populate_facet_fields(parser, type, source_proxy)
end

#providerObject


717
718
719
720
721
722
723
# File 'app/models/host/managed.rb', line 717

def provider
  if compute_resource_id
    compute_resource.provider_friendly_name
  else
    "BareMetal"
  end
end

#provision_methodObject


803
804
805
# File 'app/models/host/managed.rb', line 803

def provision_method
  self[:provision_method] || capabilities.first.to_s
end

#pxe_build?Boolean

Returns:

  • (Boolean)

823
824
825
# File 'app/models/host/managed.rb', line 823

def pxe_build?
  provision_method == 'build'
end

#pxe_loaderObject


811
812
813
# File 'app/models/host/managed.rb', line 811

def pxe_loader
  explicit_pxe_loader || hostgroup.try(:pxe_loader)
end

#pxe_loader_efi?Boolean

Returns:

  • (Boolean)

815
816
817
# File 'app/models/host/managed.rb', line 815

def pxe_loader_efi?
  pxe_loader.include?('EFI')
end

#recreate_config(only = nil) ⇒ Object

rebuilds orchestration configuration for a host takes all the methods from Orchestration modules that are registered for configuration rebuild arguments:

> only : Array of rebuild methods to execute (Example: ['TFTP'])

returns : Hash with 'true' if rebuild was a success for a given key (Example: => true, “DNS” => false)


898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
# File 'app/models/host/managed.rb', line 898

def recreate_config(only = nil)
  result = {}

  Nic::Managed.rebuild_methods_for(only).map do |method, pretty_name|
    interfaces.map do |interface|
      value = interface.send method
      result[pretty_name] = value if !result.has_key?(pretty_name) || (result[pretty_name] && !value)
    end
  end

  self.class.rebuild_methods_for(only).map do |method, pretty_name|
    raise ::Foreman::Exception.new(N_("There are orchestration modules with methods for configuration rebuild that have identical name: '%s'"), pretty_name) if result[pretty_name]
    result[pretty_name] = send method
  end
  result
end

#refresh_global_statusObject


837
838
839
# File 'app/models/host/managed.rb', line 837

def refresh_global_status
  self.global_status = build_global_status.status
end

#refresh_global_status!Object


841
842
843
844
# File 'app/models/host/managed.rb', line 841

def refresh_global_status!
  refresh_global_status
  save!(:validate => false)
end

#refresh_statuses(which = HostStatus.status_registry) ⇒ Object


846
847
848
849
850
851
852
853
# File 'app/models/host/managed.rb', line 846

def refresh_statuses(which = HostStatus.status_registry)
  which.each do |status_class|
    status = get_status(status_class)
    status.refresh! if status.relevant?
  end
  host_statuses.reload
  refresh_global_status!
end

#root_passObject

no need to store anything in the db if the password is our default


726
727
728
729
730
# File 'app/models/host/managed.rb', line 726

def root_pass
  return self[:root_pass] if self[:root_pass].present?
  return hostgroup.try(:root_pass) if hostgroup.try(:root_pass).present?
  Setting[:root_pass]
end

#set_compute_attributesObject


655
656
657
658
659
660
661
# File 'app/models/host/managed.rb', line 655

def set_compute_attributes
  if compute_profile_present?
    self.compute_attributes = compute_resource.compute_profile_attributes_for(compute_profile_id)
  elsif compute_resource
    self.compute_attributes ||= {}
  end
end

#set_hostgroup_defaults(force = false) ⇒ Object


639
640
641
642
# File 'app/models/host/managed.rb', line 639

def set_hostgroup_defaults(force = false)
  return unless hostgroup
  assign_hostgroup_attributes(inherited_attributes, force)
end

#set_ip_addressObject


663
664
665
666
667
668
669
# File 'app/models/host/managed.rb', line 663

def set_ip_address
  return unless SETTINGS[:unattended] && (new_record? || managed?)
  interfaces.select { |nic| nic.managed }.each do |nic|
    nic.ip  = nic.subnet.unused_ip(mac).suggest_ip if nic.subnet.present? && nic.ip.blank?
    nic.ip6 = nic.subnet6.unused_ip(mac).suggest_ip if nic.subnet6.present? && nic.ip6.blank?
  end
end

#setBuildObject

Called by build link in the list Build is set The boot link and autosign entry are created Any existing puppet certificates are deleted Any facts are discarded


502
503
504
505
506
507
# File 'app/models/host/managed.rb', line 502

def setBuild
  self.build = true
  self.initiated_at = Time.now.utc
  logger.warn("Set build failed: #{errors.inspect}") unless save
  errors.empty?
end

#sp_ipObject


756
757
758
# File 'app/models/host/managed.rb', line 756

def sp_ip
  bmc_nic.try(:ip)
end

#sp_macObject


760
761
762
# File 'app/models/host/managed.rb', line 760

def sp_mac
  bmc_nic.try(:mac)
end

#sp_nameObject


772
773
774
# File 'app/models/host/managed.rb', line 772

def sp_name
  bmc_nic.try(:name)
end

#sp_subnetObject


768
769
770
# File 'app/models/host/managed.rb', line 768

def sp_subnet
  bmc_nic.try(:subnet)
end

#sp_subnet_idObject


764
765
766
# File 'app/models/host/managed.rb', line 764

def sp_subnet_id
  bmc_nic.try(:subnet_id)
end

#validate_media?Boolean

Returns:

  • (Boolean)

827
828
829
# File 'app/models/host/managed.rb', line 827

def validate_media?
  managed && !image_build? && build?
end

#vm_compute_attributesObject


776
777
778
# File 'app/models/host/managed.rb', line 776

def vm_compute_attributes
  compute_resource ? compute_resource.vm_compute_attributes_for(uuid) : nil
end