[Fiware-lab-help] Object Storage example curl script

Kennedy, John M john.m.kennedy at intel.com
Fri Jan 24 22:00:52 CET 2014


Hello all,
Just in case there are still questions about accessing object storage, attached/below is a basic script to illustrate how to do the basic operations using curl. It is not fancy...but might give you ideas for your development.

It was tested on Ubuntu 13.04 with curl installed.

It is configured for fi-lab...just put in a fi-lab username and password.

The script:

-          Gets initial token, then tenantId, then token for that tenantId

-          Creates container

-          Stores / reads some basic text. Deletes the file.

-          Stores / retrieves a data file (the dat file in attached is actually a jpg file). Deletes the file

-          Deletes the container.

I will try to clean it up further on Monday and embed a version of it with the online documentation for support purposes.

In case some email firewall blocks the attachment there are two files:

-          CDMI_object_test_data.dat is a file with any data in it. My example has a jpg picture in it.

-          Cdmi_example_filab.sh - this is the script pasted below.

Rgds,

-          John.






#!/bin/bash
#
# Simple script to show some accesses to CDMI on devstack using curl
#
# Basic flow is :
#   Retrieve token
#   Check container 'capabilities'
#   Create a container, check it
#   Put an object in the container, read it, delete it - simple data
#   Put an object in the container, read it, delete it - user supplied data file
#   Delete the container
#
# There are some pauses in case the user wants to check container using the web
# portal
#
#
#-------------------------------------------------------------------------------
#
#
# Begin
username='youremail at organisation.com'
password='yourpassword'
#
node_auth='cloud.lab.fi-ware.eu'
node_cdmi='130.206.82.9'
mycontainer=CDMI_TEST
mydata='HelloWorld.txt'
myobject='CDMI_object_test_data.dat'
myobjectreceived='CDMI_object_test_data_received.dat'
#
# Initialisation check
#
if [ -f $myobject ]
then
    echo "Initialisation check complete"
else
    echo "Please create a file " $myobject " containing some test content."
    exit
fi
#
#
# Note .. assume write access to local directory
#
# Get initial token for a user/password combination
#
curl -d '{"auth": {"passwordCredentials": {"username":"'$username'", "password":"'$password'"}}}' \
     -H 'Content-type: aplication/json' \
     http://$node_auth:4730/v2.0/tokens \
     > auth_token1.dat
#
token1=$(awk -F"[,:]" '{for(i=1;i<=NF;i++)
                        {if($i~/id\042/)
                          {print $(i+1)}
                        }
                      }' auth_token1.dat | awk -F'"' '{print $2; exit}')
#
# Now get a valid tenantName for this token
#
curl -H 'x-auth-token: '$token1 \
      http://$node_auth:4730/v2.0/tenants \
      > auth_tenant.dat
#
tenantName=$(awk -F"[,:]" '{for(i=1;i<=NF;i++)
                        {if($i~/id\042/)
                          {print $(i+1)}
                        }
                      }' auth_tenant.dat | awk -F'"' '{print $2; exit}')
#
# Now get valid taken for user/password/tenant combination
#
curl -v \
    -d '{ "auth" :
           { "passwordCredentials" :
             { "username" : "'$username'" , "password" : "'$password'" },
           "tenantName" : "'$tenantName'" }
         }' \
     -H "Content-Type: application/json" \
      http://$node_auth:4730/v2.0/tokens \
      > auth_token2.dat
#
token=$(awk -F"[,:]" '{for(i=1;i<=NF;i++)
                        {if($i~/id\042/)
                          {print $(i+1)}
                        }
                      }' auth_token2.dat | awk -F'"' '{print $2; exit}')
auth=$(awk -F"[,:]" '{for(i=1;i<=NF;i++)
                       {if($i~/publicURL\042/)
                         {print $(i+3)}
                       }
                     }' auth_token2.dat | \
   grep  "v1/AUTH" | awk -F'"}]' '{print $1;}' | awk -F"/" '{print $3;}' )
#
# We need these two for any access to the CDMI proxy
#
echo " The TOKEN is : $token"
echo " The AUTH is  : $auth"
export token auth
#
#
echo " "
echo " "
#
# Now use acquired info to enquire the cdmi capabilities
#
echo "*** Enquire CDMI Capabilities"
curl -v \
     -X GET \
     -H 'X-Auth-Token: '$token \
     -H 'Accept: application/cdmi-capability' \
     -H 'X-CDMI-Specification-Version: 1.0.1' \
      http://$node_cdmi:8080/cdmi/$auth/cdmi_capabilities/
#
#
echo " "
echo " "
echo "*** Create a new Container"
curl -v -X PUT \
     -H 'X-Auth-Token: '$token \
     -H 'Content-Type: application/cdmi-container' \
     -H 'Accept: application/cdmi-container' \
     -d '{"metadata": {}}' \
      http://$node_cdmi:8080/cdmi/$auth/$mycontainer/
#
#
echo " "
echo " "
echo "*** Check the 'capabilities' on the container"
curl -v \
     -X GET \
     -H 'X-Auth-Token: '$token \
     -H 'Accept: application/cdmi-capability' \
     -H 'X-CDMI-Specification-Version: 1.0.1' \
      http://$node_cdmi:8080/cdmi/$auth/cdmi_capabilities/container/$mycontainer/
#
#
echo " "
echo " "
echo "*** Place a Data Object in the container"
curl -v -X PUT \
     -H 'X-Auth-Token: '$token \
     -H 'Accept: application/cdmi-object' \
     -H 'Content-Type: application/cdmi-object' \
     -d '{"mimetype":"text/plain", "metadata":{}, "value" : "Hello CDMI World"}' \
      http://$node_cdmi:8080/cdmi/$auth/$mycontainer/$mydata
#
#
echo " "
echo " "
echo "*** List Contents of a container"
curl -v \
     -X GET \
     -H 'X-Auth-Token: '$token \
     -H 'Content-Type: application/cdmi-container' \
     -H 'Accept: */*' \
    -H 'X-CDMI-Specification-Version: 1.0.1' \
      http://$node_cdmi:8080/cdmi/$auth/$mycontainer/
#
#
echo " "
echo " "
echo -n "There should now be an object in the container. Press Enter to continue."
read
#
#
echo " "
echo " "
echo "*** Read Contents of Data Object"
curl -v \
     -X GET \
     -H 'X-Auth-Token: '$token \
     -H 'Accept: application/cdmi-object' \
     -H 'X-CDMI-Specification-Version: 1.0.1' \
      http://$node_cdmi:8080/cdmi/$auth/$mycontainer/$mydata
#
#
echo " "
echo " "
echo "*** Read only the Value of a Data Object"
curl -v \
     -X GET \
     -H 'X-Auth-Token: '$token \
      http://$node_cdmi:8080/cdmi/$auth/$mycontainer/$mydata
#
#
echo " "
echo " "
echo "*** Delete the Data Object"
curl -v \
     -X DELETE \
     -H 'X-Auth-Token: '$token \
     -H 'Content-Type: application/cdmi-object' \
     -H 'X-CDMI-Specification-Version: 1.0.1' \
      http://$node_cdmi:8080/cdmi/$auth/$mycontainer/$mydata
#
#
echo " "
echo " "
echo "*** List Contents of a container"
curl -v \
     -X GET \
     -H 'X-Auth-Token: '$token \
     -H 'Content-Type: application/cdmi-container' \
     -H 'Accept: */*' \
     -H 'X-CDMI-Specification-Version: 1.0.1' \
      http://$node_cdmi:8080/cdmi/$auth/$mycontainer/
#
#
echo " "
echo " "
echo -n "The container should now be empty. Press Enter to continue."
read
#
#
echo " "
echo " "
echo "*** Copy a file up to the Data Object"
curl -v \
     -X PUT \
     -H 'X-Auth-Token: '$token \
     -H 'Content-Type: application/stream-octet' \
     -H 'Accept: */*' \
     --data-binary "@$myobject" \
     http://$node_cdmi:8080/cdmi/$auth/$mycontainer/$myobject
#
#
echo " "
echo " "
echo "*** List Contents of a container"
curl -v \
     -X GET \
     -H 'X-Auth-Token: '$token \
     -H 'Content-Type: application/cdmi-container' \
     -H 'Accept: */*' \
     -H 'X-CDMI-Specification-Version: 1.0.1' \
      http://$node_cdmi:8080/cdmi/$auth/$mycontainer/
#
#
echo " "
echo " "
echo -n "There should now be an object in the container. Press Enter to continue."
read
#
#
echo " "
echo " "
echo "*** Read Data back from Data Object"
curl -X GET \
     -H 'X-Auth-Token: '$token \
     http://$node_cdmi:8080/cdmi/$auth/$mycontainer/$myobject \
      --output $myobjectreceived
#
#
echo " "
echo " "
echo "*** Delete the Data Object, tidy up"
curl -v \
     -X DELETE \
     -H 'X-Auth-Token: '$token \
     -H 'Content-Type: application/cdmi-object' \
     -H 'X-CDMI-Specification-Version: 1.0.1' \
      http://$node_cdmi:8080/cdmi/$auth/$mycontainer/$myobject
#
#
echo " "
echo " "
echo "*** Delete the Container, tidy up"
curl -v \
    -X DELETE \
     -H 'X-Auth-Token: '$token \
     -H 'Content-Type: application/cdmi-object' \
     -H 'X-CDMI-Specification-Version: 1.0.1' \
      http://$node_cdmi:8080/cdmi/$auth/$mycontainer
#
#
echo " "
echo "*** Done"
exit



-------------------------------------------------------------
Intel Ireland Limited (Branch)
Collinstown Industrial Park, Leixlip, County Kildare, Ireland
Registered Number: E902934

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.fiware.org/private/fiware-lab-help/attachments/20140124/71c38553/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cdmiexample.zip
Type: application/x-zip-compressed
Size: 108742 bytes
Desc: cdmiexample.zip
URL: <https://lists.fiware.org/private/fiware-lab-help/attachments/20140124/71c38553/attachment.bin>


More information about the Fiware-lab-help mailing list

You can get more information about our cookies and privacy policies clicking on the following links: Privacy policy   Cookies policy