Skip to content

Commit

Permalink
Make documentation clear for non-privileged users
Browse files Browse the repository at this point in the history
The previous snippets in the documentation only work if the user have
admin privileges. Documentation now makes more clear what queries need
to be executed for regular non-privileged users.

Also, documentation gives some clue on how to find out the exact value
of the cloud domain name to be passed as first argument to query.run()
  • Loading branch information
jose-caballero committed Jan 7, 2025
1 parent 65bcd72 commit 8375d07
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/user_docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ a query in a declarative way.

This document describes how to use the SQL-like API to run Openstack Queries

Remember to replace `query.run("openstack-domain", as_admin=True, all_projects=True)` by `query.run("openstack-domain")` if you don't have admin privileges in the OpenStack service.

## Querying on Resources

The query library currently supports queries on the following Openstack resources
Expand Down
27 changes: 22 additions & 5 deletions docs/user_docs/USAGE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Usage
The following document contains different ways to use the query library
The following document contains different ways to use the query library.

The examples assume:
* you do not have admin privileges for the OpenStack service
* the name of your Cloud domain is `prod`

You can find the actual Cloud domain name in your `clouds.yaml` file.
If you have admin privileges, the queries can be performed for all projects in OpenStack. For that, just replace the lines

```python
query.run("prod")
```

by

```python
query.run("prod", as_admin=True, all_projects=True)
```

## Simple Query
Find Errored and Shutoff VMs
Expand All @@ -18,7 +35,7 @@ query.where("any_in", "status", values=["ERROR", "SHUTOFF"])

# Run - this will run the query in the "prod" cloud domain and with meta-params as_admin and all_projects.
# This will run the query as an admin and will find VMs on every available project
query.run("prod", as_admin=True, all_projects=True)
query.run("prod")

# Group By - This will group the results by a property - project_id
# NOTE: group by property and selected property are completely independent
Expand Down Expand Up @@ -47,7 +64,7 @@ query.where("any_in", "status", values=["ERROR", "SHUTOFF"])
query.where("older_than", "last_updated_date", days=60)


query.run("prod", as_admin=True, all_projects=True)
query.run("prod")
query.group_by("id")
print(query.to_string())
```
Expand Down Expand Up @@ -81,7 +98,7 @@ server_query = user_query.then("SERVER_QUERY", keep_previous_results=True)
server_query.select("name", "id")
server_query.where("any_in", "status", values=["ERROR", "SHUTOFF"])
server_query.where("older_than", "last_updated_date", days=60)
server_query.run("prod", as_admin=True, all_projects=True)
server_query.run("prod")
server_query.group_by("project_id")

# These results will contain VM associated values for user_name and user_email
Expand Down Expand Up @@ -109,7 +126,7 @@ server_query = user_query.then("SERVER_QUERY", keep_previous_results=True)
server_query.select("name", "id")
server_query.where("any_in", "status", values=["ERROR", "SHUTOFF"])
server_query.where("older_than", "last_updated_date", days=60)
server_query.run("prod", as_admin=True, all_projects=True)
server_query.run("prod")

# We need to get project name by running append_from()
# append_from() command below is the same as doing the following:
Expand Down

0 comments on commit 8375d07

Please sign in to comment.