Skip to content

Fix: Fixes host edit to show correct vm_attributes which were used while creating host.#41

Merged
m-bucher merged 1 commit into
mainfrom
fix_edit_host
May 22, 2026
Merged

Fix: Fixes host edit to show correct vm_attributes which were used while creating host.#41
m-bucher merged 1 commit into
mainfrom
fix_edit_host

Conversation

@Manisha15
Copy link
Copy Markdown
Contributor

Normalizes volume attributes as volumes_attributes to be consistent.

Comment thread app/views/templates/provisioning/hetzner_provision_host.erb Outdated
Comment thread app/views/templates/provisioning/hetzner_provision_host.erb Outdated
Copy link
Copy Markdown
Member

@m-bucher m-bucher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First test looks promising, apart from some smaller things I had to fix in the template 😄
IMHO disk-rendering might need some more cleanup.

@Manisha15 Manisha15 force-pushed the fix_edit_host branch 2 times, most recently from c0d97b1 to 271e9cd Compare May 20, 2026 15:14
…ile creating host. Also normalizes volume attributes as volumes_attributes to be consistent.
Comment on lines +20 to +43
def normalize_interfaces(vm_attrs)
attrs = vm_attrs.with_indifferent_access
return attrs if attrs[:interfaces_attributes].present?

networks = extract_networks(attrs)
return attrs if networks.blank?

attrs[:interfaces_attributes] = build_interfaces_attributes(networks)
attrs
end

def extract_networks(attrs)
attrs.dig(:vm, :network) ||
attrs.dig('vm', 'network') ||
attrs[:network] ||
attrs['network']
end

def build_interfaces_attributes(networks)
Array(networks).each_with_index.to_h do |net, idx|
nic = net.respond_to?(:with_indifferent_access) ? net.with_indifferent_access : net
[idx.to_s, { network_id: nic[:network_id].to_s }]
end
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seem pretty generic to me. If so, they should be moved into ProviderType so we can use them in all ProviderTypes.

disk_render_source.each_with_index.filter_map do |disk, index|
# drop removed disks; tofu will drop them automatically, if they are no longer defined
next if disk['_delete'].to_i == 1
next if disk.respond_to?(:[]) && disk['_delete'].to_i == 1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a problem if on hetzner provider all attached volumes should be removed.

In my test, removing all volumes from a Hetzner host resulted in the disk_renderer() of the ProviderType not rendering anything. This is because if all volumes have set '_delete' to 1, then the rendered_disk() is never called.
This somehow clashed with the output-block in the template

      volumes_attributes = try({
        for v in values(hcloud_volume.volumes) : tostring(v.id) => {
          id = v.id
          name = v.name
          size = v.size
          automount = try(v.automount, null)
          format = try(v.format, null)
        }
      }, {})

Tofu complained that no hcloud_volume.volumes are set.

A quick fix is to remove this line, but I assume it is needed for any other ProviderType we currently support :-/

Copy link
Copy Markdown
Member

@m-bucher m-bucher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works in combination with #39 if using non-UserData deployment (apart of the mentioned issue in regard to removing all attached volumes).
The problem with UserData deployment is that the UserData is detected as having changed.

IMHO none of the above Known-Issues should keep us from merging this, because it does improve Host edit nevertheless.

@m-bucher m-bucher merged commit f87fa07 into main May 22, 2026
7 checks passed
@m-bucher m-bucher deleted the fix_edit_host branch May 22, 2026 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants