& lt 1 & gt; Make an API request
All CloudStack API requests are submitted in the form of HTTP GET/POST related commands and any parameters. Whether in HTTP or HTTPS, the request contains the following contents:
L CloudStack API URL: this is the API entry point of the Web service (for example, mand = deployvirtualmachine &;; serviceOfferingId = 1 & amp; diskoffering id = 1 & amp; templateId = 2 & ampzoneId = 4 & ampAPI key = mivr 6 x 7 u 6 bjb 8cg 20 yi 3 yaxcgpyuairmfi _ ejtvwz 0 nukjbpmy 3 y2 bcikwfq & amp; signature = lxx 1dm 40 AJC Xu % 2 fcaik 8 rap 0 o 1hU % 3D
Or a more readable example is as follows:
1.mand=deployVirtualMachine
3.& ampserviceOfferingId= 1
4.& ampdiskOfferingId= 1
5.& amptemplateId=2
6.& ampzoneId=4
7.& ampAPI key = mivr 6 x 7 u 6 bn _ sdahobpjnejpgest 35 exqjb 8cg 20 yi 3 yaxcgpyuairmfi _ ejtvwz 0 nukkjbpmy 3 y2 bcikwfq
8.& ampsignature = lxx 1dm 40 ajcxu % 2 fcaik 8 rap 0 o 1hU % 3D % 3D
Line 1 is the CloudStackAPI URL. This is a cloud instance that you want to interact with.
The second line is the command you want to execute. In our example, we try to deploy a new virtual machine. Through the last (? ) The command to be executed is separated from the CloudStackAPI URL.
Lines 3-6 are the parameters of this command. To view the command and request parameters, refer to the corresponding sections in the CloudStack API documentation. Each parameter field-value pair (field =value) is composed of the preceding characters (&; ) separated.
Line 7 is APIkey, which can uniquely identify the account. See the signature API request on page 9.
Line 8 is the signature hash created to verify the API command executed by the user account.
See the signature API request on page 9.
2 enable API call expiration
You can set the expiration timestamp of API calls to prevent replay attacks from passing through insecure channels such as HTTP. The server tracks the expiration timestamp you specify and rejects all subsequent API requests after that expiration date.
To enable this feature, add the following parameters to the API request:
SignatureVersion = 3: If the signature version parameter is missing or not equal to 3, the expired API request parameter will be ignored.
Expires=YYYY-MM-DDThh:mm:ssZ: Specifies the date and time when the signature contained in the request expires. The timestamp indicates the format of yyyy-mm-ddthh: mm: SSZ, which is specified in the ISO 860 1 standard. Examples are as follows: Expires = 20110-10t12: 00: 00+0530.
The following is an example of an expired API request:
List area. signature inversion = 3 & amp; expires = 20 1 1- 10- 10t 12:00:00+0530 & amp; API key = mivr 6 x 7 u 6 bn _ sdahobpjnejpgest 35 exq-JB 8cg 20 yi 3 yaxcgpyuairmfi _ ejtvwz 0 nukkjbpmy 3 y2 bcikwfq & amp; signature = lxx 1dm 40 ajcxu % 2 fcaik 8 rap 0 o 1hU % 3D % 3D
3 API request signature
Whether using HTTP or HTTPS to access CloudStack API, it still has to sign CloudStack to verify the caller's authentication and the authorization to execute commands.
Please make sure that you have the API key and key provided by the CloudStack administrator for your account before signing. To illustrate how to register a request, we will use the previous example again.
Deploy the virtual machine. serviceOfferingId = 1 & amp; diskoffering id = 1 & amp; templateId = 2 & ampzoneId = 4 & ampAPI key = mivr 6 x 7 u 6 bjb 8cg 20 yi 3 yaxcgpyuairmfi _ ejtvwz 0 nukjbpmy 3 y2 bcikwfq & amp; signature = lxx 1dm 40 AJC Xu % 2 fcaik 8 rap 0 o 1hU % 3D
The format of each API request: base URL+API path)+CommandString)+ signature.
So as to generate a signature (this can be achieved by the following steps).
1. The value pairs in each field of the command string (separated by "&"), and the URL parses each value so that it can be sent safely through HTTP GET.
Make sure all spaces are coded as "%20" instead of "+".
2. The entire command string is arranged in lowercase alphabetical order, and the values of each field are sorted by field. The results of this step are as follows:
API key = mivr 6 x 7 u 6 bn _ sdahobpjnejpgest 35 exqjb 8cg 20 yi 3 yaxcgpyuairmfi _ ejtvwz 0 nukkjbpmy 3 y2 bcikwfq & amp; Command = Deploy Virtual Machine & AMPDisKoffering ID =1&; selenium
3. By verifying the user's key, run it in an ordered command string, and through the HMAC SHA- 1 hash algorithm (most programming languages provide a practical way to achieve this). UTF-8 byte array generated by Base64 encoding can be transmitted securely through HTTP. The final string generated after Base64 encoding should be:
lxx 1dm 40 ajcxu % 2 fcaik 8 rap 0 o 1hU % 3D .
The final URL is reconstructed in the format of base URL+API path)+CommandString)+ Signature.