How to invoke the CLOUDSTACSK API

Source: Internet
Author: User
Tags iso 8601 cloudstack

CloudStack API calls
<1> making API requests
all Cloudstack API requests are submitted in the form of an HTTP get/post with an associated command and any parameters. The request is made up of either HTTP or https:
L CloudStack API URL: This is the API entry point for the Web service (for example, http://Domain 8080/CLIENT/API).
l Command: A Web Service command to execute, such as starting a virtual machine or creating a disk volume.
l parameter (Parameters): Optional parameters for any additional requirements or commands.
An example of an API get request is as follows:
http. localhost 8080/client/api?command=deployvirtualmachine&serviceofferingid=1&diskofferingid=1&templateid=2 &zoneid=4&apikey=mivr6x7u6bjb8cg20yi3yaxxcgpyuairmfi_ejtvwz0nukkjbpmy3y2bcikwfq&signature= Lxx1dm40ajcxu%2fcaik8rap0o1hu%3d
or the following is a more readable example:
1. http. localhost 8080/client/api?command=deployvirtualmachine
3. &serviceofferingid=1
4. &diskofferingid=1
5. &templateid=2
6. &zoneid=4
7.&apikey=mivr6x7u6bn_sdahobpjnejpgest35exqjb8cg20yi3yaxxcgpyuairmfi_ejtvwz0nukkjbpmy3y2bcikwfq
8. &signature=lxx1dm40ajcxu%2fcaik8rap0o1hu%3d%3d
line 1th Yes Cloudstackapi URL. This is the cloud instance you want to interact with.
Line 2nd refers to the command you want to execute. In our example, we are trying to deploy a new virtual machine. Separated from the Cloudstackapi URL by the command to be executed by one of the preceding (?).
The第3-6 line is a parameter to this command. To view command and request parameters, see the appropriate section in the Cloudstack API documentation. Each parameter field-value pair (field =value) is separated by the preceding character (&).
Line 7th is the Apikey that uniquely identifies the account. See signing API requests on page 9th.
Line 8th is the API command that creates the signature hash to validate the user account execution.
See signing API requests on page 9th.
2 Enable API call expiration
you can set the expiration timestamp API call to prevent replay attacks through non-secure channels, such as HTTP. The server keeps track of the expiry time stamp that you specified, and rejects all subsequent API requests after this validity period.
to enable this feature, add the following parameters to the API request:
signatureversion = 3: If the signatureversion parameter is missing or not equal to 3, the API request parameters that expire are ignored.
EXPIRES=YYYY-MM-DDTHH:MM:SSZ: Specifies the date and time at which the signature that is included in the request has expired. The timestamp represents the YYYY-MM-DDTHH:MM:SSZ format, as specified in the ISO 8601 standard. Examples are as follows: expires=2011-10-10t12:00:00+0530.
An example of an expiry API request is given below:
http. <IPAddress>. 8080/client/api?
Command=listzones&signatureversion=3&expires=2011-10-10t12:00:00+0530&apikey=mivr6x7u6bn_ sdahobpjnejpgest35exq-jb8cg20yi3yaxxcgpyuairmfi_ejtvwz0nukkjbpmy3y2bcikwfq&signature=lxx1dm40ajcxu% 2fcaik8rap0o1hu%3d%3d
3 API Request Signature
whether you use HTTP or use HTTPS to access the Cloudstack API, it must still be signed Cloudstack can verify the caller's authentication and authorization to execute the command.
Make sure that you have the API key and secret key provided by the Cloudstack administrator for your account before you sign the process. In order to show how to register the request, we will use the previous example again.
http. localhost 8080/client/api?command=deployvirtualmachine&serviceofferingid=1&diskofferingid=1&templateid=2 &zoneid=4&apikey=mivr6x7u6bjb8cg20yi3yaxxcgpyuairmfi_ejtvwz0nukkjbpmy3y2bcikwfq&signature= Lxx1dm40ajcxu%2fcaik8rap0o1hu%3d
the format of each API request: Base URL (base URL) + API path (API paths) + command string (commandstring) + signature (Signature).
in order to generate a signature (this can be done in the following steps).
1. In each field of the command string, the value pair (separated by a "&"), the URL resolves each value so that it can be sent securely via HTTP GET.

make sure that all spaces are encoded as "%20" instead of "+".
2. The entire command string, in lowercase alphabetical order, is sorted by field for each field-value. The result of this step is as follows:
apikey=mivr6x7u6bn_sdahobpjnejpgest35exqjb8cg20yi3yaxxcgpyuairmfi_ejtvwz0nukkjbpmy3y2bcikwfq&command= Deployvirtualmachine&diskofferingid=1&se
3. Run it by validating the user's secret key to sort the command string and through the HMAC SHA-1 hash algorithm (most programming languages provide a practical way to do this). The UTF-8 byte array produced by the BASE64 encoding can be safely transmitted over HTTP. The last string produced by BASE64 encoding should be:
"Lxx1dm40ajcxu%2fcaik8rap0o1hu%3d".
The final URL is refactored by the format of the base URL (base URL) + API path (API paths) + command string (commandstring) + signature (Signature)

How to invoke the CLOUDSTACSK API

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.