Skip to content

Conversation

songponssw
Copy link
Contributor

@songponssw songponssw commented Jul 5, 2025

What does this PR do?

Implementation details

With GuestAgent:

  • The raw output from ip -j a is embedded as json_bytes in the gRPC Events message.
  • The GuestAgent listens for this event, extracts the IP information, and writes it to the instance_info.json file.

Without GuestAgent (Plain mode):

  • This PR updates the executeSSH() function signature to return both the command output and error (instead of just error).
  • After completing any requirements setup, HostAgent uses executeSSH() to run ip -j a, processes the output, and writes the instance info locally.

Testing

  • Setup: Lima upstream master, OS(Ubuntu 22.02)
  • templates: almalinux alpine debian fedora opensuse oraclelinux ubuntu
  • Test command: limactl start INSTNAME --network lima:user-v2
  • Result
    • With GuestAgent: All tests passed.
    • Plain Mode: Failed on AlmaLinux and Alpine — instances did not start successfully.

@songponssw songponssw force-pushed the guestagent-send-ip branch 2 times, most recently from ce812d0 to 7e5a9ee Compare July 6, 2025 04:25
@songponssw songponssw marked this pull request as draft July 7, 2025 08:16
jandubois added a commit to jandubois/alpine-lima that referenced this pull request Jul 7, 2025
Added unconditionally to all editions because in the future Lima will
depend on it (it is also part of the default Alpine cloud image).

Ref lima-vm/lima#3696

Signed-off-by: Jan Dubois <[email protected]>
@songponssw songponssw force-pushed the guestagent-send-ip branch from 7e5a9ee to eb07981 Compare July 11, 2025 20:04
@songponssw
Copy link
Contributor Author

songponssw commented Jul 11, 2025

Changes – Draft 2 (edited)

gRPC

  • added CommandOutput message to hold output from the client.
  • Created dedicated endpoints for GetIPv4 and GetIPv6.

Hostagent

  • agent get ipaddress as the last step in host agent routine and it should all only when the instance spin up.
  • Stores IP addresses internally
  • Exports IP address through the Info strut in hostagent/api

CLI

  • Added IPv4Address and IPv6Address fields
  • IP address are now available, e.g.: limactl ls --format "{{ .Name }} {{ .IPv4Address }}"

Note;

  • IPv6 is currently unavailable; no default route is found.
  • gRPC compiled grpc with protoc-compiler 6.30.2

P.S. I'm trying my best to follow the design patterns found in the existing code. If there are any points that need refactoring, please let me know.

@songponssw songponssw force-pushed the guestagent-send-ip branch 3 times, most recently from 3ba87dc to 438de9f Compare July 12, 2025 13:29
@songponssw songponssw force-pushed the guestagent-send-ip branch 3 times, most recently from e84ea6a to 1c9a442 Compare July 26, 2025 09:30
@songponssw songponssw marked this pull request as ready for review July 26, 2025 14:36
rpc GetIPv6(google.protobuf.Empty) returns (CommandOutput);
}

message Info {
Copy link
Member

Choose a reason for hiding this comment

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

I still think that the IP can be added here without wrapping it in CommandOutput

#3616 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ll try adding the IP address directly to RPC and remove all CommandOutput wrapping

@jandubois jandubois mentioned this pull request Sep 16, 2025
@songponssw songponssw marked this pull request as draft September 28, 2025 19:06
@songponssw
Copy link
Contributor Author

songponssw commented Sep 28, 2025

Edit:
I had a bit of confusion. I thought we were trying to use net.Interface() as a way to query the IP address.
I’ll continue making the changes according Akihiro's comment

# PR Update (draft3)

## Details
- supports only IPv4.
- Hostagent requests the guest for its IP through RPC.
- IPv4Address is added to Hostagent Info, so it can be shown when using curl on ha.sock at http://$INST/v1/info.

## Determining the IP Address
- The IP is determined by finding an address that can dial lima.host.internal.
- net.Interfaces() returns a list of all interfaces on the machine. I’m not sure whether there will be only 2 interfaces in practice (loopback and primary interface). If that is the case, the implementation could be simplified to pick the primary interface from the list.

## Not sure how to implement it yet.
Support IPv6:
- With the current implementation, we would need an IPv6 address for host.lima.internal.
- Otherwise, we could assume it uses the same interfaces as IPv4 or dial another destination such as Google DNS or Cloudflare.

Support Plain Mode:
- If we want the same implementation to work for both normal and plain mode, we might need to transfer a small binary to the VM to execute and report the IP via RPC.
- I’m not sure if we can reliably get the IP during VM initialization. This might limit the ability for the client to edit the IP after creation. (I’m not quite sure yet exactly when and how IPs are assigned)
- In plain mode, there is no lima.host.internal in /etc/hosts. We would need to dial another destination to figure out the default route.

Signed-off-by: Songpon Srisawai <[email protected]>
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.

Report VM IP addresses to host agent

4 participants