looking up node by hostname using the API

I’m currently using the following code to look up a machine by hostname:

        client = maas.client.connect(endpoint, apikey=oauthkey)
        machine = None
        for m in client.machines.list():
            if m.hostname == hostname:
                machine = m

Is there a faster way? If not, I’m thinking of just implementing a cache in my app.

When you list you can specify the hostname parameter for each hostname

$ maas $PROFILE machines read hostname=maas-test-1 hostname=maas-test-2 | jq -r '.[] | .hostname + ": " + .system_id'
maas-test-1: dken44
maas-test-2: kgntx8

Thanks @ltrager. Do you know if there’s an equivalent in python-libmaas?



This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.