next-lxd 1.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.
@@ -0,0 +1,174 @@
1
+ import { Resource } from "./Resource";
2
+
3
+ import type {
4
+ LxdClusterResponse,
5
+ LxdClusterPut,
6
+ LxdClusterCertificatePut,
7
+ LxdClusterMembersResponse,
8
+ LxdClusterMemberResponse,
9
+ LxdClusterMemberPut,
10
+ LxdClusterMemberPost,
11
+ LxdClusterMemberStateResponse,
12
+ LxdClusterMemberStatePost,
13
+ LxdClusterMemberJoinToken,
14
+ LxdClusterGroupsResponse,
15
+ LxdClusterGroupResponse,
16
+ LxdClusterGroupPut,
17
+ LxdClusterGroupPost,
18
+ LxdClusterGroupsPost,
19
+ LxdBaseResponse,
20
+ LxdClusterMembersPost,
21
+ } from "../types";
22
+
23
+ export class Cluster extends Resource {
24
+ async get(): Promise<LxdClusterResponse> {
25
+ return this.client.request({
26
+ method: "GET",
27
+ path: "/1.0/cluster",
28
+ }) as Promise<LxdClusterResponse>;
29
+ }
30
+
31
+ async put(data: LxdClusterPut): Promise<LxdBaseResponse<void>> {
32
+ return this.client.request({
33
+ method: "PUT",
34
+ path: "/1.0/cluster",
35
+ body: data,
36
+ }) as Promise<LxdBaseResponse<void>>;
37
+ }
38
+
39
+ async updateCertificate(data: LxdClusterCertificatePut): Promise<LxdBaseResponse<void>> {
40
+ return this.client.request({
41
+ method: "PUT",
42
+ path: "/1.0/cluster/certificate",
43
+ body: data,
44
+ }) as Promise<LxdBaseResponse<void>>;
45
+ }
46
+
47
+ members = {
48
+ list: async (): Promise<LxdClusterMembersResponse> => {
49
+ return this.client.request({
50
+ path: "/1.0/cluster/members",
51
+ }) as Promise<LxdClusterMembersResponse>;
52
+ },
53
+
54
+ get: async (name: string): Promise<LxdClusterMemberResponse> => {
55
+ return this.client.request({
56
+ path: `/1.0/cluster/members/${name}`,
57
+ }) as Promise<LxdClusterMemberResponse>;
58
+ },
59
+
60
+ put: async (name: string, data: LxdClusterMemberPut): Promise<LxdBaseResponse<void>> => {
61
+ return this.client.request({
62
+ method: "PUT",
63
+ path: `/1.0/cluster/members/${name}`,
64
+ body: data,
65
+ }) as Promise<LxdBaseResponse<void>>;
66
+ },
67
+
68
+ patch: async (name: string, data: LxdClusterMemberPut): Promise<LxdBaseResponse<void>> => {
69
+ return this.client.request({
70
+ method: "PATCH",
71
+ path: `/1.0/cluster/members/${name}`,
72
+ body: data,
73
+ }) as Promise<LxdBaseResponse<void>>;
74
+ },
75
+
76
+ rename: async (name: string, data: LxdClusterMemberPost): Promise<LxdBaseResponse<void>> => {
77
+ return this.client.request({
78
+ method: "POST",
79
+ path: `/1.0/cluster/members/${name}`,
80
+ body: data,
81
+ }) as Promise<LxdBaseResponse<void>>;
82
+ },
83
+
84
+ delete: async (name: string): Promise<LxdBaseResponse<void>> => {
85
+ return this.client.request({
86
+ method: "DELETE",
87
+ path: `/1.0/cluster/members/${name}`,
88
+ }) as Promise<LxdBaseResponse<void>>;
89
+ },
90
+
91
+ state: async (name: string): Promise<LxdClusterMemberStateResponse> => {
92
+ return this.client.request({
93
+ path: `/1.0/cluster/members/${name}/state`,
94
+ }) as Promise<LxdClusterMemberStateResponse>;
95
+ },
96
+
97
+ evacuate: async (name: string, data?: LxdClusterMemberStatePost): Promise<LxdBaseResponse<void>> => {
98
+ return this.client.request({
99
+ method: "POST",
100
+ path: `/1.0/cluster/members/${name}/state`,
101
+ body: data ?? { action: "evacuate" },
102
+ }) as Promise<LxdBaseResponse<void>>;
103
+ },
104
+
105
+ restore: async (name: string, data?: LxdClusterMemberStatePost): Promise<LxdBaseResponse<void>> => {
106
+ return this.client.request({
107
+ method: "POST",
108
+ path: `/1.0/cluster/members/${name}/state`,
109
+ body: data ?? { action: "restore" },
110
+ }) as Promise<LxdBaseResponse<void>>;
111
+ },
112
+
113
+ joinToken: async (data: LxdClusterMembersPost): Promise<LxdClusterMemberJoinToken> => {
114
+ return this.client.request({
115
+ method: "POST",
116
+ path: "/1.0/cluster/members",
117
+ body: data,
118
+ }) as Promise<LxdClusterMemberJoinToken>;
119
+ },
120
+ };
121
+
122
+ groups = {
123
+ list: async (): Promise<LxdClusterGroupsResponse> => {
124
+ return this.client.request({
125
+ path: "/1.0/cluster/groups",
126
+ }) as Promise<LxdClusterGroupsResponse>;
127
+ },
128
+
129
+ get: async (name: string): Promise<LxdClusterGroupResponse> => {
130
+ return this.client.request({
131
+ path: `/1.0/cluster/groups/${name}`,
132
+ }) as Promise<LxdClusterGroupResponse>;
133
+ },
134
+
135
+ post: async (data: LxdClusterGroupsPost): Promise<LxdBaseResponse<void>> => {
136
+ return this.client.request({
137
+ method: "POST",
138
+ path: "/1.0/cluster/groups",
139
+ body: data,
140
+ }) as Promise<LxdBaseResponse<void>>;
141
+ },
142
+
143
+ put: async (name: string, data: LxdClusterGroupPut): Promise<LxdBaseResponse<void>> => {
144
+ return this.client.request({
145
+ method: "PUT",
146
+ path: `/1.0/cluster/groups/${name}`,
147
+ body: data,
148
+ }) as Promise<LxdBaseResponse<void>>;
149
+ },
150
+
151
+ patch: async (name: string, data: LxdClusterGroupPut): Promise<LxdBaseResponse<void>> => {
152
+ return this.client.request({
153
+ method: "PATCH",
154
+ path: `/1.0/cluster/groups/${name}`,
155
+ body: data,
156
+ }) as Promise<LxdBaseResponse<void>>;
157
+ },
158
+
159
+ rename: async (name: string, data: LxdClusterGroupPost): Promise<LxdBaseResponse<void>> => {
160
+ return this.client.request({
161
+ method: "POST",
162
+ path: `/1.0/cluster/groups/${name}`,
163
+ body: data,
164
+ }) as Promise<LxdBaseResponse<void>>;
165
+ },
166
+
167
+ delete: async (name: string): Promise<LxdBaseResponse<void>> => {
168
+ return this.client.request({
169
+ method: "DELETE",
170
+ path: `/1.0/cluster/groups/${name}`,
171
+ }) as Promise<LxdBaseResponse<void>>;
172
+ },
173
+ };
174
+ }
@@ -0,0 +1,114 @@
1
+ import { Resource } from './Resource';
2
+ import { Client } from './Client';
3
+ import type {
4
+ LxdImageResponse,
5
+ LxdImagePut,
6
+ LxdBaseResponse,
7
+ LxdImageAliasesResponse,
8
+ LxdImageAliasResponse,
9
+ LxdImageAliasesPost,
10
+ LxdImageAliasesEntryPut
11
+ } from '../types';
12
+
13
+ export class Image extends Resource {
14
+ public name: string;
15
+ public metadata: LxdImageResponse['metadata'];
16
+
17
+ constructor(client: Client, options: LxdImageResponse) {
18
+ super(client);
19
+
20
+ this.name = options.metadata.fingerprint;
21
+ this.metadata = options.metadata;
22
+ }
23
+
24
+ async delete(): Promise<LxdBaseResponse<unknown>> {
25
+ return this.client.request({
26
+ method: 'DELETE',
27
+ path: `/1.0/images/${this.name}`
28
+ }) as Promise<LxdBaseResponse<unknown>>;
29
+ }
30
+
31
+ async put(data: LxdImagePut): Promise<LxdBaseResponse<unknown>> {
32
+ return this.client.request({
33
+ method: 'PUT',
34
+ path: `/1.0/images/${this.name}`,
35
+ body: data
36
+ }) as Promise<LxdBaseResponse<unknown>>;
37
+ }
38
+
39
+ async patch(data: LxdImagePut): Promise<LxdBaseResponse<unknown>> {
40
+ return this.client.request({
41
+ method: 'PATCH',
42
+ path: `/1.0/images/${this.name}`,
43
+ body: data
44
+ }) as Promise<LxdBaseResponse<unknown>>;
45
+ }
46
+
47
+ async refresh(): Promise<LxdBaseResponse<unknown>> {
48
+ return this.client.request({
49
+ method: 'POST',
50
+ path: `/1.0/images/${this.name}/refresh`
51
+ }) as Promise<LxdBaseResponse<unknown>>;
52
+ }
53
+
54
+ async export() {
55
+ return this.client.requestRaw({
56
+ method: 'GET',
57
+ path: `/1.0/images/${this.name}/export`
58
+ });
59
+ }
60
+
61
+ async secret(): Promise<LxdBaseResponse<{ secret: string }>> {
62
+ return this.client.request({
63
+ method: 'POST',
64
+ path: `/1.0/images/${this.name}/secret`
65
+ }) as Promise<LxdBaseResponse<{ secret: string }>>;
66
+ }
67
+
68
+ aliases = {
69
+ list: async (): Promise<LxdImageAliasesResponse> => {
70
+ return this.client.request({
71
+ path: `/1.0/images/${this.name}/aliases`
72
+ }) as Promise<LxdImageAliasesResponse>;
73
+ },
74
+
75
+ create: async (data: LxdImageAliasesPost): Promise<LxdBaseResponse<unknown>> => {
76
+ return this.client.request({
77
+ method: 'POST',
78
+ path: `/1.0/images/${this.name}/aliases`,
79
+ body: data
80
+ }) as Promise<LxdBaseResponse<unknown>>;
81
+ },
82
+
83
+ entry: (name: string) => ({
84
+ get: async (): Promise<LxdImageAliasResponse> => {
85
+ return this.client.request({
86
+ path: `/1.0/images/aliases/${name}`
87
+ }) as Promise<LxdImageAliasResponse>;
88
+ },
89
+
90
+ put: async (data: LxdImageAliasesEntryPut): Promise<LxdBaseResponse<unknown>> => {
91
+ return this.client.request({
92
+ method: 'PUT',
93
+ path: `/1.0/images/aliases/${name}`,
94
+ body: data
95
+ }) as Promise<LxdBaseResponse<unknown>>;
96
+ },
97
+
98
+ patch: async (data: LxdImageAliasesEntryPut): Promise<LxdBaseResponse<unknown>> => {
99
+ return this.client.request({
100
+ method: 'PATCH',
101
+ path: `/1.0/images/aliases/${name}`,
102
+ body: data
103
+ }) as Promise<LxdBaseResponse<unknown>>;
104
+ },
105
+
106
+ delete: async (): Promise<LxdBaseResponse<unknown>> => {
107
+ return this.client.request({
108
+ method: 'DELETE',
109
+ path: `/1.0/images/aliases/${name}`
110
+ }) as Promise<LxdBaseResponse<unknown>>;
111
+ }
112
+ })
113
+ };
114
+ }
@@ -0,0 +1,38 @@
1
+ import { Resource } from './Resource';
2
+ import { Image } from './Image';
3
+
4
+ import type { LxdImagesResponse, LxdImageResponse, LxdImagesPost, LxdBaseResponse } from '../types';
5
+
6
+ export class Images extends Resource {
7
+ /**
8
+ * Get a list of all images.
9
+ */
10
+ async list(project?: string): Promise<LxdImagesResponse> {
11
+ return this.client.request({
12
+ method: 'GET',
13
+ path: `/1.0/images${project ? `?project=${project}` : ''}`
14
+ });
15
+ }
16
+
17
+ /**
18
+ * Get a specific image by fingerprint.
19
+ */
20
+ async get(fingerprint: string, project?: string): Promise<Image> {
21
+ const data = (await this.client.request({
22
+ method: 'GET',
23
+ path: `/1.0/images/${fingerprint}${project ? `?project=${project}` : ''}`
24
+ })) as LxdImageResponse;
25
+ return new Image(this.client, data);
26
+ }
27
+
28
+ /**
29
+ * Create a new image.
30
+ */
31
+ async post(config: LxdImagesPost, project?: string): Promise<LxdBaseResponse<unknown>> {
32
+ return this.client.request({
33
+ method: 'POST',
34
+ path: `/1.0/images${project ? `?project=${project}` : ''}`,
35
+ body: config
36
+ });
37
+ }
38
+ }