Module: ForemanSalt::Concerns::Orchestration::Salt

Extended by:
ActiveSupport::Concern
Includes:
Orchestration
Defined in:
app/models/foreman_salt/concerns/orchestration/salt.rb

Instance Method Summary collapse

Instance Method Details

#initialize_saltObject



17
18
19
# File 'app/models/foreman_salt/concerns/orchestration/salt.rb', line 17

def initialize_salt
  @salt_api ||= ProxyAPI::Salt.new :url => salt_proxy.url
end

#queue_salt_autosignObject



21
22
23
24
# File 'app/models/foreman_salt/concerns/orchestration/salt.rb', line 21

def queue_salt_autosign
  return unless salt? && errors.empty?
  new_record? ? queue_salt_autosign_create : queue_salt_autosign_update
end

#queue_salt_autosign_createObject



26
27
28
# File 'app/models/foreman_salt/concerns/orchestration/salt.rb', line 26

def queue_salt_autosign_create
  # do nothing - we'll set autosign at the last second: when a host requests a provision URL
end

#queue_salt_autosign_removeObject



43
44
45
46
# File 'app/models/foreman_salt/concerns/orchestration/salt.rb', line 43

def queue_salt_autosign_remove
  return unless salt? && errors.empty?
  queue.create(:name => _("Remove autosign entry for %s") % self, :priority => 50, :action => [self, :salt_autosign_remove])
end

#queue_salt_autosign_updateObject



30
31
32
33
34
35
# File 'app/models/foreman_salt/concerns/orchestration/salt.rb', line 30

def queue_salt_autosign_update
  # Host has been built --> remove auto sign
  if old.build? and !build?
    queue.create(:name => _("Remove autosign entry for %s") % self, :priority => 50, :action => [self, :salt_autosign_remove])
  end
end

#queue_salt_destroyObject



37
38
39
40
41
# File 'app/models/foreman_salt/concerns/orchestration/salt.rb', line 37

def queue_salt_destroy
  return unless salt? && errors.empty?
  queue.create(:name => _("Remove autosign entry for %s") % self, :priority => 50, :action => [self, :salt_autosign_remove])
  queue.create(:name => _("Delete existing salt key for %s") % self, :priority => 50, :action => [self, :salt_key_delete])
end

#salt?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'app/models/foreman_salt/concerns/orchestration/salt.rb', line 13

def salt?
  name.present? && salt_proxy.present?
end

#salt_autosign_createObject



48
49
50
51
52
53
54
55
# File 'app/models/foreman_salt/concerns/orchestration/salt.rb', line 48

def salt_autosign_create
  logger.info "Create autosign entry for #{name}"
  initialize_salt
  salt_key_delete # if there's already an existing key
  @salt_api.autosign_create name
rescue => e
  failure _("Failed to create %{name}'s Salt autosign entry: %{e}") % { :name => name, :e => e }
end

#salt_autosign_removeObject



57
58
59
60
61
62
63
# File 'app/models/foreman_salt/concerns/orchestration/salt.rb', line 57

def salt_autosign_remove
  logger.info "Remove autosign entry for #{name}"
  initialize_salt
  @salt_api.autosign_remove name
rescue => e
  failure _("Failed to remove %{name}'s Salt autosign entry: %{e}") % { :name => name, :e => e }
end

#salt_key_deleteObject



65
66
67
68
69
70
71
# File 'app/models/foreman_salt/concerns/orchestration/salt.rb', line 65

def salt_key_delete
  logger.info "Delete salt key for #{name}"
  initialize_salt
  @salt_api.key_delete name
rescue => e
  failure _("Failed to delete %{name}'s Salt key: %{e}") % { :name => name, :e => e }
end