Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make documentation clear for non-privileged users #12

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
31 changes: 24 additions & 7 deletions docs/user_docs/USAGE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# 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 @@ -16,9 +34,8 @@ query.select("name", "id")
# Where - define a preset ("any in" = match any value given), a property to apply it to (server status) and value/s to look for (ERROR, SHUTOFF)
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)
# Run - this will run the query in the "prod" cloud domain and will find VMs in your project set in `clouds.yaml`.
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
Loading