Class: ForemanOrchestration::Stack

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Conversion, ActiveModel::Validations
Defined in:
app/models/foreman_orchestration/stack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Stack



14
15
16
17
18
19
20
21
# File 'app/models/foreman_orchestration/stack.rb', line 14

def initialize(params = {})
  @id = params[:id]
  @name = params[:name]
  @template_id = params[:template_id]
  @parameters = params[:parameters] || {}
  compute_resource_params(params)
  tenant_params(params)
end

Instance Attribute Details

#compute_resource_idObject

Returns the value of attribute compute_resource_id.



6
7
8
# File 'app/models/foreman_orchestration/stack.rb', line 6

def compute_resource_id
  @compute_resource_id
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'app/models/foreman_orchestration/stack.rb', line 6

def id
  @id
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'app/models/foreman_orchestration/stack.rb', line 6

def name
  @name
end

#parametersObject

Returns the value of attribute parameters.



7
8
9
# File 'app/models/foreman_orchestration/stack.rb', line 7

def parameters
  @parameters
end

#template_idObject

Returns the value of attribute template_id.



6
7
8
# File 'app/models/foreman_orchestration/stack.rb', line 6

def template_id
  @template_id
end

#tenant_idObject

Returns the value of attribute tenant_id.



6
7
8
# File 'app/models/foreman_orchestration/stack.rb', line 6

def tenant_id
  @tenant_id
end

Instance Method Details

#compute_resourceObject



57
58
59
60
61
# File 'app/models/foreman_orchestration/stack.rb', line 57

def compute_resource
  if compute_resource_id
    @compute_resource ||= Foreman::Model::Openstack.find(compute_resource_id)
  end
end

#destroyObject



35
36
37
# File 'app/models/foreman_orchestration/stack.rb', line 35

def destroy
  tenant.delete_stack(self)
end

#persisted?Boolean



23
24
25
# File 'app/models/foreman_orchestration/stack.rb', line 23

def persisted?
  false
end

#saveObject



27
28
29
30
31
32
33
# File 'app/models/foreman_orchestration/stack.rb', line 27

def save
  if valid?
    tenant.create_stack(self)
  else
    false
  end
end

#templateObject



39
40
41
42
43
# File 'app/models/foreman_orchestration/stack.rb', line 39

def template
  if template_id
    @template ||= StackTemplate.find(template_id)
  end
end

#template_bodyObject



45
46
47
48
49
# File 'app/models/foreman_orchestration/stack.rb', line 45

def template_body
  if template
    YAML.load(template.template)
  end
end

#tenantObject



51
52
53
54
55
# File 'app/models/foreman_orchestration/stack.rb', line 51

def tenant
  if tenant_id && compute_resource
    @tenant ||= compute_resource.orchestration_client_for(tenant_id)
  end
end

#tenantsObject



63
64
65
66
67
68
# File 'app/models/foreman_orchestration/stack.rb', line 63

def tenants
  # TODO: find a better place for this method
  if compute_resource
    @tenants ||= compute_resource.orchestration_clients
  end
end