cirruslabs / tart

macOS and Linux VMs on Apple Silicon to use in CI and other automations
https://tart.run
Other
3.67k stars 103 forks source link

Programmatically obtain bridge interface IP #726

Closed ghost closed 4 months ago

ghost commented 5 months ago

I'd be great for scripting purposes to be able to obtain the IP of the bridge interface used by Tart. :)

fkorotkov commented 5 months ago

Do you mean getting accurate tart ip? You can use arp resolver with --net-bridged:

tart run  --net-bridged="Wi-Fi" sonoma-base
tart ip --resolver=arp sonoma-base
ghost commented 5 months ago

The bridge interface on the host machine that Tart uses. It's currently named something along the lines of bridge100, so it's hard to programmatically determine which one it is.

There is of course a hack-around of launching a VM, getting its IP and figuring it out based on that, but that hinges on the VM having correctly configured networking (not always the case) and it presents a significant overhead in the context of a scripting workflow.

Perhaps obtaining the interface name as opposed to its IP address would open more doors with less acrobatics.

fkorotkov commented 5 months ago

I believe a new interface is created upon launching a VM so there is no way to know it in advance. You can see output of ifconfig before and after launch of the VM and see a new interface is added. Will that work for you use case?

ghost commented 5 months ago

The specific use case I have is binding a web server to the bridge interface on the host, in order to serve resources over HTTP to the VM that are used during the installation process, without exposing the web server to other networks. This happens as part of an automated process and is a pretty common pattern in DevOps. Think cloud-init and similar.

fkorotkov commented 5 months ago

If you are using Packer plugin you can look at HTTP server configuration otherwise there is also a way to connect to service running on the host via NAT. Does either of the options work for you?