3.12. Example: Create Virtual Machine
The following example creates a virtual machine called
vm1
on the Default
cluster using the virtualization environment's Blank
template as a basis. The request also defines the virtual machine's memory
as 512 MB and sets the boot
device to a virtual hard disk.
Example 3.14. Create a virtual machine
Request:
POST /api/vms HTTP/1.1 Accept: application/xml Content-type: application/xml <vm> <name>vm1</name> <cluster> <name>default</name> </cluster> <template> <name>Blank</name> </template> <memory>536870912</memory> <os> <boot dev="hd"/> </os> <cpu_profile id="0000001a-001a-001a-001a-00000000035e"/> </vm>
POST /api/vms HTTP/1.1
Accept: application/xml
Content-type: application/xml
<vm>
<name>vm1</name>
<cluster>
<name>default</name>
</cluster>
<template>
<name>Blank</name>
</template>
<memory>536870912</memory>
<os>
<boot dev="hd"/>
</os>
<cpu_profile id="0000001a-001a-001a-001a-00000000035e"/>
</vm>
cURL command:
curl -X POST -H "Accept: application/xml" -H "Content-Type: application/xml" -u [USER:PASS] --cacert [CERT] -d "<vm><name>vm1</name><cluster><name>default</name></cluster><template><name>Blank</name></template><memory>536870912</memory><os><boot dev='hd'/></os><cpu_profile id='0000001a-001a-001a-001a-00000000035e'/></vm>" https://[RHEVM Host]:443/api/vms
# curl -X POST -H "Accept: application/xml" -H "Content-Type: application/xml" -u [USER:PASS] --cacert [CERT] -d "<vm><name>vm1</name><cluster><name>default</name></cluster><template><name>Blank</name></template><memory>536870912</memory><os><boot dev='hd'/></os><cpu_profile id='0000001a-001a-001a-001a-00000000035e'/></vm>" https://[RHEVM Host]:443/api/vms
Result:
HTTP/1.1 200 OK Accept: application/xml <vm id="6efc0cfa-8495-4a96-93e5-ee490328cf48" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48"> <name>vm1</name> <actions> <link rel="shutdown" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/shutdown"/> <link rel="start" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/start"/> <link rel="stop" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/stop"/> <link rel="reboot" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/reboot"/> <link rel="suspend" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/suspend"/> <link rel="detach" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/detach"/> <link rel="export" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/export"/> <link rel="move" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/move"/> <link rel="ticket" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/ticket"/> <link rel="migrate" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/migrate"/> <link rel="undo_snapshot" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/undo_snapshot"/> <link rel="commit_snapshot" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/commit_snapshot"/> <link rel="preview_snapshot" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/preview_snapshot"/> <link rel="logon" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/logon"/> <link rel="cancelmigration" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/cancelmigration"/> <link rel="maintenance" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/maintenance"/> <link rel="clone" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/clone"/> </actions> <link rel="applications" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/applications"/> <link rel="disks" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/disks"/> <link rel="nics" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/nics"/> <link rel="cdroms" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/cdroms"/> <link rel="snapshots" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/snapshots"/> <link rel="tags" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/tags"/> <link rel="permissions" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/permissions"/> <link rel="statistics" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/statistics"/> <link rel="reporteddevices" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/reporteddevices"/> <link rel="watchdogs" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/watchdogs"/> <link rel="sessions" href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/sessions"/> <type>desktop</type> <status> <state>down</state> </status> <memory>536870912</memory> <cpu> <topology cores="1" sockets="1"/> </cpu> <os type="Unassigned"> <boot dev="cdrom"/> </os> <high_availability> <enabled>false</enabled> <priority>0</priority> </high_availability> <display> <type>spice</type> <monitors>1</monitors> <single_qxl_pci>false</single_qxl_pci> <allow_override>false</allow_override> <smartcard_enabled>false</smartcard_enabled> <file_transfer_enabled>true</file_transfer_enabled> <copy_paste_enabled>true</copy_paste_enabled> </display> <cluster id="99408929-82cf-4dc7-a532-9d998063fa95" href="/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95"/> <template id="00000000-0000-0000-0000-000000000000" href="/api/templates/00000000-0000-0000-0000-000000000000"/> <stop_time>2011-06-15T04:48:02.167Z</stop_time> <creation_time>2011-06-15T14:48:02.078+10:00</creation_time> <origin>rhev</origin> <stateless>false</stateless> <delete_protected>false</delete_protected> <sso> <methods> <method id="GUEST_AGENT"/> </methods> </sso> <console enabled="false"/> <timezone>Etc/GMT</timezone> <initialization> <configuration> <type>ovf</type> <data>...</data> </configuration> </initialization> <placement_policy> <affinity>migratable</affinity> </placement_policy> <memory_policy> <guaranteed>536870912</guaranteed> <ballooning>true</ballooning> </memory_policy> <usb> <enabled>false</enabled> </usb> <soundcard_enabled>true</soundcard_enabled> <migration_downtime>-1</migration_downtime> <virtio_scsi enabled="true"/> <cpu_profile id="0000001a-001a-001a-001a-00000000035e"/> <next_run_configuration_exists>false</next_run_configuration_exists> <numa_tune_mode>interleave</numa_tune_mode> </vm>
HTTP/1.1 200 OK
Accept: application/xml
<vm id="6efc0cfa-8495-4a96-93e5-ee490328cf48"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48">
<name>vm1</name>
<actions>
<link rel="shutdown"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/shutdown"/>
<link rel="start"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/start"/>
<link rel="stop"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/stop"/>
<link rel="reboot"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/reboot"/>
<link rel="suspend"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/suspend"/>
<link rel="detach"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/detach"/>
<link rel="export"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/export"/>
<link rel="move"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/move"/>
<link rel="ticket"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/ticket"/>
<link rel="migrate"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/migrate"/>
<link rel="undo_snapshot"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/undo_snapshot"/>
<link rel="commit_snapshot"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/commit_snapshot"/>
<link rel="preview_snapshot"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/preview_snapshot"/>
<link rel="logon"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/logon"/>
<link rel="cancelmigration"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/cancelmigration"/>
<link rel="maintenance"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/maintenance"/>
<link rel="clone"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/clone"/>
</actions>
<link rel="applications"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/applications"/>
<link rel="disks"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/disks"/>
<link rel="nics"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/nics"/>
<link rel="cdroms"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/cdroms"/>
<link rel="snapshots"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/snapshots"/>
<link rel="tags"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/tags"/>
<link rel="permissions"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/permissions"/>
<link rel="statistics"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/statistics"/>
<link rel="reporteddevices"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/reporteddevices"/>
<link rel="watchdogs"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/watchdogs"/>
<link rel="sessions"
href="/api/vms/6efc0cfa-8495-4a96-93e5-ee490328cf48/sessions"/>
<type>desktop</type>
<status>
<state>down</state>
</status>
<memory>536870912</memory>
<cpu>
<topology cores="1" sockets="1"/>
</cpu>
<os type="Unassigned">
<boot dev="cdrom"/>
</os>
<high_availability>
<enabled>false</enabled>
<priority>0</priority>
</high_availability>
<display>
<type>spice</type>
<monitors>1</monitors>
<single_qxl_pci>false</single_qxl_pci>
<allow_override>false</allow_override>
<smartcard_enabled>false</smartcard_enabled>
<file_transfer_enabled>true</file_transfer_enabled>
<copy_paste_enabled>true</copy_paste_enabled>
</display>
<cluster id="99408929-82cf-4dc7-a532-9d998063fa95"
href="/api/clusters/99408929-82cf-4dc7-a532-9d998063fa95"/>
<template id="00000000-0000-0000-0000-000000000000"
href="/api/templates/00000000-0000-0000-0000-000000000000"/>
<stop_time>2011-06-15T04:48:02.167Z</stop_time>
<creation_time>2011-06-15T14:48:02.078+10:00</creation_time>
<origin>rhev</origin>
<stateless>false</stateless>
<delete_protected>false</delete_protected>
<sso>
<methods>
<method id="GUEST_AGENT"/>
</methods>
</sso>
<console enabled="false"/>
<timezone>Etc/GMT</timezone>
<initialization>
<configuration>
<type>ovf</type>
<data>...</data>
</configuration>
</initialization>
<placement_policy>
<affinity>migratable</affinity>
</placement_policy>
<memory_policy>
<guaranteed>536870912</guaranteed>
<ballooning>true</ballooning>
</memory_policy>
<usb>
<enabled>false</enabled>
</usb>
<soundcard_enabled>true</soundcard_enabled>
<migration_downtime>-1</migration_downtime>
<virtio_scsi enabled="true"/>
<cpu_profile id="0000001a-001a-001a-001a-00000000035e"/>
<next_run_configuration_exists>false</next_run_configuration_exists>
<numa_tune_mode>interleave</numa_tune_mode>
</vm>