Using the API in the IDCF Cloud (cloudstack-api command note)

9

Basically, if you read the document, you can do almost anything you can do from the management screen.

So, as a simple usage note. (If there is a command you are interested in, we will continue to update it)

Let's install the cloudstack-api command and configure the environment in advance.

Specify the [-t] option in all commands to display the table. If not specified, it is output in JSON format. It can also be output in CSV format [-c] or XML format [-x], so if you need to call it from a script, it is convenient to specify options as appropriate. In addition, when outputting in CSV format, if you specify the option [--noheaders] together, the header line will not be output, so it is convenient when using it in a script.


Checking the ZoneID


$ cloudstack-api listZones -t name,id
+-------+--------------------------------------+
|  name |                  id                  |
+-------+--------------------------------------+
| tesla | a117e75f-d02e-4074-806d-889c61261394 |
+-------+--------------------------------------+

Confirm ServiceOffering ID

Lists the virtual machine types. Prices must be confirmed separately on the web.


$ cloudstack-api listServiceOfferings -t displaytext,cpuspeed,memory,id,name
+------------------------------------+----------+--------+--------------------------------------+---------------+
|            displaytext             | cpuspeed | memory |                  id                  |      name     |
+------------------------------------+----------+--------+--------------------------------------+---------------+
| highcpu.2XL32( 16 CPU / 32GB RAM ) | 2600     | 32768  | 7c548831-427b-437c-9c8b-80dde8031303 | highcpu.2XL32 |
| highcpu.L8( 4CPU / 8GB RAM )       | 2600     | 8192   | 435c1aab-e796-42c7-9320-22ebdc8f50aa | highcpu.L8    |
| highcpu.M4( 2CPU / 4GB RAM )       | 2600     | 4096   | 8cf15770-c3c8-4efc-8ae5-b8327790db76 | highcpu.M4    |
| highcpu.XL16 ( 8CPU / 16GB RAM )   | 2600     | 16384  | 6fda5e0c-e64d-46ea-893d-7e2ac9e128e7 | highcpu.XL16  |
| highmem.L32( 4CPU / 32GB RAM )     | 2200     | 32768  | d59817bc-ed79-4083-8b71-51b26c76d311 | highmem.L32   |
| highmem.M16( 2CPU / 16GB RAM )     | 2200     | 16384  | 12e39b73-3ce6-4e57-9036-3dac0c2b2b06 | highmem.M16   |
| highmem.XL64( 8CPU / 64GB RAM )    | 2200     | 65536  | ee5ee568-76b2-46ad-9221-c695e6f2149d | highmem.XL64  |
| light.S1( 1CPU / 1GB RAM )         | 800      | 1024   | e01a9f32-55c4-4c0d-9b7c-d49a3ccfd3f6 | light.S1      |
| light.S2( 1CPU / 2GB RAM )         | 800      | 2048   | d1aac6d2-bb47-4106-90d0-6a73ac3ae78e | light.S2      |
| standard.L16( 4CPU / 16GB RAM )    | 2400     | 16384  | 6a99ff4c-1a24-4aa6-b4cc-600220987ed0 | standard.L16  |
| standard.M8( 2CPU / 8GB RAM )      | 2400     | 8192   | 7ae143a6-5662-4f1d-bc4c-10defa775bcb | standard.M8   |
| standard.S4( 1CPU / 4GB RAM )      | 2400     | 4096   | 55621f17-4d38-457c-ba34-e6199701b67b | standard.S4   |
| standard.XL32( 8CPU / 32 GB RAM )  | 2400     | 32768  | 354c62e6-b99b-42f2-b5c7-e741f1085422 | standard.XL32 |
+------------------------------------+----------+--------+--------------------------------------+---------------+

Checking the TemplateID

Lists the image templates for creating virtual machines.


$ cloudstack-api listTemplates --templatefilter all -t name,id
+-----------------------------------------------------+--------------------------------------+
|                         name                        |                  id                  |
+-----------------------------------------------------+--------------------------------------+
| AppTemplate CentOS 6.5 64-bit                       | 8f641617-0d03-459c-9736-b903654f6d35 |
| CentOS 5.10 32-bit                                  | 9d6249ff-e84c-4ed9-82df-c8d54c770201 |
| CentOS 5.10 64-bit                                  | 7d373b69-c27a-42dd-a2ac-c015b53e67d4 |
| CentOS 5.3(64-bit) no GUI (vSphere)                 | c1ad59b8-4ada-11e4-bd06-005056812ba5 |
| CentOS 6.5 64-bit                                   | a6896a7d-42a7-4bd7-8534-1b809d22abb8 |
| CentOS 6.5 64-bit for Vagrant                       | 2e5ced0d-13cd-4848-93e6-6e6a0571ffc3 |
| CentOS 7.0 64-bit                                   | 8c54dbd6-4fab-4500-b02f-0e3fa0bb1086 |
| Gen3-SQL                                            | 796fa698-9800-4e0e-915b-77bac7c6b6e5
※以下省略※

Checking the SSH Key Pair Name

Lists SSH key pair names. Since only FingerPrint is displayed, the private key cannot be verified.


$ cloudstack-api listSSHKeyPairs -t 
+-------------------------------------------------+-------+
|                   fingerprint                   |  name |
+-------------------------------------------------+-------+
※以下省略※

Creating a Virtual Machine

The example below shows how to Virtual Machine Type : light. S1( 1CPU / 1GB RAM ) Template : CentOS 6.5 64-bit If you want to: In addition, "vmtest01" is specified as the display name, "Work" is specified as the group name, "vmtest01" is the host name, and "key01" is specified for the SSH key pair name.


$ cloudstack-api deployVirtualMachine \\
                 --serviceofferingid e01a9f32-55c4-4c0d-9b7c-d49a3ccfd3f6 \\
                 --templateid a6896a7d-42a7-4bd7-8534-1b809d22abb8 \\
                 --zoneid a117e75f-d02e-4074-806d-889c61261394 \\
                 --displayname vmtest01 \\
                 --group Work \\
                 --name vmtest01 \\
                 --keypair key01 \\
                 -t

Viewing the list of virtual machines


$ cloudstack-api listVirtualMachines -t

There are a lot of items, so it is a little easier to see if you specify only frequently used items.


$ cloudstack-api listVirtualMachines -t id,displayname,group,state,zonename

Starting a virtual machine

Specify the virtual machine ID in ID.


$ cloudstack-api startVirtualMachine --id [ID] -t

Stopping a virtual machine

Specify the virtual machine ID in ID. If you create a server from a Linux template, the shutdown command is automatically issued. There is no confirmation, so be careful when specifying a server in operation.


$ cloudstack-api stopVirtualMachine --id [ID] -t

Deleting a virtual machine

Specify the virtual machine ID in ID. Specify "--expunge true" to delete the entire volume. There is also no deletion confirmation here, so be careful when executing. Also、-- because expunge true is specified, recovery is not possible in case of accidental deletion. Important!!


$ cloudstack-api destroyVirtualMachine --id [ID] --expunge true -t
Share:
9
Keisuke Takahashi
Author by

Keisuke Takahashi

インフラエンジニア(L1~L7)ですが、開発・情シス・物流・業務改善と…何屋だかよくわからないPerlerです。他PHP/VB/VB.net/Bashなど○、Ruby/Python/Goとかのイマドキ言語は×。 2018年10月に親会社である株式会社オークファンに転籍となり、2019年4月にインフラグループのプレイングジャーマネになりました(笑)

Updated on October 24, 2014