hetzner-cli 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +907 -0
- package/dist/auction/client.d.ts +4 -0
- package/dist/auction/client.js +103 -0
- package/dist/auction/commands.d.ts +2 -0
- package/dist/auction/commands.js +138 -0
- package/dist/auction/formatter.d.ts +3 -0
- package/dist/auction/formatter.js +87 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +39 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +4 -0
- package/dist/cloud/client.d.ts +511 -0
- package/dist/cloud/client.js +706 -0
- package/dist/cloud/commands/certificate.d.ts +2 -0
- package/dist/cloud/commands/certificate.js +77 -0
- package/dist/cloud/commands/context.d.ts +2 -0
- package/dist/cloud/commands/context.js +78 -0
- package/dist/cloud/commands/datacenter.d.ts +2 -0
- package/dist/cloud/commands/datacenter.js +20 -0
- package/dist/cloud/commands/firewall.d.ts +2 -0
- package/dist/cloud/commands/firewall.js +77 -0
- package/dist/cloud/commands/floating-ip.d.ts +2 -0
- package/dist/cloud/commands/floating-ip.js +83 -0
- package/dist/cloud/commands/image.d.ts +2 -0
- package/dist/cloud/commands/image.js +60 -0
- package/dist/cloud/commands/index.d.ts +2 -0
- package/dist/cloud/commands/index.js +41 -0
- package/dist/cloud/commands/iso.d.ts +2 -0
- package/dist/cloud/commands/iso.js +22 -0
- package/dist/cloud/commands/load-balancer-type.d.ts +2 -0
- package/dist/cloud/commands/load-balancer-type.js +20 -0
- package/dist/cloud/commands/load-balancer.d.ts +2 -0
- package/dist/cloud/commands/load-balancer.js +177 -0
- package/dist/cloud/commands/location.d.ts +2 -0
- package/dist/cloud/commands/location.js +20 -0
- package/dist/cloud/commands/network.d.ts +2 -0
- package/dist/cloud/commands/network.js +96 -0
- package/dist/cloud/commands/placement-group.d.ts +2 -0
- package/dist/cloud/commands/placement-group.js +53 -0
- package/dist/cloud/commands/primary-ip.d.ts +2 -0
- package/dist/cloud/commands/primary-ip.js +83 -0
- package/dist/cloud/commands/server-type.d.ts +2 -0
- package/dist/cloud/commands/server-type.js +20 -0
- package/dist/cloud/commands/server.d.ts +2 -0
- package/dist/cloud/commands/server.js +260 -0
- package/dist/cloud/commands/ssh-key.d.ts +2 -0
- package/dist/cloud/commands/ssh-key.js +63 -0
- package/dist/cloud/commands/volume.d.ts +2 -0
- package/dist/cloud/commands/volume.js +92 -0
- package/dist/cloud/context.d.ts +28 -0
- package/dist/cloud/context.js +172 -0
- package/dist/cloud/formatter.d.ts +37 -0
- package/dist/cloud/formatter.js +413 -0
- package/dist/cloud/helpers.d.ts +18 -0
- package/dist/cloud/helpers.js +48 -0
- package/dist/cloud/types.d.ts +398 -0
- package/dist/cloud/types.js +5 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.js +2 -0
- package/dist/formatter.d.ts +3 -0
- package/dist/formatter.js +6 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +17 -0
- package/dist/robot/client.d.ts +256 -0
- package/dist/robot/client.js +656 -0
- package/dist/robot/commands/auth.d.ts +2 -0
- package/dist/robot/commands/auth.js +54 -0
- package/dist/robot/commands/boot.d.ts +2 -0
- package/dist/robot/commands/boot.js +72 -0
- package/dist/robot/commands/cancel.d.ts +2 -0
- package/dist/robot/commands/cancel.js +36 -0
- package/dist/robot/commands/failover.d.ts +2 -0
- package/dist/robot/commands/failover.js +42 -0
- package/dist/robot/commands/firewall.d.ts +2 -0
- package/dist/robot/commands/firewall.js +66 -0
- package/dist/robot/commands/index.d.ts +2 -0
- package/dist/robot/commands/index.js +36 -0
- package/dist/robot/commands/interactive.d.ts +2 -0
- package/dist/robot/commands/interactive.js +134 -0
- package/dist/robot/commands/ip.d.ts +2 -0
- package/dist/robot/commands/ip.js +52 -0
- package/dist/robot/commands/key.d.ts +2 -0
- package/dist/robot/commands/key.js +64 -0
- package/dist/robot/commands/order.d.ts +2 -0
- package/dist/robot/commands/order.js +33 -0
- package/dist/robot/commands/rdns.d.ts +2 -0
- package/dist/robot/commands/rdns.js +41 -0
- package/dist/robot/commands/reset.d.ts +2 -0
- package/dist/robot/commands/reset.js +77 -0
- package/dist/robot/commands/server.d.ts +2 -0
- package/dist/robot/commands/server.js +29 -0
- package/dist/robot/commands/storagebox.d.ts +2 -0
- package/dist/robot/commands/storagebox.js +116 -0
- package/dist/robot/commands/subnet.d.ts +2 -0
- package/dist/robot/commands/subnet.js +21 -0
- package/dist/robot/commands/traffic.d.ts +2 -0
- package/dist/robot/commands/traffic.js +20 -0
- package/dist/robot/commands/vswitch.d.ts +2 -0
- package/dist/robot/commands/vswitch.js +64 -0
- package/dist/robot/commands/wol.d.ts +2 -0
- package/dist/robot/commands/wol.js +20 -0
- package/dist/robot/formatter.d.ts +58 -0
- package/dist/robot/formatter.js +500 -0
- package/dist/robot/types.d.ts +352 -0
- package/dist/robot/types.js +5 -0
- package/dist/shared/config.d.ts +86 -0
- package/dist/shared/config.js +273 -0
- package/dist/shared/formatter.d.ts +29 -0
- package/dist/shared/formatter.js +118 -0
- package/dist/shared/helpers.d.ts +17 -0
- package/dist/shared/helpers.js +72 -0
- package/dist/shared/reference.d.ts +2 -0
- package/dist/shared/reference.js +626 -0
- package/dist/types.d.ts +75 -0
- package/dist/types.js +1 -0
- package/package.json +112 -0
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Hetzner Cloud API Client
|
|
3
|
+
// Base URL: https://api.hetzner.cloud/v1
|
|
4
|
+
// Auth: Bearer Token
|
|
5
|
+
// ============================================================================
|
|
6
|
+
const BASE_URL = 'https://api.hetzner.cloud/v1';
|
|
7
|
+
export class HetznerCloudClient {
|
|
8
|
+
token;
|
|
9
|
+
constructor(token) {
|
|
10
|
+
this.token = token;
|
|
11
|
+
}
|
|
12
|
+
async request(endpoint, options = {}) {
|
|
13
|
+
const url = `${BASE_URL}${endpoint}`;
|
|
14
|
+
const headers = {
|
|
15
|
+
Authorization: `Bearer ${this.token}`,
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
Accept: 'application/json',
|
|
18
|
+
...options.headers,
|
|
19
|
+
};
|
|
20
|
+
const response = await fetch(url, {
|
|
21
|
+
...options,
|
|
22
|
+
headers,
|
|
23
|
+
});
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
|
26
|
+
try {
|
|
27
|
+
const errorBody = await response.json();
|
|
28
|
+
if (errorBody.error) {
|
|
29
|
+
errorMessage = `${errorBody.error.code ?? 'ERROR'}: ${errorBody.error.message ?? 'Unknown error'}`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// Use default error message
|
|
34
|
+
}
|
|
35
|
+
throw new Error(errorMessage);
|
|
36
|
+
}
|
|
37
|
+
if (response.status === 204) {
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
return response.json();
|
|
41
|
+
}
|
|
42
|
+
buildQuery(params) {
|
|
43
|
+
const parts = [];
|
|
44
|
+
for (const [key, value] of Object.entries(params)) {
|
|
45
|
+
if (value === undefined)
|
|
46
|
+
continue;
|
|
47
|
+
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
48
|
+
}
|
|
49
|
+
return parts.length > 0 ? `?${parts.join('&')}` : '';
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Fetch all pages of a paginated endpoint.
|
|
53
|
+
*/
|
|
54
|
+
async listAll(endpoint, key, params = {}) {
|
|
55
|
+
const allItems = [];
|
|
56
|
+
let page = 1;
|
|
57
|
+
const perPage = 50;
|
|
58
|
+
while (true) {
|
|
59
|
+
const query = this.buildQuery({ ...params, page, per_page: perPage });
|
|
60
|
+
const response = await this.request(`${endpoint}${query}`);
|
|
61
|
+
const items = response[key];
|
|
62
|
+
if (!items || items.length === 0)
|
|
63
|
+
break;
|
|
64
|
+
allItems.push(...items);
|
|
65
|
+
const meta = response.meta;
|
|
66
|
+
if (!meta?.pagination?.next_page)
|
|
67
|
+
break;
|
|
68
|
+
page = meta.pagination.next_page;
|
|
69
|
+
}
|
|
70
|
+
return allItems;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Poll an action until it completes.
|
|
74
|
+
*/
|
|
75
|
+
async waitForAction(actionId, timeoutMs = 300000) {
|
|
76
|
+
const start = Date.now();
|
|
77
|
+
while (Date.now() - start < timeoutMs) {
|
|
78
|
+
const { action } = await this.request(`/actions/${actionId}`);
|
|
79
|
+
if (action.status === 'success')
|
|
80
|
+
return action;
|
|
81
|
+
if (action.status === 'error') {
|
|
82
|
+
throw new Error(`Action ${actionId} failed: ${action.error?.message ?? 'Unknown error'}`);
|
|
83
|
+
}
|
|
84
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
85
|
+
}
|
|
86
|
+
throw new Error(`Action ${actionId} timed out after ${timeoutMs}ms`);
|
|
87
|
+
}
|
|
88
|
+
// =========================================================================
|
|
89
|
+
// Datacenters (read-only)
|
|
90
|
+
// =========================================================================
|
|
91
|
+
async listDatacenters() {
|
|
92
|
+
return this.listAll('/datacenters', 'datacenters');
|
|
93
|
+
}
|
|
94
|
+
async getDatacenter(id) {
|
|
95
|
+
const { datacenter } = await this.request(`/datacenters/${id}`);
|
|
96
|
+
return datacenter;
|
|
97
|
+
}
|
|
98
|
+
// =========================================================================
|
|
99
|
+
// Locations (read-only)
|
|
100
|
+
// =========================================================================
|
|
101
|
+
async listLocations() {
|
|
102
|
+
return this.listAll('/locations', 'locations');
|
|
103
|
+
}
|
|
104
|
+
async getLocation(id) {
|
|
105
|
+
const { location } = await this.request(`/locations/${id}`);
|
|
106
|
+
return location;
|
|
107
|
+
}
|
|
108
|
+
// =========================================================================
|
|
109
|
+
// Server Types (read-only)
|
|
110
|
+
// =========================================================================
|
|
111
|
+
async listServerTypes() {
|
|
112
|
+
return this.listAll('/server_types', 'server_types');
|
|
113
|
+
}
|
|
114
|
+
async getServerType(id) {
|
|
115
|
+
const { server_type } = await this.request(`/server_types/${id}`);
|
|
116
|
+
return server_type;
|
|
117
|
+
}
|
|
118
|
+
// =========================================================================
|
|
119
|
+
// Load Balancer Types (read-only)
|
|
120
|
+
// =========================================================================
|
|
121
|
+
async listLoadBalancerTypes() {
|
|
122
|
+
return this.listAll('/load_balancer_types', 'load_balancer_types');
|
|
123
|
+
}
|
|
124
|
+
async getLoadBalancerType(id) {
|
|
125
|
+
const { load_balancer_type } = await this.request(`/load_balancer_types/${id}`);
|
|
126
|
+
return load_balancer_type;
|
|
127
|
+
}
|
|
128
|
+
// =========================================================================
|
|
129
|
+
// ISOs (read-only)
|
|
130
|
+
// =========================================================================
|
|
131
|
+
async listIsos(params = {}) {
|
|
132
|
+
return this.listAll('/isos', 'isos', params);
|
|
133
|
+
}
|
|
134
|
+
async getIso(id) {
|
|
135
|
+
const { iso } = await this.request(`/isos/${id}`);
|
|
136
|
+
return iso;
|
|
137
|
+
}
|
|
138
|
+
// =========================================================================
|
|
139
|
+
// Servers
|
|
140
|
+
// =========================================================================
|
|
141
|
+
async listServers(params = {}) {
|
|
142
|
+
return this.listAll('/servers', 'servers', params);
|
|
143
|
+
}
|
|
144
|
+
async getServer(id) {
|
|
145
|
+
const { server } = await this.request(`/servers/${id}`);
|
|
146
|
+
return server;
|
|
147
|
+
}
|
|
148
|
+
async createServer(opts) {
|
|
149
|
+
return this.request('/servers', {
|
|
150
|
+
method: 'POST',
|
|
151
|
+
body: JSON.stringify(opts),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
async deleteServer(id) {
|
|
155
|
+
return this.request(`/servers/${id}`, { method: 'DELETE' });
|
|
156
|
+
}
|
|
157
|
+
async updateServer(id, opts) {
|
|
158
|
+
return this.request(`/servers/${id}`, {
|
|
159
|
+
method: 'PUT',
|
|
160
|
+
body: JSON.stringify(opts),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
async powerOnServer(id) {
|
|
164
|
+
return this.request(`/servers/${id}/actions/poweron`, { method: 'POST' });
|
|
165
|
+
}
|
|
166
|
+
async powerOffServer(id) {
|
|
167
|
+
return this.request(`/servers/${id}/actions/poweroff`, { method: 'POST' });
|
|
168
|
+
}
|
|
169
|
+
async rebootServer(id) {
|
|
170
|
+
return this.request(`/servers/${id}/actions/reboot`, { method: 'POST' });
|
|
171
|
+
}
|
|
172
|
+
async resetServer(id) {
|
|
173
|
+
return this.request(`/servers/${id}/actions/reset`, { method: 'POST' });
|
|
174
|
+
}
|
|
175
|
+
async shutdownServer(id) {
|
|
176
|
+
return this.request(`/servers/${id}/actions/shutdown`, { method: 'POST' });
|
|
177
|
+
}
|
|
178
|
+
async rebuildServer(id, image) {
|
|
179
|
+
return this.request(`/servers/${id}/actions/rebuild`, {
|
|
180
|
+
method: 'POST',
|
|
181
|
+
body: JSON.stringify({ image }),
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
async changeServerType(id, serverType, upgradeDisk) {
|
|
185
|
+
return this.request(`/servers/${id}/actions/change_type`, {
|
|
186
|
+
method: 'POST',
|
|
187
|
+
body: JSON.stringify({ server_type: serverType, upgrade_disk: upgradeDisk }),
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
async enableServerRescue(id, type = 'linux64', sshKeys) {
|
|
191
|
+
return this.request(`/servers/${id}/actions/enable_rescue`, {
|
|
192
|
+
method: 'POST',
|
|
193
|
+
body: JSON.stringify({ type, ssh_keys: sshKeys }),
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
async disableServerRescue(id) {
|
|
197
|
+
return this.request(`/servers/${id}/actions/disable_rescue`, { method: 'POST' });
|
|
198
|
+
}
|
|
199
|
+
async enableServerBackup(id) {
|
|
200
|
+
return this.request(`/servers/${id}/actions/enable_backup`, { method: 'POST' });
|
|
201
|
+
}
|
|
202
|
+
async disableServerBackup(id) {
|
|
203
|
+
return this.request(`/servers/${id}/actions/disable_backup`, { method: 'POST' });
|
|
204
|
+
}
|
|
205
|
+
async createServerImage(id, opts) {
|
|
206
|
+
return this.request(`/servers/${id}/actions/create_image`, {
|
|
207
|
+
method: 'POST',
|
|
208
|
+
body: JSON.stringify(opts),
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
async attachIsoToServer(id, iso) {
|
|
212
|
+
return this.request(`/servers/${id}/actions/attach_iso`, {
|
|
213
|
+
method: 'POST',
|
|
214
|
+
body: JSON.stringify({ iso }),
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
async detachIsoFromServer(id) {
|
|
218
|
+
return this.request(`/servers/${id}/actions/detach_iso`, { method: 'POST' });
|
|
219
|
+
}
|
|
220
|
+
async resetServerPassword(id) {
|
|
221
|
+
return this.request(`/servers/${id}/actions/reset_password`, { method: 'POST' });
|
|
222
|
+
}
|
|
223
|
+
async setServerRdns(id, ip, dnsPtr) {
|
|
224
|
+
return this.request(`/servers/${id}/actions/change_dns_ptr`, {
|
|
225
|
+
method: 'POST',
|
|
226
|
+
body: JSON.stringify({ ip, dns_ptr: dnsPtr }),
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
async enableServerProtection(id, opts) {
|
|
230
|
+
return this.request(`/servers/${id}/actions/change_protection`, {
|
|
231
|
+
method: 'POST',
|
|
232
|
+
body: JSON.stringify(opts),
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
async requestServerConsole(id) {
|
|
236
|
+
return this.request(`/servers/${id}/actions/request_console`, { method: 'POST' });
|
|
237
|
+
}
|
|
238
|
+
async attachServerToNetwork(id, network, ip, aliasIps) {
|
|
239
|
+
return this.request(`/servers/${id}/actions/attach_to_network`, {
|
|
240
|
+
method: 'POST',
|
|
241
|
+
body: JSON.stringify({ network, ip, alias_ips: aliasIps }),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
async detachServerFromNetwork(id, network) {
|
|
245
|
+
return this.request(`/servers/${id}/actions/detach_from_network`, {
|
|
246
|
+
method: 'POST',
|
|
247
|
+
body: JSON.stringify({ network }),
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
async addServerToPlacementGroup(id, placementGroup) {
|
|
251
|
+
return this.request(`/servers/${id}/actions/add_to_placement_group`, {
|
|
252
|
+
method: 'POST',
|
|
253
|
+
body: JSON.stringify({ placement_group: placementGroup }),
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
async removeServerFromPlacementGroup(id) {
|
|
257
|
+
return this.request(`/servers/${id}/actions/remove_from_placement_group`, { method: 'POST' });
|
|
258
|
+
}
|
|
259
|
+
async getServerMetrics(id, type, start, end) {
|
|
260
|
+
const query = this.buildQuery({ type, start, end });
|
|
261
|
+
return this.request(`/servers/${id}/metrics${query}`);
|
|
262
|
+
}
|
|
263
|
+
// =========================================================================
|
|
264
|
+
// Networks
|
|
265
|
+
// =========================================================================
|
|
266
|
+
async listNetworks(params = {}) {
|
|
267
|
+
return this.listAll('/networks', 'networks', params);
|
|
268
|
+
}
|
|
269
|
+
async getNetwork(id) {
|
|
270
|
+
const { network } = await this.request(`/networks/${id}`);
|
|
271
|
+
return network;
|
|
272
|
+
}
|
|
273
|
+
async createNetwork(opts) {
|
|
274
|
+
return this.request('/networks', {
|
|
275
|
+
method: 'POST',
|
|
276
|
+
body: JSON.stringify(opts),
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
async deleteNetwork(id) {
|
|
280
|
+
await this.request(`/networks/${id}`, { method: 'DELETE' });
|
|
281
|
+
}
|
|
282
|
+
async updateNetwork(id, opts) {
|
|
283
|
+
return this.request(`/networks/${id}`, {
|
|
284
|
+
method: 'PUT',
|
|
285
|
+
body: JSON.stringify(opts),
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
async addSubnetToNetwork(id, subnet) {
|
|
289
|
+
return this.request(`/networks/${id}/actions/add_subnet`, {
|
|
290
|
+
method: 'POST',
|
|
291
|
+
body: JSON.stringify(subnet),
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
async deleteSubnetFromNetwork(id, ipRange) {
|
|
295
|
+
return this.request(`/networks/${id}/actions/delete_subnet`, {
|
|
296
|
+
method: 'POST',
|
|
297
|
+
body: JSON.stringify({ ip_range: ipRange }),
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
async addRouteToNetwork(id, route) {
|
|
301
|
+
return this.request(`/networks/${id}/actions/add_route`, {
|
|
302
|
+
method: 'POST',
|
|
303
|
+
body: JSON.stringify(route),
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
async deleteRouteFromNetwork(id, route) {
|
|
307
|
+
return this.request(`/networks/${id}/actions/delete_route`, {
|
|
308
|
+
method: 'POST',
|
|
309
|
+
body: JSON.stringify(route),
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
async changeNetworkIpRange(id, ipRange) {
|
|
313
|
+
return this.request(`/networks/${id}/actions/change_ip_range`, {
|
|
314
|
+
method: 'POST',
|
|
315
|
+
body: JSON.stringify({ ip_range: ipRange }),
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
async changeNetworkProtection(id, deleteProtection) {
|
|
319
|
+
return this.request(`/networks/${id}/actions/change_protection`, {
|
|
320
|
+
method: 'POST',
|
|
321
|
+
body: JSON.stringify({ delete: deleteProtection }),
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
// =========================================================================
|
|
325
|
+
// Cloud Firewalls
|
|
326
|
+
// =========================================================================
|
|
327
|
+
async listFirewalls(params = {}) {
|
|
328
|
+
return this.listAll('/firewalls', 'firewalls', params);
|
|
329
|
+
}
|
|
330
|
+
async getFirewall(id) {
|
|
331
|
+
const { firewall } = await this.request(`/firewalls/${id}`);
|
|
332
|
+
return firewall;
|
|
333
|
+
}
|
|
334
|
+
async createFirewall(opts) {
|
|
335
|
+
return this.request('/firewalls', {
|
|
336
|
+
method: 'POST',
|
|
337
|
+
body: JSON.stringify(opts),
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
async deleteFirewall(id) {
|
|
341
|
+
await this.request(`/firewalls/${id}`, { method: 'DELETE' });
|
|
342
|
+
}
|
|
343
|
+
async updateFirewall(id, opts) {
|
|
344
|
+
return this.request(`/firewalls/${id}`, {
|
|
345
|
+
method: 'PUT',
|
|
346
|
+
body: JSON.stringify(opts),
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
async setFirewallRules(id, rules) {
|
|
350
|
+
return this.request(`/firewalls/${id}/actions/set_rules`, {
|
|
351
|
+
method: 'POST',
|
|
352
|
+
body: JSON.stringify({ rules }),
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
async applyFirewall(id, applyTo) {
|
|
356
|
+
return this.request(`/firewalls/${id}/actions/apply_to_resources`, {
|
|
357
|
+
method: 'POST',
|
|
358
|
+
body: JSON.stringify({ apply_to: applyTo }),
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
async removeFirewallFromResources(id, removeFrom) {
|
|
362
|
+
return this.request(`/firewalls/${id}/actions/remove_from_resources`, {
|
|
363
|
+
method: 'POST',
|
|
364
|
+
body: JSON.stringify({ remove_from: removeFrom }),
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
// =========================================================================
|
|
368
|
+
// Floating IPs
|
|
369
|
+
// =========================================================================
|
|
370
|
+
async listFloatingIps(params = {}) {
|
|
371
|
+
return this.listAll('/floating_ips', 'floating_ips', params);
|
|
372
|
+
}
|
|
373
|
+
async getFloatingIp(id) {
|
|
374
|
+
const { floating_ip } = await this.request(`/floating_ips/${id}`);
|
|
375
|
+
return floating_ip;
|
|
376
|
+
}
|
|
377
|
+
async createFloatingIp(opts) {
|
|
378
|
+
return this.request('/floating_ips', {
|
|
379
|
+
method: 'POST',
|
|
380
|
+
body: JSON.stringify(opts),
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
async deleteFloatingIp(id) {
|
|
384
|
+
await this.request(`/floating_ips/${id}`, { method: 'DELETE' });
|
|
385
|
+
}
|
|
386
|
+
async updateFloatingIp(id, opts) {
|
|
387
|
+
return this.request(`/floating_ips/${id}`, {
|
|
388
|
+
method: 'PUT',
|
|
389
|
+
body: JSON.stringify(opts),
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
async assignFloatingIp(id, serverId) {
|
|
393
|
+
return this.request(`/floating_ips/${id}/actions/assign`, {
|
|
394
|
+
method: 'POST',
|
|
395
|
+
body: JSON.stringify({ server: serverId }),
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
async unassignFloatingIp(id) {
|
|
399
|
+
return this.request(`/floating_ips/${id}/actions/unassign`, { method: 'POST' });
|
|
400
|
+
}
|
|
401
|
+
async changeFloatingIpProtection(id, deleteProtection) {
|
|
402
|
+
return this.request(`/floating_ips/${id}/actions/change_protection`, {
|
|
403
|
+
method: 'POST',
|
|
404
|
+
body: JSON.stringify({ delete: deleteProtection }),
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
async changeFloatingIpDnsPtr(id, ip, dnsPtr) {
|
|
408
|
+
return this.request(`/floating_ips/${id}/actions/change_dns_ptr`, {
|
|
409
|
+
method: 'POST',
|
|
410
|
+
body: JSON.stringify({ ip, dns_ptr: dnsPtr }),
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
// =========================================================================
|
|
414
|
+
// Primary IPs
|
|
415
|
+
// =========================================================================
|
|
416
|
+
async listPrimaryIps(params = {}) {
|
|
417
|
+
return this.listAll('/primary_ips', 'primary_ips', params);
|
|
418
|
+
}
|
|
419
|
+
async getPrimaryIp(id) {
|
|
420
|
+
const { primary_ip } = await this.request(`/primary_ips/${id}`);
|
|
421
|
+
return primary_ip;
|
|
422
|
+
}
|
|
423
|
+
async createPrimaryIp(opts) {
|
|
424
|
+
return this.request('/primary_ips', {
|
|
425
|
+
method: 'POST',
|
|
426
|
+
body: JSON.stringify(opts),
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
async deletePrimaryIp(id) {
|
|
430
|
+
await this.request(`/primary_ips/${id}`, { method: 'DELETE' });
|
|
431
|
+
}
|
|
432
|
+
async updatePrimaryIp(id, opts) {
|
|
433
|
+
return this.request(`/primary_ips/${id}`, {
|
|
434
|
+
method: 'PUT',
|
|
435
|
+
body: JSON.stringify(opts),
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
async assignPrimaryIp(id, assigneeId, assigneeType = 'server') {
|
|
439
|
+
return this.request(`/primary_ips/${id}/actions/assign`, {
|
|
440
|
+
method: 'POST',
|
|
441
|
+
body: JSON.stringify({ assignee_id: assigneeId, assignee_type: assigneeType }),
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
async unassignPrimaryIp(id) {
|
|
445
|
+
return this.request(`/primary_ips/${id}/actions/unassign`, { method: 'POST' });
|
|
446
|
+
}
|
|
447
|
+
async changePrimaryIpProtection(id, deleteProtection) {
|
|
448
|
+
return this.request(`/primary_ips/${id}/actions/change_protection`, {
|
|
449
|
+
method: 'POST',
|
|
450
|
+
body: JSON.stringify({ delete: deleteProtection }),
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
async changePrimaryIpDnsPtr(id, ip, dnsPtr) {
|
|
454
|
+
return this.request(`/primary_ips/${id}/actions/change_dns_ptr`, {
|
|
455
|
+
method: 'POST',
|
|
456
|
+
body: JSON.stringify({ ip, dns_ptr: dnsPtr }),
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
// =========================================================================
|
|
460
|
+
// Volumes
|
|
461
|
+
// =========================================================================
|
|
462
|
+
async listVolumes(params = {}) {
|
|
463
|
+
return this.listAll('/volumes', 'volumes', params);
|
|
464
|
+
}
|
|
465
|
+
async getVolume(id) {
|
|
466
|
+
const { volume } = await this.request(`/volumes/${id}`);
|
|
467
|
+
return volume;
|
|
468
|
+
}
|
|
469
|
+
async createVolume(opts) {
|
|
470
|
+
return this.request('/volumes', {
|
|
471
|
+
method: 'POST',
|
|
472
|
+
body: JSON.stringify(opts),
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
async deleteVolume(id) {
|
|
476
|
+
await this.request(`/volumes/${id}`, { method: 'DELETE' });
|
|
477
|
+
}
|
|
478
|
+
async updateVolume(id, opts) {
|
|
479
|
+
return this.request(`/volumes/${id}`, {
|
|
480
|
+
method: 'PUT',
|
|
481
|
+
body: JSON.stringify(opts),
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
async attachVolume(id, serverId, automount) {
|
|
485
|
+
return this.request(`/volumes/${id}/actions/attach`, {
|
|
486
|
+
method: 'POST',
|
|
487
|
+
body: JSON.stringify({ server: serverId, automount }),
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
async detachVolume(id) {
|
|
491
|
+
return this.request(`/volumes/${id}/actions/detach`, { method: 'POST' });
|
|
492
|
+
}
|
|
493
|
+
async resizeVolume(id, size) {
|
|
494
|
+
return this.request(`/volumes/${id}/actions/resize`, {
|
|
495
|
+
method: 'POST',
|
|
496
|
+
body: JSON.stringify({ size }),
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
async changeVolumeProtection(id, deleteProtection) {
|
|
500
|
+
return this.request(`/volumes/${id}/actions/change_protection`, {
|
|
501
|
+
method: 'POST',
|
|
502
|
+
body: JSON.stringify({ delete: deleteProtection }),
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
// =========================================================================
|
|
506
|
+
// Load Balancers
|
|
507
|
+
// =========================================================================
|
|
508
|
+
async listLoadBalancers(params = {}) {
|
|
509
|
+
return this.listAll('/load_balancers', 'load_balancers', params);
|
|
510
|
+
}
|
|
511
|
+
async getLoadBalancer(id) {
|
|
512
|
+
const { load_balancer } = await this.request(`/load_balancers/${id}`);
|
|
513
|
+
return load_balancer;
|
|
514
|
+
}
|
|
515
|
+
async createLoadBalancer(opts) {
|
|
516
|
+
return this.request('/load_balancers', {
|
|
517
|
+
method: 'POST',
|
|
518
|
+
body: JSON.stringify(opts),
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
async deleteLoadBalancer(id) {
|
|
522
|
+
await this.request(`/load_balancers/${id}`, { method: 'DELETE' });
|
|
523
|
+
}
|
|
524
|
+
async updateLoadBalancer(id, opts) {
|
|
525
|
+
return this.request(`/load_balancers/${id}`, {
|
|
526
|
+
method: 'PUT',
|
|
527
|
+
body: JSON.stringify(opts),
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
async addTargetToLoadBalancer(id, target) {
|
|
531
|
+
return this.request(`/load_balancers/${id}/actions/add_target`, {
|
|
532
|
+
method: 'POST',
|
|
533
|
+
body: JSON.stringify(target),
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
async removeTargetFromLoadBalancer(id, target) {
|
|
537
|
+
return this.request(`/load_balancers/${id}/actions/remove_target`, {
|
|
538
|
+
method: 'POST',
|
|
539
|
+
body: JSON.stringify(target),
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
async addServiceToLoadBalancer(id, service) {
|
|
543
|
+
return this.request(`/load_balancers/${id}/actions/add_service`, {
|
|
544
|
+
method: 'POST',
|
|
545
|
+
body: JSON.stringify(service),
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
async updateServiceOnLoadBalancer(id, service) {
|
|
549
|
+
return this.request(`/load_balancers/${id}/actions/update_service`, {
|
|
550
|
+
method: 'POST',
|
|
551
|
+
body: JSON.stringify(service),
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
async deleteServiceFromLoadBalancer(id, listenPort) {
|
|
555
|
+
return this.request(`/load_balancers/${id}/actions/delete_service`, {
|
|
556
|
+
method: 'POST',
|
|
557
|
+
body: JSON.stringify({ listen_port: listenPort }),
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
async changeLoadBalancerAlgorithm(id, type) {
|
|
561
|
+
return this.request(`/load_balancers/${id}/actions/change_algorithm`, {
|
|
562
|
+
method: 'POST',
|
|
563
|
+
body: JSON.stringify({ type }),
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
async changeLoadBalancerType(id, loadBalancerType) {
|
|
567
|
+
return this.request(`/load_balancers/${id}/actions/change_type`, {
|
|
568
|
+
method: 'POST',
|
|
569
|
+
body: JSON.stringify({ load_balancer_type: loadBalancerType }),
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
async attachLoadBalancerToNetwork(id, network, ip) {
|
|
573
|
+
return this.request(`/load_balancers/${id}/actions/attach_to_network`, {
|
|
574
|
+
method: 'POST',
|
|
575
|
+
body: JSON.stringify({ network, ip }),
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
async detachLoadBalancerFromNetwork(id, network) {
|
|
579
|
+
return this.request(`/load_balancers/${id}/actions/detach_from_network`, {
|
|
580
|
+
method: 'POST',
|
|
581
|
+
body: JSON.stringify({ network }),
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
async enableLoadBalancerPublicInterface(id) {
|
|
585
|
+
return this.request(`/load_balancers/${id}/actions/enable_public_interface`, { method: 'POST' });
|
|
586
|
+
}
|
|
587
|
+
async disableLoadBalancerPublicInterface(id) {
|
|
588
|
+
return this.request(`/load_balancers/${id}/actions/disable_public_interface`, { method: 'POST' });
|
|
589
|
+
}
|
|
590
|
+
async changeLoadBalancerProtection(id, deleteProtection) {
|
|
591
|
+
return this.request(`/load_balancers/${id}/actions/change_protection`, {
|
|
592
|
+
method: 'POST',
|
|
593
|
+
body: JSON.stringify({ delete: deleteProtection }),
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
// =========================================================================
|
|
597
|
+
// Images
|
|
598
|
+
// =========================================================================
|
|
599
|
+
async listImages(params = {}) {
|
|
600
|
+
return this.listAll('/images', 'images', params);
|
|
601
|
+
}
|
|
602
|
+
async getImage(id) {
|
|
603
|
+
const { image } = await this.request(`/images/${id}`);
|
|
604
|
+
return image;
|
|
605
|
+
}
|
|
606
|
+
async updateImage(id, opts) {
|
|
607
|
+
return this.request(`/images/${id}`, {
|
|
608
|
+
method: 'PUT',
|
|
609
|
+
body: JSON.stringify(opts),
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
async deleteImage(id) {
|
|
613
|
+
await this.request(`/images/${id}`, { method: 'DELETE' });
|
|
614
|
+
}
|
|
615
|
+
async changeImageProtection(id, deleteProtection) {
|
|
616
|
+
return this.request(`/images/${id}/actions/change_protection`, {
|
|
617
|
+
method: 'POST',
|
|
618
|
+
body: JSON.stringify({ delete: deleteProtection }),
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
// =========================================================================
|
|
622
|
+
// SSH Keys (Cloud)
|
|
623
|
+
// =========================================================================
|
|
624
|
+
async listSshKeys(params = {}) {
|
|
625
|
+
return this.listAll('/ssh_keys', 'ssh_keys', params);
|
|
626
|
+
}
|
|
627
|
+
async getSshKey(id) {
|
|
628
|
+
const { ssh_key } = await this.request(`/ssh_keys/${id}`);
|
|
629
|
+
return ssh_key;
|
|
630
|
+
}
|
|
631
|
+
async createSshKey(opts) {
|
|
632
|
+
return this.request('/ssh_keys', {
|
|
633
|
+
method: 'POST',
|
|
634
|
+
body: JSON.stringify(opts),
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
async updateSshKey(id, opts) {
|
|
638
|
+
return this.request(`/ssh_keys/${id}`, {
|
|
639
|
+
method: 'PUT',
|
|
640
|
+
body: JSON.stringify(opts),
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
async deleteSshKey(id) {
|
|
644
|
+
await this.request(`/ssh_keys/${id}`, { method: 'DELETE' });
|
|
645
|
+
}
|
|
646
|
+
// =========================================================================
|
|
647
|
+
// Certificates
|
|
648
|
+
// =========================================================================
|
|
649
|
+
async listCertificates(params = {}) {
|
|
650
|
+
return this.listAll('/certificates', 'certificates', params);
|
|
651
|
+
}
|
|
652
|
+
async getCertificate(id) {
|
|
653
|
+
const { certificate } = await this.request(`/certificates/${id}`);
|
|
654
|
+
return certificate;
|
|
655
|
+
}
|
|
656
|
+
async createCertificate(opts) {
|
|
657
|
+
return this.request('/certificates', {
|
|
658
|
+
method: 'POST',
|
|
659
|
+
body: JSON.stringify(opts),
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
async updateCertificate(id, opts) {
|
|
663
|
+
return this.request(`/certificates/${id}`, {
|
|
664
|
+
method: 'PUT',
|
|
665
|
+
body: JSON.stringify(opts),
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
async deleteCertificate(id) {
|
|
669
|
+
await this.request(`/certificates/${id}`, { method: 'DELETE' });
|
|
670
|
+
}
|
|
671
|
+
// =========================================================================
|
|
672
|
+
// Placement Groups
|
|
673
|
+
// =========================================================================
|
|
674
|
+
async listPlacementGroups(params = {}) {
|
|
675
|
+
return this.listAll('/placement_groups', 'placement_groups', params);
|
|
676
|
+
}
|
|
677
|
+
async getPlacementGroup(id) {
|
|
678
|
+
const { placement_group } = await this.request(`/placement_groups/${id}`);
|
|
679
|
+
return placement_group;
|
|
680
|
+
}
|
|
681
|
+
async createPlacementGroup(opts) {
|
|
682
|
+
return this.request('/placement_groups', {
|
|
683
|
+
method: 'POST',
|
|
684
|
+
body: JSON.stringify(opts),
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
async updatePlacementGroup(id, opts) {
|
|
688
|
+
return this.request(`/placement_groups/${id}`, {
|
|
689
|
+
method: 'PUT',
|
|
690
|
+
body: JSON.stringify(opts),
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
async deletePlacementGroup(id) {
|
|
694
|
+
await this.request(`/placement_groups/${id}`, { method: 'DELETE' });
|
|
695
|
+
}
|
|
696
|
+
// =========================================================================
|
|
697
|
+
// Actions (generic)
|
|
698
|
+
// =========================================================================
|
|
699
|
+
async getAction(id) {
|
|
700
|
+
const { action } = await this.request(`/actions/${id}`);
|
|
701
|
+
return action;
|
|
702
|
+
}
|
|
703
|
+
async listActions(params = {}) {
|
|
704
|
+
return this.listAll('/actions', 'actions', params);
|
|
705
|
+
}
|
|
706
|
+
}
|