Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

10/28/22, 11:57 AM Dell EMC Unity: How To Use cURL to interact with Unity REST API (User Correctable)

o interact with Unity REST API (User Correctable) | Dell Singapore

Article Number: 000009634 Print

Dell EMC Unity: How To Use cURL to interact with Unity


REST API (User Correctable)
Summary: Users might use cURL tool to manage the Unity storage via its REST API. The cURL command is
a quick alternative to Perl or other scripting languages which leverage standard JSON data structure. By
using cURL, simple operations such as LUN query, LUN creation and LUN deletion can be encapsulated
within a single cURL command and passed to Unity for quick execution.

Audience Level: Customer

Article Content

Instructions

cURL version tested: 7.37.0


OS tested: SUSE Linux (SLES 12)
Unity OE tested: 4.1.1.9138882

The article describes the following actions through REST API with cURL commands:
1. Logging into the Unisphere Management REST API server.
2. Querying an existing LUN information.
3. Creating a new LUN.
4. Resizing the newly created LUN.
5. Querying the resized LUN.
6. Deleting that LUN.
7. Logging out of the Unisphere Management REST API server.

Here below are the related commands and outputs:


The following information in the commands examples need to be replaced by the ones in your own case.
- Unisphere admin user name: admin
- admin account password: P@ssw0rd
- VNXe management IP: 10.32.106.115
- cookies file name: cookies1.txt
- EMC-CSRF-TOKEN: Session token retrieved from the first logging command verbose output
- Old LUN CLI ID: sv_7
- New LUN name: curlLUN
- New LUN CLI ID: sv_19

1. Logging into the Unisphere Management REST API server.


curl -X GET -H "X-EMC-REST-CLIENT: true" -H "Accept: application/json" -H "Content-type: application/json" -u "admin:P@ssw0rd" -c
cookies1.txt -verbose -L -k https://10.32.106.115/api/types/loginSessionInfo/instances

Result ==>
{"@base":"https://10.32.106.115/api/types/loginSessionInfo/instances?per_page=2000","updated":"2017-04-
12T02:50:20.921Z","links":[{"rel":"self","href":"&page=1"}],"entries":
[{"@base":"https://10.32.106.115/api/instances/loginSessionInfo","updated":"2017-04-12T02:50:20.921Z","links":
[{"rel":"self","href":"/admin"}],"content":{"id":"admin","roles":[{"id":"administrator"}],"user":
{"id":"user_admin"},"idleTimeout":3600,"isPasswordChangeRequired":false}}]}02:50:20 service@VIRT170979R20E-spa spa:~>

EMC-CSRF-TOKEN information in the verbose output ==>


EMC-CSRF-TOKEN:
dgdY8lbuzvXQMypEXA93/aue+REgLbHw+TTO27c8Pry2jdJos6nfLlMC58b9+JP7Kjn6xfr6BCz959hqflGHcmCVEH/ypCDZWNmvfEPXs
LI=

2. Querying an existing LUN information.

https://www.dell.com/support/kbdoc/en-sg/article/lkbprint?ArticleNumber=000009634&AccessLevel=30&Lang=en 1/4
10/28/22, 11:57 AM Dell EMC Unity: How To Use cURL to interact with Unity REST API (User Correctable) | Dell Singapore

curl -X GET -H "X-EMC-REST-CLIENT: true" -H "Accept: application/json" -H "Content-type: application/json" -b cookies1.txt -L -k


https://10.32.106.115/api/instances/lun/sv_7?fields=id,name,sizeTotal

Result ==>
{"@base":"https://10.32.106.115/api/instances/lun","updated":"2017-04-12T02:50:55.914Z","links":[{"rel":"self","href":"/sv_7"}],"content":
{"id":"sv_7","name":"DR_Rep_test_Des","sizeTotal":1073741824}}02:50:55 service@VIRT170979R20E-spa spa:~>

3. Creating a new LUN (Size=1GB(1073741824 Bytes)).


curl -X POST -H "X-EMC-REST-CLIENT: true" -H "EMC-CSRF-TOKEN:
dgdY8lbuzvXQMypEXA93/aue+REgLbHw+TTO27c8Pry2jdJos6nfLlMC58b9+JP7Kjn6xfr6BCz959hqflGHcmCVEH/ypCDZWNmvfEPXs
LI=" -H "Accept: application/json" -H "Content-type: application/json" -b cookies1.txt -L -d '{"name":"curlLUN","lunParameters":{"pool":
{"id":"pool_2"},"isThinEnabled":"false","size":"1073741824"}}' -k https://10.32.106.115/api/types/storageResource/action/createLun

Result ==>
{"@base":"https://10.32.106.115/api/types/storageResource/action/createLun","updated":"2017-04-12T02:51:51.120Z","links":
[{"rel":"self","href":"/sv_19"}],"content":{"storageResource":{"id":"sv_19"}}}02:51:51 service@VIRT170979R20E-spa spa:~>

4. Resizing the newly created LUN (from 1GB to 1.6GB).


curl -X POST -H "X-EMC-REST-CLIENT: true" -H "EMC-CSRF-TOKEN:
dgdY8lbuzvXQMypEXA93/aue+REgLbHw+TTO27c8Pry2jdJos6nfLlMC58b9+JP7Kjn6xfr6BCz959hqflGHcmCVEH/ypCDZWNmvfEPXs
LI=" -H "Accept: application/json" -H "Content-type: application/json" -b cookies1.txt -L -d '{"lunParameters":{"size":"1717986918"}}' -k
https://10.32.106.115/api/instances/storageResource/sv_19/action/modifyLun

Result ==>
HTTP/1.1 204 No Content (because there is no output in the content of the HTTP response of the above request)

5. Querying the resized LUN.


curl -X GET -H "X-EMC-REST-CLIENT: true" -H "Accept: application/json" -H "Content-type: application/json" -b cookies1.txt -L -k
https://10.32.106.115/api/instances/lun/sv_19?fields=id,name,sizeTotal

Result ==>
{"@base":"https://10.32.106.115/api/instances/lun","updated":"2017-04-12T02:54:05.763Z","links":
[{"rel":"self","href":"/sv_19"}],"content":{"id":"sv_19","name":"curlLUN","sizeTotal":1717987328}}02:54:05 service@VIRT170979R20E-spa
spa:~>

6. Deleting that LUN.


curl -X DELETE -H "X-EMC-REST-CLIENT: true" -H "EMC-CSRF-TOKEN:
dgdY8lbuzvXQMypEXA93/aue+REgLbHw+TTO27c8Pry2jdJos6nfLlMC58b9+JP7Kjn6xfr6BCz959hqflGHcmCVEH/ypCDZWNmvfEPXs
LI=" -H "Accept: application/json" -H "Content-type: application/json" -b cookies1.txt -L -k
https://10.32.106.115/api/instances/storageResource/sv_19

Result ==>
HTTP/1.1 204 No Content

7. Logging out of the Unisphere Management REST API server.


curl -X POST -H "X-EMC-REST-CLIENT: true" -H "EMC-CSRF-TOKEN:
dgdY8lbuzvXQMypEXA93/aue+REgLbHw+TTO27c8Pry2jdJos6nfLlMC58b9+JP7Kjn6xfr6BCz959hqflGHcmCVEH/ypCDZWNmvfEPXs
LI=" -H "X-EMC-REST-CLIENT: true" -H "Accept: application/json" -H "Content-type: application/json" -b cookies1.txt -L -k
https://10.32.106.115/api/types/loginSessionInfo/action/logout

Result ==>
Logout successful

Additional Information
Explanation about the cURL parameters.

X-EMC-REST-CLIENT: true
This tells the server to use the HTTP Basic access authentication mechanism to authenticate the login request.

EMC-CSRF-TOKEN

https://www.dell.com/support/kbdoc/en-sg/article/lkbprint?ArticleNumber=000009634&AccessLevel=30&Lang=en 2/4
10/28/22, 11:57 AM Dell EMC Unity: How To Use cURL to interact with Unity REST API (User Correctable) | Dell Singapore

Token header, which is required for POST and DELETE requests.


This token header is good for the entirety of the session.
This token string is retrieved from the verbose output of the first login cURL command.

-u "admin:P@ssw0rd"
Passing the username and password to REST API server for authentication in the login request.

-verbose
Verbose output of the communication process. Useful to retrieve the EMC-CSRF-TOKEN from the login command output.
Also useful when there is error of the command to have debug level information.

-H "Accept: application/json"
To indicate that the format of the response content is JSON.

-H "Content-type: application/json"
To indicate that the format of the request contains body is JSON; required if there is a request body.

-c cookies1.txt
Set the cookies file name to record cookies information.

-b cookies1.txt
Get the cookies information from previously saved cookies file.

-L
Necessary when there is URI redirection (HTTP 302). The command will resend the parameters to redirected URI.

-d '{"name":"curlLUN","lunParameters":{"pool":{"id":"pool_2"},"isThinEnabl ed":"false","size":"1073741824"}}'
curl data format to fit into JSON data structure

-k
Ignore the SSL certificate verification.
This option explicitly allows curl to perform "insecure" SSL connections and transfers.

Any further question, please refer to the attached Unity REST API programmer guide.

Attachments

REST_API_guide_csp_en_US_1.pdf

Article Properties

Affected Product
Dell EMC Unity Family

Product
Dell EMC Unity Family |Dell EMC Unity All Flash, Dell EMC Unity Family, Dell EMC Unity Hybrid, Dell EMC UnityVSA (Virtual Storage
Appliance)

Last Published Date


23 Nov 2020

Version
2

Article Type
How To
https://www.dell.com/support/kbdoc/en-sg/article/lkbprint?ArticleNumber=000009634&AccessLevel=30&Lang=en 3/4
10/28/22, 11:57 AM Dell EMC Unity: How To Use cURL to interact with Unity REST API (User Correctable) | Dell Singapore

https://www.dell.com/support/kbdoc/en-sg/article/lkbprint?ArticleNumber=000009634&AccessLevel=30&Lang=en 4/4

You might also like