Bookmark this page

Guided Exercise: Providing Object Storage Using the Swift API

In this exercise, you will configure the RADOS Gateway and access the gateway using the Swift API.

Outcomes

You should be able to configure the Ceph Object Gateway to allow access to Ceph object storage via the Swift API.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

[student@workstation ~]$ lab start api-swift

This command confirms that the hosts required for this exercise are accessible. It installs the awscli package on clienta and creates the operator user and the testbucket bucket.

Procedure 9.2. Instructions

  1. Log in to clienta as the admin user.

    [student@workstation ~]$ ssh admin@clienta
    [admin@clienta ~]$
  2. Create a Swift subuser called operator:swift on the Ceph Object Gateway for accessing object storage using the Swift API.

    You are creating a new subuser attached to the operator user that was created by the lab start command. The operator user can currently access Ceph object storage using the S3 API. With this additional configuration, the operator user can create objects and buckets using the S3 API, and then use the Swift API to manage the same objects.

    Use opswift as the Swift secret key. Assign full permissions to the user.

    [admin@clienta ~]$ sudo cephadm shell -- radosgw-admin subuser create \
      --uid="operator" --subuser="operator:swift" --access="full" --secret="opswift"
    {
        "user_id": "operator",
        "display_name": "S3 Operator",
        "email": "operator@example.com",
        "suspended": 0,
        "max_buckets": 1000,
        "subusers": [
            {
                "id": "operator:swift",
                "permissions": "full-control"
            }
        ],
        "keys": [
            {
                "user": "operator",
                "access_key": "12345",
                "secret_key": "67890"
            }
        ],
        "swift_keys": [
            {
                "user": "operator:swift",
                "secret_key": "opswift"
            }
        ],
        "caps": [],
        "op_mask": "read, write, delete",
        "default_placement": "",
        "default_storage_class": "",
    ...output omitted...
  3. Install the swift client on clienta. Verify access using the operator:swift subuser credentials. Use -K to specify the Swift secret key for the user.

    1. Install the swift client on clienta.

      [admin@clienta ~]$ sudo pip3 install --upgrade python-swiftclient
      ...output omitted...
    2. Verify the bucket status. Your output might be different in your lab environment.

      [admin@clienta ~]$ swift -A http://serverc:80/auth/1.0 \
        -U operator:swift -K opswift stat
                                          Account: v1
                                       Containers: 1
                                          Objects: 0
                                            Bytes: 0
      Objects in policy "default-placement-bytes": 0
        Bytes in policy "default-placement-bytes": 0
         Containers in policy "default-placement": 1
            Objects in policy "default-placement": 0
              Bytes in policy "default-placement": 0
                                      X-Timestamp: 1633518961.75503
                      X-Account-Bytes-Used-Actual: 0
                                       X-Trans-Id: tx00000000000000000000a-00615d8571-ace6-default
                           X-Openstack-Request-Id: tx00000000000000000000a-00615d8571-ace6-default
                                    Accept-Ranges: bytes
                                     Content-Type: text/plain; charset=utf-8
                                       Connection: Keep-Alive
  4. Create and list the Swift containers.

    1. List the currently available containers.

      [admin@clienta ~]$ swift -A http://serverc:80/auth/1.0 \
        -U operator:swift -K opswift list
      testbucket
    2. Create a Swift container called testcontainer.

      [admin@clienta ~]$ swift -A http://serverc:80/auth/1.0 \
        -U operator:swift -K opswift post testcontainer
      [admin@clienta ~]$ swift -A http://serverc:80/auth/1.0 \
        -U operator:swift -K opswift list
      testbucket
      testcontainer
  5. Create a 10 MB file called swift.dat. Upload the file to testcontainer.

    [admin@clienta ~]$ dd if=/dev/zero of=/tmp/swift.dat bs=1024K count=10
    10+0 records in
    10+0 records out
    10485760 bytes (10 MB) copied, 0.00926399 s, 1.1 GB/s
    [admin@clienta ~]$ swift -A http://serverc:80/auth/1.0 \
     -U operator:swift -K opswift upload testcontainer /tmp/swift.dat
    tmp/swift.dat
  6. View the statistics for testcontainer.

    [admin@clienta ~]$ swift -A http://serverc:80/auth/1.0 \
      -U operator:swift -K opswift stat testcontainer
                          Account: v1
                        Container: testcontainer
                          Objects: 1
                            Bytes: 10485760
                         Read ACL:
                        Write ACL:
                          Sync To:
                         Sync Key:
                      X-Timestamp: 1615999768.12521
    X-Container-Bytes-Used-Actual: 10485760
                 X-Storage-Policy: default-placement
                  X-Storage-Class: STANDARD
                    Last-Modified: Wed, 06 Oct 2021 16:50:13 GMT
                       X-Trans-Id: tx000000000000000000013-0060523354-853f-default
           X-Openstack-Request-Id: tx000000000000000000013-0060523354-853f-default
                    Accept-Ranges: bytes
                     Content-Type: text/plain; charset=utf-8
                       Connection: Keep-Alive
  7. View the statistics for the operator:swift subuser.

    [admin@clienta ~]$ swift -A http://serverc:80/auth/1.0 \
      -U operator:swift -K opswift stat
                                        Account: v1
                                     Containers: 2
                                        Objects: 1
                                          Bytes: 10485760
       Containers in policy "default-placement": 2
          Objects in policy "default-placement": 1
            Bytes in policy "default-placement": 10485760
    Objects in policy "default-placement-bytes": 0
      Bytes in policy "default-placement-bytes": 0
                                    X-Timestamp: 1615999935.32600
                    X-Account-Bytes-Used-Actual: 10485760
                                     X-Trans-Id: tx000000000000000000015-00605233bf-853f-default
                         X-Openstack-Request-Id: tx000000000000000000015-00605233bf-853f-default
                                  Accept-Ranges: bytes
                                   Content-Type: text/plain; charset=utf-8
                                     Connection: Keep-Alive
  8. Return to workstation as the student user.

    [admin@clienta ~]$ exit
    [student@workstation ~]$

Finish

On the workstation machine, use the lab command to complete this exercise. This is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish api-swift

This concludes the guided exercise.

Revision: cl260-5.0-29d2128