saltstack / saltstack/salt

[BUG] hetzner cloud driver create method does not correctly handle volume and network attachments

Open
#59,872 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-testcase Salt-Cloud severity-medium
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description
The create method of the hetzner cloud driver takes networks and volumes in its combined data. This is passed to the create function of the hetzner cloud api. Before it is passed, there is a check if the given volumes or networks are existing in the hetzner cloud project. The corresponding code lines are the following (https://github.com/saltstack/salt/blob/master/salt/cloud/clouds/hetzner.py#L298):

# Get the volumes
    volumes = vm_.get("volumes", None)
    if volumes:
        volumes = [vol for vol in client.volumes.get_all() if vol in volumes]

    # Get the networks
    networks = vm_.get("networks", None)
    if networks:
        networks = [vol for vol in client.networks.get_all() if vol in networks]

    # Create the machine
    response = client.servers.create(
        name=name,
        server_type=server_type,
        image=image,
        ssh_keys=ssh_keys,
        volumes=volumes,
        networks=networks,
        location=location,
        user_data=vm_.get("user_data", None),
        labels=vm_.get("labels", None),
        datacenter=datacenter,
        automount=vm_.get("automount", None),
    )

This can't work, because the functions client.volumes.get_all() and client.networks.get_all() return a list of objects. You can't pass in object references in profiles/providers/maps/grains etc., so the vol in volumes or vol in networks will never return True. networks and volumes will always be empty.

This means you are not able to pass in networks or volumes at creation time, which should visibly be possible.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in salt/cloud/clouds/hetzner.py around line 298, where the Hetzner driver resolves volumes and networks before calling client.servers.create. Check how profile, provider, map, and grain values are represented compared with objects returned by client.volumes.get_all() and client.networks.get_all(). Done means valid volume and network attachments supplied at creation time reach the Hetzner API.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cloud
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.