Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e0dfb0356 | |||
| 84780647da | |||
| 1645d7881a | |||
| 88351db20f | |||
| 18cbf8693f | |||
| 7d64a2bc4d | |||
| 4c327e5e32 | |||
| a898928bd3 | |||
| aba8182422 | |||
| 5412ab524b | |||
| 2f175e9d64 | |||
| d2b1018234 | |||
| e7babf5222 | |||
| 63660ecc03 |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@apiclient.xyz/hetznercloud",
|
"name": "@apiclient.xyz/hetznercloud",
|
||||||
"version": "1.0.10",
|
"version": "1.0.17",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "an unofficial api client for the hetzner cloud api",
|
"description": "an unofficial api client for the hetzner cloud api",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
|||||||
+20
-6
@@ -6,7 +6,9 @@ const testQenv = new qenv.Qenv('./', './.nogit/');
|
|||||||
let testAccount: hetznercloud.HetznerAccount;
|
let testAccount: hetznercloud.HetznerAccount;
|
||||||
|
|
||||||
tap.test('should create a valid hetzer account', async () => {
|
tap.test('should create a valid hetzer account', async () => {
|
||||||
testAccount = new hetznercloud.HetznerAccount(await testQenv.getEnvVarOnDemand('HETZNER_API_TOKEN'));
|
testAccount = new hetznercloud.HetznerAccount(
|
||||||
|
await testQenv.getEnvVarOnDemand('HETZNER_API_TOKEN')
|
||||||
|
);
|
||||||
expect(testAccount).toBeInstanceOf(hetznercloud.HetznerAccount);
|
expect(testAccount).toBeInstanceOf(hetznercloud.HetznerAccount);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -14,15 +16,27 @@ tap.test('should be able to list all servers', async () => {
|
|||||||
const servers = await testAccount.getServers();
|
const servers = await testAccount.getServers();
|
||||||
expect(servers).toBeArray();
|
expect(servers).toBeArray();
|
||||||
console.log(JSON.stringify(servers, null, 2));
|
console.log(JSON.stringify(servers, null, 2));
|
||||||
})
|
});
|
||||||
|
|
||||||
tap.test('should be able to create a server', async () => {
|
const testserver = tap.test('should be able to create a server', async (toolsArg) => {
|
||||||
const newServer = await testAccount.createServer({
|
const newServer = await testAccount.createServer({
|
||||||
name: 'testserver',
|
name: 'testserver',
|
||||||
location: 'nbg1'
|
location: 'nbg1',
|
||||||
|
type: 'cpx41',
|
||||||
|
labels: {
|
||||||
|
servezoneId: 'testzone',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
expect(newServer).toBeInstanceOf(hetznercloud.HetznerServer);
|
expect(newServer).toBeInstanceOf(hetznercloud.HetznerServer);
|
||||||
console.log(newServer);
|
console.log(newServer);
|
||||||
})
|
await toolsArg.delayFor(10000);
|
||||||
|
return newServer;
|
||||||
|
});
|
||||||
|
|
||||||
tap.start()
|
tap.test('should be able to delete a server', async () => {
|
||||||
|
const testServer: hetznercloud.HetznerServer =
|
||||||
|
await (testserver.testResultPromise as Promise<hetznercloud.HetznerServer>);
|
||||||
|
// await testServer.delete();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@apiclient.xyz/hetznercloud',
|
name: '@apiclient.xyz/hetznercloud',
|
||||||
version: '1.0.10',
|
version: '1.0.17',
|
||||||
description: 'an unofficial api client for the hetzner cloud api'
|
description: 'an unofficial api client for the hetzner cloud api'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ export class HetznerAccount {
|
|||||||
return HetznerServer.getServers(this);
|
return HetznerServer.getServers(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getServersByLabel(labelObject: plugins.tsclass.typeFestOwn.SecondArgument<typeof HetznerServer.getServersByLabel>) {
|
||||||
|
return HetznerServer.getServersByLabel(this, labelObject);
|
||||||
|
}
|
||||||
|
|
||||||
public async createServer(optionsArg: plugins.tsclass.typeFestOwn.SecondArgument<typeof HetznerServer.create>) {
|
public async createServer(optionsArg: plugins.tsclass.typeFestOwn.SecondArgument<typeof HetznerServer.create>) {
|
||||||
return HetznerServer.create(this, optionsArg);
|
return HetznerServer.create(this, optionsArg);
|
||||||
}
|
}
|
||||||
@@ -32,6 +36,7 @@ export class HetznerAccount {
|
|||||||
Authorization: `Bearer ${this.token}`,
|
Authorization: `Bearer ${this.token}`,
|
||||||
},
|
},
|
||||||
requestBody: payloadArg,
|
requestBody: payloadArg,
|
||||||
|
keepAlive: false,
|
||||||
});
|
});
|
||||||
console.log(response.statusCode);
|
console.log(response.statusCode);
|
||||||
console.log(response.body);
|
console.log(response.body);
|
||||||
|
|||||||
+23
-3
@@ -8,8 +8,10 @@ export class HetznerServer {
|
|||||||
hetznerAccountRefArg: HetznerAccount,
|
hetznerAccountRefArg: HetznerAccount,
|
||||||
optionsArg: {
|
optionsArg: {
|
||||||
name: string;
|
name: string;
|
||||||
location: 'nbg1';
|
type: types.THetznerCloudServerName;
|
||||||
labels: {[key: string]: string},
|
location: types.THetznerCloudLocationName;
|
||||||
|
labels?: {[key: string]: string},
|
||||||
|
userData?: string,
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const server = new HetznerServer(hetznerAccountRefArg);
|
const server = new HetznerServer(hetznerAccountRefArg);
|
||||||
@@ -18,10 +20,11 @@ export class HetznerServer {
|
|||||||
const createServerPayload: types.TServerCreateRequestBody = {
|
const createServerPayload: types.TServerCreateRequestBody = {
|
||||||
name: optionsArg.name,
|
name: optionsArg.name,
|
||||||
image: 'ubuntu-22.04',
|
image: 'ubuntu-22.04',
|
||||||
server_type: 'cx11',
|
server_type: optionsArg.type,
|
||||||
start_after_create: true,
|
start_after_create: true,
|
||||||
labels: optionsArg.labels || {} as any,
|
labels: optionsArg.labels || {} as any,
|
||||||
location: optionsArg.location,
|
location: optionsArg.location,
|
||||||
|
user_data: optionsArg.userData || '',
|
||||||
public_net: {
|
public_net: {
|
||||||
enable_ipv4: true,
|
enable_ipv4: true,
|
||||||
enable_ipv6: true,
|
enable_ipv6: true,
|
||||||
@@ -49,6 +52,23 @@ export class HetznerServer {
|
|||||||
return servers;
|
return servers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async getServersByLabel(hetznerAccountRefArg: HetznerAccount, labelObject: {[key: string]: string}) {
|
||||||
|
const servers = await HetznerServer.getServers(hetznerAccountRefArg);
|
||||||
|
const results: HetznerServer[] = [];
|
||||||
|
for (const server of servers) {
|
||||||
|
let isMatch = true;
|
||||||
|
for (const key in labelObject) {
|
||||||
|
if (server.data.labels[key] !== labelObject[key]) {
|
||||||
|
isMatch = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isMatch) {
|
||||||
|
results.push(server);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
public hetznerAccountRef: HetznerAccount;
|
public hetznerAccountRef: HetznerAccount;
|
||||||
public data: types.IServer;
|
public data: types.IServer;
|
||||||
|
|||||||
+30
@@ -10,3 +10,33 @@ export type TServersGetResponseBody = plugins.hetznerOpenapi.paths['/servers']['
|
|||||||
export type TServerCreateRequestBody = plugins.hetznerOpenapi.paths['/servers']['post']['requestBody']['content']['application/json'];
|
export type TServerCreateRequestBody = plugins.hetznerOpenapi.paths['/servers']['post']['requestBody']['content']['application/json'];
|
||||||
export type TServerCreateResponseBody = plugins.hetznerOpenapi.paths['/servers']['post']['responses']['201']['content']['application/json'];
|
export type TServerCreateResponseBody = plugins.hetznerOpenapi.paths['/servers']['post']['responses']['201']['content']['application/json'];
|
||||||
|
|
||||||
|
// server types
|
||||||
|
export type THetznerCloudServerName =
|
||||||
|
| 'cx11'
|
||||||
|
| 'cx21'
|
||||||
|
| 'cx31'
|
||||||
|
| 'cx41'
|
||||||
|
| 'cx51'
|
||||||
|
| 'ccx11'
|
||||||
|
| 'ccx21'
|
||||||
|
| 'ccx31'
|
||||||
|
| 'ccx41'
|
||||||
|
| 'ccx51'
|
||||||
|
| 'ccx13'
|
||||||
|
| 'ccx23'
|
||||||
|
| 'ccx33'
|
||||||
|
| 'ccx43'
|
||||||
|
| 'ccx53'
|
||||||
|
| 'ccx63'
|
||||||
|
| 'cpx11'
|
||||||
|
| 'cpx21'
|
||||||
|
| 'cpx31'
|
||||||
|
| 'cpx41'
|
||||||
|
| 'cpx51'
|
||||||
|
| 'cpx61'
|
||||||
|
| 'cpx70'
|
||||||
|
| 'cpx71'
|
||||||
|
| 'cpx90';
|
||||||
|
|
||||||
|
// location types
|
||||||
|
export type THetznerCloudLocationName = 'fsn1' | 'nbg1' | 'hel1' | 'ash' | 'hil';
|
||||||
Reference in New Issue
Block a user