add "owner" as a search constraint to maas cli machines command

Bug #1906724 reported by Jeff Lane 
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MAAS documentation
Triaged
Low
Unassigned

Bug Description

For anyone with an admin account who has logged into the MAAS api and is using maas-cli, they should be able to list all machines a user owns, in any state, or in a specified state...

the user story would be "As a MAAS admin, I want to see every machine $USER currently owns in any state so I can determine if they have too many allocated systems"

or

"As a MAAS admin, I want to see every deployed machine $USER currently owns"

As a workaround it IS kinda possible to do this with some jq hackery (sauce: https://maas.io/docs/cli-cookbook#heading--lsmm):

$ maasuser=jdoe; maas $MYMAAS machines read | jq -r '(.[] | [.hostname, .system_id, .owner]) | @tsv' | column -t |grep $maasuser
littleserver pqfcag jdoe
bigserver 86wp7a jdoe

however, this seems like such a basic admin task that any account with admin privileges should be able to do this without hackery like so:

maas $MYMASS machines read owner=jdoe
maas $MYMAAS machines read owner=jdoe status_name="Deployed"

I use "machines" here because getting info about machines is part of machine/machines commands in maas-cli. The JSON output for maas LOGIN machines read includes ownership ( "owner": "bladernr") and status like power state ("power_state": "on") and deployment status ("status_name": "Deployed")
So it seems reasonable that maas-cli could just add those fields as filters like it already does for things like id, hostname, vlan, etc.

In fact, it already lets you grab a dump of every machine in a given status:
maas LOGIN machines read status=deployed

So it seems just adding in owner as a new constraint would resolve this. (*well, you'd also need to define "status" better, because status appears to be not well described. But searching for status=failed_deployment seems to work just fine, I just had to guess a few times before I found the right status value to use)

There was the suggestion that the biggest issue would be permissions, but that seems fairly easy to sort out too...

if I'm an admin user, I can see the status of every machine registered in MAAS.

If I'm a standard user, I can still only see the machines I own or are available to me:
$ maas ubuntu machines read |grep owner
        "owner_data": {},
        "owner": "ubuntu",
        "owner_data": {},
        "owner": null,
        "owner_data": {},
        "owner": null,
        "owner_data": {},
        "owner": null,

$ maas ubuntu machines read | jq -r '(.[] | [.hostname, .system_id, .owner]) | @tsv' | column -t
server1 hs8fxs ubuntu
server2 4nbeyy
server3 pcyggy
server4 4w4b46

Those last two are the same MAAS server used before, only I'm doing the commands as a non-admin user, so instead of seeing the 30 registered machines I'd see as an admin, I only see the one machine the ubuntu user has deployed, and the three that are not allocated to anyone else.

Tags: cli
Jeff Lane  (bladernr)
description: updated
summary: - maas cli should make it easy for an admin to list all machines a user
- owns
+ add "owner" as a search constraint to maas cli machines command
tags: added: cli
Changed in maas:
status: New → Triaged
importance: Undecided → Low
milestone: none → 2.10-next
Changed in maas:
milestone: 3.0.0 → none
Revision history for this message
Adam Collard (adam-collard) wrote :

Hi Jeff,

You can already do this, and the maas cli allows filtering by owner e.g. https://pastebin.canonical.com/p/3xJvGmFFYD/

Does look like it's missing from the doc though

Changed in maas:
status: Triaged → Incomplete
Changed in maas-doc:
status: New → Incomplete
status: Incomplete → Triaged
importance: Undecided → Medium
milestone: none → 3.5.0
Revision history for this message
Bill Wear (billwear) wrote :

There is no search documentation for the CLI, per the standing prohibition on creating new CLI documentation in the short-term. Willing to rework the search page to add CLI instructions pending an okay from the bug council.

Changed in maas-doc:
status: Triaged → Incomplete
tags: added: bug-council
Revision history for this message
Jerzy Husakowski (jhusakowski) wrote :

Let's add this to the doc.

Changed in maas-doc:
importance: Medium → Low
status: Incomplete → Triaged
no longer affects: maas
tags: removed: bug-council
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.