-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* generate client * setup ci * fix ci * add check workflow * update check action * update readme * add error handling to readme * remove dry-run
- Loading branch information
Theophilus Okwugwuni
authored
May 7, 2024
1 parent
ef1d8e7
commit 97a2830
Showing
78 changed files
with
7,336 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Check | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
registry-url: https://registry.npmjs.org | ||
|
||
- uses: pnpm/action-setup@v2 | ||
name: Install pnpm | ||
with: | ||
version: 9 | ||
run_install: false | ||
|
||
- name: Get pnpm store directory | ||
id: pnpm-cache-dir-path | ||
run: echo "dir=$(pnpm store path --silent)" >> $GITHUB_OUTPUT | ||
|
||
- uses: actions/cache@v4 | ||
name: Setup pnpm cache | ||
with: | ||
path: ${{ steps.pnpm-cache-dir-path.outputs.dir }} | ||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-pnpm-store | ||
- name: Install dependencies | ||
run: pnpm install --frozen-lockfile | ||
|
||
- run: pnpm build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: ["*"] | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
registry-url: https://registry.npmjs.org | ||
|
||
- uses: pnpm/action-setup@v2 | ||
name: Install pnpm | ||
with: | ||
version: 9 | ||
run_install: false | ||
|
||
- name: Get pnpm store directory | ||
id: pnpm-cache-dir-path | ||
run: echo "dir=$(pnpm store path --silent)" >> $GITHUB_OUTPUT | ||
|
||
- uses: actions/cache@v4 | ||
name: Setup pnpm cache | ||
with: | ||
path: ${{ steps.pnpm-cache-dir-path.outputs.dir }} | ||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-pnpm-store | ||
- name: Install dependencies | ||
run: pnpm install --frozen-lockfile | ||
|
||
- name: Build | ||
run: pnpm build | ||
|
||
- name: Publish | ||
run: pnpm publish --access public --no-git-checks | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
web_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
.stylelintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
.temp | ||
.cache | ||
|
||
# Docusaurus cache and generated files | ||
.docusaurus | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
# Genesis Cloud JavaScript Client | ||
|
||
The JavaScript library for the [Genesis Cloud](http://genesiscloud.com) 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: | ||
|
||
```bash | ||
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](https://console.genesiscloud.com/dashboard). | ||
|
||
Here's how to configure the SDK: | ||
|
||
```typescript | ||
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](/src/core/ApiError.ts). | ||
|
||
```typescript | ||
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: | ||
|
||
```typescript | ||
const { instances } = await genesiscloud.instances.listInstances({ | ||
page: 1, | ||
perPage: 100, | ||
}); | ||
``` | ||
|
||
Creating a new Instance: | ||
|
||
```typescript | ||
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: | ||
|
||
```typescript | ||
const updatedInstance = await genesiscloud.instances.updateInstance({ | ||
instanceId: "your_instance_id", | ||
requestBody: { | ||
name: "New Instance Name", | ||
volumes: ["volume_id_here"], | ||
}, | ||
}); | ||
``` | ||
|
||
Deleting an Instance: | ||
|
||
```typescript | ||
await genesiscloud.instances.deleteInstance({ | ||
instanceId: "your_instance_id", | ||
}); | ||
``` | ||
|
||
### Managing Volumes | ||
|
||
Creating a Volume | ||
|
||
```typescript | ||
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 | ||
|
||
```typescript | ||
await genesiscloud.volumes.deleteVolume({ | ||
volumeId: "your_volume_id", | ||
}); | ||
``` | ||
|
||
### Managing Snapshots | ||
|
||
Creating a Snapshot from an instance: | ||
|
||
```typescript | ||
const snapshot = await genesiscloud.instances.createInstanceSnapshot({ | ||
instanceId: "your_instance_id", | ||
requestBody: { | ||
name: "Test snapshot", | ||
}, | ||
}); | ||
``` | ||
|
||
Deleting a Snapshot: | ||
|
||
```typescript | ||
await genesiscloud.snapshots.deleteSnapshot({ | ||
snapshotId: "your_snapshot_id", | ||
}); | ||
``` | ||
|
||
### Managing SSH Keys | ||
|
||
Listing SSH Keys: | ||
|
||
```typescript | ||
const sshKeys = await genesiscloud.sshKeys.listSshKeys({}); | ||
``` | ||
|
||
Creating an SSH Key: | ||
|
||
```typescript | ||
const sshKey = await genesiscloud.sshKeys.createSshKey({ | ||
requestBody: { | ||
name: "test key", | ||
value: "ssh-rsa XXXXXXXXXXXXXXXXXXXXXXXX...", | ||
}, | ||
}); | ||
``` | ||
|
||
Deleting an SSH Key: | ||
|
||
```typescript | ||
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](https://developers.genesiscloud.com/). |
Oops, something went wrong.