Groups API
Before you start, make sure that the igz_mgmt package is installed and that you are logged in to the system with the igz_mgmt.Client API. If not, see Control plane API.
import igz_mgmt
client = igz_mgmt.Client(access_key="some-access-id")
Create a group
group = igz_mgmt.Group.create(client, name="random-people")
List groups
groups = igz_mgmt.Group.list(client, filter_by={"name": "random-people"})
Tip:
- To list resources and filter by a field, use
filter_by={"fieldname": "fieldvalue"}
.
Get a group
# get the group with its users
group = igz_mgmt.Group.get(client, group.id, include=["users"])
Note: this function gets a group using its id that was already generated in the database, and not by its GID.
Tips:
- To include a resource related to another (e.g.: group includes users), use
include=["users"]
when you.get()
the group. This is optional. - You can also to get a group by name, instead of by id, by using:
group = igz_mgmt.Group.get_by_name(client, group.name, include=["users"])
Add / remove user from a group
An example of creating a user, and adding / removing the user from the group:
# create user
import time
new_user = igz_mgmt.User.create(
client,
username="anewuser",
password="rePlaceme12@!",
email="user@iguazio.com",
first_name="someone",
last_name="fromthepast",
)
# add user to group
group.add_user(client, new_user.id)
# get the group with its users
group = igz_mgmt.Group.get(client, group.id, include=["users"])
# make sure you see the user in group users
found = (
len(
list(
filter(
lambda user: user["id"] == new_user.id,
group.relationships.get("users").get("data"),
)
)
)
> 0
)
print("User was added: " + str(found))
# remove user from group
group.remove_user(client, new_user.id)
Tip:
To remove a user from its primary group, add force=True
to the remove_user
function.
Delete a group
Set wait_for_job_deletion=False
to continue with the functions flow without waiting for a response. The delete function
does not return a response.
group.delete(client, ignore_missing=False)
Ensure project membership
Ensure that the group has the given role in the given project. If the group is not a member of the project, it is added to the project with the given role. By default, this overrides the group’s current role in the project, if it is already a member.
group = igz_mgmt.Group.get_by_name(client, "default-group")
group.ensure_project_membership(client, project_name="default", role=igz_mgmt.constants.ProjectAuthorizationRoles.admin)
Remove from project
Remove the group as a member of the project.
group = igz_mgmt.Group.get_by_name(client, "default-group")
group.remove_from_project(client, project_name="default")