此内容没有您所选择的语言版本。
Appendix B. API Usage with cURL
A Red Hat Enterprise Linux user installs cURL with the following terminal command:
yum install curl
cURL uses a command line interface to send requests to a HTTP server. Integrating a request requires the following command syntax:
Usage: curl [options]uri
Usage: curl [options]uri
uri refers to target HTTP address to send the request. This is a location on your Red Hat Gluster Storage Console host within the API entry point path (/api).
cURL options
- -X COMMAND, --request COMMAND
- The request command to use. In the context of the REST API, use
GET,POST,PUTorDELETE.Example:-X GET - -H LINE, --header LINE
- HTTP header to include with the request. Use multiple header options if more than one header is required.Example:
-H "Accept: application/xml" -H "Content-Type: application/xml" - -u USERNAME:PASSWORD, --user USERNAME:PASSWORD
- The username and password of the Red Hat Gluster Storage Console user. This attribute acts as a convenient replacement for the
Authorization:header.Example:-u admin@internal:p@55w0rd! - --cacert CERTIFICATE
- The location of the certificate file for SSL communication to the REST API. The certificate file is saved locally on the client machine. Use the
-kattribute to bypass SSL. See Chapter 2, Authentication and Security for more information on obtaining a certificate.Example:--cacert ~/Certificates/rhsc.cer - -d BODY, --data BODY
- The body to send for requests. Use with
POST,PUTandDELETErequests. Ensure to specify theContent-Type: application/xmlheader if a body exists in the request.Example:-d "<bricks><brick><server_id>fcb46b88-f32e-11e1-918a-0050568c4349</server_id><brick_dir>/export/data/brick3</brick_dir></brick></bricks>"
The following examples show how to adapt REST requests to cURL command syntax:
Example B.1. GET request
GET request lists the clusters in the cluster collection. Note that a GET request does not contain a body.
GET /api/clusters HTTP/1.1 Accept: application/xml
GET /api/clusters HTTP/1.1
Accept: application/xml
GET), header (Accept: application/xml) and URI (https://[RHGSC Host]/api/clusters) into the following cURL command:
curl -X GET -H "Accept: application/xml" -u [USER:PASS] --cacert [CERT] https://[RHGSC Host]/api/clusters
$ curl -X GET -H "Accept: application/xml" -u [USER:PASS] --cacert [CERT] https://[RHGSC Host]/api/clusters
clusters collection displays.
Example B.2. POST request
POST request creates a volume in the server collection. Note that a POST request requires a body.
POST), headers (Accept: application/xml and Content-type: application/xml), URI (https://[RHGSC Host]/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95/glustervolumes) and request body into the following cURL command:
curl -X POST -H "Accept: application/xml" -H "Content-Type: application/xml" -u [USER:PASS] --cacert [CERT] https://[RHGSC HOST]/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95/glustervolumes -d "<gluster_volume><name>data</name><volume_type>DISTRIBUTE</volume_type><bricks><brick><server_id>fcb46b88-f32e-11e1-918a-0050568c4349</server_id><brick_dir>/export/data/brick1</brick_dir></brick><brick><server_id>de173e6a-fb05-11e1-a2fc-0050568c4349</server_id><brick_dir>/export/data/brick2</brick_dir></brick></bricks></gluster_volume>"
curl -X POST -H "Accept: application/xml" -H "Content-Type: application/xml" -u [USER:PASS] --cacert [CERT] https://[RHGSC HOST]/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95/glustervolumes -d "<gluster_volume><name>data</name><volume_type>DISTRIBUTE</volume_type><bricks><brick><server_id>fcb46b88-f32e-11e1-918a-0050568c4349</server_id><brick_dir>/export/data/brick1</brick_dir></brick><brick><server_id>de173e6a-fb05-11e1-a2fc-0050568c4349</server_id><brick_dir>/export/data/brick2</brick_dir></brick></bricks></gluster_volume>"
Example B.3. PUT request
PUT request updates the cluster. Note that a PUT request requires a body.
PUT), headers (Accept: application/xml and Content-type: application/xml), URI (https://[RHGSC Host]/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95) and request body into the following cURL command:
curl -X PUT -H "Accept: application/xml" -H "Content-type: application/xml" -u [USER:PASS] --cacert [CERT] -d "<cluster><description>Cluster 1</description></cluster>" https://[RHGSC Host]/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95
$ curl -X PUT -H "Accept: application/xml" -H "Content-type: application/xml" -u [USER:PASS] --cacert [CERT] -d "<cluster><description>Cluster 1</description></cluster>" https://[RHGSC Host]/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95
Example B.4. DELETE request
DELETE request removes a cluster resource.
DELETE /api/clusters/082c794b-771f-452f-83c9-b2b5a19c0399 HTTP/1.1
DELETE /api/clusters/082c794b-771f-452f-83c9-b2b5a19c0399 HTTP/1.1
DELETE) and URI (https://[RHGSC Host]/api/clusters/082c794b-771f-452f-83c9-b2b5a19c0399) into the following cURL command:
curl -X DELETE -u [USER:PASS] --cacert [CERT] https://[RHGSC Host]/api/clusters/082c794b-771f-452f-83c9-b2b5a19c0399
$ curl -X DELETE -u [USER:PASS] --cacert [CERT] https://[RHGSC Host]/api/clusters/082c794b-771f-452f-83c9-b2b5a19c0399
Accept: application/xml request header is optional due to the empty result of DELETE requests.
In addition the the standard command line tools, cURL also features libcurl, a library for programming language integration. For more information on supported programming languages and integration methods, see the libcurl website (http://curl.haxx.se/libcurl/).