Allows the enterprise admin to manage the Storage Policies for users in their enterprise. Used for an enterprise to decide storage location for users based on where they work/reside.
- Get Storage Policy
- List Available Storage Policies
- Assign a Storage Policy to a User
- Get Assignment Information about a Storage Policy Assignment
- Get Assignment for User
- Delete Assignment
To get a storage policy object, first call client.storage_policy(policy_id)
to construct the
appropriate Storage Policy
object, and then calling storage_policy.get(*, fields=None, headers=None, **kwargs)
will return the StoragePolicy
object populated with data from the API.
storage_policy = client.storage_policy(policy_id='12345').get()
print(f'Storage Policy ID is {storage_policy.id} and name is {storage_policy.name}')
To retrieve all storage policies for an enterprise, call client.get_storage_policies(limit=None, fields=None)
.
This method returns a BoxObjectCollection
that allows you to iterate over the StoragePolicy
objects in the collection.
storage_policies = client.get_storage_policies(limit=100)
for storage_policy in storage_policies:
print(f'The storage policy id is {storage_policy.id} and name is {storage_policy.name}')
To assign a storage policy to a user, call storage_policy.assign(user)
will create a
StoragePolicyAssignment
object with data populated from the API.
user = client.user(user_id='12345')
assignment = client.storage_policy(policy_id='56781').assign(user)
print(f'Assignment ID is {assignment.id} and the assignee id is {assignment.assigned_to.id}')
If you know the user does not have a storage policy assigned you can directly create a storage policy assignment by calling
storage_policy.create_assignment(user)
will create a StoragePolicyAssignment
object with data populated from the API.
user = client.user('56781')
assignment = client.storage_policy(policy_id='12345').create_assignment(user)
print(f'Storage Policy Assignment ID is {assignment.id} and the assignee ID is {assignment.assigned_to.id}')
If the user already has an assignment, you can call [storage_policy_assignment.update_info(data=updated_storage_policy)][update_info]
with a dict
of properties to update on the storage policy assignment. This method returns a newly update
StoragePolicyAssignment
object with data populated from the API, leaving the original
object unmodified.
updated_storage_policy = {'storage_policy': {'type': 'storage_policy', 'id': '12345'}}
updated_assignment = client.storage_policy_assignment(assignment_id='ZW50ZXJwcmldfgeV82MDMwMDQ=').update_info(data=updated_storage_policy)
print(f'Update storage policy ID is {updated_assignment.storage_policy.id}')
To get a storage policy assignment object, first call client.storage_policy_assignment(assignment_id)
to construct the appropriate Storage Policy Assignment
object, and then calling
storage_policy_assignment.get(*, fields=None, headers=None, **kwargs)
will return the StoragePolicyAssignment
object populated with data from the API.
assignment = client.storage_policy_assignment(assignment_id='12345').get()
print(f'Assignment ID is {assignment.id} and the storage policy ID is {assignment.storage_policy.id}')
To get a storage policy assignment object for a user, calling user.get_storage_policy_assignment()
will
return the StoragePolicyAssignment
object populated with data from the API.
assignment = client.user(user_id='12345').get_storage_policy_assignment()
print(f'Assignment ID is {assignment.id} and the storage policy ID is {assignment.storage_policy.id}')
To delete a storage policy assignment, call storage_policy_assignment.delete()
. This method returns True
to indicate that the deletion was successful.
client.storage_policy_assignment(assignment_id='12345').delete()
print('The storage policy assignment was successfully delete!')