orchestra/remote: add resolve_ip method#2067
Conversation
b7e2390 to
8441bb9
Compare
| else: | ||
| raise Exception(f'Unknown IP version {ipv}, expected 4 or 6') | ||
| if 'has address' in remote_host_ip: | ||
| (host, ip) = remote_host_ip.strip().split(' has address ') |
There was a problem hiding this comment.
If the name resolves to multiple addresses, we will get:
ValueError: too many values to unpack (expected 2)
There was a problem hiding this comment.
hm, didn't test it against google.com, it has indeed strange response:
$ host -4 google.com
google.com has address 142.250.185.110
google.com has IPv6 address 2a00:1450:4001:80f::200e
google.com mail is handled by 10 smtp.google.com.
I only verified this against target nodes. I guess in this case it is only needed to find first occurrence of "has address" line if any.
zmc
left a comment
There was a problem hiding this comment.
I'm curious why we wouldn't prefer to use native python APIs, e.g.:
>>> pprint(socket.getaddrinfo('google.com', None))
[(<AddressFamily.AF_INET6: 30>,
<SocketKind.SOCK_DGRAM: 2>,
17,
'',
('2607:f8b0:400f:802::200e', 0, 0, 0)),
(<AddressFamily.AF_INET6: 30>,
<SocketKind.SOCK_STREAM: 1>,
6,
'',
('2607:f8b0:400f:802::200e', 0, 0, 0)),
(<AddressFamily.AF_INET: 2>,
<SocketKind.SOCK_DGRAM: 2>,
17,
'',
('142.250.69.238', 0)),
(<AddressFamily.AF_INET: 2>,
<SocketKind.SOCK_STREAM: 1>,
6,
'',
('142.250.69.238', 0))]
It handles multiple results gracefully, and the same call can return both v4 and v6 addresses with an easy way to filter for one or the other if necessary.
because the idea is to get addresses remotely and not all targets can be resolved from teuthology host, for example, in case of using bastion hosts |
8441bb9 to
618ab8a
Compare
|
@zmc I updated the code, take another look please |
Add utility method to resolve a hostname from within remote host. This is useful to resolve ip address of the remote host itself, because getting ip address from transport object of ssh is not suitable because it may have only bastion host and port, which is not relevant for the purpose of configuring a cluster. Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@clyso.com>
Update before bootstrap Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@clyso.com>
618ab8a to
382c6d9
Compare
I just tried this for google.com in sepia lab: That's interesting, a bunch of addresses of each type, however the introduced function is supposed to be used for target nodes only, which supposed to have only one address correspondingly, does it makes sense to take first found or to return all of them as a list. |
This patch addresses the error in the logs, like this: Using python: python3.12 /usr/bin/lsb_release Deleting existing virtual environment Creating new venv at ./virtualenv ./bootstrap: line 131: [: missing `]' ./bootstrap: line 131: 12: command not found Fixes: 0b5a5bc Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@clyso.com>
The `git config --unset` returns 5 if there is missing variable supposed to be unset. Just always return true for this command so the bootstrap can proceed. Fixes: 7cc6ba4 Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@clyso.com>
zmc
left a comment
There was a problem hiding this comment.
Thanks for updating to handle the multiple-value-in-response case, and for adding a unit test. Looks good to me!
Add utility method to resolve a hostname from within remote host. This is useful to resolve ip address of the remote host itself, because getting ip address from transport object of ssh is not suitable because it may have only bastion host and port, which is not relevant for the purpose of configuring a cluster.