Python (SDK)
import latitudesh_python_sdk
from latitudesh_python_sdk import Latitudesh
import os
with Latitudesh(
bearer=os.getenv("LATITUDESH_BEARER", ""),
) as latitudesh:
latitudesh.virtual_machines.create_virtual_machine_action(virtual_machine_id="vm_5LA73qkjdaJ2o", id="vm_5LA73qkjdaJ2o", type_=latitudesh_python_sdk.CreateVirtualMachineActionVirtualMachinesType.VIRTUAL_MACHINES, attributes={
"action": latitudesh_python_sdk.CreateVirtualMachineActionVirtualMachinesAction.REBOOT,
})
# Use the SDK ...package main
import(
"context"
"os"
latitudeshgosdk "github.com/latitudesh/latitudesh-go-sdk"
"github.com/latitudesh/latitudesh-go-sdk/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := latitudeshgosdk.New(
latitudeshgosdk.WithSecurity(os.Getenv("LATITUDESH_BEARER")),
)
res, err := s.VirtualMachines.CreateVirtualMachineAction(ctx, "vm_5LA73qkjdaJ2o", operations.CreateVirtualMachineActionVirtualMachinesRequestBody{
ID: "vm_5LA73qkjdaJ2o",
Type: operations.CreateVirtualMachineActionVirtualMachinesTypeVirtualMachines,
Attributes: operations.CreateVirtualMachineActionVirtualMachinesAttributes{
Action: operations.CreateVirtualMachineActionVirtualMachinesActionReboot,
},
})
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}import { Latitudesh } from "latitudesh-typescript-sdk";
const latitudesh = new Latitudesh({
bearer: process.env["LATITUDESH_BEARER"] ?? "",
});
async function run() {
await latitudesh.virtualMachines.createVirtualMachineAction({
virtualMachineId: "vm_5LA73qkjdaJ2o",
requestBody: {
id: "vm_5LA73qkjdaJ2o",
type: "virtual_machines",
attributes: {
action: "reboot",
},
},
});
}
run();curl --request POST \
--url https://api.latitude.sh/virtual_machines/{virtual_machine_id}/actions \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"id": "vm_5LA73qkjdaJ2o",
"type": "virtual_machines",
"attributes": {
"action": "reboot"
}
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
id: 'vm_5LA73qkjdaJ2o',
type: 'virtual_machines',
attributes: {action: 'reboot'}
})
};
fetch('https://api.latitude.sh/virtual_machines/{virtual_machine_id}/actions', 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.latitude.sh/virtual_machines/{virtual_machine_id}/actions",
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([
'id' => 'vm_5LA73qkjdaJ2o',
'type' => 'virtual_machines',
'attributes' => [
'action' => 'reboot'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.latitude.sh/virtual_machines/{virtual_machine_id}/actions")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"id\": \"vm_5LA73qkjdaJ2o\",\n \"type\": \"virtual_machines\",\n \"attributes\": {\n \"action\": \"reboot\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.latitude.sh/virtual_machines/{virtual_machine_id}/actions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": \"vm_5LA73qkjdaJ2o\",\n \"type\": \"virtual_machines\",\n \"attributes\": {\n \"action\": \"reboot\"\n }\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "act_5LA73qkjdaJ2o",
"type": "actions",
"attributes": {
"status": "Rebooting virtual machine"
}
}
}Virtual machines
Run VM power action
Performs a power action on a given virtual machine:
power_on- Starts the virtual machinepower_off- Stops the virtual machinereboot- Restarts the virtual machine
POST
/
virtual_machines
/
{virtual_machine_id}
/
actions
Python (SDK)
import latitudesh_python_sdk
from latitudesh_python_sdk import Latitudesh
import os
with Latitudesh(
bearer=os.getenv("LATITUDESH_BEARER", ""),
) as latitudesh:
latitudesh.virtual_machines.create_virtual_machine_action(virtual_machine_id="vm_5LA73qkjdaJ2o", id="vm_5LA73qkjdaJ2o", type_=latitudesh_python_sdk.CreateVirtualMachineActionVirtualMachinesType.VIRTUAL_MACHINES, attributes={
"action": latitudesh_python_sdk.CreateVirtualMachineActionVirtualMachinesAction.REBOOT,
})
# Use the SDK ...package main
import(
"context"
"os"
latitudeshgosdk "github.com/latitudesh/latitudesh-go-sdk"
"github.com/latitudesh/latitudesh-go-sdk/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := latitudeshgosdk.New(
latitudeshgosdk.WithSecurity(os.Getenv("LATITUDESH_BEARER")),
)
res, err := s.VirtualMachines.CreateVirtualMachineAction(ctx, "vm_5LA73qkjdaJ2o", operations.CreateVirtualMachineActionVirtualMachinesRequestBody{
ID: "vm_5LA73qkjdaJ2o",
Type: operations.CreateVirtualMachineActionVirtualMachinesTypeVirtualMachines,
Attributes: operations.CreateVirtualMachineActionVirtualMachinesAttributes{
Action: operations.CreateVirtualMachineActionVirtualMachinesActionReboot,
},
})
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}import { Latitudesh } from "latitudesh-typescript-sdk";
const latitudesh = new Latitudesh({
bearer: process.env["LATITUDESH_BEARER"] ?? "",
});
async function run() {
await latitudesh.virtualMachines.createVirtualMachineAction({
virtualMachineId: "vm_5LA73qkjdaJ2o",
requestBody: {
id: "vm_5LA73qkjdaJ2o",
type: "virtual_machines",
attributes: {
action: "reboot",
},
},
});
}
run();curl --request POST \
--url https://api.latitude.sh/virtual_machines/{virtual_machine_id}/actions \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"id": "vm_5LA73qkjdaJ2o",
"type": "virtual_machines",
"attributes": {
"action": "reboot"
}
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
id: 'vm_5LA73qkjdaJ2o',
type: 'virtual_machines',
attributes: {action: 'reboot'}
})
};
fetch('https://api.latitude.sh/virtual_machines/{virtual_machine_id}/actions', 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.latitude.sh/virtual_machines/{virtual_machine_id}/actions",
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([
'id' => 'vm_5LA73qkjdaJ2o',
'type' => 'virtual_machines',
'attributes' => [
'action' => 'reboot'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.latitude.sh/virtual_machines/{virtual_machine_id}/actions")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"id\": \"vm_5LA73qkjdaJ2o\",\n \"type\": \"virtual_machines\",\n \"attributes\": {\n \"action\": \"reboot\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.latitude.sh/virtual_machines/{virtual_machine_id}/actions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": \"vm_5LA73qkjdaJ2o\",\n \"type\": \"virtual_machines\",\n \"attributes\": {\n \"action\": \"reboot\"\n }\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "act_5LA73qkjdaJ2o",
"type": "actions",
"attributes": {
"status": "Rebooting virtual machine"
}
}
}Authorizations
Path Parameters
Body
application/jsonapplication/vnd.api+json
Response
201 - application/vnd.api+json
Created
Was this page helpful?
⌘I