Create virtual machine
curl --request POST \
--url https://api.example.com/compute/v1/virtualmachines \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"image": "<string>",
"machineClass": "<string>",
"ports": [
{
"name": "<string>",
"guestPort": 123
}
],
"sshAuthorizedKeys": [
{
"publicKey": "<string>",
"username": "<string>"
}
]
}
'import requests
url = "https://api.example.com/compute/v1/virtualmachines"
payload = {
"name": "<string>",
"image": "<string>",
"machineClass": "<string>",
"ports": [
{
"name": "<string>",
"guestPort": 123
}
],
"sshAuthorizedKeys": [
{
"publicKey": "<string>",
"username": "<string>"
}
]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
image: '<string>',
machineClass: '<string>',
ports: [{name: '<string>', guestPort: 123}],
sshAuthorizedKeys: [{publicKey: '<string>', username: '<string>'}]
})
};
fetch('https://api.example.com/compute/v1/virtualmachines', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/compute/v1/virtualmachines",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => '<string>',
'image' => '<string>',
'machineClass' => '<string>',
'ports' => [
[
'name' => '<string>',
'guestPort' => 123
]
],
'sshAuthorizedKeys' => [
[
'publicKey' => '<string>',
'username' => '<string>'
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/compute/v1/virtualmachines"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"image\": \"<string>\",\n \"machineClass\": \"<string>\",\n \"ports\": [\n {\n \"name\": \"<string>\",\n \"guestPort\": 123\n }\n ],\n \"sshAuthorizedKeys\": [\n {\n \"publicKey\": \"<string>\",\n \"username\": \"<string>\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/compute/v1/virtualmachines")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"image\": \"<string>\",\n \"machineClass\": \"<string>\",\n \"ports\": [\n {\n \"name\": \"<string>\",\n \"guestPort\": 123\n }\n ],\n \"sshAuthorizedKeys\": [\n {\n \"publicKey\": \"<string>\",\n \"username\": \"<string>\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/compute/v1/virtualmachines")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"image\": \"<string>\",\n \"machineClass\": \"<string>\",\n \"ports\": [\n {\n \"name\": \"<string>\",\n \"guestPort\": 123\n }\n ],\n \"sshAuthorizedKeys\": [\n {\n \"publicKey\": \"<string>\",\n \"username\": \"<string>\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"virtualMachine": {
"name": "<string>",
"image": "<string>",
"machineClass": "<string>",
"ports": [
{
"name": "<string>",
"guestPort": 123
}
],
"sshAuthorizedKeys": [
{
"publicKey": "<string>",
"username": "<string>"
}
],
"status": {
"id": "<string>",
"state": "MACHINE_STATE_UNSPECIFIED",
"ready": true,
"message": "<string>"
},
"createdAt": "2023-11-07T05:31:56Z"
}
}Virtual machines
Create virtual machine
Creates a virtual machine from high-level intent. image and machine_class are validated against the catalog; an unknown value is rejected with 422 before the machine is created, rather than surfacing later as a failed workload.
POST
/
compute
/
v1
/
virtualmachines
Create virtual machine
curl --request POST \
--url https://api.example.com/compute/v1/virtualmachines \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"image": "<string>",
"machineClass": "<string>",
"ports": [
{
"name": "<string>",
"guestPort": 123
}
],
"sshAuthorizedKeys": [
{
"publicKey": "<string>",
"username": "<string>"
}
]
}
'import requests
url = "https://api.example.com/compute/v1/virtualmachines"
payload = {
"name": "<string>",
"image": "<string>",
"machineClass": "<string>",
"ports": [
{
"name": "<string>",
"guestPort": 123
}
],
"sshAuthorizedKeys": [
{
"publicKey": "<string>",
"username": "<string>"
}
]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
image: '<string>',
machineClass: '<string>',
ports: [{name: '<string>', guestPort: 123}],
sshAuthorizedKeys: [{publicKey: '<string>', username: '<string>'}]
})
};
fetch('https://api.example.com/compute/v1/virtualmachines', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/compute/v1/virtualmachines",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => '<string>',
'image' => '<string>',
'machineClass' => '<string>',
'ports' => [
[
'name' => '<string>',
'guestPort' => 123
]
],
'sshAuthorizedKeys' => [
[
'publicKey' => '<string>',
'username' => '<string>'
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/compute/v1/virtualmachines"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"image\": \"<string>\",\n \"machineClass\": \"<string>\",\n \"ports\": [\n {\n \"name\": \"<string>\",\n \"guestPort\": 123\n }\n ],\n \"sshAuthorizedKeys\": [\n {\n \"publicKey\": \"<string>\",\n \"username\": \"<string>\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/compute/v1/virtualmachines")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"image\": \"<string>\",\n \"machineClass\": \"<string>\",\n \"ports\": [\n {\n \"name\": \"<string>\",\n \"guestPort\": 123\n }\n ],\n \"sshAuthorizedKeys\": [\n {\n \"publicKey\": \"<string>\",\n \"username\": \"<string>\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/compute/v1/virtualmachines")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"image\": \"<string>\",\n \"machineClass\": \"<string>\",\n \"ports\": [\n {\n \"name\": \"<string>\",\n \"guestPort\": 123\n }\n ],\n \"sshAuthorizedKeys\": [\n {\n \"publicKey\": \"<string>\",\n \"username\": \"<string>\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"virtualMachine": {
"name": "<string>",
"image": "<string>",
"machineClass": "<string>",
"ports": [
{
"name": "<string>",
"guestPort": 123
}
],
"sshAuthorizedKeys": [
{
"publicKey": "<string>",
"username": "<string>"
}
],
"status": {
"id": "<string>",
"state": "MACHINE_STATE_UNSPECIFIED",
"ready": true,
"message": "<string>"
},
"createdAt": "2023-11-07T05:31:56Z"
}
}Body
application/json
Optional. If you do not supply a name, the platform generates one.
image is a catalog image ref (see ListImages). Required, validated.
machine_class is a catalog SKU (see ListMachineClasses). Required, validated.
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Response
200 - application/json
OK
VirtualMachine is the friendly view/return shape of a VM.
Show child attributes
Show child attributes