Roles#
The SDK provides functionality to interact with roles on on-prem Cloud Pak for Data deployments.
- This includes operations such as:
Creating roles
Listing roles
Updating roles
Deleting roles
Creating roles#
To create a new role using the SDK, you can call Platform.create_role_on_prem() method with name, description and permissions parameters.
>>> new_role = platform.create_role_on_prem(
... name='MyNewRole',
... description='iam-groups',
... permissions=['create_project', 'manage_locations', 'manage_data_planes', 'view_locations'],
... )
>>> new_role
RoleOnPrem(role_id='12345' role_name='MyNewRole')
Listing roles#
To retrieve roles you can use the Platform.roles property.
>>> platform.roles
[..., RoleOnPrem(role_id='12345' role_name='MyNewRole')...]
- You can filter roles by using the
get()method on thePlatform.rolesproperty and providing any of the following arguments: role_id: The role id.role_name: Name of the role.
>>> platform.roles.get(role_name='MyNewRole')
RoleOnPrem(role_id='12345' role_name='MyNewRole')
Updating roles#
To update a role using the SDK, first retrieve it by using the Platform.roles property.
Next, make in-memory changes to the object and pass it into the Platform.update_role() method.
>>> new_role.role_name='updated role name'
>>> new_role.description='updated description'
>>> new_role.permissions=['administrator']
>>> platform.update_role(new_role)
<Response [200]>
>>> updated_role = platform.roles.get(role_id=new_role.id)
>>> updated_role
RoleOnPrem(role_id='12345' role_name='updated role name')
Deleting roles#
To delete a role using the SDK, first retrieve it by using Platform.roles property.
Then, pass the object into the Platform.delete_role() method.
>>> platform.delete_role(updated_role)
<Response [204]>