Class: ForemanOpentofu::TemplateSnapshotService
- Inherits:
-
Object
- Object
- ForemanOpentofu::TemplateSnapshotService
- Defined in:
- app/services/foreman_opentofu/template_snapshot_service.rb
Overview
< Foreman::TemplateSnapshotService
Constant Summary collapse
- TEMPLATES_DIRECTORY =
ForemanOpentofu::Engine.root.join('app', 'views', 'templates', 'provisioning')
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.render_template(template, host_name = :empty) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/services/foreman_opentofu/template_snapshot_service.rb', line 10 def self.render_template(template, host_name = :empty) raise 'TemplateSnapshotService can only be used in test environment' unless Rails.env.test? require 'factory_bot_rails' cr_attrs = new.send(host_name.to_sym) provider_type = template.name.split(' ').first.downcase variables = { compute_resource: FactoryBot.build("opentofu_#{provider_type}_cr".to_sym), cr_attrs: cr_attrs || {}, use_backend: true, token: 'very_secret_token', host_name: host_name, resource: nil, } variables[:ssh_key] = variables[:compute_resource].key_pair if variables[:compute_resource].key_pair source = ForemanOpentofu::Renderer::Source::Snapshot.new(template) scope = Foreman::Renderer.get_scope(source: source, variables: variables) Foreman::Renderer::UnsafeModeRenderer.render(source, scope) end |
.templates ⇒ Object
6 7 8 |
# File 'app/services/foreman_opentofu/template_snapshot_service.rb', line 6 def self.templates new.templates end |
Instance Method Details
#empty ⇒ Object
58 59 60 |
# File 'app/services/foreman_opentofu/template_snapshot_service.rb', line 58 def empty {} end |
#hetzner_host ⇒ Object
34 35 36 37 38 |
# File 'app/services/foreman_opentofu/template_snapshot_service.rb', line 34 def hetzner_host { server_type: 'cx23', } end |
#nutanix_host ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/services/foreman_opentofu/template_snapshot_service.rb', line 40 def nutanix_host { 'cluster_uuid' => 'my_cluster_uuid', 'volumes_attributes' => [ { size_gb: 40, container_uuid: 'my_container_uuid', }, ], 'interfaces_attributes' => [ { model: 'E1000', subnet_uuid: 'my_subnet_uuid', }, ], } end |
#templates ⇒ Object
30 31 32 |
# File 'app/services/foreman_opentofu/template_snapshot_service.rb', line 30 def templates files.map { |path| ForemanOpentofu::Renderer::Source::Snapshot.load_file(path) } end |