Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with servers that have numbers as server name #874

Open
asarubbo opened this issue Oct 1, 2024 · 2 comments
Open

issue with servers that have numbers as server name #874

asarubbo opened this issue Oct 1, 2024 · 2 comments
Labels

Comments

@asarubbo
Copy link

asarubbo commented Oct 1, 2024

When you create a server an you give it a numeric name, like 123, when you do operations from the cli it does not work, because it threats the number as ID instead of as server name.

In my opinion you should do one of the following:

  1. deny server creation that has only numbers as name
  2. check if the numbers refers to a server name and not just to an id.

Minimal working example

 ~ $ hcloud server create --datacenter fsn1-dc14 --image rocky-9 --type cx22 --ssh-key agostino.sarubbo --name 123
 ✓ Waiting for create_server       100% 10s (server: 53764860)                                                                                                                         
 ✓ Waiting for start_server        100% 10s (server: 53764860)                                                                                                                         
Server 53764860 created
IPv4: 49.13.122.232
IPv6: 2a01:4f8:c013:675f::1
IPv6 Network: 2a01:4f8:c013:675f::/64
 ~ $ hcloud server rebuild --image rocky-9 123
hcloud: server not found: 123
@asarubbo asarubbo added the bug label Oct 1, 2024
@phm07 phm07 self-assigned this Oct 1, 2024
@phm07
Copy link
Contributor

phm07 commented Oct 1, 2024

The root cause for this issue actually lays in hcloud-go. Here's the link to the relevant code.

I agree that allowing numbers as resource names is a design oversight and shouldn't be allowed. However I don't agree with your proposals to solve this problem.

deny server creation that has only numbers as name

The API allows this behavior so we can't disallow it. Even if we did, you could still create resources with numeric names from the Console or the API.

check if the numbers refers to a server name and not just to an id.

While this would theoretically be possible, it would be very inefficient. API endpoints only support referencing resources by their IDs, so to make our commands work with resource names, we fetch the list of resources and then search for the name. By checking if the search string is a number, we can skip that step and just use the ID as is. If we searched for the name first every time, we would need to fetch the entire list of resources (which is especially inefficient in the case of servers), even though in almost all of the cases the ID is already provided.

My proposal would be to stop using numeric names for resources. You probably want more descriptive names anyway. If you really need to use numeric names, you will still be able to use the resource ID instead of the names. hcloud <resource> list will show you the IDs for each resource.

@phm07 phm07 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 7, 2024
@jooola
Copy link
Member

jooola commented Oct 11, 2024

I believe there is some room for improvement, we can try to guess locally, and then query both GetByID and GetByName if no resource was found.

@jooola jooola reopened this Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants