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

Feature request... private_net in server-list query #228

Closed
seimic opened this issue Feb 25, 2020 · 3 comments · Fixed by #229
Closed

Feature request... private_net in server-list query #228

seimic opened this issue Feb 25, 2020 · 3 comments · Fixed by #229

Comments

@seimic
Copy link

seimic commented Feb 25, 2020

Hi,

at first thanks for the last update (1.16 release) with json results in list queries. This simplifies
few things. :)
But the list query for servers doesn't contain any information about the private networks.
At now we have to loop the results of 'server list' and invoke a 'describe' for each server
to get the private network information.

For example: Generate a nginx upstream template for private network IPs of all servers with a specific label. (Assuming there is only one network assignment on each server).

#!/usr/bin/env bash

fetch_server_list() {
  local server_list=$(hcloud server list -l ${1} -o noheader -o columns=name,id | sort)
  echo "${server_list[@]}"
}

fetch_server_ip() {
  local server_ip=$(hcloud server describe "${1}" -o json | jq -cr '.private_net | .[0] | .ip')
  echo "${server_ip}"
}

while read server_name server_id; do
  if [[ ! -z $server_id ]]; then
    server_ip=$(fetch_server_ip "${server_id}")
    server_line="server ${server_ip}:\$PORT; # id=${server_id}, name=${server_name}"
    echo $server_line
  fi
done < <(fetch_server_list 'lb_group=controlplane')

This generates something like this:

server 10.0.0.10:$PORT; # id=1234567, name=control-node0
server 10.0.0.11:$PORT; # id=1234568, name=control-node1
server 10.0.0.12:$PORT; # id=1234569, name=control-node2

With the private network information in the list command and an additional '-o columns=id,name,private_net' the list command could return only the necessary information at once.

Any chance to see this in future release?

Thanks,
Michael

@seimic seimic changed the title Feature request... Feature request... private_net in server-list query Feb 25, 2020
@LKaemmerling
Copy link
Member

Hello,

I missed the private_net properties when I added the JSON list response. I added a PR to fix this.

When you use something like hcloud server list -o columns=id,private_net you get already the names of the networks where the server is attached to.

When the PR is merged we will release a bugfix update.

@LKaemmerling
Copy link
Member

@seimic v1.16.1 was released.

@seimic
Copy link
Author

seimic commented Feb 26, 2020

Thank you very much. Works fine.
Now only one API call necessary. Its suddenly no O(n+1) anymore. :-)

#!/usr/bin/env bash

fetch_server_list() {
  local server_list=$(hcloud server list -l ${1} -o json | jq -cr '.[] | .id, .name, .private_net[0].ip' )
  echo "${server_list[@]}"
}

while read server_id; read server_name; read server_ip; do
  if [[ ! -z $server_id ]]; then
    server_line="server ${server_ip}:\$PORT; # id=${server_id}, name=${server_name}"
    echo $server_line
  fi
done < <(fetch_server_list 'lb_group=controlplane')

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 a pull request may close this issue.

2 participants