//native
type Fly = {
token: string;
};
/**
* Create Volume
* Create a volume for a specific app using the details provided in the request body.
*/
export async function main(
auth: Fly,
app_name: string,
body: {
compute?: {
cpu_kind?: string;
cpus?: number;
gpu_kind?: string;
gpus?: number;
host_dedication_id?: string;
kernel_args?: string[];
memory_mb?: number;
};
compute_image?: string;
encrypted?: false | true;
fstype?: string;
name?: string;
region?: string;
require_unique_zone?: false | true;
size_gb?: number;
snapshot_id?: string;
snapshot_retention?: number;
source_volume_id?: string;
unique_zone_app_wide?: false | true;
},
) {
const url = new URL(`https://api.machines.dev/v1/apps/${app_name}/volumes`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago