foreman_opentofu 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/concerns/foreman_opentofu/compute_resources_controller.rb +22 -0
- data/app/lib/foreman_opentofu/concerns/base_template_scope_extensions.rb +14 -10
- data/app/models/concerns/foreman_opentofu/compute_attribute_validation.rb +25 -0
- data/app/models/concerns/foreman_opentofu/power_commands.rb +57 -0
- data/app/models/concerns/foreman_opentofu/vm_command_collection_normalization.rb +2 -2
- data/app/models/concerns/orchestration/tofu/compute.rb +2 -0
- data/app/models/foreman_opentofu/compute_vm.rb +22 -0
- data/app/models/foreman_opentofu/opentofu_vm_commands.rb +19 -21
- data/app/models/foreman_opentofu/tofu.rb +14 -6
- data/app/services/foreman_opentofu/app_wrapper.rb +72 -7
- data/app/services/foreman_opentofu/opentofu_executer.rb +50 -20
- data/app/services/foreman_opentofu/provider_type.rb +89 -5
- data/app/services/foreman_opentofu/tofu_key_pair.rb +9 -3
- data/app/views/compute_resources/form/_tofu.html.erb +21 -4
- data/app/views/compute_resources/show/_tofu.html.erb +6 -4
- data/app/views/compute_resources_vms/form/tofu/_dynamic_attrs.html.erb +11 -2
- data/app/views/templates/provisioning/hetzner_provision_host.erb +9 -2
- data/app/views/templates/provisioning/stackit_provision_default.erb +103 -0
- data/lib/foreman_opentofu/engine.rb +2 -0
- data/lib/foreman_opentofu/provider_types/hetzner.rb +19 -1
- data/lib/foreman_opentofu/provider_types/nutanix.rb +11 -4
- data/lib/foreman_opentofu/provider_types/stackit.rb +266 -0
- data/lib/foreman_opentofu/version.rb +1 -1
- data/test/controllers/compute_resources_controller_test.rb +40 -0
- data/test/factories/compute_resources.rb +8 -8
- data/test/fixtures/foreman_opentofu/app_wrapper/apply_error.jsonl +9 -0
- data/test/fixtures/renderer/snapshots/ProvisioningTemplate/opentofu_script/Hetzner_provision_default.empty.snap.txt +9 -2
- data/test/fixtures/renderer/snapshots/ProvisioningTemplate/opentofu_script/Hetzner_provision_default.hetzner_host.snap.txt +9 -2
- data/test/lib/foreman_opentofu/concerns/base_template_scope_extensions_test.rb +17 -0
- data/test/lib/foreman_opentofu/provider_types/hetzner_test.rb +45 -0
- data/test/lib/foreman_opentofu/provider_types/nutanix_test.rb +40 -0
- data/test/lib/foreman_opentofu/provider_types/stackit_test.rb +52 -0
- data/test/models/foreman_opentofu/compute_attribute_validation_test.rb +79 -0
- data/test/models/foreman_opentofu/compute_vm_test.rb +38 -0
- data/test/models/foreman_opentofu/opentofu_vm_commands_test.rb +146 -18
- data/test/models/foreman_opentofu/tofu_test.rb +25 -2
- data/test/renderer/stackit_template_test.rb +210 -0
- data/test/services/app_wrapper_test.rb +145 -0
- data/test/services/foreman_opentofu/provider_type_test.rb +121 -0
- data/test/services/opentofu_executer_test.rb +81 -4
- data/test/services/tofu_key_pair_test.rb +12 -3
- metadata +21 -4
- data/app/views/templates/provisioning/ovirt_provision_default.erb +0 -43
- data/lib/foreman_opentofu/provider_types/ovirt.rb +0 -21
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
module ForemanOpentofu
|
|
2
2
|
class ProviderType
|
|
3
|
-
attr_reader :id, :name, :default_attributes, :default_interfaces, :default_volumes
|
|
3
|
+
attr_reader :id, :name, :default_attributes, :default_interfaces, :default_volumes,
|
|
4
|
+
:connection_attrs
|
|
4
5
|
attr_accessor :capabilities, :disk_renderer, :nic_renderer,
|
|
5
|
-
:recreate_type_allow_list
|
|
6
|
+
:recreate_type_allow_list, :default_template
|
|
6
7
|
|
|
7
8
|
def initialize(id)
|
|
8
9
|
@id = id.to_sym
|
|
9
10
|
@name = id.capitalize
|
|
10
11
|
@capabilities = [:build]
|
|
11
12
|
@provider_attrs = []
|
|
13
|
+
@connection_attrs = []
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
def provider_attrs=(input)
|
|
15
|
-
@provider_attrs =
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
@provider_attrs = normalize_attributes(input)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def connection_attrs=(input)
|
|
21
|
+
@connection_attrs = normalize_attributes(input)
|
|
18
22
|
end
|
|
19
23
|
|
|
20
24
|
# if necessary, select-parameter named 'available_images' must be specified!
|
|
@@ -110,6 +114,20 @@ module ForemanOpentofu
|
|
|
110
114
|
vm_attrs
|
|
111
115
|
end
|
|
112
116
|
|
|
117
|
+
def validate_vm!(vm_attrs, compute_resource)
|
|
118
|
+
attrs = vm_attrs.with_indifferent_access
|
|
119
|
+
validate_attribute_constraints!(attrs, compute_resource)
|
|
120
|
+
validate_provider_specific!(attrs, compute_resource)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def validate_provider_specific!(_attrs, _compute_resource)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def active_volumes(attrs, compute_resource)
|
|
127
|
+
disks = attrs[:volumes].presence || compute_resource&.default_volumes
|
|
128
|
+
active_collection(disks)
|
|
129
|
+
end
|
|
130
|
+
|
|
113
131
|
def filter_resource_changes(resources)
|
|
114
132
|
return [] if resources.blank?
|
|
115
133
|
|
|
@@ -120,10 +138,76 @@ module ForemanOpentofu
|
|
|
120
138
|
result
|
|
121
139
|
end
|
|
122
140
|
|
|
141
|
+
# Whether the NIC renderer emits resources for the complete collection.
|
|
142
|
+
def nic_renderer_collection?
|
|
143
|
+
false
|
|
144
|
+
end
|
|
145
|
+
|
|
123
146
|
# Whether disk renderer emits one collection resource for all disks (for_each)
|
|
124
147
|
# instead of one resource block per disk entry.
|
|
125
148
|
def disk_renderer_collection?
|
|
126
149
|
false
|
|
127
150
|
end
|
|
151
|
+
|
|
152
|
+
private
|
|
153
|
+
|
|
154
|
+
def validate_attribute_constraints!(attrs, compute_resource)
|
|
155
|
+
numeric_constraints.each do |attribute|
|
|
156
|
+
constraint_values(attribute, attrs, compute_resource).each do |values|
|
|
157
|
+
value = values.fetch(attribute['name'], attribute['default'])
|
|
158
|
+
next if (value.nil? || value == '') && !attribute['mandatory']
|
|
159
|
+
|
|
160
|
+
validate_numeric_constraint!(attribute, value)
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def numeric_constraints
|
|
166
|
+
attributes.select { |attribute| attribute['type'] == 'number' && (attribute.key?('min') || attribute.key?('max')) }
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def constraint_values(attribute, attrs, compute_resource)
|
|
170
|
+
case attribute['group']
|
|
171
|
+
when 'disk'
|
|
172
|
+
active_volumes(attrs, compute_resource)
|
|
173
|
+
when 'vm', nil
|
|
174
|
+
[default_attributes.to_h.with_indifferent_access.merge(attrs)]
|
|
175
|
+
else
|
|
176
|
+
[]
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def active_collection(collection)
|
|
181
|
+
collection = collection.values if collection.is_a?(Hash)
|
|
182
|
+
Array(collection).map(&:with_indifferent_access).reject { |entry| entry[:_delete].to_s == '1' }
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def validate_numeric_constraint!(attribute, value)
|
|
186
|
+
field = [name, attribute['name']].join(' ')
|
|
187
|
+
raise ArgumentError, format(_('%<attribute>s must be present.'), attribute: field) if value.nil? || value == ''
|
|
188
|
+
|
|
189
|
+
number = constraint_number!(attribute, value, field)
|
|
190
|
+
raise ArgumentError, format(_('%<attribute>s must be greater than or equal to %<minimum>s.'), attribute: field, minimum: attribute['min']) if attribute['min'] && number < attribute['min']
|
|
191
|
+
raise ArgumentError, format(_('%<attribute>s must be less than or equal to %<maximum>s.'), attribute: field, maximum: attribute['max']) if attribute['max'] && number > attribute['max']
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def constraint_number!(attribute, value, field)
|
|
195
|
+
if attribute['step'] == 1
|
|
196
|
+
raise ArgumentError, format(_('%<attribute>s must be a whole number.'), attribute: field) unless value.to_s.match?(/\A-?[0-9]+\z/)
|
|
197
|
+
|
|
198
|
+
return value.to_i
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
number = Float(value, exception: false) unless value.is_a?(String) && value != value.strip
|
|
202
|
+
raise ArgumentError, format(_('%<attribute>s must be a number.'), attribute: field) unless number&.finite?
|
|
203
|
+
|
|
204
|
+
number
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def normalize_attributes(input)
|
|
208
|
+
Array(input).map do |attr|
|
|
209
|
+
ActiveSupport::HashWithIndifferentAccess.new(attr)
|
|
210
|
+
end
|
|
211
|
+
end
|
|
128
212
|
end
|
|
129
213
|
end
|
|
@@ -11,9 +11,15 @@ module ForemanOpentofu
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def generate
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
if defined?(Foreman::Provision::SshKey) && Foreman::Provision::SshKey.respond_to?(:generate)
|
|
15
|
+
key = Foreman::Provision::SshKey.generate(type: 'rsa', bits: Setting[:tofu_ssh_key_bits])
|
|
16
|
+
@private_key = key.private_key
|
|
17
|
+
@public_key = key.public_key
|
|
18
|
+
else
|
|
19
|
+
key = OpenSSL::PKey::RSA.generate(Setting[:tofu_ssh_key_bits])
|
|
20
|
+
@private_key = key.private_to_pem
|
|
21
|
+
@public_key = "#{key.ssh_type} #{[key.to_blob].pack('m0')}"
|
|
22
|
+
end
|
|
17
23
|
end
|
|
18
24
|
|
|
19
25
|
def destroy
|
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
<%= field_set_tag _("Common fields"), :id => "compute_ressource_common_field_set" do %>
|
|
2
|
-
<%= select_f f,
|
|
2
|
+
<%= select_f f,
|
|
3
|
+
:opentofu_provider,
|
|
4
|
+
ForemanOpentofu::ProviderTypeManager.enabled_provider_types,
|
|
5
|
+
:id,
|
|
6
|
+
:name,
|
|
7
|
+
{ :include_blank => @compute_resource.opentofu_provider.blank? ? _("Choose a provider") : false },
|
|
8
|
+
{
|
|
9
|
+
label: _("OpenTofu Provider"),
|
|
10
|
+
onchange: "tfm.computeResource.providerSelected(this)",
|
|
11
|
+
data: {
|
|
12
|
+
url: provider_selected_compute_resources_path(
|
|
13
|
+
opentofu_provider_selected: true
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
} %>
|
|
3
17
|
<%= select_f f, :opentofu_template_id, ProvisioningTemplate.of_kind('opentofu_script'), :id, :name, {}, {:label => _("OpenTofu Template")} %>
|
|
4
|
-
<%=
|
|
5
|
-
|
|
6
|
-
|
|
18
|
+
<%= render :partial => provider_partial(@compute_resource, "dynamic_attrs"), :locals => {
|
|
19
|
+
f: f,
|
|
20
|
+
attrs: @compute_resource.tofu_provider&.connection_attrs || [],
|
|
21
|
+
compute_resource: @compute_resource,
|
|
22
|
+
unset_password: unset_password?,
|
|
23
|
+
} %>
|
|
7
24
|
<%= checkbox_f f, :caching_enabled, :label => _("Enable caching"),
|
|
8
25
|
:help_inline => _("Cache slow calls to OpenTofu Compute resources to speed up page rendering") %>
|
|
9
26
|
|
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
<td><%= _('OpenTofu Template') %></td>
|
|
7
7
|
<td><%= link_to @compute_resource.opentofu_template, edit_provisioning_template_path(@compute_resource.opentofu_template) %></td>
|
|
8
8
|
</tr>
|
|
9
|
-
|
|
10
|
-
<
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
<% if @compute_resource.url.present? %>
|
|
10
|
+
<tr>
|
|
11
|
+
<td><%= _('URL') %></td>
|
|
12
|
+
<td><%= @compute_resource.url %></td>
|
|
13
|
+
</tr>
|
|
14
|
+
<% end %>
|
|
13
15
|
<tr>
|
|
14
16
|
<td><%= _("Caching") %></td>
|
|
15
17
|
<td><%= @compute_resource.caching_enabled ? _("Enabled") : _("Disabled") %></td>
|
|
@@ -3,16 +3,25 @@
|
|
|
3
3
|
common_options = {
|
|
4
4
|
label: _(label),
|
|
5
5
|
label_help: attr['help'],
|
|
6
|
+
help_block: attr['help_block'],
|
|
6
7
|
required: attr['mandatory'],
|
|
7
|
-
} %>
|
|
8
|
+
}.compact %>
|
|
8
9
|
|
|
9
10
|
<% case attr['type'] %>
|
|
10
11
|
<% when 'string' %>
|
|
11
12
|
<%= text_f f, attr['name'].to_sym, common_options %>
|
|
13
|
+
<% when 'password' %>
|
|
14
|
+
<%= password_f f, attr['name'].to_sym, common_options.merge(unset: local_assigns.fetch(:unset_password, false)) %>
|
|
12
15
|
<% when 'bool' %>
|
|
13
16
|
<%= checkbox_f f, attr['name'].to_sym, common_options %>
|
|
14
17
|
<% when 'number' %>
|
|
15
|
-
|
|
18
|
+
<% number_options = common_options.merge(attr.slice('min', 'max', 'step').symbolize_keys)
|
|
19
|
+
default_value = attr['default']
|
|
20
|
+
if default_value.nil? && attr['min'].present? && attr['max'].present?
|
|
21
|
+
default_value = attr['min'] unless 0.between?(attr['min'].to_f, attr['max'].to_f)
|
|
22
|
+
end
|
|
23
|
+
number_options[:value] = default_value if f.object.public_send(attr['name']).blank? && !default_value.nil? %>
|
|
24
|
+
<%= counter_f f, attr['name'].to_sym, number_options %>
|
|
16
25
|
<% when 'select' %>
|
|
17
26
|
<% if attr.key? 'options' %>
|
|
18
27
|
<% if attr['options'].is_a?(Hash) && attr['options'].key?('data_source') -%>
|
|
@@ -34,6 +34,13 @@ data "hcloud_ssh_key" "deploy_key" {
|
|
|
34
34
|
resource "hcloud_server" "node1" {
|
|
35
35
|
name = "<%= @host_name %>"
|
|
36
36
|
|
|
37
|
+
# User data is creation-only. The provider returns its hash in state, which
|
|
38
|
+
# might change on edit, resulting in replacing the server. Ignore user data
|
|
39
|
+
# attribute changes.
|
|
40
|
+
lifecycle {
|
|
41
|
+
ignore_changes = [user_data]
|
|
42
|
+
}
|
|
43
|
+
|
|
37
44
|
<%= vm_attributes(['name', 'image']) %>
|
|
38
45
|
|
|
39
46
|
<%- if @cr_attrs['image_id'].present? %>
|
|
@@ -66,7 +73,7 @@ output "vm_attrs" {
|
|
|
66
73
|
vm_ip6_address = hcloud_server.node1.ipv6_address
|
|
67
74
|
vm = hcloud_server.node1
|
|
68
75
|
volumes_attributes = try({
|
|
69
|
-
for k, v in try(
|
|
76
|
+
for k, v in try(hcloud_volume.volumes, {}) : tostring(try(v.id, k)) => {
|
|
70
77
|
id = try(v.id, null)
|
|
71
78
|
name = try(v.name, "volume-${k}")
|
|
72
79
|
size = try(v.size, 20)
|
|
@@ -74,6 +81,6 @@ output "vm_attrs" {
|
|
|
74
81
|
format = try(v.format, null)
|
|
75
82
|
} if try(v["_delete"], "0") != "1"
|
|
76
83
|
}, {})
|
|
77
|
-
}
|
|
84
|
+
}
|
|
78
85
|
}
|
|
79
86
|
<% end %>
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<%#
|
|
2
|
+
kind: opentofu_script
|
|
3
|
+
name: Stackit provision default
|
|
4
|
+
model: ProvisioningTemplate
|
|
5
|
+
description: |
|
|
6
|
+
Stackit Cloud image-based server with a boot volume, network interfaces, and optional data volumes.
|
|
7
|
+
Project ID and service account key JSON are configured on the compute resource.
|
|
8
|
+
Region is configured on the VM or compute profile (default eu01).
|
|
9
|
+
-%>
|
|
10
|
+
|
|
11
|
+
<%= terraform_block({ stackit: { source: 'stackitcloud/stackit', version: '= 0.121.0' } }) %>
|
|
12
|
+
|
|
13
|
+
provider "stackit" {
|
|
14
|
+
enable_beta_resources = true
|
|
15
|
+
default_region = <%= to_hcl(@cr_attrs['region'].presence || 'eu01') %>
|
|
16
|
+
service_account_key = var.password
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
locals {
|
|
20
|
+
project_id = var.username
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
<% if @resource %>
|
|
24
|
+
<%= resource_block(@resource) %>
|
|
25
|
+
<% elsif @keygen %>
|
|
26
|
+
<%# Retained for cleanup of deployment keys created by older versions. %>
|
|
27
|
+
<% if @ssh_key.present? %>
|
|
28
|
+
resource "stackit_key_pair" "deploy_key" {
|
|
29
|
+
name = <%= to_hcl(@ssh_key.name) %>
|
|
30
|
+
public_key = <%= to_hcl(@ssh_key.public_key) %>
|
|
31
|
+
}
|
|
32
|
+
<% end %>
|
|
33
|
+
<% elsif !@dry_run %>
|
|
34
|
+
locals {
|
|
35
|
+
boot_volume_size = <%= to_hcl(format_value(@cr_attrs['boot_volume_size'].presence || 64, 'number')) %>
|
|
36
|
+
assign_public_ip = <%= to_hcl(format_value(@cr_attrs['assign_public_ip'] || false, 'bool')) %>
|
|
37
|
+
image_id = <%= to_hcl(@cr_attrs['image_id'].to_s) %>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
resource "stackit_server" "node1" {
|
|
41
|
+
desired_status = <%= to_hcl(@compute_resource.tofu_provider.desired_status(@cr_attrs)) %>
|
|
42
|
+
project_id = local.project_id
|
|
43
|
+
name = <%= to_hcl(@host_name) %>
|
|
44
|
+
<%= vm_attributes(['power_state', 'region', 'project_id', 'network_id', 'security_group_id', 'boot_volume_size', 'assign_public_ip']) %>
|
|
45
|
+
|
|
46
|
+
boot_volume = {
|
|
47
|
+
source_type = "image"
|
|
48
|
+
source_id = local.image_id
|
|
49
|
+
size = local.boot_volume_size
|
|
50
|
+
delete_on_termination = true
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
network_interfaces = [for nic in values(stackit_network_interface.interfaces) : nic.network_interface_id]
|
|
54
|
+
<% if @user_data_filename.present? %>
|
|
55
|
+
user_data = file(<%= to_hcl(@user_data_filename) %>)
|
|
56
|
+
<% elsif @cr_attrs['user_data'].present? %>
|
|
57
|
+
user_data = <%= to_hcl(@cr_attrs['user_data'].gsub('${', '$${').gsub('%{', '%%{')) %>
|
|
58
|
+
<% elsif @ssh_key.present? %>
|
|
59
|
+
keypair_name = "<%= @ssh_key.name %>"
|
|
60
|
+
<% end %>
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
resource "stackit_public_ip" "primary" {
|
|
64
|
+
count = local.assign_public_ip ? 1 : 0
|
|
65
|
+
project_id = local.project_id
|
|
66
|
+
network_interface_id = values(stackit_network_interface.interfaces)[0].network_interface_id
|
|
67
|
+
}
|
|
68
|
+
<%= build_nics %>
|
|
69
|
+
<%= build_disks %>
|
|
70
|
+
|
|
71
|
+
output "vm_attrs" {
|
|
72
|
+
value = {
|
|
73
|
+
mac = values(stackit_network_interface.interfaces)[0].mac
|
|
74
|
+
identity = stackit_server.node1.server_id
|
|
75
|
+
vm_ip_address = local.assign_public_ip ? stackit_public_ip.primary[0].ip : values(stackit_network_interface.interfaces)[0].ipv4
|
|
76
|
+
vm = merge(stackit_server.node1, {
|
|
77
|
+
power_state = stackit_server.node1.desired_status == "active" ? "on" : "off"
|
|
78
|
+
region = <%= to_hcl(@cr_attrs['region'].presence || 'eu01') %>
|
|
79
|
+
image_id = local.image_id
|
|
80
|
+
boot_volume_size = local.boot_volume_size
|
|
81
|
+
assign_public_ip = local.assign_public_ip
|
|
82
|
+
})
|
|
83
|
+
interfaces_attributes = {
|
|
84
|
+
for k, nic in stackit_network_interface.interfaces : k => {
|
|
85
|
+
mac = nic.mac
|
|
86
|
+
identifier = try(local.active_interfaces[k].identifier, "")
|
|
87
|
+
network_id = nic.network_id
|
|
88
|
+
managed_network = contains(keys(stackit_network.interfaces), k)
|
|
89
|
+
security_group_id = try(local.active_interfaces[k].security_group_id, "")
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
volumes_attributes = {
|
|
93
|
+
for k, volume in stackit_volume.volumes : k => {
|
|
94
|
+
id = volume.volume_id
|
|
95
|
+
name = volume.name
|
|
96
|
+
size = volume.size
|
|
97
|
+
volume_availability_zone = volume.availability_zone
|
|
98
|
+
performance_class = volume.performance_class
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
<% end %>
|
|
@@ -46,7 +46,9 @@ module ForemanOpentofu
|
|
|
46
46
|
config.autoload_paths << File.expand_path('../lib', __dir__)
|
|
47
47
|
# Include concerns in this config.to_prepare block
|
|
48
48
|
config.to_prepare do
|
|
49
|
+
::ComputeAttribute.include ForemanOpentofu::ComputeAttributeValidation
|
|
49
50
|
::ComputeResourcesController.include ForemanOpentofu::Controller::Parameters::ComputeResource
|
|
51
|
+
::ComputeResourcesController.include ForemanOpentofu::ComputeResourcesController
|
|
50
52
|
::Api::V2::ComputeResourcesController.include ForemanOpentofu::Controller::Parameters::ComputeResource
|
|
51
53
|
::ComputeResourcesVmsController.include ForemanOpentofu::ComputeResourcesVmsController
|
|
52
54
|
::Host::Managed.include Orchestration::Tofu::Compute
|
|
@@ -4,6 +4,7 @@ require "#{ForemanOpentofu::Engine.root}/app/services/foreman_opentofu/provider_
|
|
|
4
4
|
|
|
5
5
|
ForemanOpentofu::ProviderTypeManager.register('hetzner') do
|
|
6
6
|
@capabilities = [:image, :key_pair, :power_status_only]
|
|
7
|
+
self.default_template = 'Hetzner provision default'
|
|
7
8
|
|
|
8
9
|
def disk_renderer_collection?
|
|
9
10
|
true
|
|
@@ -21,6 +22,18 @@ ForemanOpentofu::ProviderTypeManager.register('hetzner') do
|
|
|
21
22
|
true
|
|
22
23
|
end
|
|
23
24
|
|
|
25
|
+
def validate_provider_specific!(attrs, compute_resource)
|
|
26
|
+
disks = active_volumes(attrs, compute_resource)
|
|
27
|
+
raise ArgumentError, _('Hetzner allows at most 16 volumes per server.') if disks.size > 16
|
|
28
|
+
|
|
29
|
+
disks.each { |disk| validate_volume!(disk) }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def validate_volume!(disk)
|
|
33
|
+
raise ArgumentError, _('Hetzner volume format is required when automount is enabled.') if Foreman::Cast.to_bool(disk[:automount]) && disk[:format].blank?
|
|
34
|
+
raise ArgumentError, _('Hetzner volume format must be ext4 or xfs.') if disk[:format].present? && !%w[ext4 xfs].include?(disk[:format])
|
|
35
|
+
end
|
|
36
|
+
|
|
24
37
|
def normalize_interfaces(vm_attrs)
|
|
25
38
|
attrs = vm_attrs.with_indifferent_access
|
|
26
39
|
return attrs if attrs[:interfaces_attributes].present?
|
|
@@ -46,6 +59,10 @@ ForemanOpentofu::ProviderTypeManager.register('hetzner') do
|
|
|
46
59
|
end
|
|
47
60
|
end
|
|
48
61
|
|
|
62
|
+
self.connection_attrs = [
|
|
63
|
+
{ name: 'password', type: 'password', mandatory: true, label: 'Token' },
|
|
64
|
+
]
|
|
65
|
+
|
|
49
66
|
self.provider_attrs = [
|
|
50
67
|
{ name: 'server_type', type: 'select', group: 'vm', mandatory: true,
|
|
51
68
|
label: 'Server Type', options: {
|
|
@@ -83,7 +100,8 @@ ForemanOpentofu::ProviderTypeManager.register('hetzner') do
|
|
|
83
100
|
{ name: 'name', type: 'string', group: 'disk', mandatory: true,
|
|
84
101
|
label: 'Volume Name' },
|
|
85
102
|
{ name: 'size', type: 'number', group: 'disk', mandatory: true,
|
|
86
|
-
label: 'Size (GB)'
|
|
103
|
+
label: 'Size (GB)', min: 10, max: 10_240, step: 1,
|
|
104
|
+
help: 'Volume size must be between 10 and 10240 GB.' },
|
|
87
105
|
{ name: 'automount', type: 'bool', group: 'disk', mandatory: false,
|
|
88
106
|
label: 'Automount', help: 'Requires Format to be set.' },
|
|
89
107
|
{ name: 'format', type: 'select', group: 'disk', mandatory: false,
|
|
@@ -5,6 +5,13 @@ require "#{ForemanOpentofu::Engine.root}/app/services/foreman_opentofu/provider_
|
|
|
5
5
|
ForemanOpentofu::ProviderTypeManager.register('nutanix') do
|
|
6
6
|
# FIXME: Requires Nutanix-server that supports v2-API (see 'available_images')
|
|
7
7
|
# @capabilities = [:build, :image]
|
|
8
|
+
self.default_template = 'Nutanix provision default'
|
|
9
|
+
|
|
10
|
+
self.connection_attrs = [
|
|
11
|
+
{ name: 'url', type: 'string', mandatory: true, label: 'Endpoint', help_block: '127.0.0.1' },
|
|
12
|
+
{ name: 'user', type: 'string', mandatory: true, label: 'Username', help_block: 'e.g. admin' },
|
|
13
|
+
{ name: 'password', type: 'password', mandatory: true, label: 'Password' },
|
|
14
|
+
]
|
|
8
15
|
|
|
9
16
|
self.provider_attrs = [
|
|
10
17
|
{ "name": 'cluster_uuid', "type": 'select', "group": 'vm', "mandatory": true,
|
|
@@ -26,11 +33,11 @@ ForemanOpentofu::ProviderTypeManager.register('nutanix') do
|
|
|
26
33
|
"output_path_postfix": 'images',
|
|
27
34
|
} },
|
|
28
35
|
{ "name": 'num_sockets', "type": 'number', "group": 'vm', "mandatory": false,
|
|
29
|
-
"label": 'Sockets' },
|
|
36
|
+
"label": 'Sockets', "min": 1, "step": 1 },
|
|
30
37
|
{ "name": 'num_vcpus_per_socket', "type": 'number', "group": 'vm', "mandatory": false,
|
|
31
|
-
"label": 'Cores per socket' },
|
|
38
|
+
"label": 'Cores per socket', "min": 1, "step": 1 },
|
|
32
39
|
{ "name": 'memory_size_mib', "type": 'number', "group": 'vm', "mandatory": false,
|
|
33
|
-
"label": 'Memory (MB)' },
|
|
40
|
+
"label": 'Memory (MB)', "min": 1, "step": 1 },
|
|
34
41
|
{ "name": 'enable_cpu_passthrough', "label": 'CPU Passthrough Enable', "type": 'bool', "group": 'vm', "mandatory": false },
|
|
35
42
|
{ "name": 'num_vnuma_nodes', "type": 'number', "group": 'vm', "mandatory": false,
|
|
36
43
|
"label": 'vNUMA Nodes', "help": 'Number of vNUMA nodes. 0 means vNUMA is disabled.' },
|
|
@@ -43,7 +50,7 @@ ForemanOpentofu::ProviderTypeManager.register('nutanix') do
|
|
|
43
50
|
{ "name": 'vga_console_enabled', "type": 'bool', "group": 'vm', "mandatory": false,
|
|
44
51
|
"label": 'VGA Console Enable' },
|
|
45
52
|
{ "name": 'disk_size_mib', "type": 'number', "group": 'disk', "mandatory": true,
|
|
46
|
-
"label": 'Size (MB)' },
|
|
53
|
+
"label": 'Size (MB)', "min": 1, "step": 1 },
|
|
47
54
|
{ "name": 'nic_type', "type": 'select', "group": 'nic', "mandatory": false,
|
|
48
55
|
"label": 'NIC Type', "options": %w[NORMAL_NIC DIRECT_NIC NETWORK_FUNCTION_NIC] },
|
|
49
56
|
{ "name": 'model', "type": 'select', "group": 'nic', "mandatory": true,
|