canonical / craft-providers

Python interfaces for instantiating and executing builds for a variety of target environments.
https://canonical-craft-providers.readthedocs-hosted.com/en/latest/
GNU Lesser General Public License v3.0
6 stars 20 forks source link

Provide a way to query a build instance's network info #579

Open tigarmo opened 2 weeks ago

tigarmo commented 2 weeks ago

What needs to get done

Provide API support on the Executor class to retrieve a build instance's networking info. What I need specifically is to know the instance's gateway, but I imagine the info as a whole would have uses. Currently I'm doing the following (only for LXD instances):

    instance_name = instance.instance_name
    project = instance.project
    output = subprocess.check_output(
        ["lxc", "--project", project, "config", "show", instance_name, "--expanded"],
        text=True,
    )
    config = util.safe_yaml_load(io.StringIO(output))
    network = config["devices"]["eth0"]["network"]

    route = subprocess.check_output(
        ["ip", "route", "show", "dev", network],
        text=True,
    )
    gateway = route.strip().split()[-1]

Why it needs to get done

In my case I need the application inside the instance to be able to talk to a service that is listening on a port on the host.

syncronize-issues-to-jira[bot] commented 2 weeks ago

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CRAFT-3019.

This message was autogenerated

sergiusens commented 2 weeks ago

For eventual multipass

sergiusens@cuivienen:~$ multipass info prophetic-marten --format json
{
    "errors": [
    ],
    "info": {
        "prophetic-marten": {
            "cpu_count": "1",
            "disks": {
                "sda1": {
                    "total": "5116440064",
                    "used": "1966147072"
                }
            },
            "image_hash": "32a9d30d18803da72f5936cf2b7b9efcb4d0bb63c67933f17e3bdfd1751de3f3",
            "image_release": "24.04 LTS",
            "ipv4": [
                "10.188.41.35"
            ],
            "load": [
                0.04,
                0.01,
                0
            ],
            "memory": {
                "total": 2057912320,
                "used": 300941312
            },
            "mounts": {
            },
            "release": "Ubuntu 24.04 LTS",
            "snapshot_count": "0",
            "state": "Running"
        }
    }
}