How to manage storage

> See also: juju:storage

This document shows how to manage storage. This will enable you to allocate resources at a granular level and can be useful in optimizing the deployment of an application. The level of sophistication is limited by your cloud (whether it supports dynamic storage or storage configuration attributes), and by the charm in charge of that application (whether it supports storage persistence, additional cache, etc.).

Add storage

To create and attach a storage instance to a unit, on a Unit object, use the add_storage() method, passing the storage name as an argument. For example:

await my_unit.add_storage("pgdata", size=512)

To attach an existing storage to an application during deployment, on a connected Model object, use the attach_storage parameter of the deploy() method.

await model.deploy('postgresql', attach_storage=[tag.storage("my-storage")])

> See more: add_storage(), Unit (module), deploy(), Model (module)

List available storage

To list available storage instances, on a connected Model object, use the list_storage() method. For example:

await model.list_storage()

> See more: list_storage(), Model (module)

Detach storage

To detach a storage instance from a unit, on a Unit object, use the detach_storage() method, passing the storage id as an argument. For example:

await my_unit.detach_storage("osd-devices/2")

> See more: detach_storage(), Unit (module)

Attach storage

To attach an existing storage instance to a unit, on a Unit object, use the attach_storage() method, passing the storage id as an argument. For example:

await my_unit.attach_storage(["osd-devices/2"])

> See more: attach_storage(), Unit (module)

Remove storage

> See also: juju-removing-things

To remove a storage instance, on a connected Model object, use the remove_storage() method, passing the storage id as an argument. For example:

# use force=True to remove storage even if it is currently attached
await my_model.remove_storage(["osd-devices/2"], force=True)

> See more: remove_storage(), Model (module)