@genesiscloud/genesiscloud-js
v1.0.3
Published
JavaScript client for the Genesis Cloud API
Downloads
79
Maintainers
Readme
Genesis Cloud JavaScript Client
The JavaScript library for the Genesis Cloud API offers an easy way to manage resources like instances, volumes, snapshots, filesystems, floating IPs, security groups and more in your JavaScript or TypeScript applications.
Installation
You can install the Genesis Cloud SDK using your preferred node package manager:
npm install @genesiscloud/genesiscloud-js
# or
yarn add @genesiscloud/genesiscloud-js
# or
pnpm add @genesiscloud/genesiscloud-js
Configuration
Before you start, you'll need to configure the client with your Genesis Cloud API token. You can generate your API token from the Genesis Cloud console.
Here's how to configure the SDK:
const genesiscloud = new GenesisCloudClient({
TOKEN: process.env.GENESISCLOUD_TOKEN,
});
Examples
Error handling
Error handling can be done using the try/catch with the async/await syntax. The Genesis Cloud errors are of this format.
try {
const instance = await genesiscloud.instances.createInstance({
requestBody: {
// ...
},
});
//... do something with instance
} catch (error) {
if (error instanceof ApiError) {
const { code, message } = error.body;
// ... handle genesiscloud error
} else {
// ... handle other errors
}
}
Managing Instances
Listing Instances:
const { instances } = await genesiscloud.instances.listInstances({
page: 1,
perPage: 100,
});
Creating a new Instance:
const instance = await genesiscloud.instances.createInstance({
requestBody: {
name: "test instance",
hostname: "test instance",
type: "vcpu-192_memory-1920g_nvidia-h100-sxm5-8",
image: "ubuntu-ml-nvidia-pytorch",
region: "NORD-NO-KRS-1",
ssh_keys: ["ssh_key_id_here"],
},
});
Updating an Instance:
const updatedInstance = await genesiscloud.instances.updateInstance({
instanceId: "your_instance_id",
requestBody: {
name: "New Instance Name",
volumes: ["volume_id_here"],
},
});
Deleting an Instance:
await genesiscloud.instances.deleteInstance({
instanceId: "your_instance_id",
});
Managing Volumes
Creating a Volume
const volume = await genesiscloud.volumes.createVolume({
requestBody: {
name: "volume name",
description: "volume description",
type: "ssd",
size: 10, // in GiB
region: "NORD-NO-KRS-1",
},
});
Deleting a Volume
await genesiscloud.volumes.deleteVolume({
volumeId: "your_volume_id",
});
Managing Snapshots
Creating a Snapshot from an instance:
const snapshot = await genesiscloud.instances.createInstanceSnapshot({
instanceId: "your_instance_id",
requestBody: {
name: "Test snapshot",
},
});
Deleting a Snapshot:
await genesiscloud.snapshots.deleteSnapshot({
snapshotId: "your_snapshot_id",
});
Managing SSH Keys
Listing SSH Keys:
const sshKeys = await genesiscloud.sshKeys.listSshKeys({});
Creating an SSH Key:
const sshKey = await genesiscloud.sshKeys.createSshKey({
requestBody: {
name: "test key",
value: "ssh-rsa XXXXXXXXXXXXXXXXXXXXXXXX...",
},
});
Deleting an SSH Key:
await genesiscloud.sshKeys.deleteSshKey({
sshKeyId: "your-ssh-key-id",
});
For more detailed information on the Genesis Cloud API refer to the Genesis Cloud API documentation.