Chapter 5. Performing operations with the Object Storage service (swift) The Object Storage service (swift) stores its objects, or data, in containers. Containers are similar to directories in a file system although you cannot nest them. You can store any kind of unstructured data in containers. For example, objects can include photos, text files, or images. Stored objects are not compressed. You can create pseudo-folders in containers to organize data. Pseudo-folders are logical devices for containing objects and creating a nested structure in containers. For example, you might create an Images folder in which to store pictures and a Media folder in which to store videos. You can create one or more containers in each project, and one or more objects or pseudo-folders in each container. 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: Use this option if you access more than one cloud. Create an environment variable for the cloud name in your bashrc file: 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.1. Creating private and public containers You can create private or public containers to store data in the Object Storage service (swift): Private: Limits access to a member of a project. Public: Permits access to anyone with the public URL. New containers use the default storage policy. If your Red Hat OpenStack Services on OpenShift (RHOSO) deployment has multiple storage policies defined, for example, a default policy and another policy that enables erasure coding, you can configure a container to use a non-default storage policy. Procedure 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: 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: Configure the container to use a non-default storage policy: Replace <policy> with the name or alias of the policy you want to use for the container. 5.2. Creating pseudo-folders in containers You can create pseudo-folders to organize data in a container in the OpenStack Object Storage service (swift). You create a pseudo-folder by prefixing the names of the objects with the name of the pseudo-folder and a forward slash character (/). For example, if you have a container called container , and you want to organize objects in a pseudo-folder called folder , you add folder/ at the beginning of the name of the object data file: folder/object.ext . You can create nested pseudo-folders in the same way, by including the name of the nested folder and a forward slash at the beginning of the object name, for example, folder/nested_folder/object.ext . The URL of the object will end with container/folder/object.ext or container/folder/nested_folder/object.ext . You can use the GET method with prefix and delimiter parameters to navigate pseudo-folders. Procedure Upload an object and create a pseudo-folder in a container: 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. Upload an object and create a nested pseudo-folder: Replace <nested_folder> with the name of your nested pseudo-folder. View a list of objects, including nested pseudo-folders, in a pseudo-folder: Replace <account> with your namespace for containers, for example, your Red Hat OpenStack Services on OpenShift (RHOSO) project or tenant. 5.3. Deleting containers from the Object Storage service If you want to delete a container from the Object Storage service (swift), ensure that you delete all objects in the container first. For more information, see Deleting objects from the Object Storage service . Procedure Delete a container: Replace <container> with the name of the container you want to delete. 5.4. Uploading objects to containers You can upload object data files to a container or pseudo-folder in the Object Storage service (swift). Alternatively, you can create an object as a placeholder in a container or pseudo-folder, and upload the file to the object later. Procedure Upload an object to a container: Replace <container> with the name of the container. Replace <object_filename> with the name of the object data file. 5.5. Copying objects between containers You can copy an object from a source container or pseudo-folder to a destination container or pseudo-folder in the Object Storage service (swift). 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 object. Procedure Copy an object from one container to a destination container: 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.6. 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: 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.

Commands:
openstack flavor list --os-cloud <cloud_name>
`export OS_CLOUD=<cloud_name>`
openstack container create <container> --read-acl "<project_id>":*" --write-acl "<project_id>:*"
openstack container create <container> --read-acl ".r:*,.rlistings"
openstack container set -H "X-Storage-Policy:<policy>" <container>
openstack object create <container> <pseudo_folder>/<object_filename>
openstack object create <container> <pseudo_folder>/<nested_folder>/<object_filename>
curl -X GET -i -H "X-Auth-Token: USDtoken" USDpublicurl/v1/<account>/<container>?prefix=<folder>&delimiter=/
openstack container delete <container>
openstack object create <container> <object_filename>
openstack copy --destination </container/object> <container> <object> [<object>] [...]
openstack object delete [--all] <container> <object> [...]