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