Ce contenu n'est pas disponible dans la langue sélectionnée.

Chapter 5. Performing operations with the Object Storage service (swift)


You can use the Object Storage service (swift) to store and manage unstructured data such as photos, documents, backups, and media files in containers. Containers provide a scalable storage solution for large amounts of static data without the overhead of traditional file systems. You can create private containers to restrict access to project members or public containers to share data with external users, and organize objects using pseudo-folders to create logical hierarchical structures.

Note

To execute openstack client commands on the cloud, you must specify the name of the cloud detailed in your clouds.yaml file. You can specify the name of the cloud by using one of the following methods:

  • Use the --os-cloud option with each command:
$ openstack flavor list --os-cloud <cloud_name>

Use this option if you access more than one cloud.

  • Create an environment variable for the cloud name in your bashrc file:
`export OS_CLOUD=<cloud_name>`

5.1. Prerequisites

  • The administrator has created a project for you, and they have provided you with a clouds.yaml file for you to access the cloud.
  • You have installed the python-openstackclient package.

5.2. Creating private and public Object Storage containers

You can create private or public containers in the Object Storage service (swift) to store unstructured data objects. Private containers limit access to members of your project, protecting sensitive data, while public containers allow anyone with the URL to access stored objects, making them useful for sharing content publicly. You can also configure containers to use non-default storage policies if your deployment has multiple policies defined.

Procedure

  1. Create a private or public container:

    • Create a private container to allow members of a project to list the objects in the container, upload, and download objects. Project members include an Identity service (keystone) token for the project in their requests:

      $ openstack container create <container> \
          --read-acl "<project_id>:*" \
          --write-acl "<project_id>:*"
      • Replace <container> with the name of your container.
      • Replace <project_id> with the ID of the project.
    • Create a public container to allow anyone with the public URL to list objects in the container and download objects from the container:

      $ openstack container create <container> \
          --read-acl ".r:*,.rlistings"
  2. Configure the container to use a non-default storage policy:

    $ openstack container set -H "X-Storage-Policy:<policy>" <container>
    • Replace <policy> with the name or alias of the policy you want to use for the container.

5.3. Creating pseudo-folders in Object Storage containers

You can create pseudo-folders to organize objects within containers in a hierarchical structure, making it easier to manage and navigate large collections of data. You create pseudo-folders by prefixing object names with the folder name and a forward slash character (folder/object.ext). You can nest pseudo-folders by including multiple folder names in the prefix (folder/nested_folder/object.ext).

Procedure

  1. Upload an object and create a pseudo-folder in a container:

    $ openstack object create <container> <pseudo_folder>/<object_filename>
    • Replace <container> with the name of your container.
    • Replace <pseudo_folder> with the name of the pseudo-folder you want to create.
    • Replace <object_filename> with the name of your object data file.
  2. Upload an object and create a nested pseudo-folder:

    $ openstack object create <container> <pseudo_folder>/<nested_folder>/<object_filename>
    • Replace <nested_folder> with the name of your nested pseudo-folder.
  3. View a list of objects, including nested pseudo-folders, in a pseudo-folder:

    $ curl -X GET -i -H "X-Auth-Token: $token" \
     $publicurl/v1/<account>/<container>?prefix=<folder>&delimiter=/
    • Replace <account> with your namespace for containers, for example, your Red Hat OpenStack Services on OpenShift (RHOSO) project or tenant.

5.4. Deleting containers from the Object Storage service

You can delete containers from the Object Storage service (swift) to remove them and free up resources when they are no longer needed. Before you can delete a container, you must first delete all objects stored within it, as the service does not allow deletion of containers that contain objects. Deleting unused containers helps keep your project organized and prevents accumulation of obsolete storage structures.

Procedure

  • Delete a container:

    $ openstack container delete <container>
    • Replace <container> with the name of the container you want to delete.

5.5. Uploading objects to Object Storage containers

You can upload object data files to containers or pseudo-folders in the Object Storage service (swift) to store your unstructured data. Uploading objects allows you to store files such as images, documents, backups, or any other binary data in a scalable cloud storage system. Alternatively, you can create placeholder objects first and upload the actual file content to them later.

Procedure

  • Upload an object to a container:

    $ openstack object create <container> <object_filename>
    • Replace <container> with the name of the container.
    • Replace <object_filename> with the name of the object data file.

5.6. Copying objects between Object Storage containers

You can copy objects from one container or pseudo-folder to another within the Object Storage service (swift). Copying objects is useful for creating duplicates of data in different locations, reorganizing your storage structure, or migrating data between containers.

Note

If you do not specify a unique name for the destination object, it keeps the same name as the source object. If you use a name that already exists in the destination, the new object overwrites the contents of the previous object.

Procedure

  • Copy an object from one container to a destination container:

    $ openstack copy --destination </container/object> \
                     <container> <object> \
                     [<object>] [...]
    • Replace </container/object> with the container and name of the destination object.
    • Replace <container> with the name of the container you want to copy the object from.
    • Replace <object> with the name of the object you want to copy. You can specify multiple objects to copy.

5.7. Deleting objects from the Object Storage service

Delete an object from a container in the Object Storage service (swift).

Procedure

  • Delete an object from a container:

    $ openstack object delete [--all] <container> <object> [...]
    • Replace <container> with the name of the container you are deleting the object from.
    • Replace <object> with the name of the object you are deleting. You can specify multiple objects to delete.
    • Optional: To delete all objects in the container, use the --all command option.
Red Hat logoGithubredditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance. Découvrez nos récentes mises à jour.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez le Blog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

Theme

© 2026 Red Hat
Retour au début